如何使用节点中的paypal-rest直接付款?

时间:2016-08-12 15:29:06

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

我发现了一个自己为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商业账户。

1 个答案:

答案 0 :(得分:2)

你正在寻找不正确的方法。您需要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);
    }
});