我尝试将PayPal PLUS API集成到NativeScript Mobile App中。当创建付款(调用此API:https://developer.paypal.com/docs/api/payments/#create_payment)并且旁边显示缩短的调用时,我一直收到500错误。可悲的是,我没有找到如何显示它的消息。
我通过NativeScript在iOS模拟器(Xcode 7)上运行我的代码。
我尝试了以下curl-call,这对我有用:
我尝试使用curl:
<router-outlet></router-outlet>
回复201创建的回复。
现在我在TypeScript中使用相同的元素创建了一个XHR-Object。到目前为止我的代码:
curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type:application/json" \
-H "Authorization: Bearer <my-token>„ \
-d '{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "EUR",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "0.03",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "0.01"
}
},
"item_list": {
"items": [
{
"name": "hat",
"description": "Brown hat.",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "EUR"
},
{
"name": "handbag",
"description": "Black handbag.",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "EUR"
}
]}
}
],
"redirect_urls": {
"return_url": "http://www.paypal.com/return",
"cancel_url": "http://www.paypal.com/cancel"
}
}'
(如上所述)不适合我。有人知道,如何显示该XHR-Object的错误消息?或许有人甚至可以看到我的代码可能出现的问题。如果您需要一个有效的API调用(通过XHR):
var oReq = new XMLHttpRequest();
oReq.open("POST", PayPalEndpoints.getPaymentEndpoint, true);
oReq.setRequestHeader('Authorization', "Bearer " + access_token);
oReq.setRequestHeader('Accept', "application/json");
oReq.onreadystatechange = function () {
console.log("state changed - new state: " + oReq.readyState + " and Status: " + oReq.status);
if (oReq.readyState === 4) {
if (oReq.status === 200) {
var response = JSON.parse(oReq.responseText);
console.log("response = " + response);
} else {
console.log("Error: " + oReq.status + " Message: " + oReq.responseText);
}
}
};
oReq.send({
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "EUR",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "0.03",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "0.01"
}
},
"item_list": {
"items": [
{
"name": "hat",
"description": "Brown hat.",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "EUR"
},
{
"name": "handbag",
"description": "Black handbag.",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "EUR"
}
]
}
}
],
"redirect_urls": {
"return_url":"http://www.paypal.com/return",
"cancel_url":"http://www.paypal.com/cancel"
}
});
API参考:
整合pdf: https://www.paypalobjects.com/webstatic/de_DE/downloads/PayPal-PLUS-IntegrationGuide.pdf
来电参考: https://developer.paypal.com/docs/integration/direct/make-your-first-call/
我缩短了电话: https://developer.paypal.com/docs/api/payments/#create_payment
答案 0 :(得分:0)
如果有人正在研究同等问题:
您需要更改
oReq.setRequestHeader('Accept', "application/json");
到
oReq.setRequestHeader('Grant-Type', "application/json");
并且您需要将send-Method中的数据作为json-string传递,因此请调用:
oReq.send(JSON.stringify(data));
使用&#34;数据&#34;成为你的JSON字符串。