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

Viewed 1105

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

2 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,

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

You may find the decent examples along with Json in Paypal official documentation.

Below is the example based on official PayPal payment page.

curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type:application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "30.11",
        "currency": "USD",
        "details": {
          "subtotal": "30.00",
          "tax": "0.07",
          "shipping": "0.03",
          "handling_fee": "1.00",
          "shipping_discount": "-1.00",
          "insurance": "0.01"
        }
      },
      "description": "This is the payment transaction description.",
      "custom": "EBAY_EMS_SOMENUMBER",
      "invoice_number": "INV000001",
      "payment_options": {
        "allowed_payment_method": "INSTANT_FUNDING_SOURCE"
      },
      "soft_descriptor": "ECHI5786786",
      "item_list": {
        "items": [
          {
            "name": "dontation",
            "description": "dontation",
            "quantity": "1",
            "price": "10",
            "tax": "0.00",
            "sku": "1",
            "currency": "USD"
          }
        ]
      }
    }
  ],
  "note_to_payer": "Thankyour for your donation.",
  "redirect_urls": {
    "return_url": "https://example.com",
    "cancel_url": "https://example.com"
  }
}
Related