Overview
If your billing model uses dynamic amounts or does not follow a fixed cycle, you can save a customer’s payment method and charge it later on demand. This feature supports:- Cards
- APMs that support tokenization for recurring charges, such as ShopeePay Recurring and GrabPay Recurring. Click here for the full supported list.
Create a Recurring Billing
Create a recurring billing with save payment method enabled
Present the Checkout UI
Redirect the customer to attach a payment method
Charge the Saved Method
Charge the saved card or APM anytime
Handle Payment Processing
After the customer confirms, handle payment processing and schedule recurring charges.
Step 1 – Save a Payment Method
This step creates the billing session the customer will use to attach their payment method.HTTP Request
Query Parameters
Mandatory fields are
name, customer_email, and amount. Remember to
include the header Content-Type: application/x-www-form-urlencoded.| Parameter | Description | Example |
|---|---|---|
| name | Plan name | Spotify Premium |
| description | description of the plan | Spotify Membership |
| save_payment_method | New. Saves any supported payment method (cards or APMs) to charge later. Recommended. | true |
| save_card | Deprecated field, equivalent to save_payment_method. Still supported for now. | true |
| customer_email | Customer email | [email protected] |
| customer_name | Customer name | Paul |
| amount | Amount related to the recurring billing | 9.90 |
| currency | Currency related to the recurring billing | SGD |
| payment_methods[] | Choice of payment methods you want to offer the customer. Default value is card | giro, card, grabpay_direct, shopee_pay |
| redirect_url | URL where hitpay redirects the user after the users enters the card details and the subscription is active. Query arguments reference (subscription id) and status are sent along | https://spotify.com/subscription-completed |
| reference | Arbitrary reference number that you can map to your internal reference number. This value cannot be edited by the customer | XXXX123 |
| webhook | Optional URL value to which hitpay will send a POST request when there is a new charge or if there is an error charging the card | https://webhoo.site/test |
| send_email | Hitpay to send email receipts to the customer. Default value is false | true |
Response
Step 2 - Redirect customer to recurring billing page (One time set up)
Redirect the customer to the “url” value.
Step 3 - Charge the Saved Payment Method
Use this endpoint anytime after the customer attaches their payment method to charge it.HTTP Request
Query Parameters
| Parameter | Description | Example |
|---|---|---|
| currency | Currency related to the recurring billing | SGD |
| amount | Amount related to the recurring billing | 9.90 |
Step 4: Handle Successful Payment
Webhooks
HitPay will send a Webhook POST request when there is a new charge or if there is an error charging the card.If you are using HitPay APIs to integrate into your app you must mark your order as paid ONLY after the webhook is received and validated.
- Create an endpoint (E.g. /payment-confirmation/webhook) in your server that accepts POST requests. This request is
application/x-www-form-urlencoded. - Validate the webhook data using your salt value
- Return HTTP status code 200 to Hitpay
- Mark your order as paid
sample webhook payload data
Webhook fields
Following fields are sent with the webhook request:| Parameter | Description |
|---|---|
| payment_id | Payment ID |
| recurring_billing_id | Recurring billing request ID |
| amount | Amount related to the recurring billing |
| currency | Currency related to the recurring billing |
| status | Payment status (succeeded / failed) |
| reference | Arbitrary reference number that you have mapped during recurring billing request creation |
| hmac | Message Authentication code of this webhook request |
Validate Webhook
Hitpay creates a list of all values from the key-value pairs that we send in the POST request and sort them in the order of their keys alphabetically. We then concatenate all these values together. We then use the HMAC-SHA256 algorithm to generate the signature. The HMAC key for the signature generation is the secretsalt from your dashboard under API Keys.
FAQs
Is it possible to Authorization an amount before charging?
Is it possible to Authorization an amount before charging?
Do I need to specify an amount when saving a payment method?
Do I need to specify an amount when saving a payment method?
Yes, a minimum amount of 1 is required to initiate the save-payment-method session.
Can I modify the amount I will charge my customer later on?
Can I modify the amount I will charge my customer later on?
Yes, once your customer has attached a payment method to the
subscription, you can charge any amount using the charge the saved payment method
API.
Product Checklist
Product Checklist
Ensure the following before moving to production - Change the base URL
for all API calls to https://api.hit-pay.com/v1/ - Update API keys and
Salt values from the production dashboard