【问题标题】:How do i make a direct payment using paypal-rest in node?如何在节点中使用 paypal-rest 直接付款?
【发布时间】:2016-12-19 16:17:42
【问题描述】:

我找到了一个 paypal 自己为 node 编写的库,他们编写了一个很棒的关于如何支付的库。我还在纠结如何收款,现在没时间了。

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

我的目标仍然是信用卡/借记卡,用户决定使用信用卡/借记卡接收付款,我使用 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,没有数量,我真的很困惑。

再说一遍用例

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

【问题讨论】:

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


    【解决方案1】:

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

    这是来自payment documentation的代码sn-p

    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);
        }
    });
    

    【讨论】:

    • 所以我只需要将数据替换为req.body.data?
    • 例如"amount": { "total": req.body.price }?
    • 是的,看起来像这样
    • 我想再问你一个问题,如果你不介意的话,对于 express checkout,我应该使用哪种付款方式?
    • 我认为您应该为此使用前端库,但我并不精通 PayPal SDK
    猜你喜欢
    • 2016-05-20
    • 2014-01-05
    • 2014-03-29
    • 2015-06-21
    • 2015-08-08
    • 2014-08-09
    • 2013-08-30
    • 2013-08-31
    • 2021-11-26
    相关资源
    最近更新 更多