Overview

If your business model requires the amount to be dynamic and does not have a fixed billing cycle, you can use the “save card” feature of the recurring billing.

This API integration includes 4 Steps

Create a Recurring Billing

Create a recurring billing with “save card” configuration

Present the Checkout UI

Present the checkout user interface to the customer for subscription confirmation

Charge the saved card

Call the charge card API to charge the saved card

Step 1 - Save card for billing

NOTE: Similar API as creating a recurring billing with save_card set to true, plan_id should be null and start_date is not required.

HTTP Request

POST https://api.sandbox.hit-pay.com/v1/recurring-billing

Query Parameters

Mandatory fields are name, customer_email, and amount. Remember to include the header Content-Type: application/x-www-form-urlencoded.

ParameterDescriptionExample
namePlan nameSpotify Premium
descriptiondescription of the planSpotify Membership
save_cardSave the card to charge the customer latertrue
customer_emailCustomer emailpaul@hitpayapp.com
customer_nameCustomer namePaul
amountAmount related to the recurring billing9.90
currencyCurrency related to the recurring billingSGD
payment_methods[]Choice of payment methods you want to offer the customer. Default value is cardgiro, card
redirect_urlURL 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 alonghttps://spotify.com/subscription-completed
referenceArbitrary reference number that you can map to your internal reference number. This value cannot be edited by the customerXXXX123
webhookOptional URL value to which hitpay will send a POST request when there is a new charge or if there is an error charging the cardhttps://webhoo.site/test
send_emailHitpay to send email receipts to the customer. Default value is falsetrue
curl --location --request POST 'https://api.staging.hit-pay.com/v1/recurring-billing' \
--header 'X-BUSINESS-API-KEY: meowmeowmeow' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=Spotify Premium' \
--data-urlencode 'description=Spotify Membership' \
--data-urlencode 'save_card=true' \
--data-urlencode 'customer_email=paul@hitpayapp.com' \
--data-urlencode 'customer_name=Paul' \
--data-urlencode 'amount=9.90' \
--data-urlencode 'currency=SGD' \
--data-urlencode 'payment_methods[]=giro' \
--data-urlencode 'payment_methods[]=card' \
--data-urlencode 'redirect_url=https://spotify.com/subscription-completed' \
--data-urlencode 'reference=cust_id_123' \
--data-urlencode 'webhook=https://webhoo.site/test' \
--data-urlencode 'send_email=true'

Response

{
    "id": "9741164c-06a1-4dd7-a649-72cca8f9603a",
    "business_recurring_plans_id": "",
    "customer_name": "Paul",
    "customer_email": "paul@hitpayapp.com",
    "name": "Spotify Premium",
    "description": "Spotify Membership",
    "reference": "cust_id_123",
    "cycle": "save_card",
    "cycle_repeat": null,
    "cycle_frequency": null,
    "currency": "sgd",
    "amount": 9.90,
    "times_to_be_charged": 3,
    "times_charged": 0,
    "status": "scheduled",
    "send_email": false,
    "save_card": 1,
    "redirect_url": "https://github.com/",
    "payment_methods": [
        "giro",
        "card"
    ],
    "created_at": "2022-09-13T16:33:47",
    "updated_at": "2022-09-13T16:33:47",
    "expires_at": null,
    "url": "https://securecheckout.staging.hit-pay.com/9673bdea-058c-44b5-a957-845a7c487bc2/recurring-plan/9741164c-06a1-4dd7-a649-72cca8f9603a",
    "webhook": "https://webhoo.site/test"
}

Step 2 - Redirect customer to recurring billing page (One time set up)

Redirect the customer to the “url” value.

Once the customer enters the payment information, the card will be saved and you can charge the card anytime using the charge the saved card API.

Step 3 - Charge the saved card

Once the card is saved you can charged the card anytime using the following endpoint

HTTP Request

POST https://api.sandbox.hit-pay.com/v1/charge/recurring-billing/{recurring-billing-id}

recurring-billing-id is the id value from step 1 response.

Query Parameters

ParameterDescriptionExample
currencyCurrency related to the recurring billingSGD
amountAmount related to the recurring billing9.90
curl --location --request POST 'https://api.sandbox.hit-pay.com/v1/charge/recurring-billing/{recurring_billing_id}' \
--header 'X-BUSINESS-API-KEY: meowmeowmeow' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI4YjdiYzdhYS1iZGUxLTQzODAtYjQ5ZS03ZjFiYWViOGMzY2UiLCJqdGkiOiJjYTA4NjVmMjMxYzA2Yjg2NTY5ODc1ZTFkNjVlMmUwM2EwMmI1ZDcxZTBiMTEwMWUwYzE4Y2Y3NWU2ZjYwZmM0MTIxYmVkMTExZWI4YjRlZSIsImlhdCI6MTY2MzExNzUxOCwibmJmIjoxNjYzMTE3NTE4LCJleHAiOjE2OTQ2NTM1MTcsInN1YiI6IjkwMjdjYTRkLTBhYmItNDk2NC04MzIxLTQ0NWQ0YjMyNzY5NCIsInNjb3BlcyI6W119.VfQoR_luqIZKSBTEXMv_srTVRApk9OfimbX_ghmRkCjrnvZUm-gCSHUbVnBUSzUcjRbVs-rCFs5wKZX4V0bL_76_WqBwxmNzsxRFf-QXFHSt1dDG7TnH6OSduHFeI-6akfQX0DGqal2pStz-UQY07lUiJ_aRe6QnvYqKZaA_eKsAn5XnEo0vn92mk8_i9KTxhvPH85qinfpg23-j3RJNlTDXeRWPn7CmufsrFfdRGtDL2h2thyqEQvju47XAM_Nyar2IjHw_ZcT9ZWnS7sskSwrsrBmOvjSuHA-ANr55ufc11GwjdRyzBPLu3SOUJ8kHJnprdep70VIpYLtO_nKG1xMzJRJzSno-Hvhn7RzjT-xpSudfUzRKb6M9z_BVmSQ8eUfuigwcmadH-pAFP67noNQAL5zeOjlr4RXGRKoMdeOOM4hxciojZRqoiBT-i74aAHg0AAlJHx4NQnM4LcDkN_Sh0kK4Ip4BHZHuxE4t9CZ24erizjXcdwvzv0UG0QCYRSfWN41PcHTbljDXQWmV719PDtPVwoAb1Ht2EKzuAQ4umuLx6NzOpBFuXpElZfwVT9XoDr22Dwts-7cW2fqj_C6igptqoAeRuCGEejDRgq2dA-UJTpRxfi6J02XXKpeDv-hGyFCYE8TUHBqTg5HMRQeHtga3-Hq05IPFhp9fmyk' \
--data-urlencode 'amount=9.90' \
--data-urlencode 'currency=SGD

Response

{
    "payment_id": "9746f906-bdbb-4064-8372-642cf5877e0c",
    "recurring_billing_id": "9746f8c2-2b7c-4c78-8832-012f203ae687",
    "amount": 9.90,
    "currency": "sgd",
    "status": "succeeded"
}

Congrats! You have now successfully completed the recurring billing integration by saving the card.

FAQs