我正在使用Android和Node JS进行paypal集成,以便从一个帐户自动付款到另一个帐户。(未来付款)
我可以从买家访问paypal帐户,并将Authorization Code
和MetaData Id
从我的Android应用程序传递到我的节点服务器上。
我从授权码中获取了refresh token
和access token
,并使用以下代码创建了未来付款并获取付款:
var future_payment_config = {
"PayPal-Client-Metadata-Id": metaId,
"Authorization": refresh_token
};
//Set up payment details
var create_payment_json = {
"intent": "authorize",
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"currency": "USD",
"total": "1.88"
},
"description": "future of sauces"
}]
};
var pay_id = "";
var url = "";
//Create future payment
paypal.payment.create(create_payment_json, future_payment_config, function(error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
console.log("Authorization Object : " + JSON.stringify(payment));
pay_id = payment.id;
for (var index = 0; index < payment.transactions[0].related_resources[0].authorization.links.length; index++) {
//Redirect user to this endpoint for redirect url
if (payment.transactions[0].related_resources[0].authorization.links[index].rel === 'capture') {
// console.log(payment.links[index].href);
url = payment.transactions[0].related_resources[0].authorization.links[index].href;
var execute_payment_json = { "amount": { "currency": "USD", "total": "1.50" }, "is_final_capture": true }
var payer_id = payment.payer.payer_info.payer_id;
// var paymentId = { "paymentId" : pay_id};
// paymentId = {
// "PayPal-Client-Metadata-Id": metaId,
// "Authorization": refresh_token
// };
// console.log(execute_payment_json, paymentId);
paypal.authorization.capture(payment.transactions[0].related_resources[0].authorization.id, execute_payment_json, function(error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
console.log("Get Payment Response");
console.log(JSON.stringify(payment));
}
});
}
}
}
});
我无法进行交易。我想知道,如果我需要为交易做更多的事情。我还尝试使用paypal.execute
(如下所示):
function executePayment(paymentId, payerId) {
var details = {
"payer_id": payerId,
"transactions": [{
"amount": {
"currency": "USD",
"total": "1.88"
},
"description": "future of sauces"
}]
};
paypal.payment.execute(paymentId, details, function(error, payment) {
if (error) {
console.log("Error :", error);
} else {
console.log("Result : ",payment);
}
})
}
我在paypal.execute
上遇到的错误是:
Error : { [Error: Response Status : 400]
response:
{ name: 'INTERNAL_SERVICE_ERROR',
message: 'An internal service error has occurred',
information_link: 'https://developer.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR',
debug_id: 'a544d3865cd51',
httpStatusCode: 400 }
我想知道,如果我走在正确的轨道上!我希望买方订阅未来付款,协调人将自动扣除付款。
先谢谢。