-
Notifications
You must be signed in to change notification settings - Fork 393
/
get-subscription-url.js
50 lines (47 loc) · 1.17 KB
/
get-subscription-url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import "isomorphic-fetch";
import { gql } from "apollo-boost";
export function RECURRING_CREATE(url) {
return gql`
mutation {
appSubscriptionCreate(
name: "Super Duper Plan"
returnUrl: "${url}"
test: true
lineItems: [
{
plan: {
appUsagePricingDetails: {
cappedAmount: { amount: 10, currencyCode: USD }
terms: "$1 for 1000 emails"
}
}
}
{
plan: {
appRecurringPricingDetails: {
price: { amount: 10, currencyCode: USD }
}
}
}
]
) {
userErrors {
field
message
}
confirmationUrl
appSubscription {
id
}
}
}`;
}
export const getSubscriptionUrl = async ctx => {
const { client } = ctx;
const confirmationUrl = await client
.mutate({
mutation: RECURRING_CREATE(process.env.HOST)
})
.then(response => response.data.appSubscriptionCreate.confirmationUrl);
return ctx.redirect(confirmationUrl);
};