If you've found this helpful you can say thank you by buying me a beer
This is a demo of billing using Shopify Remix and has been created to show an idea of adding billing to your app. It has two plans in it that users can select, creates a theme app extension that only renders if a user has an active subscription and allows users to cancel subscriptions.
This package was created by running npm init @shopify/app@latest
You can start this app by installing NPM packages and running npm run dev
Also note: For billing to work your app must be set for public distribution in your partner account otherwise billing will not function even when testing.
This file contains 2 functions.
- getSubscriptionStatus get active subscriptions
- createSubscriptionMetafield create an app metafield with a boolean value
This is the main entry point and shows a screen with current subscription and two subscription options you can subscribe to.
This file has a Remix loader which gets current subscriptions and passes these to the page. This loader also sets the app only metafield based on the subscription status.
This file has a Remix action which is used to process cancelling and subscribing using the Remix billing methods
In this file I have:
- Created 2 billing options which are exported to be available to other apps (MONTHLY_SUBSCRIPTION and ANNUAL_SUBSCRIPTION)
- Added the APP_SUBSCRIPTIONS_UPDATE webhook to the webhooks object which will pass this webhook to /webhooks when it is actioned (e.g. a new subscription is started, subscription is cancelled etc)
In this file we grab the payload from the webhook request and add APP_SUBSCRIPTIONS_UPDATE into the switch statement, perform a check on the subscription status and use our createSubscriptionMetafield method to update the app metafield with the subscription status
This is a very basic shopify app extension which contains the available_if property in the schema which checks the app metafield we created. If the app has an active subscription then the extension is available to the app.
For support please email hello@marktiddy.co.uk