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

ぃ、小莉子 提交于 2019-12-08 00:38:27

问题


I found a library that paypal themselves have written for node, they wrote a great library on how to pay. Im still in the confused state on how to receive payment and Im running out of time right now.

The use case is very simple, User A click add an item to his cart , then he has a choice, its either to pay using Credit/debit card or paypal(express checkout)

My goal still at the credit/debit card, where user decided to use credit/debit card to receive payments, and im using paypal-rest-api sdk to do this. But looking at the code samples Im super confused on which sample to choose, from

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

In the card_data, there is no amount, and im really confused.

Again the use case

User could buy the item on website, and he pays using credit/debit card and it will automatically send the money from his bank account to my paypal business account.


回答1:


You're looking at not the right method. You need payment.create

Here's the code snippet from 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);
    }
});


来源:https://stackoverflow.com/questions/38921540/how-do-i-make-a-direct-payment-using-paypal-rest-in-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!