Chargebee API calls during the onboarding flow
-
First call to GET /api/v2/subscription/plan to get the plans' data on the pwyw/checkout step and a call to the Chargebee script:
https://js.chargebee.com/v2/chargebee.jsto load it on the frontend. -
On starting purchasing, a call to POST /api/v2/subscription/paymentIntent happens. During that call, a few internal Chargebee APIs are called:
- POST card_bin:
https://fabulous-test.chargebee.com/api/internal/card_bin - POST get_gw_payment_method_config:
https://fabulous-test.chargebee.com/api/internal/payment_intents/get_gw_payment_method_config - POST tokens:
https://api.stripe.com/v1/tokens - GET retrieve_config:
https://fabulous-test.chargebee.com/api/internal/component/retrieve_config - GET deploy_status_henson.json:
https://js.stripe.com/v3/.deploy_status_henson.json - POST
https://api.hcaptcha.com/getcaptcha/20000000-ffff-ffff-ffff-000000000002 - POST confirm:
https://fabulous-test.chargebee.com/api/internal/payment_intents/confirm - POST
https://m.stripe.com/6 - POST
https://r.stripe.com/b
- POST card_bin:
-
A call to POST /api/v2/subscription comes next, where the backend interacts with the Chargebee interface:
-
Get the user’s account to check if the user already has active subscriptions.
-
const {list} = await chargebee.customer.list({
'email[is]': email
}).request();
-
-
-
First, check for/get the user’s account (Retrieve Customer API)
-
Create a new customer account (Create Customer API) if it doesn’t exist- with the customer data; e.g,
accountCode,email,country,paymentIntentId.- If
paymentIntentIdexists, create a payment source usingpaymentIntentId(Chargebee API) - If
paypalNonceexists, create a payment source usingpaypalNonce(Chargebee API) - If
googlePayTokenexists, create a payment source usinggooglePayToken. (Chargebee API)
- If
-
Then, create the subscription based on the data collected about the plan and the user.
chargebee.subscription.create_with_items(customerId, data) -
Save the trail length as a custom field (Chargebee API)
chargebee.subscription.update_for_items(subscriptionId, {
'cf_trial_period_days': trialPeriodInDays
})
-
-
For PayPal users:
- Get PayPal email to check for any other active subscriptions.
- terminateAllSubscriptions if any active subscriptions with different account codes are found
-