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
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)".
[WebMethod(EnableSession = true)]
public static PayPalCheckoutSdk.Orders.Order SetupTransaction()
{
data.tessutigenovataddei.com.Order oOrder = null;
//save order in database.
oOrder = CreateOrderWithPaypal();
OrdersCreateRequest oRequest = new OrdersCreateRequest();
oRequest.Prefer("return=representation");
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
oRequest.RequestBody(BuildRequestBodyWithMinimumFields(oOrder));
PayPalHttp.HttpClient oClient = PayPalClient.client();
oClient.SetConnectTimeout(new TimeSpan(0, 0, 0, 10, 0));
var oResponseTask = SetupTransactionAsync(oClient, oRequest);
oResponseTask.Wait();
return oResponseTask.Result.Result<PayPalCheckoutSdk.Orders.Order>();
}
private async static Task<PayPalHttp.HttpResponse> SetupTransactionAsync(PayPalHttp.HttpClient client, OrdersCreateRequest request)
{
SynchronizationContext.SetSynchronizationContext(null);
PayPalHttp.HttpResponse oResponse = await client.Execute(request);
return oResponse;
}
thank you for the support