Mixing products
There can be a number of situations where the customer will combine the purchase of a subscription and a one-off payment. A common use case could be the situation where you sell a physical product and at the same time sign people up to a subscription.
Example: A customer buys a new mobile phone and at the same time signs up to a new mobile subscription.
In these situations the one-off order should be paid independently of the subscription.
Reepay Checkout can be used to solve this use-case by following the following steps:
- Create a Reepay Checkout charge session with recurring flag
- Present Checkout window to customer for purchase and sign-up
- Create subscription
Step 1/3: Checkout charge session
Create a charge session with the recurring
flag set to true
. The recurring flag indicates that in addition to making a payment the payment method should also be returned and stored for the customer.
curl -X POST \
--url https://checkout-api.reepay.com/v1/session/charge \
-u 'priv_11118ec111dc1a7faaa192cef2226917e:' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"recurring":true,
"order": {
"handle": "order-id-221",
"currency": "DKK",
"customer": {
"handle":"c-1",
"email": "[email protected]",
"phone": "+2313123123",
"first_name": "John",
"last_name": "Doe"
},
"currency": "USD,
"amount": 20000
}
}'
The customer will be created if the customer does not already exist. A reference to an existing customer can also be provided in the parameter customer_handle
instead. For details on creating a charge session see: Reepay Checkout
Step 2/3: Customer payment in Checkout
Use the session id returned from the session API call to present a payment form using Reepay Checkout. For details on how to open Reepay Checkout see: Reepay Checkout
After a successful payment the parameter payment_method
will be returned among other return parameters. The parameter is a reference to a saved customer payment method that can be used when creating a subscription or making one-off payments.
Step 3/3: Create subscription
A subscription is created with an API call where the customer handle and payment method reference from previous step is used.
curl -X POST \
-u 'priv_12051dfac75143fc827cf63a87f46df3:' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"handle": "s-101",
"plan": "gold",
"signup_method": "source",
"customer": "c-1",
"source": "<payment method>"
}' \
https://api.reepay.com/v1/subscription
For full details on the create subscription operation, see: Create subscription.
A subscription now exists for the customer. The handle for the subscription is the reference for the subscription that can be stored in your system. We recommend using a supplied handle, but it is also possible to use the argument generate_handle=true
instead of handle
to let Reepay generate a handle.
Updated almost 5 years ago