Skip to content

Instantly share code, notes, and snippets.

@nutterbrand
Created January 4, 2021 01:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
server/getSubscriptionUrl.js
const getSubscriptionUrl = async (ctx, accessToken, shop) => {
const query = JSON.stringify({
query: `mutation {
appSubscriptionCreate(
name: "Super Duper Plan"
returnUrl: "${process.env.HOST}"
test: true
lineItems: [
{
plan: {
appRecurringPricingDetails: {
price: { amount: 10, currencyCode: USD }
}
}
}
]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}`,
});
const response = await fetch(
`https://${shop}/admin/api/2019-10/graphql.json`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": accessToken,
},
body: query,
}
);
const responseJson = await response.json();
const confirmationUrl =
responseJson.data.appSubscriptionCreate.confirmationUrl;
return ctx.redirect(confirmationUrl);
};
module.exports = getSubscriptionUrl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment