Created
June 10, 2021 17:32
-
-
Save perrupa/eb9d546f82ee70426ca133d8df4abebf to your computer and use it in GitHub Desktop.
Pricing Plan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "isomorphic-fetch"; | |
import { gql } from "apollo-boost"; | |
const PRICING_PLANS = { | |
begginer: { | |
returnUrl: `${process.env.HOST}/getting_started`, | |
planName: "Kenyarlow Beginner Plan", | |
price: 5, | |
}, | |
pro: { | |
returnUrl: `${process.env.HOST}/getting_started`, | |
planName: "Kenyarlow Proffesionals", | |
price: 20, | |
}, | |
premium: { | |
returnUrl: `${process.env.HOST}/premium_getting_started`, | |
planName: "Kenyarlow Gold Member", | |
price: 50, | |
}, | |
}; | |
export function RECURRING_CREATE({ returnUrl, price, planName }) { | |
return gql` | |
mutation { | |
appSubscriptionCreate( | |
name: "${planName}" | |
returnUrl: "${returnUrl}" | |
lineItems: [ | |
{ | |
plan: { | |
appRecurringPricingDetails: { | |
price: { amount: ${price}, currencyCode: USD } | |
} | |
} | |
} | |
# { | |
# plan: { | |
# appUsagePricingDetails: { | |
# cappedAmount: { amount: ${price}, currencyCode: USD } | |
# terms: "$1 for 1000 emails" | |
# } | |
# } | |
# } | |
] | |
) { | |
userErrors { | |
field | |
message | |
} | |
confirmationUrl | |
appSubscription { | |
id | |
} | |
} | |
}`; | |
} | |
export const getSubscriptionUrl = async (ctx) => { | |
const chosenPlan = getPlanFromRequest(ctx) | |
const { client } = ctx; | |
const confirmationUrl = await client | |
.mutate({ | |
mutation: RECURRING_CREATE(PRICING_PLANS[chosenPlan]), | |
}) | |
.then((response) => response.data.appSubscriptionCreate.confirmationUrl); | |
return ctx.redirect(confirmationUrl); | |
}; | |
function getPlanFromRequest() { | |
return 'begginer'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file is originally from the Shopify Demo App.
Original file: https://github.com/Shopify/shopify-app-node/blob/master/server/handlers/mutations/get-subscription-url.js