Building a new app. I’ve got a button that does the following:
-
Creates a new product
-
Creates a variant on new product
-
Creates a new selling plan group.
-
Assigns the subscription selling plan group to the variant.
All of these things seem to happen successfully. In the Dawn theme, I’ve added a variant selector. When I pick the variant with the recurring subscription plan assigned to it and checkout, there is no indication that the subscription has successfully started. As far as I can tell, its a one-time purchase.
My question is this:
1) how can I tell if the subscription has been successfully started (aside from waiting 24hrs to see if its renewed)?
2) Beyond simply submitting the variant with the subscription assigned to it, is there more I need to submit to checkout to initiate a successful subscription?
export async function action({ request }) {
const { admin } = await authenticate.admin(request);
const productResponse = await admin.graphql(`mutation {
productCreate(input: {
title: "Sweet new productzzY",
productType: "TEST Product",
vendor: "JadedPixel",
options: ["Interval"]
}) {
product {
id
options {
id
name
}
}
}
}`,
);
// Convert the response into JSON
const productData = await productResponse.json();
const productId = productData.data.productCreate.product.id;
const variantResponse = await admin.graphql(`
mutation {
productVariantCreate(input: {
productId: "`+productId+`",
price: "39.99",
options: ["1 Week"],
sku: "UNIQUE-SKU",
title: "New Variant Title"
}) {
productVariant {
id
}
userErrors {
field
message
}
}
}
`);
const variantData = await variantResponse.json();
const variantId = variantData.data.productVariantCreate.productVariant.id;
const planResponse = await admin.graphql(`
mutation {
sellingPlanGroupCreate(input: {
name: "Subscribe and save",
merchantCode: "subscribe-and-save",
options: ["Delivery every"],
position: 1,
sellingPlansToCreate: [
{
name: "Delivered every week",
options: "1 Day",
position: 1,
category: SUBSCRIPTION,
billingPolicy: {
recurring: {
interval: DAY,
intervalCount: 1,
anchors: { type: WEEKDAY, day: 1 }
}
},
deliveryPolicy: {
recurring: {
interval: DAY,
intervalCount: 1,
anchors: { type: WEEKDAY, day: 1 },
preAnchorBehavior: ASAP,
cutoff: 0,
intent: FULFILLMENT_BEGIN
}
},
pricingPolicies: [
{
fixed: {
adjustmentType: PERCENTAGE,
adjustmentValue: { percentage: 15.0 }
}
}
]
}
]
}) {
sellingPlanGroup {
id
}
userErrors {
field
message
}
}
}
`);
const planData = await planResponse.json();
const planId = planData.data.sellingPlanGroupCreate.sellingPlanGroup.id;
// Logging the JSON to see the structure
const planAssocResponse = await admin.graphql(`
mutation {
sellingPlanGroupAddProductVariants(id: "`+planId+`", productVariantIds: ["`+variantId+`"]) {
userErrors {
field
message
}
}
}
`);

