Pay Pal - bad request error - c#

I am trying to get pay pal user info once he login to paypal and get authenticated by paypal.
At first step I get the Authorization code. But when the execution reach to get the access token of the user that will help me to get user info in next step gives me the following error.
"Invalid Http rsponse The remote server returned an error : (400) bad
request."
I refer the paypal documentation and sdk for donet
Fowlling is my code
Dictionary<string, string> configurationMap = new Dictionary<string,
string>(); configurationMap.Add("mode", "sandbox"); APIContext
apiContext = new APIContext(); apiContext.Config = configurationMap;
CreateFromAuthorizationCodeParameters param = new
CreateFromAuthorizationCodeParameters(); param.setClientId("**My
ClientID goes here**");
param.setClientSecret("**My Client Secert
goes here**");
param.SetCode(code); // **Authorization code
goes here**
Tokeninfo info =
Tokeninfo.CreateFromAuthorizationCode(apiContext, param);
GetUserInfor(info);
Please guide me where I am lacking or how can i solve this.

Related

SetExpressCheckout token received but Sandbox claims transaction has expired

I've been attempting to process a very simple express checkout Sandbox transaction using the C# Paypal API, but keep getting a session timeout error on the Paypal website after the redirect.
I should emphasize that I get a successful ACK response from SetExpressCheckout along with a Token string.
Here is an example of the checkout URL I've been trying to redirect to:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-9RY2628262462061J
My return address is localhost, but I couldn't see anywhere that this would be a problem in Sandbox.
On trying to redirect to the Sandbox I arrive not at the checkout URL but at this address:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=CzvBHQErPEHw5gOt51FV88G_4L9HUCLypeGkwVZLW6mkWsZOofIpFR2K6Aa&dispatch=50a222a57771920b6a3d7b606239e4d529b525e0b7e69bf0224adecfb0124e9b61f737ba21b081984719ecfa9a8ffe80733a1a700ced90ae
And see the following error message:
"This transaction has expired. Please return to the recipient's website to complete your transaction using their regular checkout flow."
How can the transaction be timing out when [1] I have a successful API response along with a token and [2] I literally redirect there immediately after getting the token.
Does anyone have any idea what's going on here?
If it helps here is the C# I wrote to access the API. As noted, I get a success ACK response plus a token.
try
{
var details = ToPaymentDetails(data);
var request = new SetExpressCheckoutReq();
request.SetExpressCheckoutRequest = new SetExpressCheckoutRequestType
{
SetExpressCheckoutRequestDetails = details,
Version = Version
};
var result = await client.SetExpressCheckoutAsync(credentials, request);
var response = result.SetExpressCheckoutResponse1;
FailOnError(response);
return Result.Success(response.Token);
}
catch (Exception ex)
{
return Result.Error<string>("Received an error from Paypal.SetExpressCheckout.", exception: ex);
}
The EC token only last for 3 hours. You will have to recall the SetEC API to get a new EC token and proceed with the checkout flow.
I am not closer to understanding why the SOAP API call generates a token that is rejected by Paypal, but I found that I was able to reach the Sandbox payment page if I used the SDK to generate a payment.
This hasn't exactly been an enlightening or educational experience ...

PayPal-NET-SDK GetTransaction from a sale on eBay

I was trying to get the paypal transaction's details from an eBay sale. I'm using Paypal-NET-SDK built on PayPal's REST APIs.
Here is the code:
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
string accessToken = new OAuthTokenCredential(clientID, secret, sdkConfig).GetAccessToken();
string transactionID = "98395731SM1933421";
APIContext apiContext = new APIContext(accessToken);
apiContext.Config = sdkConfig;
Sale sale = Sale.Get(apiContext, transactionID );
But I'm getting this error:
The remote server returned an error: (404) Not Found.
And this is the response:
{"name":"INVALID_RESOURCE_ID","message":"The requested resource ID was not found","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"8a0a9ae305a35"}
It looks like I have to use another transaction ID, but this is the transaction ID I'm getting from the eBay API, and also when I enter into my account in paypal this is the transaction ID I'm seeing.
I want to know if I can use this API to get this transaction's details, if not, any suggestions.
Transaction IDs from PayPal's REST APIs and from PayPal's classic APIs are completely unrelated. eBay uses PayPal classic transaction IDs.
Or to put it another way: you cannot use PayPal's REST APIs with eBay transactions. Use PayPal's classic APIs, namely GetTransactionDetails.

Posting to a Facebook page without logging in using C#

I've read a lot of posts about how to handle posting to FB without logging in - specifically in my instance to a managed page, some using the defunct "offline_access" method, others relating to tokens.
I've created a token from my graph API - https://developers.facebook.com/tools/explorer
I've also created a little test in some code e.g.
FacebookClient fb = new FacebookClient("Access_Token"]);
Dictionary<string, object> argList = new Dictionary<string, object>();
argList["message"] = "my message";
fb.Post("mypage/feed", argList);
This works perfectly as expected and posts to the page wall in question. If however I log out of Facebook, it doesn't work and in turn throws an error.
Facebook.FacebookOAuthException: (OAuthException - #190)
Error validating access token: This may be because the user logged out
I'm stuck about why this happens when I've set the permissions correctly in the https://developers.facebook.com/tools/explorer area e.g. "publish_stream", "manage_pages" etc.
I've even assigned the token to an app I've created too which still doesn't help.
Has anyone got an example in C# that illustrates how to post when you are not logged in?
Thanks in advance,
Deeds.
Its may be because of access token validation expired, if you have application Id and Secret key of which you used to generate access token, You can use the following code to extend the access token validation period upto 60 days .
public string exchange_access_token(string actoken)
{
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "xxxxxxxxx",
client_secret = "xxxxxxxxxxxx",
grant_type = "fb_exchange_token",
fb_exchange_token = actoken
});
return result;
}
But if you dont have application details you cant do this ...

RestAPISDK .Net Execute Payment

I'm trying to implement Paypal in an ASP.Net website. I've installed the RestAPISDK and I've been following this guide by Paypal (https://devtools-paypal.com/guide/pay_paypal/dotnet) as well as looking at the references located here (https://developer.paypal.com/webapps/developer/docs/api/#execute-an-approved-paypal-payment)
So far it's going well, but upon returning from Paypal's website, I'm not able to execute the payment as per their documentation.
The Guide says to use the following code
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
string accessToken = "TOKEN";
APIContext apiContext = new APIContext(accessToken);
apiContext.Config = sdkConfig;
Payment payment = new Payment("PAYMENT ID");
PaymentExecution pymntExecution = new PaymentExecution();
pymntExecution.payer_id = ("DYRNAJP829GTN");
Payment executedPayment = pymnt.Execute(apiContext,pymntExecution);
But Payment has no constructor that take in the Payment ID.
The Rest API Reference says to use the following method
Payment payment = Payment.Get(accessToken, "Payment ID");
However, Payment.Get is depreciated. If I use it anyway I just get an Exception saying the server responded with a 404.
What are we supposed to use instead? I can't find any up to date documentation to point me in the right direction.
I'm thinking I may have to use HttpClient to send the Request myself but surely I shouldn't have to do that.
I agree, the C# samples do not work and produce the same 404 exception when you try to Execute a payment with your own sandbox store.
What you need to do is:
Payment payment = Payment.Get(context, paymentID);
where context is your apiContext and paymentID is the id passed back in by the return url from PayPal.
you then need:
var paymentExecution = new PaymentExecution
{
payer_id = payerId
};
finally you can then call:
payment.Execute(context, paymentExecution);
this returns a payment object, which should have the 'state' of approved...
It is the PaymentHistory retrieval method that is deprecated in favor of the Payment.List() method. To retrieve a single payment, you still use the Payment.Get method.
Are you sure you are passing in a valid payment id for the second parameter here? A 404 (Not Found) error is thrown when a payment with the passed in ID does not exist.

How to get the list of all pages that i like on facebook and post on their wall

i have tried this
string accessToken = "MYTOKEN";
FacebookClient fbClient = new FacebookClient(accessToken);
var args = new Dictionary<string, object>();
args["message"] = richTextBoxMessage.Text;
fbClient.Post("/PAGENAME/feed", args);
i have this error
(OAuthException - #200) (#200) The user hasn't authorized the
application to perform this action
if i can post on the page wall by that code,so what is the permission name that i should add on the App settings.
And how can i get the names of all pages that i liked
Thank you!
with fbClient.get("me/likes"); you can get all the pages that you have liked.
and the with fbClient.Post("/PAGEID/feed", args); you can post to page wall, provided your app has publish_stream permission from current user.
The permission that your application should request for is the publish_stream
Please refer to the facebook developer docs for more information on permissions.
https://developers.facebook.com/docs/reference/login/extended-permissions/

Categories

Resources