export async function requestBilling(res, next) {
const plans = Object.keys(billingConfig);
const session = getCurrentSession(res);
const hasPayment = await shopify.api.billing.check({
session,
plans: plans,
isTest: true ,
});
if (hasPayment) {
next();
} else {
res.redirect(
await shopify.api.billing.request({
session,
plan: plans[0],
isTest: true,
},
{
session,
plan: plans[1],
isTest: true,
}
)
);
}
}
export const billingConfig = {
“My plan1”: {
amount: 100.0,
currencyCode: “USD”,
interval: BillingInterval.Every30Days,
trialDays: 30
}
};
Following this documentation page Javascript shopify.billing.request → Multi-plan setup - charge based on user selection you have to let the user select the plan he wants before calling shopify.api.billing.request
app.get('/auth/callback', async () => {
const callback = await shopify.auth.callback({
rawRequest: req,
rawResponse: res,
});
// Check if we require payment, using shopify.billing.check()
const confirmationUrl = await shopify.billing.request({
session: callback.session,
plan: 'My billing plan',
isTest: true,
});
res.redirect(confirmationUrl);
});
Does it help?
Hello @snakecase ,
Thank you for providing a solution to my question. I appreciate your assistance. Additionally, I have a few more questions.
As per documentation we need to create a post api `/api/select-plan`.
1. Do we need to create the UI for select-plan api?
2. We are using RecurringApplicationCharge API of shopify.
[https://shopify.dev/docs/api/admin-rest/2023-04/resources/recurringapplicationcharge](https://shopify.dev/docs/api/admin-rest/2023-04/resources/recurringapplicationcharge),)
what is the preferred way?
Do we need to call the shopify.billing.request API or are we correct here ?
3. Can we call the shopify.billing.request API multiple time?
4. How to handle trial days with shopify.billing.request API
I’m going to try to respond as best as I can:
-
I’m not aware of any built-in UI for that, so I would reply yes, you do need to create the UI. Maybe someone else going through this thread can add an input?
-
We are not using the Javascript framework but from my reading of the code you should use shopify.billing.request. This request under the hood call the right endpoint (cf. shopify-api-js/lib/billing/request.ts)
-
I don’t see why you should do. I think it should be avoided.
-
Trial days are one more parameter to add to you call to shopify.billing.request. cf. code shopify-api-js/lib/billing/types.ts)
I hope it is going to help you.
1 Like