2016-08-12 162 views
1

我发现了一个paypal自己写的为node的图书馆,他们写了一个关于如何支付的伟大图书馆。我仍然处于困惑的状态,如何收到付款,我现在用尽了时间。如何使用节点中的paypal-rest进行直接付款?

使用情况非常简单,用户A单击某个项目添加到他的车,他就可以有选择,它要么支付使用信用卡/借记卡或PayPal(快速结账)

我的目标依然在信用卡/借记卡,用户决定使用信用卡/借记卡来接收付款,并使用paypal-rest-api sdk来完成此操作。但看代码示例IM在选择哪个样品超级混乱,从

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,没有量,我真的糊涂了。

再次使用的情况下

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

回答

1

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

,所以我只需要更换与'req.body.data'数据的代码片段? – sinusGob

+0

例如'“金额”:{“total”:req.body.price}'? – sinusGob

+0

是的,看起来像 –