问题描述
亲爱的大家, 我从贝宝开始, 并且我已经尝试实现SDK(c#,FW 4.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,10,0));
var oResponse = await oClient.Execute(oRequest);
var result = oResponse.Result<Order>();
return oResponse;
}
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,并用绿色标记进行标记。
您有一些想法吗?
先谢谢您
解决方法
“永不退缩”是什么意思?您说有一个“绿色标志”,这是否意味着有一个HTTP 2xx成功响应?响应正文中是否有id
?
如果要将响应正文转发到前端,则前端不应在寻找data.orderID
密钥,因为除非您提供它,否则不会有这样的密钥。这是您的前端使用的更好的示例,其示例为data.id
:https://developer.paypal.com/demo/checkout/#/pattern/server
请注意,该示例还在onApprove函数中包含访存。您需要实施这样一种路线来捕获您的订单,否则将不会创建任何交易。
,亲爱的, 我终于找到了解决方案。
如前所述,在API调用之后,在developer.paypal网站上,相关的调用已标有绿色标记,这表示该调用已正确进行。
然后,我研究了服务器代码以及如何管理任务。
异步调用被嵌入到私有方法中,并由“等待”响应的同步方法调用。
通过这种方式,一切正常工作
这是允许例程正常运行且不停止的代码段:“ client.Execute(oRequest)”。
dotnet ef database update
感谢您的支持