A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi!
Please shed some light on Billing configurations for the apps in shopify-cli 3.0 node template.
1. How to create different billing plans
2. How to redirect to Shopify billing page once the merchants choose the plan from our pricing page.
3. How to redirect to our Pricing page once the app is installed.
Hey @Sharan_oapps,
Just wanted to share a few things after taking a closer look at the questions asked concerning app billing.
While the Shopify CLI is a great tool for quickly scaffolding apps from our various templates, generating extensions, managing theme development and even custom storefronts, the examples apps are meant to offer a staring point and likely require additional development to achieve intended functionality. Any feedback about those sample apps generated with the CLI or the corresponding API libraries (eg. Node.js, PHP, Ruby), please consider opening an issue in their official Github repos directly.
Lastly, it is always a good idea keeping an eye here in these forums for any related threads or replies back from other community members - Cheers!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
@ShopifyDevSup Hello !
I am stuck in enabling billing. Actually, I want to enable recurring billing for my app but it does not enable yet I apply the solution you tell above by providing a link but it didn't work for me please can you tell me how can I enable billing for Every30Days?
Node js Template contains Shopify.js file which has the following code :
Hey @syedusama0786 - thanks for reaching out. Our team was able to do some testing, and your input should work to set up a recurring subscription. This guide here is for single usage charges, but the configuration should work the same way for recurring subscriptions, so I wanted to share it with you. I'd also recommend taking a look here at our md doc for billing request configs via Node.js specifically - this may help get you set up.
Could you let us know if you're still encountering errors after you've reviewed the links above? If you're still seeing errors, just respond back here with any specific error messages or an X-Request-ID you receive from any related API responses and we can investigate further.
Hope this helps!
Al | Shopify Developer Support
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This works when the session is created and asks for the billing to be activated, but if the admin of the store clicks Cancel he can easily continue to use the current app session with no billing activated.
What is the fix for that? The only way I could go about this was to check in every API that the billing is accepted. Is there a better way?
@ovidiucaramida I am also facing the same issue in this. you got any solution or not ?
This works when the session is created and asks for the billing to be activated, but if the admin of the store clicks Cancel he can easily continue to use the current app session with no billing activated.
What is the fix for that? The only way I could go about this was to check in every API that the billing is accepted. Is there a better way?
I didn't find a solution. I just added a middleware and used that on every API request
So for me the solution is:
- Create a middleware to check actual Plan and secure some routes
const hasPayment = await shopify.api.billing.check({
session,
plans: plans,
isTest: true,
});
const response = await shopify.api.rest.RecurringApplicationCharge.all({
session: res.locals.shopify.session,
});
- You can create an api route to check that from react and redirect user to a dedicated page to select a plan.
- When user has a plan you can set an app-metafield
//Set Plan Metafield
const client = new shopify.api.clients.Graphql({ session })
try {
const response = await client.query({
data: {
query: `query {
currentAppInstallation {
id
}
}`
}
})
const appInstallationId = response.body.data.currentAppInstallation.id
await client.query({
data: {
query: `mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
id
namespace
key
}
userErrors {
field
message
}
}
}`,
variables: {
"metafieldsSetInput": [
{
"namespace": "applicationInstallation",
"key": "hasPlan",
"type": "boolean",
"value": `${hasPlan.toString()}`,
"ownerId": `${appInstallationId}`
}
]
},
},
});
- If you use theme extension you can use available_if of schema
I tried to implement Billing in this same way but its giving me error can ypu please help me?