Dears all,
I’m starting with payPal,
and I’ve tried to implement the standard sample provided with SDK (c#, FW 4.6.1)
here below my server-side method
public async static Task<PayPalHttp.HttpResponse> CreateOrder()
{
OrdersCreateRequest oRequest = new OrdersCreateRequest();
oRequest.Prefer("return=representation");
//System.Net.ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
oRequest.RequestBody(BuildRequestBodyWithMinimumFields());
//3. Call PayPal to set up a transaction
PayPalHttp.HttpClient oClient = PayPalClient.client();
oClient.SetConnectTimeout(new TimeSpan(0, 0, 0, 10, 0));
var oResponse = await oClient.Execute(oRequest);
var result = oResponse.Result<Order>();
return oResponse;
}
while here jquery call
paypal.Buttons({
style: {
shape: 'rect',
color: 'blue',
layout: 'vertical',
label: 'pay',
},
createOrder: function () {
return fetch('/shop/paypal_test.aspx/CreateOrder', {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.orderID; // Use the same key name for order ID on the client and server
});
}
}).render('#paypal-button-container');
The issue is that the response to oClient.Execute never gets back.
PayPalClient has been built exactly as SDK sample.
Looking at PayPal API Calls Log, the API is called correctly and it is marked with a green flag.
Have you some ideas?
thank you in advance
2
Answers
Dears, I've finally found a solution.
As said before, after API call, on developer.paypal web site the related call has been marked with a green flag, that means that the call has been made correctly.
Then, I've investigated on server code, and how the tasks are managed.
The asynchrounous call is embedded in a private method and it's called by a sync method that "waits" for the response.
In this way all works correctly
Here the snippet code that allows the routine to work and not to be stopped to "client.Execute(oRequest)".
thank you for the support
What do you mean "never gets back" ? You say there is a "green flag", does this mean there was an HTTP 2xx success response? Was there an
id
in the response body?If you are forwarding the response body to your front end, the front end should not be looking for the
data.orderID
key, since there will be no such key unless you provide it. Here is a better sample to use for your front end, which readsdata.id
: https://developer.paypal.com/demo/checkout/#/pattern/serverNote that that sample also includes a fetch in the onApprove function. You need to implement such a route that will capture your order, otherwise there will be no transaction created.