使用Paypal REST API创建付款

时间:2022-02-28 20:16:53

This is how I create Paypal payment from my webapp :

这是我从我的webapp创建Paypal付款的方式:

paypal.configure(paypal_config.api);
var payment = {
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  //"receiver_email":  "business@place.fr",
  "redirect_urls": {
    "return_url": "http://yoururl.com/execute",
    "cancel_url": "http://yoururl.com/cancel"
  },

  "transactions": [{
    "item_list": {
        "items": [{
            "name": "item",
            "sku": "item",
            "price": "1.00",
            "currency": "USD",
            "quantity": 1
        }]
    },
    "amount": {
        "currency": "USD",
        "total": "1.06",
        "details": {
          "subtotal": "1.00",
          "tax": "0.03",
          "shipping": "0.03"
        }
    },
    "description": "This is the payment description."
  }]
};

paypal.payment.create(payment, function (error, payment) {
  if (error) {
    console.log(error);
  } else {
    if(payment.payer.payment_method === 'paypal') {
      req.session.paymentId = payment.id;
      var redirectUrl;
      for(var i=0; i < payment.links.length; i++) {
        var link = payment.links[i];
        if (link.method === 'REDIRECT') {
          redirectUrl = link.href;
        }
      }
      res.redirect(redirectUrl);
    }
  }
});

It works perfectly but I have 2 problems, I need to set the receiver email, and the request is said to be malformed when I add the key "receiver_email".

它工作得很好但我有2个问题,我需要设置接收者电子邮件,并且当我添加密钥“receiver_email”时,该请求被认为是格式错误。

My second problem is more a question in fact, with this method I know directly if the payment is validated or not, but what happened when a payment need more time to be validated (bank transfer etc..), there's no ipn url to give ?

我的第二个问题实际上是一个问题,通过这种方法,我直接知道付款是否经过验证,但是当付款需要更多时间进行验证(银行汇款等等)时发生了什么,没有ipn url给出?

Thank you !

谢谢 !

2 个解决方案

#1


1  

Currently with PayPal rest payments, you cannot configure the receiver, so the payee has to be the one with the client_id/client_secret pair.

目前使用PayPal休息付款,您无法配置接收方,因此收款人必须是具有client_id / client_secret对的收款人。

To your second question, currently ipn support is not there for REST payments but the "http post to your server when payment status changes" feature will be coming for REST payments soon. Currently the best option is to fetch the payment with the PAY-XXX id by doing a GET to check change of status.

对于你的第二个问题,目前ipn支持不适用于REST支付,但是当支付状态发生变化时“http发布到你的服务器”功能将很快用于REST支付。目前最好的选择是通过执行GET来检查PAY-XXX id的付款以检查状态的变化。

#2


0  

I don't think setting receiver to be different from the client_id is supported at the moment.

我不认为此时支持设置接收器与client_id不同。

#1


1  

Currently with PayPal rest payments, you cannot configure the receiver, so the payee has to be the one with the client_id/client_secret pair.

目前使用PayPal休息付款,您无法配置接收方,因此收款人必须是具有client_id / client_secret对的收款人。

To your second question, currently ipn support is not there for REST payments but the "http post to your server when payment status changes" feature will be coming for REST payments soon. Currently the best option is to fetch the payment with the PAY-XXX id by doing a GET to check change of status.

对于你的第二个问题,目前ipn支持不适用于REST支付,但是当支付状态发生变化时“http发布到你的服务器”功能将很快用于REST支付。目前最好的选择是通过执行GET来检查PAY-XXX id的付款以检查状态的变化。

#2


0  

I don't think setting receiver to be different from the client_id is supported at the moment.

我不认为此时支持设置接收器与client_id不同。