Step 3 of 3: Get customer payment information
The simplest way to get customer payment information is to use the link provided in the subscription object :
JSON :
"hosted_page_links": { "payment_info": "https://checkout.reepay.com/#/subscription/pay/da_DK/.../..." }
The link will start a subscription session, where the customer can attach payment information to the subscription.
If the subscription is pending: it will activated when valid payment information has been entered.
If the subscription has an initial invoice: it will be paid before using the payment information for the subscription.
The link can be sent to the customer on mail or the customer can be redirected to the link.
Note
This simple approach has limited integration possibilities. To get full control of the process a subscription session can be created as described in the below steps.
3.1 Create a subscription session
Use the Billwerk+ Checkout API to create a subscription session for the subscription.
cURL :
curl --request POST \ --url https://checkout-api.reepay.com/v1/session/subscription \ -u '<your private key>:' \ --header 'content-type: application/json' \ --data '{ "button_text":"Signup", "subscription": "subscription-101", "accept_url": "https://mysystem.com/accept", "cancel_url": "https://mysystem.com/cancel" }'
Response
JSON :
{ "id": "cs_5fb7cc4e5c7ed6629c6c8b16d91683aa", "url": "https://checkout.reepay.com/#/subscription/cs_5fb7cc4e5c7ed6629c6c8b16d91683aa" }
3.2 Include the Checkout Web SDK
Read more about different ways to use Checkout.
JavaScript :
<script src="https://checkout.reepay.com/checkout.js"></script>
3.3 Show the customer the signup window
In order to integrate the payment window in your web shop you will need to add a few lines of code to your web page.
Here is example code to include in your HTML file :
JavaScript :
<script src="https://checkout.reepay.com/checkout.js"></script> <script> var rp = new Reepay.WindowCheckout('cs_5fb7cc4e5c7ed6629c6c8b16d91683aa'); </script>
3.4 Show a receipt page
If the accept and cancel url has been used the customer will be redirected back to one of these.
Note
Please notice
The customer might close the browser before reaching the return url, or there might be a connection problem, so we recommend to also listen for webhooks if you need to update state on your side.
Warning
HTTP Basic Authentication
The private API key must be provided as the HTTP Basic Auth username. Remember a colon : after the private API key. The colon separates username and password in HTTP Basic Auth. In this case the password is empty.
The basic authentication needs to be base64 encoded before submitting. Some coding frameworks will do this for you, but most commonly you need to do the encoding. You can base64 encode online using https://www.base64encode.org/.
Example :
The private API key is priv_11111111111111111111111111111111
. This is encoded as base64(priv_11111111111111111111111111111111:)
= cHJpdl8xMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTo=
(notice the : after the API key)
The full HTTP header will be :
Authorization: Basic
cHJpdl8xMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTo=
Replace priv_11111111111111111111111111111111
with your own API key, which you can find at https://admin.reepay.com under "Developers" > "API Credentials".
Danger
Keep your private key secret
Your private API keys carry many privileges, so be sure to keep them secret! Only use the private key in server-to-server API calls, never from the frontend, as that will expose the private key to anybody.
Note
Please remember to replace :
plan-AAAAA with the plan ID from step 1 <payment method> with the customer payment method obtained in the previous step.
You have now successfully created a subscription, which automatically will be deducted each month.