Build subscriptions integration
Card
CARD BRAND | Popular country / region | Subscription |
---|---|---|
Visa | Global | ✅ |
Mastercard | Global | ✅ |
Wallets
Payment methods | Popular country / region | Subscription | Processing currency |
---|---|---|---|
Alipay | China | ✅ | CNY,GBP,USD,EUR,HKD |
AlipayHK | Hong Kong | ✅ | HKD,GBP,USD,EUR |
Boost | Malaysia | ✅ | MYR,GBP,USD,EUR |
DANA | Indonesia | ✅ | IDR,GBP,USD,EUR |
GCash | Philippines | ✅ | PHP,GBP,USD,EUR |
KakaoPay | South Korea | ✅ | KRW,GBP,USD,EUR |
Touch'n Go | Malaysia | ✅ | MYR,GBP,USD,EUR |
TrueMoney | Thailand | ✅ | THB,GBPUSD,EUR |
What you’ll build
1.Create the pricing model
{
"currency": "USD",
"product_data": {
"name":"Plus plan"
},
"unit_amount": 1000,
"active": true,
"recurring": {
"interval": "month",
"interval_count": 1
}
}
{
"id": "price_1795818288165421056",
"object": "price",
"created": 1716991419000,
"livemode": false,
"active": true,
"currency": "USD",
"product": {
"id": "prod_1795818288173809664",
"object": "product",
"created": 1716991419000,
"livemode": false,
"active": true,
"name": "Plus plan",
"updated": 1716991419000
},
"type": "recurring",
"recurring": {
"interval": "month",
"interval_count": 1,
"usage_type": "licensed"
},
"unit_amount": 1000,
"billing_scheme": "per_unit"
}
2. Create a Checkout Session
success_url
, a page on your website that Checkout returns your customer to after they complete the paymentcancel_url
, a page on your website that Checkout returns your customer to if they cancel the payment process.{
"mode": "subscription",
"success_url": "https://yourwebsite.com",
"line_items": [
{
"quantity": 1,
"price":"price_1795818288165421056"
}
]
}
{
"id": "cs_1796010789673369600",
"object": "checkout.session",
"created": 1717037315000,
"livemode": false,
"currency": "USD",
"customer": "",
"mode": "subscription",
"status": "open",
"url": "https://checkouttest.wooshpay.com/pay/cs_test_1796010789673369600?key=cGtfdGVzdF9OVEUzTWpFME9UUXpOalkyTkRrNU56ZzRPREV4T2pGbFJWaDNXWGxSTTBReE0wRnBkRmhZUm14T1JqTTBWVEUyT1RreU56RXlNVFU0T0RZ",
"line_items": {
"object": "list",
"data": [
{
"id": "li_1796010789715312640",
"object": "item",
"currency": "USD",
"description": "Plus plan",
"price": {
"id": "price_1795818288165421056",
"object": "price",
"created": 1716991419000,
"livemode": false,
"active": true,
"currency": "USD",
"product": {
"id": "prod_1795818288173809664",
"object": "product",
"created": 1716991419000,
"livemode": false,
"active": true,
"name": "Plus plan",
"updated": 1716991419000
},
"type": "recurring",
"recurring": {
"interval": "month",
"interval_count": 1,
"usage_type": "licensed"
},
"unit_amount": 1000,
"billing_scheme": "per_unit"
},
"quantity": 1,
"amount_subtotal": 1000,
"amount_total": 1000
}
]
},
"payment_intent": "pi_1796010789782421504",
"payment_method_types": [
"card"
],
"payment_status": "unpaid",
"success_url": "https://baidu.com",
"amount_subtotal": 1000,
"amount_total": 1000,
"billing_address_collection": "auto",
"expires_at": 1717123715183,
"payment_link": "",
"client_secret": "pi_1796010789782421504_secret_VpKljsEZq43gYYmetS1gHh03",
"customer_creation": "if_required",
"total_details": {
"amount_discount": 0
}
}
3. Provision and monitor subscriptions
1.
success_url
, which initiates a checkout.session.completed
webhooks.2.
checkout.session.completed
event, you can provision the subscription.3.
invoice.paid
events.4.
invoice.payment_failed
event, notify your customer that the subscription has failed.invoice.paid
. Store the subscription.id
and customer.id
event objects in your database for verification.{
"url": "https://apitest.wooshpay.com/v1/receives",
"description": "I am description",
"enabled_events": [
"checkout.session.completed",
"invoice.payment_failed",
"invoice.paid",
"payment_intent.succeeded",
"customer.created",
"customer.subscription.updated",
"customer.subscription.created"
]
}
EVENT NAME | DESCRIPTION |
---|---|
checkout.session.completed | Sent when a customer clicks the Pay or Subscribe button in Checkout, informing you of a new purchase. |
invoice.paid | Sent each billing interval when a payment succeeds. |
invoice.payment_failed | Sent each billing interval if there is an issue with your customer’s payment method. |
Delay payments on active subscriptions using trial periods.
trial_period_days
parameter: an integer representing the number of days the trial lasts, from the current moment.{
"mode": "subscription",
"success_url": "https://yourwebsite.com",
"subscription_data":{
"trial_period_days":"1"
},
"line_items": [
{
"quantity": 1,
"price_data": {
"currency": "EUR",
"unit_amount": 15100,
"recurring": {
"interval": "weekly",
"interval_count": 1
},
"product_data": {
"name": "Shit",
"description": "tsetsetdescription1112",
"images": [
"https://appletservice.oss-cn-hangzhou.aliyuncs.com/checkout_0517/Snipaste_2023-08-10_16-35-10.png"
]
}
}
}
]
}
Add discounts to subscriptions and subscription items using coupons
1.
{
"percent_off" :20,
"duration":"once",
"name" : "TEST 20% off"
}
discounts
parameter in the API. To create a session with an applied discount, pass the coupon ID in the coupon
parameter of the discounts
array. This coupon overrides any coupon on the customer.{
"mode": "subscription",
"success_url": "https://yourwebsite.com",
"line_items": [
{
"quantity": 1,
"price":"price_1795818288165421056"
}
],
"discounts":[{
"coupon":"coupon_1866449681802854400"
}]
}
2.
{
"percent_off" :20,
"duration":"forever",
"name" : "TEST 20% off"
}
iterations
parameter indicates how many billing cycles the discount applies to in the subscription.{
"mode": "subscription",
"success_url": "https://yourwebsite.com",
"line_items": [
{
"quantity": 1,
"price":"price_1795818288165421056"
}
],
"discounts":[{
"coupon":"coupon_1866449681802854400",
"iterations":2
}]
}
Test Your Integration
{
"currency": "USD",
"product_data": {
"name":"Plus plan"
},
"unit_amount": 1000,
"active": true,
"recurring": {
"interval": "test_minute",
"interval_count": 5
}
}
{
"mode": "subscription",
"success_url":"https://yourwebsite.com",
"cancel_url":"https://yourwebsite.com"
"line_items": [
{
"quantity": 1,
"price":"price_XXXXXXXX"
}
]
}
{
"id": "cs_1796162148158668800",
"object": "checkout.session",
"created": 1717073402000,
"livemode": false,
"currency": "USD",
"customer": "",
"mode": "subscription",
"status": "open",
"url": "https://checkouttest.wooshpay.com/pay/cs_test_1796162148158668800?key=cGtfdGVzdF9OVEUzTWpFME9UUXpOalkyTkRrNU56ZzRPREV4T2pGbFJWaDNXWGxSTTBReE0wRnBkRmhZUm14T1JqTTBWVEUyT1RreU56RXlNVFU0T0RZ",
"line_items": {
"object": "list",
"data": [
{
"id": "li_1796162148209000448",
"object": "item",
"currency": "USD",
"description": "Plus plan",
"price": {
"id": "price_1796162090960945152",
"object": "price",
"created": 1717073388000,
"livemode": false,
"active": true,
"currency": "USD",
"product": {
"id": "prod_1796162090981916672",
"object": "product",
"created": 1717073388000,
"livemode": false,
"active": true,
"name": "Plus plan",
"updated": 1717073388000
},
"type": "recurring",
"recurring": {
"interval": "month",
"interval_count": 1,
"usage_type": "licensed"
},
"unit_amount": 1000,
"billing_scheme": "per_unit"
},
"quantity": 1,
"amount_subtotal": 1000,
"amount_total": 1000
}
]
},
"payment_intent": "pi_1796162148305469440",
"payment_method_types": [
"card"
],
"payment_status": "unpaid",
"success_url": "https://yourwebsite.com",
"amount_subtotal": 1000,
"amount_total": 1000,
"billing_address_collection": "auto",
"expires_at": 1717159801859,
"payment_link": "",
"client_secret": "pi_1796162148305469440_secret_zATcpA9yn8FObbcBwsbtHenl",
"customer_creation": "if_required",
"total_details": {
"amount_discount": 0
}
}
Card Number | 4000020951595032 |
---|---|
Card Holder Name | FL-BRW1 |
Expiration Month | 12 |
Expiration Year | 25 |
CVV | 217 |
Modified at 2024-12-26 07:57:44