gpt4 book ai didi

node.js - 我如何在 Node 中使用 paypal-rest 进行直接付款?

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:15 24 4
gpt4 key购买 nike

我找到了一个paypal自己写的库node ,他们写了一个很棒的关于如何支付的图书馆。我仍然对如何接收付款感到困惑,我现在时间不多了。

用例非常简单,用户 A 单击将商品添加到他的购物车,然后他可以选择使用信用卡/借记卡或 paypal(快速结帐)支付

我的目标仍然是信用卡/借记卡,用户决定使用信用卡/借记卡来接收付款,我使用 paypal-rest-api sdk 来执行此操作。但是看着代码示例,我对从中选择哪个示例感到非常困惑

https://github.com/paypal/PayPal-node-SDK/tree/master/samples

var card_data = {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "123",
"first_name": "Joe",
"last_name": "Shopper"
};

paypal.creditCard.create(card_data, function(error, credit_card){
if (error) {
console.log(error);
throw error;
} else {
console.log("Create Credit-Card Response");
console.log(credit_card);
}
})

card_data里面,没有金额,我很疑惑。

再次用例

用户可以在网站上购买商品,他使用信用卡/借记卡付款,系统会自动将钱从他的银行账户发送到我的 paypal 企业账户。

最佳答案

您正在寻找不正确的方法。你需要 payment.create

这是来自 payment documentation 的代码片段

var create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "874",
"first_name": "Joe",
"last_name": "Shopper",
"billing_address": {
"line1": "52 N Main ST",
"city": "Johnstown",
"state": "OH",
"postal_code": "43210",
"country_code": "US"
}
}
}]
},
"transactions": [{
"amount": {
"total": "7",
"currency": "USD",
"details": {
"subtotal": "5",
"tax": "1",
"shipping": "1"
}
},
"description": "This is the payment transaction description."
}]
};

paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
}
});

关于node.js - 我如何在 Node 中使用 paypal-rest 进行直接付款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38921540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com