# Recurring payments

Here is general flow of using "Recurrent" methods and connecting your subscribers to the service.

1. Firsly, you should create a merchant in "Recurrent" section on a website
2. There will be identificator of merchant on "Recurrents" page. This ID should be provided in all API methods in the field `merchantId`
3. Next you can call method for creating url for binding subscriber's address to the service. (create-subscriber-billing-link)
4. You should send to your user a link obtained from previous response
5. After connecting web3 wallet, user binds his address with particular network and token to the service
6. After successful creation of billing link, you will receive a webhook with billing link's data on your `webhookUrl` provided in 3rd step

From now on, you can use billing link by two following options:

* Create a subscription - payment with fixed sum once in a period
* Call a method for one-time payment - forced payment with specified sum from user's address

## API Interaction Scheme

### Connect client

{% @mermaid/diagram content="sequenceDiagram
Client ->> Merchant: Payment request
Merchant ->> Apollopayment: Creating a payment link request
Apollopayment ->> Merchant: Link for connect client address
Merchant ->> Client: Link for connect client address

```
Note over Client: Go to link
Note over Client: Connect wallet

Apollopayment -->> Merchant: Webhook with new billing link

Note over Merchant: Save billing link ID" %}
```

### Create subscription

Automatic payment once per period

{% @mermaid/diagram content="sequenceDiagram
Client ->> Merchant: Choosing subscription

```
Note over Merchant: Getting available client billing links
Note over Merchant: Select a link to a suitable coin/network that the client has previously created

Merchant ->> Apollopayment: Creating subscription
Apollopayment ->> Merchant: Subscription data
Merchant ->> Client: Notification of successful subscription creation

Note over Apollopayment: Attempt to pay from client's wallet

Apollopayment -->> Merchant: Webhook about subscription status change
Merchant ->> Client: Notification of successful payment or payment error" %}
```

### Свободный платеж

{% @mermaid/diagram content="sequenceDiagram
Merchant ->> Apollopayment: Creating a payment
Apollopayment ->> Merchant: Payment data

```
Note over Apollopayment: Attempt to pay from client's wallet

Apollopayment -->> Merchant: Webhook for payment status change" %}
```
