我如何在节点中使用 paypal-rest 进行直接付款?

How do i make a direct payment using paypal-rest in node?

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

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

我的目标仍然是 credit/debit 卡,用户决定使用 credit/debit 卡接收付款,我使用 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里面没有金额,我真的很迷茫

再次用例

用户可以在网站上购买商品,他使用 credit/debit 卡付款,它会自动将钱从他的银行账户发送到我的 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);
    }
});