【发布时间】:2014-12-21 08:27:20
【问题描述】:
我一直在尝试使用 Parse.com Cloud Code 中的 Paypal 创建和发送发票。 下面是我的代码。我收到此错误请求失败,响应代码为 0
Parse.Cloud.define("send_paypal_invoice", function(request, response){
var headerParams = [{ //Setting PayPal request headers
'X-PAYPAL-SECURITY-USERID' : '****************',
'X-PAYPAL-SECURITY-PASSWORD' : '***********',
'X-PAYPAL-SECURITY-SIGNATURE' : '****************',
// Global Sandbox Application ID
'X-PAYPAL-APPLICATION-ID ' : 'APP-80W284485P519543T',
// Input and output formats
'X-PAYPAL-REQUEST-DATA-FORMAT' : 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT' : 'JSON'
}];
var payload = {
requestEnvelope: {
errorLanguage: 'en_US'
},
invoice: {
merchantEmail: '*****************',
payerEmail: '*****************',
currencyCode: 'SGD',
paymentTerms: 'DueOnReceipt',
itemList: [{ name:'BananaPlant',
quantity:'1',
unitPrice:'38.95'
},
{ name:'testPlant',
quantity:'2',
unitPrice:'18.20'}]
}
};
var bodyJsonParams = JSON.stringify(payload);
var headerJsonParams = JSON.stringify(headerParams);
Parse.Cloud.httpRequest({
url: 'https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice',
headers: headerJsonParams,
body: bodyJsonParams,
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
});
有什么建议吗? cloudcode 没有错误。
我已经使用 curl 命令来验证我的调用是否有效。
curl -s -v -D --insecure -H "X-PAYPAL-SECURITY-USERID: *************" -H "X-PAYPAL-SECURITY-PASSWORD: *************" -H "X-PAYPAL-SECURITY-SIGNATURE: *************" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice -d \
"{\"requestEnvelope\":{\"errorLanguage\":\"en_US\"},\"invoice\":{\"merchantEmail\":\"*************\",\"payerEmail\":\"*************\",\"currencyCode\":\"USD\",\"paymentTerms\":\"DueOnReceipt\",\"itemList\":{\"item\":[{\"name\":\"BananaPlant\",\"quantity\":\"1\",\"unitPrice\":\"38.95\"},{\"name\":\"PeachTree\",\"quantity\":\"2\",\"unitPrice\":\"18.95\"}]}}}"
【问题讨论】:
标签: javascript paypal parse-platform paypal-sandbox parse-cloud-code