Question

This is how I create Paypal payment from my webapp :

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".

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 ?

Thank you !

Was it helpful?

Solution

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.

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top