Subscription Integration Process
Subscription allows merchants to create and publish subscription plans on-chain via the admin console, then generate subscription links for users through the API. After users complete signing and authorization on the subscription page, merchants can initiate periodic charges and synchronize subscription status via callback notifications or query interfaces.
1. Subscription Activation Processâ
The sequence diagram of the subscription activation process is as follows:
The integration flow is as follows:
- The admin first creates a subscription plan in the admin console and completes multi-sig approval. The plan only takes effect on-chain after approval passes. The merchant must record the corresponding
planId. - The merchant system calls
/subscribe/payment/create(Create Subscription Link) to initiate a subscription request to Pay Protocol. After validating the request parameters, Pay Protocol returns the subscription ID, the subscription page pathpaymentUrl, and the link expiration time. - The merchant system must append the official domain to
paymentUrlbefore redirecting the user to the subscription page. The user completes wallet connection, signing confirmation, and deduction allowance authorization on that page. - When a subscription-related event is triggered, Pay Protocol sends a callback notification via POST to
notifyUrl(provided by the merchant when creating the subscription). The merchant must distinguish between signing, authorization, billing, and cancellation events using thesubscriptionTypefield in the callback. - The merchant may also call
/subscribe/list(Get Subscription List) to query subscription status without relying solely on the frontend redirect result.
- The
paymentUrlreturned by the API is a relative path. It must be prepended with the Pay Protocol official domain before it can be accessed:https://payment.payprotocol.networkfor production andhttps://payment-sandbox.payprotocol.networkfor sandbox. - After receiving a callback notification, the merchant system must verify the signature (by validating the
X-PAY-SIGNheader) to ensure the notification was sent by Pay Protocol. See Callback Signature Verification for details. - After verifying the signature, make sure to validate the subscription ID, plan ID, and user identifier in the notification, and handle subsequent business logic based on
subscriptionTypeand the status fields. - A frontend page redirect does not mean the subscription has taken effect. Merchants should treat the
SubscriptionApprovecallback or the subscription status returned by the query interface as the authoritative result.
2. Periodic Billing Processâ
After the user completes authorization, the merchant must actively initiate periodic billing. The sequence diagram of the billing process is as follows:
The integration flow is as follows:
- The merchant system calls
/subscribe/chargeable/list(Get Chargeable Subscription List) to retrieve subscriptions that are due for billing. The response includessubscriptionId,userHash,nextPayTime, and other fields that serve as inputs for signing and reconciliation. - The merchant submits the chargeable subscription data to the signer interface, which completes signing and automatically broadcasts the transaction. Use the Sign EVM Subscription Billing interface for EVM chains and the Sign TVM Subscription Billing interface for TVM chains.
- After a successful or failed deduction, Pay Protocol sends a
subscriptionType=SubscriptionBillingcallback notification. The merchant can use this to update the subscription validity period, service status, or trigger a retry/compensation flow. - The merchant may also call
/subscribe/listto query the current subscription status, or call/subscribe/chargeable/listagain to confirm whether the subscription is still in the chargeable list.
- Periodic billing depends on the Signer service. Merchants must complete the signer deployment in advance. See Signer API Reference for deployment instructions.
- When calling the signer,
subscriptionIdsanduserHashsmust be in strict one-to-one correspondence, otherwise signing or billing will fail. - Only process subscriptions where
isChargeableCurrentCycle=0in the query response; if the field indicates the current cycle is not billable, do not initiate a charge for this period. - Even after the signer interface returns a result, merchants must treat the
SubscriptionBillingcallback or the final queried status as the authoritative source for billing records.
3. Unsubscription Processâ
When a user wishes to cancel a subscription, the merchant can create an unsubscription link to guide the user through revoking their on-chain authorization. The sequence diagram of the unsubscription process is as follows:
The integration flow is as follows:
- When a user needs to cancel their subscription, the merchant system calls
/subscribe/cancel/create(Create Unsubscription Link) to initiate an unsubscription request to Pay Protocol. - After validating the request parameters, Pay Protocol returns the unsubscription page path
paymentUrland the link expiration time. The merchant must prepend the official domain topaymentUrlbefore providing the link to the user. - After the user enters the unsubscription page and confirms the authorization cancellation via their wallet, the system sends a
SubscriptionCancelcallback notification asynchronously. - The merchant may also call
/subscribe/listto query the subscription status and confirm whether the subscription has entered the authorization-cancelled or terminated state.
- The access rules for unsubscription links are the same as for subscription links: the official domain must be prepended before use; the relative path returned by the API cannot be used directly.
- After receiving a
SubscriptionCancelcallback, the merchant system must verify the signature before updating the local subscription status and stopping further automatic billing or service provisioning. - After a user unsubscribes, merchants should confirm the subscription status via the query interface or callback result to avoid initiating charges against users who have already revoked their authorization.