# 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 ->> Onchainpay: Creating a payment link request
Onchainpay ->> Merchant: Link for connect client address
Merchant ->> Client: Link for connect client address

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

Onchainpay -->> 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 ->> Onchainpay: Creating subscription
Onchainpay ->> Merchant: Subscription data
Merchant ->> Client: Notification of successful subscription creation

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

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

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

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

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onchainpay.io/api-reference/10recurring_payments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
