Paypal Rest API Working with Demo Account but not with Live Account - c#

I use below code for Paypal Rest API to Store Credit Card Information
String AccessToken = "";
PaypalAccessToken pat = new PaypalAccessToken();
AccessToken = pat.GetPaypalAccessToken();
PayPal.Api.Payments.Address add = new PayPal.Api.Payments.Address();
add.city = TextBoxCity.Text;
add.line1 = TextBoxAddress.Text;
add.phone = TextBoxPhoneNumber.Text;
add.postal_code = TextBoxZipcode.Text;
add.state = DropDownState.SelectedValue;
PayPal.Api.Payments.CreditCard cc = new PayPal.Api.Payments.CreditCard();
cc.number = TextBoxCreditCardNumber.Text;
cc.expire_month = Convert.ToInt16(TextBoxExpiryMonth.Text);
cc.expire_year = Convert.ToInt16(TextBoxExpiryYear.Text);
cc.cvv2 = TextBoxCVVNumber.Text;
cc.type = DropDownCreditCardType.SelectedValue;
//cc.billing_address = add;
PayPal.Api.Payments.CreditCard ResultCC = cc.Create(AccessToken);
This Code working good with Demo Credentials but When I try to use same with Live Credentials, It is giving me error : 401 Unauthorized. I can still get token in live credentials but I could not store credit card.

PayPal's REST API's are available globally as of the 31st of July 2013.
However, this applies only to PayPal payments. That is, setting the payment_method to paypal in the JSON payload and redirecting the buyer to PayPal.
If you want to process credit card payments, this is currently only supported in the US, UK or Canada.
You will need to enable this capability for your app via https://developer.paypal.com/ > Applications.
Note: Enabling card payments for live transactions requires a review of your account.
If you try to process card payments in live, with an account that's not enabled for it, you will get a HTTP 401 in the response from the /payment resource.

Have you updated your endpoints to use the live endpoints?

It was something wrong with Paypal Rest ApI because its still in Beta version . They fixed it for me.

Related

Authorize.net C# API. Refund Pay Pal transaction

I use authprize.net for auth, capture -> auth, capture continue Pay Pal payment transactions. I need to get original Pay Pal unique transaction ID (not authprize.net). It's an ideal way for our system, because client has code for refund Pay Pal transactions using this original pay pal Id. What I tried:
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = _apiLogin,
ItemElementName = ItemChoiceType.transactionKey,
Item = _transactionKey,
};
var request = new getTransactionDetailsRequest();
request.transId = transactionId;
var controller = new getTransactionDetailsController(request);
controller.Execute();
var response = controller.GetApiResponse();
But I only see general info like date or amount, etc. Then I tried to refund Pay Pal transaction using this code sample: http://developer.authorize.net/api/reference/index.html#paypal-express-checkout-credit
But I received an error: http://prntscr.com/d5rong For this code I used authorize.net internal ID too. I have to say that I tried in sandbox. So, what am I doing wrong? Could anyone, please, explain and provide example?
Referencing your comment "Yes. But I did sandbox transactions", per PayPal Express Checkout feature overview:
As the Sandbox does not permit settlement of PayPal transactions, you
will not be able to test refunds.
https://developer.authorize.net/api/reference/features/paypal.html

tweetsharp - app stops being able to tweet after a few hours

I have a asp.net 4.5 webforms site that allows users to link their account to twitter and tweet directly from my site.
My app is registered with twitter and I am able to successfully authorise my app for the user's account and initially can tweet fine, but after a few hours the tweets stop working. I am using tweetsharp to handle the authorisation.
my code is:
TwitterClientInfo twitterClientInfo = new TwitterClientInfo();
twitterClientInfo.ConsumerKey = ConsumerKey;
twitterClientInfo.ConsumerSecret = ConsumerSecret;
var requestToken = new OAuthRequestToken { Token = oauthtoken };
TwitterService twitterService = new TwitterService(ConsumerKey, ConsumerSecret);
OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, oauthverifier);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
TwitterUser user = twitterService.VerifyCredentials(new VerifyCredentialsOptions());
SendTweetOptions options = new SendTweetOptions();
options.Status = tweetText;
twitterService.SendTweet(options);
what i have noticed is that while the app is successfully tweeting, the accessToken.Token value that is being used to authenticate the user has a proper value (a long string of numbers and upper/lowercase characters) however when it stops tweeting the accessToken.Token value is just a single question mark "?".
Twitter says it doesn't expire tokens so i am at a loss to understand what is happening or how it can be resolved? if i went in to my twitter account and deauthorised my app and went through the authorisation again it would work fine for a few hours, but obviously that's not something i can ask my users to do.
can anyone suggest a resolution to this - either to stop the accessToken value becoming ? or to handle it and get a proper value if it does (without reauthorising the app)
Well, without beginning to understand the actual issue, I managed to fix it
Instead of retrieving the access token every time via:
var requestToken = new OAuthRequestToken { Token = oauthtoken };
OAuthAccessToken accessToken = twitterService.GetAccessToken(requestToken, oauthverifier);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
i only do that once and store accessToken.Token and accessToken.TokenSecret in the database and retrieve them when tweeting and supply them
twitterService.AuthenticateWith(accessTokenFromDB, accessokenSecretFromDB);
I have seen somewhere that Twitter doesn't expire tokens, so this should work. Certainly it's been working for me all weekend whereas the original code would stop working after a few hours.
Thought this might help some others who have the same issue.

How to check payment status with any PayPal sdk

I am currently working with PayPal's Merchant SDK and I am wondering how can I check a payment status? That's especially useful for pending payment or delayed. All I keep in database is the Payer ID.
I want a method to check the payment status so that I can proceed with the payment once is it approved, or canceled, using PayPal's Merchant SDK.
Here's an example:
GetExpressCheckoutDetailsRequestType req = new GetExpressCheckoutDetailsRequestType
{
Token = token
};
GetExpressCheckoutDetailsReq detailsReq = new GetExpressCheckoutDetailsReq
{
GetExpressCheckoutDetailsRequest = req
};
GetExpressCheckoutDetailsResponseType response = service.GetExpressCheckoutDetails(detailsReq);
However in this current example I do not have the token, which is a value returned when I first create the payment, and I am not sure if I will get the payment status.
What should I do to achieve what I want? Or do I need to proceed with another SDK, or the REST Api?
Try the getAck() method per this documentation
It will return an AckCodeType (which can be one of the values here). You'll want to proceed if that value is Success and potentially SuccessWithWarning.

Get Facebook's Application Access Token

I have to use Facebook's notification for my web app.
Facebook Graph API requires the Application Access Token for this action.
Is there a way to get this token by code (C# SDK) or is this generated by Facebook a single time?
Is this token static (and secret) or with expire datetime?
For info: https://developers.facebook.com/tools/access_token/ - App Token, not User Token!
Thanks
The answer is the dynamic way by code:
var fb = new FacebookClient();
dynamic result = fb.Get( "oauth/access_token", new
{
client_id = <myAppID>,
client_secret = <mySecretID>,
grant_type = "client_credentials"
} );
var apptoken = result.access_token;
Or by the combination or appid|secretid
You can just use the concatenation of id and secret with a pipe symbol in the middle:
app_id|app_secret
This is actually how the PHP SDK creates the app access token internally, so there should be no question about the reliability of this method. (From other endpoints where you actively query for an app access token you might get another token that does not match this scheme though.)
you can investigate the getApplicationAccessToken method as in another c# sdk project from github
https://github.com/barans/FacebookCsharpSdk/blob/master/FacebookCSharpSDK/FacebookClient/FacebookClient.cs

DotNetOpenAuth with Google Calendar Feed

I have been racking my brain for a few days trying to get a list of calendars from Google using DotNetOpenAuth.
I can successfully get a list of contacts using the DotNetOpenAuth Samples. I have integrated it with my domain using the OpenId+OAuth. Everything works great to get a list of contacts.
So from there I modified the code to try to retrieve a list of Calendars and I keep getting a 401 Unauthorized error.
I know it is authorizing because I can get the contact list. Does anyone have a code example how they are retrieving calendars or calendar events using the DotNetOpenAuth with Google???
Thanks
Update:
Thanks for the response. I have read everything I can get my hands on. Here is what I have done so far
Step 1: I created a new GetCalendarEndPoint in the GoogleConsumer.cs
private static readonly MessageReceivingEndpoint GetCalendarEndpoint = new MessageReceivingEndpoint("https://www.google.com/calendar/feeds/default", HttpDeliveryMethods.GetRequest);
Step 2: Next I created a new method GetCalendars patterned after the GetContacts Method in GoogleConsumer.cs - (Rebuilt the dll etc.)
public static XDocument GetCalendars(ConsumerBase consumer, string accessToken, int maxResults/* = 25*/, int startIndex/* = 1*/) {
if (consumer == null)
{
throw new ArgumentNullException("consumer");
}
var request = consumer.PrepareAuthorizedRequest(GetCalendarEndpoint, accessToken);
var response = consumer.Channel.WebRequestHandler.GetResponse(request);
string body = response.GetResponseReader().ReadToEnd();
XDocument result = XDocument.Parse(body);
return result;
Step 3: In my Application I modified the ScopeURI to the the Calendar URI from GoogleConsumer as follows
private IAuthenticationRequest GetGoogleRequest()
{
Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/";
IAuthenticationRequest authReq = relyingParty.CreateRequest(GoogleOPIdentifier, realm);
// Prepare the OAuth extension
string scope = GoogleConsumer.GetScopeUri(GoogleConsumer.Applications.Calendar);
Global.GoogleWebConsumer.AttachAuthorizationRequest(authReq, scope);
// We also want the user's email address
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
authReq.AddExtension(fetch);
return authReq;
}
However, when I run the app I get 401 Unauthorized when I make the following call
var calendars = GoogleConsumer.GetCalendars(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);
I have also checked that the State.GoogleAccess token exists by simply displaying it on my screen before I trigger the method that makes this call.
Again, if I exectute
var calendars = GoogleConsumer.GetContacs(Global.GoogleWebConsumer, State.GoogleAccessToken, 25, 1);
then it works??????? Thanks for you help.
I've been suffering through exactly the same thing for most of the weekend.
I think that after much fiddling with Fiddler I've found the cause and have a solution which, although not pretty, seems to work. I found that I was able to access the calendar feed by copying and pasting the DNOA-generated Uri into a browser, but always got a 401 when attempting programmatic access. This is apparently because the default auto-redirect behavior of HttpWebRequest discards any cookies that the redirect is attempting to set. The Contacts feed doesn't set any cookies during the redirect, so it is immune.
The first time you request a calendar feed (even with a properly constructed and signed OAuth request), Google replies with a redirect containing a cookie. If you don't present that "calendar cookie" at the same time as your feed request you will get a 401 Unauthorized when you attempt to follow the redirect to the feed.
here's the cookie-setting header from Google:
HTTP/1.1 302 Moved Temporarily
Set-Cookie: S=calendar=y7AlfgbmcqYl0ugrF-Zt9A;Expires=Tue, 10-Jan-2012 03:54:20 GMT;Secure
Here's what I'm doing to make it work:
// wc: WebConsumer
var calRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
// need to stop redirect to capture calendar cookie token:
calRequest.AllowAutoRedirect = false;
var calResponse = calRequest.GetResponse();
var redirectCookie = calResponse.Headers[System.Net.HttpResponseHeader.SetCookie];
var cookiedCalRequest = wc.PrepareAuthorizedRequest(erp2, authTokenRsp.AccessToken);
cookiedCalRequest.Headers[System.Net.HttpRequestHeader.Cookie] = redirectCookie;
var calFeedResponse = cookiedCalRequest.GetResponse();
Have you read the Google Calendar data API documentation to make sure you have the right endpoints programmed in? Have you also modified the code that acquires the access token to request access to Google Calendar in addition to Google Contacts? The access token in the sample only gets Contacts permissions unless you change it.

Categories