亲爱的,我从payPal开始,我尝试实现SDK提供的标准示例(c#,FW4.6.1)
下面是我的服务器端方法
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;
}在这里,jquery调用
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');问题是对oClient.Execute的响应再也回不来了。
PayPalClient完全是作为SDK示例构建的。
查看PayPal API调用日志,将正确调用该API,并将其标记为绿色标志。
你有什么想法吗?
先谢谢你
发布于 2020-11-17 08:38:20
亲爱的,我终于找到解决办法了。
如前所述,在API调用之后,developer.paypal网站上的相关调用被标记为绿色标志,这意味着调用已正确进行。
然后,我研究了服务器代码,以及如何管理这些任务。
异步调用嵌入到私有方法中,并由“等待”响应的同步方法调用。
这样,所有的操作都是正确的
在这里,允许例程工作而不被停止到"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;
}谢谢你的支持
发布于 2020-10-27 01:08:12
“再也回不来”是什么意思?你说有一个“绿色标志”,这是否意味着有一个HTTP2xx成功响应?在响应体中是否有id?
如果您正在将响应体转发到您的前端,则前端不应该查找data.orderID密钥,因为除非您提供该密钥,否则不会有这样的密钥。下面是一个用于前端的更好的示例,它是data.id:https://developer.paypal.com/demo/checkout/#/pattern/server
注意,该示例还在onApprove函数中包含了一个fetch。您需要实现这样一个路由来捕获您的订单,否则将不会创建任何事务。
https://stackoverflow.com/questions/64546978
复制相似问题