App reviews, troubleshooting, and recommendations
After searching for days on how to redirect the customer from the app to the checkout subscription page when browsing the app or pressing a button, I discovered the appSubscriptionCreate mutation to create a charge. But after many attempts I get a 500 error when I try to create a subscription and I don't know if I'm missing something. I tried to set test: true but I still get the same error. Any ideas? Thanks.
Also, does anyone know how to return the url of the application in returnUrl?
This is the code I have been using to create a charge, does anyone see any errors?
Shopify.js file configuration:
import { LATEST_API_VERSION } from "@shopify/shopify-api";
import { shopifyApp } from "@shopify/shopify-app-express";
import { SQLiteSessionStorage } from "@shopify/shopify-app-session-storage-sqlite";
import { restResources } from "@shopify/shopify-api/rest/admin/2023-01";
import { billingConfig } from "./billing.js";
const DB_PATH = `${process.cwd()}/database.sqlite`;
const shopify = shopifyApp({
api: {
apiVersion: LATEST_API_VERSION,
restResources,
billing: billingConfig,
},
auth: {
path: "/api/auth",
callbackPath: "/api/auth/callback",
},
webhooks: {
path: "/api/webhooks",
},
sessionStorage: new SQLiteSessionStorage(DB_PATH),
});
export default shopify;
Billing.js file configuration:
import { BillingInterval, BillingReplacementBehavior, GraphqlQueryError, ApiVersion } from "@shopify/shopify-api";
import shopify from "./shopify.js";
export const billingConfig = {
"My Shopify Charge": {
amount: 5.0,
currencyCode: "USD",
trialDays: 15,
interval: BillingInterval.Every30Days,
replacementBehavior: BillingReplacementBehavior.ApplyImmediately
},
};
const CREATE_SUBSCRIPTION_RECORD = `
mutation appSubscriptionCreate($lineItems: [AppSubscriptionLineItemInput!]!, $name: String!, $returnUrl: URL!, $trialDays: Int, $test: Boolean) {
appSubscriptionCreate(lineItems: $lineItems, name: $name, returnUrl: $returnUrl, trialDays: $trialDays, test: $test) {
appSubscription {
id
}
confirmationUrl
userErrors {
field
message
}
}
}
`;
export async function createSubscriptionRecord(session, req) {
let response = {}
try {
const client = new shopify.api.clients.Graphql({ session });
response = await client.query({
data: {
query: CREATE_SUBSCRIPTION_RECORD,
variables: {
lineItems: [
{
plan: {
appRecurringPricingDetails: {
price: {
amount: 10,
currencyCode: "USD"
},
interval: "EVERY_30_DAYS"
}
}
}
],
name: Object.keys(billingConfig)[0],
returnUrl: shopify.utils.sanitizeShop(req.query.shop, true),
trialDays: 15,
test: true
},
},
});
console.log(response);
} catch (error) {
if (error instanceof GraphqlQueryError) {
throw new Error(
`${error.message}\n${JSON.stringify(error.response, null, 2)}`
);
} else {
throw error;
}
}
return response;
}
Solved! Go to the solution
This is an accepted solution.
After a lot of research I realized that the problem was the "returnUrl", now it was working correctly.
This is an accepted solution.
After a lot of research I realized that the problem was the "returnUrl", now it was working correctly.
please guide returnUrl correct format i'm also facing issue in subscription with 7 days trail using
mutation appSubscriptionCreate
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025