How to implement BillingApi subscription in NodeJs React?

ForZe
Shopify Partner
1 0 0

Hello. My application is currently being reviewed and I'm stuck at one stage.

I was asked to add a BillingApi implementation so that during application installation the user is prompted to subscribe.

I'm using the Shopify template on NodeJs React and noticed that their setup for the Billing Api simply doesn't work. Therefore, I created middleware with verification and redirect to the subscription page

The problem is that I have the isTest flag, which is disabled on the production server, but somehow Shopify support turned on the test mod during testing, and although they “pay for the subscription,” my middleware does not see this and redirects back to the payment page

export const validateSubscription = async (req, res, next) => {
  const plans = Object.keys(billingConfig)
  const session = res.locals.shopify.session
  const hasPayment = await shopify.api.billing.check({
    session,
    plans: plans,
    isTest: process.env.NODE_ENV !== 'production',
  })

  if (hasPayment) {
    next()
  } else {
    shopify.redirectOutOfApp({
      req,
      res,
      redirectUri: await shopify.api.billing.request({
        session: res.locals.shopify.session,
        plan: plans[0],
        isTest: process.env.NODE_ENV !== 'production',
      }),
      shop: shopify.api.utils.sanitizeShop(res.locals.shopify.session.shop),
    })
  }
}



Replies 0 (0)