8Pay
Search…
Recurring payments
This guide covers step by step what you need to do in order to start accepting recurring crypto payments with 8Pay.
We will assume you are a streaming service provider who offers a monthly plan of 10 USDT and wants to integrate a Subscribe button into its website.

1. Create a plan

Go to the Plans page of the web app and click on Create a Plan.
Select the billing model that better suits your needs. For this specific case, we need billings to be performed in advance so the Fixed Recurring biling model is the perfect fit.
Fill the rest of the parameters and confirm the creation through MetaMask.

2. Generate a button

Go to the newly created plan's page and click on Buttons.
Configure the behaviour by customizing the available parameters (full details are available here) then click on Generate.
The HTML code for the button will be automatically copied to your clipboard.
Go into your website's source code and paste it there.

3. Setup webhook

To receive notifications whenever a new event related to your plan occurs (e.g. when a customer subscribes) you can setup a webhook URL.
To do so, go to the plan's management page and click on Manage webhook.
More info on webhook notifications can be found here.

4. Wait for customers to subscribe

Upon clicking on the button generated in step 2, customers will be redirected to 8Pay's hosted checkout page where they will be guided through the payment process.
After payment is completed, you will get a notification to the webhook configured in step 3 which will look like this:
1
{
2
"id": "5ccf8bdc7707a8effa371d01452644d3a388b975290b968874d0a44ec0219226",
3
"type": "fixed-recurring",
4
"event": "Subscription",
5
"timestamp": 1585220116,
6
"transactionHash": "0xb0f21bf5d722d981330d45d8625568cd0b356e8c7c464857131a6ebf99eadf80",
7
"transactionStatus": "confirmed",
8
"data": {
9
"planId": "0xb7934ebf676eb81606da5dded26433ce994d9767924387d65378f263845f3af9",
10
"subscriptionId": "0xf0e6a20e8069d403a538729549a17544a2bca3672312a4aed571d115e1fde7d4",
11
"user": "0xB2e9F6F9414ea12A33302923A55b9B4Cf99CCD90"
12
}
13
}
Copied!

5. Bill the customers

After the current cycle is over, customers will have to be billed for the next cycle in order to continue using the service. To do so, you can use the Javascript SDK and program a server side script that triggers billing for the subscription when it's due.
Here is a simple script used the charge the customer of a subscription:
1
const Web3 = require('web3');
2
const EightPaySDK = require('@8pay/sdk');
3
4
const web3 = new Web3('<provider-url>');
5
const eightPay = new EightPaySDK(web3, 'bsc-mainnet');
6
7
const privateKey = '<private-key>';
8
9
const planId = '0xb7934ebf676eb81606da5dded26433ce994d9767924387d65378f263845f3af9';
10
const subscriptionIds = ['0xf0e6a20e8069d403a538729549a17544a2bca3672312a4aed571d115e1fde7d4'];
11
12
eightPay.fixedRecurring.bill(planId, subscriptionIds)
13
.send({ privateKey })
Copied!
Notes:
    The plan's ID can be found in the url of the plan's page.
    SDKs for different programming languages will be release in the near future. Until then, you will need to develop a custom integration to call our smart contracts directly.
Last modified 3mo ago