Understanding the two-step process
When using recurring payments, the process involves two separate steps:1. Token creation (after 3DS authentication)
After the customer completes 3DS viaqfpay.confirmPayment() on the frontend, the system creates a payment token.
This step verifies the cardholder’s identity and stores the payment method securely for future billing.
2. Subscription creation
Thetoken_id generated in step 1 is then used to call the API /subscription/v1/create, which creates the subscription and schedules recurring billing.
Why you see two transaction records
Because these two steps serve different purposes, you will normally see two transaction records:- One for token creation / payment verification
- One for subscription billing
Billing options
Depending on your business logic, you can implement the first charge in two different ways:Option 1 — Verification charge + first subscription charge
Example: subscription HKD 100 / month starting January Token creation: HKD 1 verification charge (Jan)- Used only for identity verification and tokenisation.
- First billing HKD 100 in January
- Subsequent charges HKD 100 every month.
Option 2 — First subscription charge during token creation
Example: subscription HKD 100 / month starting January Token creation: HKD 100- This charge serves both as identity verification and the first subscription payment.
- Billing starts from February onwards (HKD 100 monthly).
Prerequisites
Before you begin, ensure you have:- A QFPay merchant account with recurring payment features enabled
- API credentials (app_code and API key)
- A web application with HTTPS enabled
- Basic understanding of REST APIs and webhooks
Integration steps
Step 1: Create customer
Create a customer record to associate with subscriptions.Step 2: Create product
Define the subscription product with pricing and billing cycle.Step 3: Render payment element (frontend)
Initialize the payment element on your checkout page.Step 4: Confirm payment and create token
After customer enters card details, confirm the payment to trigger 3DS and create token.Step 5: Create subscription (backend)
Use the token to create the subscription.Step 6: Handle webhooks
Set up webhook endpoints to receive subscription events.Testing
Use test card numbers in sandbox environment:- Success: 4111 1111 1111 1111
- 3DS Required: 4000 0027 6000 3184
- Declined: 4000 0000 0000 0002
Best practices
- Always validate webhooks - Verify webhook signatures to ensure authenticity
- Handle failed payments gracefully - Implement retry logic and notify customers
- Store subscription IDs - Keep subscription_id in your database for management
- Test thoroughly - Test all scenarios including failures and cancellations
- Monitor subscription health - Track payment success rates and churn

