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

标签 node.js paypal paypal-sandbox paypal-rest-sdk

我找到了一个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/

相关文章:

node.js - 如何在 Sequelize 中创建表以使用 Node JS 存储在 Postgresql 中

Paypal 沙盒账户 : facilitator and premier types?

c# - 如何用paypal C# sdk获取直接支付方式的transactionid

paypal - developer.paypal.com 和 x.com 有什么区别?

html - 如何使用沙盒测试 Paypal 订阅按钮?

node.js - 无法运行 eletrode 应用程序获取错误

javascript - 网页包/NPM : Use build version of installed module instead of re-building from source

php - 在 WooCommerce 上获取 Paypal 付款详情

php - paypal-php-sdk 中的 PayPal-Mock-Response

node.js - 异步 - 等待 NodeJS 无法与 Mongoose 一起工作