Solved

How can I add recurring charge to my Shopify app

Ridzz
Shopify Partner
11 2 0

Hi, 

I am developing a Shopify app and looking to add a recurring charge of just 1 USD every month. I just want to add one plan and I am unable to find a proper step by step guide to get this. I followed https://workshops.shopify.dev/workshops/usage-billing#4 and now I can see the app is asking for approval when I try to install my app. But I am able to access my app even after I click on cancel button.


Here is the code I added in my code [index.js]

import { BillingInterval } from "@shopify/shopify-api";

export const billingConfig = {
  "Monthly charge": {
    amount: 1.00,
    currencyCode: "USD",
    interval: BillingInterval.Every30Days,
    usageTerms: "One euro per button click",
  },
};

app.get(
  shopify.config.auth.callbackPath,
  shopify.auth.callback(),
  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: true,
    });

    if (hasPayment) {
      next();
    } else {
      res.redirect(
        await shopify.api.billing.request({
          session,
          plan: plans[0],
          isTest: true,
        }),
      );
    }
  },
  shopify.redirectToShopifyOrAppRoot()
);
 
Can someone please help me understand how to add recurring charge for my app code ?

 

Accepted Solution (1)

Ridzz
Shopify Partner
11 2 0

This is an accepted solution.

I can resolve this issue by utilizing Shopify's Recurring Charge REST APIs after app charge is approved or cancel.
By monitoring the status of the recurring charge using API, I can dynamically enable or disable my app features accordingly. I believe this is the most suitable approach for addressing the issue.

View solution in original post

Reply 1 (1)

Ridzz
Shopify Partner
11 2 0

This is an accepted solution.

I can resolve this issue by utilizing Shopify's Recurring Charge REST APIs after app charge is approved or cancel.
By monitoring the status of the recurring charge using API, I can dynamically enable or disable my app features accordingly. I believe this is the most suitable approach for addressing the issue.