export const onSuccess = async ({ params, record, logger, api, connections }) => {
const shopifyClient = await connections.shopify.forShopDomain(connections.shopify.currentShop);
logger.info(
{ currentShop: connections.shopify.currentShop },
"Current shop"
);
const response = await shopifyClient.graphql(/* GraphQL */ `
{
appInstallation {
activeSubscriptions {
name
status
lineItems {
plan {
pricingDetails {
... on AppRecurringPricing {
__typename
price {
amount
currencyCode
}
interval
}
}
}
}
test
}
}
}
`);
const planStatus =
response?.data?.appInstallation?.activeSubscriptions?.some(
(sub) => sub.status === "ACTIVE"
);
const appID = await shopifyClient.graphql(/* GraphQL */ `
query {
currentAppInstallation {
id
}
}
`);
const appOwnerId = await appID?.data?.currentAppInstallation?.id;
const writeToMetafield = await shopifyClient.graphql(
/* GraphQL */ `
mutation CreateAppDataMetafield(
$metafieldsSetInput: [MetafieldsSetInput!]!
) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
key
ownerType
type
value
namespace
}
userErrors {
field
message
}
}
}
`,
{
variables: {
metafieldsSetInput: [
{
ownerId: appOwnerId,
namespace: "block_studio",
key: "extension_manager",
value: JSON.stringify(planStatus),
type: "boolean",
},
],
},
}
);
};
export const onSuccess = async ({ params, record, logger, api, connections }) => {
const shopifyClient = await connections.shopify.forShopDomain(connections.shopify.currentShop);
logger.info(
{ currentShop: connections.shopify.currentShop },
"Current shop"
);
const response = await shopifyClient.graphql(/* GraphQL */ `
{
appInstallation {
activeSubscriptions {
name
status
lineItems {
plan {
pricingDetails {
... on AppRecurringPricing {
__typename
price {
amount
currencyCode
}
interval
}
}
}
}
test
}
}
}
`);
const planStatus =
response?.data?.appInstallation?.activeSubscriptions?.some(
(sub) => sub.status === "ACTIVE"
);
const appID = await shopifyClient.graphql(/* GraphQL */ `
query {
currentAppInstallation {
id
}
}
`);
const appOwnerId = await appID?.data?.currentAppInstallation?.id;
const writeToMetafield = await shopifyClient.graphql(
/* GraphQL */ `
mutation CreateAppDataMetafield(
$metafieldsSetInput: [MetafieldsSetInput!]!
) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
key
ownerType
type
value
namespace
}
userErrors {
field
message
}
}
}
`,
{
variables: {
metafieldsSetInput: [
{
ownerId: appOwnerId,
namespace: "block_studio",
key: "extension_manager",
value: JSON.stringify(planStatus),
type: "boolean",
},
],
},
}
);
};