Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a simple, minimal example of a JSON payment paypal definition?

I am looking for a simple JSON example of a paypal definition for a donation. This does not seem to be covered in PayPal docs. It needs a simple parameter for a specific date for the payment to be made, and a option for it to be recurring on this date annually. I have tried the following , but it does not allow for a payment date or recurring. What needs adding?

var create_payment_json = {
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://return.url",
        "cancel_url": "http://cancel.url"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                "name": "item",
                "sku": "item",
                "price": "1.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "currency": "USD",
            "total": "1.00"
        },
        "description": "This is the payment description."
    }]
};

Thank you

like image 412
harry lakins Avatar asked Nov 08 '22 16:11

harry lakins


1 Answers

There is no such parameter to control whether a payment is recurring or will be captured or charged at a later time in the future that way.

In order to achieve semblance of what's possible in Stripe, you need to work different.

For recurring billing,

  • create a billing plan featuring recurring payment.
  • create a billing agreement for the customer to that billing plan. Executing this agreement sets the recurring billing process in motion.

For later capture,

  • create a payment of type authorization
  • store the capture URL returned in the response.

    Note that this capture URL is live for a certain period of time. This capture url can be refreshed just one time by re-authorizing payment if the payment isn't captured within that period of time.

    Sadly, Paypal doesn't provide an API to automatically capture payment at a later time you can specify like Stripe does it. You have the responsibility to ensure that.

    However, there are service integrations that extend Paypal to provide this functionality, see Braintree Vault for Paypal).

like image 129
Oluwafemi Sule Avatar answered Nov 14 '22 22:11

Oluwafemi Sule