HaiPay.js Integration (Apple Pay Subscribe & Google Pay Subscribe)
HaiPay provides a convenient Apple Pay Subscribe and Google Pay Subscribe payment integration solution that allows you to quickly integrate payment functionality into web pages through simple configuration.- Import HaiPay script ([https://cashier.haipay.top/js/applePayGooglePaySubscribe_1.0.0.min.js])
- Page structure requirements
- Payment button container: Used for rendering Apple Pay/Google Pay Subscribe buttons.
- Quick integration example
- Parameter description
-
- Initialization configuration parameters (HaiPay constructor parameters)
-
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| sandbox | Yes | Boolean | Environment type,default value true, optional values: - true: Test environment (for integration testing) - false: Production environment (for live use) |
| clientToken | Yes | String | Client Toke(clientToken) |
| buttonType | No | String | Button text type, default value buy, optional values: - plain: “Display payment logo only, no text” - add-money: “Add funds” - book: “Book” - buy: “Buy” (default) - check-out: “Checkout” - contribute: “Donate” - order: “Order” - reload: “Reload” - rent: “Rent” - subscribe: “Subscribe” - support: “Support” - tip: “Tip” - top-up: “Top-up” |
| buttonTheme | No | String | Button theme style, default value black, optional values: - black: Black background - white: White background |
| buttonHeight | No | number | Button height, default value 50 |
-
- Common error types and solutions
| Error Message | Error Cause | Solution |
|---|---|---|
| Missing required parameters: clientToken | Missing required initialization parameters | Check if parameters clientToken are passed |
| Unsupported region: CN | Production environment does not support China region | Check if there is a DOM element with the corresponding ID in the page |
HaiPay.js Integration (creditCard Subscribe)
HaiPay provides a convenient creditCard Subscribe payment integration solution that allows you to quickly integrate payment functionality into web pages through simple configuration.- Import HaiPay script ([https://cashier.haipay.top/js/creditCardSubscription_1.0.0.min.js])
- Page structure requirements
- Page Container: used for rendering the creditCard Subscribe page.
- Quick integration example
- Parameter description
-
- Initialization configuration parameters (HaiPay constructor parameters)
-
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| sandbox | Yes | Boolean | Environment type,default value true, optional values: - true: Test environment (for integration testing) - false: Production environment (for live use) |
| clientToken | Yes | String | Client Toke(clientToken) |
| cardTheme | No | String | Theme style, default value white, optional values: - black: Black background - white: White background |
-
- Common error types and solutions
| Error Message | Error Cause | Solution |
|---|---|---|
| Missing required parameters: clientToken | Missing required initialization parameters | Check if parameters clientToken are passed |
| Unsupported region: CN | Production environment does not support China region | Check if there is a DOM element with the corresponding ID in the page |
⚠️ Note
Apple Pay does not support W (week) as a subscription period.
If you need to implement a weekly subscription, the correct approach is to use D as the unit and set the interval to 7 days.
Limit
| Transaction Type | Limit (Unit: USD) |
|---|---|
| Subscription | 0.99-1000 |
1. Subscription API
Subscription Apply
Brief Description:- Create a subscription order
/subscription/apply
Parameters:
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| appId | Yes | Long | Business ID (obtained from the backend, must pass the corresponding business ID according to the currency parameter) |
| subscriptionOrderId | Yes | String | Merchant order ID (must be unique, max length 48) |
| amount | Yes | String | Transaction amount (accurate to two decimals; punctuation such as “,” is not allowed) |
| name | Yes | String | User name, recommended to use real name. Format: includes firstName and lastName, separated by space. Example: Donald John Trump |
| phone | Yes | String | Real phone number (format reference: Phone Format) |
| Yes | String | Real email | |
| subject | Yes | String | Subscription title |
| body | No | String | Remark details |
| inBankCode | Yes | String | CREDIT_CARD, GOOGLE_PAY, APPLE_PAY |
| payType | Yes | String | SUBSCRIPTION |
| callBackUrl | Yes | String | Redirect URL after successful payment |
| notifyUrl | Yes | String | Asynchronous notification URL |
| country | Yes | String | Country |
| currency | Yes | String | Currency, currently supported: USD |
| partnerUserId | Yes | String | User unique identifier (e.g., userId). Used for risk control. Must be real and valid, otherwise it will affect the transaction. Format: digits, letters, or common symbols -~!@#$%&*()_. |
| recurringInterval | Yes | String | Recurring cycle type D(day),W(week),M(month),Y(year) |
| recurringIntervalCount | Yes | Integer | Recurring cycle interval |
| recurringMaxNumber | Yes | Integer | Maximum number of cycles. Regardless of cycle type, maximum duration cannot exceed 3 years. Subscription will be automatically canceled at expiration. |
| website | Yes | String | Transaction website |
| retryTimes | Yes | Integer | Retry attempts for failed periodic deductions, default 3 |
| cancelUrl | No | String | If provided, the user can click “Back” on the payment page to return to this URL. |
| couponPeriod | No | Integer | Discount Period (Currently only the first period discount and the full period discount are supported, i.e., couponPeriod can only be equal to 1 or recurringMaxNumber) |
| couponAmountPerPeriod | No | String | Discount amount per period |
| sign | Yes | String | Signature |
| Parameter Name | Type | Description |
|---|---|---|
| subscriptionOrderId | String | Merchant subscription ID (must be unique) |
| subscriptionNo | String | Platform subscription ID |
| appId | String | Business ID |
| subject | String | Payment note |
| payType | String | Subscription fixed as SUBSCRIPTION |
| inBankCode | String | Bank code |
| amount | String | Amount |
| payUrl | String | Authorization URL |
| recurringInterval | String | Recurring cycle W, M, Y |
| recurringIntervalCount | String | Recurring cycle interval |
| status | String | Subscription status (-1: Error, 1: Processing, 2: Success, 3: Failed, 4: Canceled) |
| clientToken | String | Client token used in the JavaScript Web SDK (see HaiPaySDK.js) |
| sign | String | Signature |
Query Subscription
Brief Description:- Query subscription order
/subscription/query
Parameters:
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| appId | Yes | Long | Business ID (obtained from the backend, must pass the corresponding business ID according to the currency in the URL) |
| subscriptionNo | Yes | String | Platform subscription ID |
| sign | Yes | String | Signature |
| Parameter Name | Type | Description |
|---|---|---|
| subscriptionOrderId | String | Merchant subscription ID (must be unique) |
| subscriptionNo | String | Platform subscription ID |
| appId | String | Business ID |
| subject | String | Payment note |
| currency | String | Currency |
| payType | String | Subscription fixed as SUBSCRIPTION |
| inBankCode | String | Bank code |
| amount | String | Amount |
| recurringInterval | String | Recurring cycle W, M, Y |
| recurringIntervalCount | String | Recurring cycle interval |
| status | String | Subscription status (-1: Error, 1: Processing, 2: Success, 3: Failed, 4: Canceled) |
| deductList | String | Deduction list |
| sign | String | Signature |
| Parameter Name | Type | Description |
|---|---|---|
| deductNo | String | Subscription deduction ID |
| amount | String | Deduction amount |
| status | Integer | Deduction status (0: Not started, 1: In progress, 2: Success, 3: Failed) |
| orderNo | String | Payment note |
| startTime | String | Subscription deduction cycle - start time |
| endTime | String | Subscription deduction cycle - end time |
Cancel Subscription
Brief Description:- Cancel a subscription
/subscription/cancel
Parameters:
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| appId | Yes | Long | Business ID (obtained from the backend, must pass the corresponding business ID according to the currency in the URL) |
| subscriptionNo | Yes | String | Platform subscription ID |
| sign | Yes | String | Signature |
| Parameter Name | Type | Description |
|---|---|---|
| subscriptionOrderId | String | Merchant subscription ID (must be unique) |
| subscriptionNo | String | Platform subscription ID |
| appId | String | Business ID |
| payType | String | Subscription fixed as SUBSCRIPTION |
| inBankCode | String | Bank code |
| status | String | Subscription status (-1: Error, 1: Processing, 2: Success, 3: Failed, 4: Canceled) |
| sign | String | Signature |
Subscription Refund
Brief Description:- Subscription refund
/subscription/refund/apply
Parameters:
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| appId | Yes | Long | Business ID (obtained from the backend, must pass the corresponding business ID according to the currency in the URL) |
| subscriptionNo | Yes | String | Platform subscription ID |
| orderNo | Yes | String | Platform order ID |
| sign | Yes | String | Signature |
| Parameter Name | Type | Description |
|---|---|---|
| orderNo | String | Platform order ID |
| subscriptionNo | String | Platform subscription ID |
| appId | String | Business ID |
| refundNo | String | Refund order ID |
| sign | String | Signature |
2. Asynchronous Notification
Brief Description:- When the customer’s subscription status changes or during a subscription deduction cycle, we will send a callback notification.
Provided by you
Subscription status change callback parameters:
| Parameter Name | Type | Description |
|---|---|---|
| type | String | Fixed value SUBSCRIPTION |
| appId | Long | Business ID |
| currency | String | Currency |
| subscriptionOrderId | String | Merchant subscription ID |
| subscriptionNo | String | Platform subscription ID |
| status | String | Subscription status (-1: Error, 1: Processing, 2: Success, 3: Failed, 4: Canceled) |
| recurringInterval | String | Recurring interval W, M, Y |
| recurringIntervalCount | String | Recurring interval count |
| subject | String | Subscription title |
| sign | String | Signature, (verification required using the business key corresponding to the currency) |
| Parameter Name | Type | Description |
|---|---|---|
| type | String | Fixed value SUBSCRIPTIONS_DEDUCT |
| appId | Long | Business ID |
| currency | String | Currency |
| subscriptionOrderId | String | Merchant subscription ID |
| subscriptionNo | String | Platform subscription ID |
| deductNo | String | Subscription deduction ID |
| orderNo | String | Deduction order ID |
| amount | String | Deduction amount |
| status | Integer | Deduction status (0: Not started, 1: In progress, 2: Success, 3: Failed) |
| startTime | String | Subscription deduction cycle - start time Format: yyyy-MM-dd HH:mm:ss |
| endTime | String | Subscription deduction cycle - end time Format: yyyy-MM-dd HH:mm:ss |
| sign | String | Signature, (verification required using the business key corresponding to the currency) |
3. Test Card Numbers
Simulate successful payment
Use the following test card number, enter any CVC (3 digits) and a valid expiration date (future date) to simulate a successful payment:- Card No. 1: 4242424242424242
Simulate payment failure
Use the following test card number and invalid data to simulate a failed payment:- Card No.1: 4000000000009995
- Invalid month: 13
- Invalid CVV: 99

