API examples

A couple of examples on how to create sessions with the Checkout API.

Charge session potentially creating customer if not already exists

Charge session, potentially creating customer if not already exists.

curl -X POST \
  --url https://checkout-api.reepay.com/v1/session/charge \
  -u 'priv_xxxx:' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "order": {
    "handle": "order-12345",
    "customer": {
        "handle": "customer-123",
        "first_name": "John",
        "last_name": "Doe",
        "phone":"+4531313131"
    },
    "amount": 50000
  },
  "accept_url":"https://webshop.com/accept/order-12345",
  "cancel_url":"https://webshop.com/decline/order-12345"
}'

Charge session created with order lines instead of amount

Either amount or order_lines must be provided. In this example order lines are used to create charge session.

curl -X POST \
  --url https://checkout-api.reepay.com/v1/session/charge \
  -u 'priv_xxxx:' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "order": {
    "handle": "order-123456",
    "customer": {
        "handle": "customer-123",
        "first_name": "John",
        "last_name": "Doe",
        "phone":"+4531313131"
    },
    "order_lines": [
        {
            "amount": 10000,
            "quantity": 5,
            "ordertext": "Product 1"
        },
        {
            "amount": 20000,
            "quantity": 1,
            "ordertext": "Product 2",
            "amount_incl_vat": false,
            "vat": 0.20
        }
    ]
  },
  "accept_url":"https://webshop.com/accept/order-12345",
  "cancel_url":"https://webshop.com/decline/order-12345"
}'

Charge session saving payment method

Charge session also creating a saved payment method for later recurring use (e.g. for merchant initiated payments or as payment method on subscription). Currency defined, maybe different from account default.

curl -X POST \
  --url https://checkout-api.reepay.com/v1/session/charge \
  -u 'priv_xxxx:' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
    "recurring": true,
    "order": {
        "ordertext": "Awesome product",
        "handle": "order-12345",
        "amount": 10000,
        "currency": "EUR",
        "customer":{
            "email":"[email protected]",
            "handle":"customer-1",
            "first_name":"John",
            "last_name":"Doe"
        }
    },
    "accept_url":"https://webshop.com/accept/order-12345",
    "cancel_url":"https://webshop.com/decline/order-12345"
}'

As a result of a charge session with recurring=true a reference to a saved payment method will be returned in parameter payment_method. The saved payment method can be used later to create a charge with create charge. Example with the saved payment method reference ca_...:

curl -X POST\
 --url https://api.reepay.com/v1/charge \ 
 -H 'Accept: application/json'  \
 -u 'priv_xxxxxx:' \
 -H 'Content-Type: application/json' \
--data '{ 
      "handle": "order_101", 
      "amount": 20000, 
      "source": "ca_...."
}'

The saved payment method can also be used as source argument when creating a subscription: create subscription session

Charge session for an existing unpaid invoice

Create a charge session for an existing unpaid invoice/charge (state created, pending, dunning or failed).

curl -X POST \
  --url https://checkout-api.reepay.com/v1/session/charge \
  -u 'priv_xxxx:' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
    "invoice": "order-123452",
    "accept_url":"https://webshop.com/accept/order-12345",
    "cancel_url":"https://webshop.com/decline/order-12345"
}' | jsonlint

Recurring session creating customer if not exists

Creating a session for saving a payment method without making a payment. Customer will be created if not already existing.

curl -X POST \
  --url https://checkout-api.reepay.com/v1/session/recurring \
  -u 'priv_xxxxx:' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "create_customer" : {
        "handle": "customer-123"
    }
  },
  "accept_url":"https://webshop.com/accept/recurring",
  "cancel_url":"https://webshop.com/decline/recurring"
}'