嵌入式应用程序本身在Shopify中加载确认URL

发布于 2025-02-07 12:01:19 字数 1902 浏览 3 评论 0原文

我在Shopify中有一个嵌入式应用程序,该应用程序是一个付费应用程序,一旦用户批准了帐单,我希望该应用在嵌入式应用程序本身中显示确认URL,而是外部加载。

getsubscriptionurl.js

export const getSubscriptionUrl = async (ctx, shop) => {
  const { client } = ctx;
  console.log(`process.env.HOST - ${process.env.HOST}`);
  console.log(`shop - ${shop}`);
  console.log(`${process.env.HOST}/?shop=${shop}`);
  const confirmationUrl = await client
    .mutate({
      mutation: RECURRING_CREATE(),
      variables: {
        returnUrl: `www.abc.com`,
      }
    })
    .then(response => response.data.appSubscriptionCreate.confirmationUrl);
console.log("me "+ confirmationUrl);
  return ctx.redirect(confirmationUrl);
};

server.js

app.prepare().then(async () => {
  const server = new Koa();
  const router = new Router();
  server.keys = [Shopify.Context.API_SECRET_KEY];
  server.use(
    createShopifyAuth({
      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken, scope } = ctx.state.shopify;
        const host = ctx.query.host;
        ACTIVE_SHOPIFY_SHOPS[shop] = {scope:scope,accessToken:accessToken};

        const response = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "APP_UNINSTALLED",
          webhookHandler: async (topic, shop, body) =>
            delete ACTIVE_SHOPIFY_SHOPS[shop],
        });

        if (!response.success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${response.result}`
          );
        }

        // Redirect to app with shop parameter upon auth
        // ctx.redirect(`/?shop=${shop}&host=${host}`);

        server.context.client = await handlers.createClient(shop, accessToken);

        await handlers.getSubscriptionUrl(ctx, shop);
      },
    })
  );

I have an embedded app in shopify which is an paid app ,Once user approves the billing ,i want the app to show the confirmation url in the embedded app itself instead it loads externally.

getsubscriptionurl.js

export const getSubscriptionUrl = async (ctx, shop) => {
  const { client } = ctx;
  console.log(`process.env.HOST - ${process.env.HOST}`);
  console.log(`shop - ${shop}`);
  console.log(`${process.env.HOST}/?shop=${shop}`);
  const confirmationUrl = await client
    .mutate({
      mutation: RECURRING_CREATE(),
      variables: {
        returnUrl: `www.abc.com`,
      }
    })
    .then(response => response.data.appSubscriptionCreate.confirmationUrl);
console.log("me "+ confirmationUrl);
  return ctx.redirect(confirmationUrl);
};

server.js

app.prepare().then(async () => {
  const server = new Koa();
  const router = new Router();
  server.keys = [Shopify.Context.API_SECRET_KEY];
  server.use(
    createShopifyAuth({
      async afterAuth(ctx) {
        // Access token and shop available in ctx.state.shopify
        const { shop, accessToken, scope } = ctx.state.shopify;
        const host = ctx.query.host;
        ACTIVE_SHOPIFY_SHOPS[shop] = {scope:scope,accessToken:accessToken};

        const response = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "APP_UNINSTALLED",
          webhookHandler: async (topic, shop, body) =>
            delete ACTIVE_SHOPIFY_SHOPS[shop],
        });

        if (!response.success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${response.result}`
          );
        }

        // Redirect to app with shop parameter upon auth
        // ctx.redirect(`/?shop=${shop}&host=${host}`);

        server.context.client = await handlers.createClient(shop, accessToken);

        await handlers.getSubscriptionUrl(ctx, shop);
      },
    })
  );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2025-02-14 12:01:19

您不能 基本上显示您的应用程序中的确认URL,Shopify不会相信应用程序开发人员会获取敏感信息,例如付款详细信息,因此必须将确认URL打开新标签,商人正在查看一个shopify付款页面(由Shopify制作),其中包含要输入的付款详细信息,并在确认页面上将将商家重定向到您之前指定的返回URL

为了进行测试目的,

您可以在查询中发送测试参数,以允许您进行测试

const CREATE_SUB_MUTATION_RECURRING_ONLY = gql`
  mutation RecurringSubscription(
    $returnUrl: URL!
    $test: Boolean!
    $planName: String!
    $amount: Decimal!
  ) {
    appSubscriptionCreate(
      test: $test
      name: $planName
      returnUrl: $returnUrl
      lineItems: [
        {
          plan: {
            appRecurringPricingDetails: {
              price: { amount: $amount, currencyCode: USD }
              interval: EVERY_30_DAYS
            }
          }
        }
      ]
    ) {
      userErrors {
        field
        message
      }
      confirmationUrl
      appSubscription {
        id,
        currentPeriodEnd
      }
    }
  }
`;

而无需输入任何付款详细信息即可测试,只需通过true test> test

    result = await graphQlClient?.mutate({
      mutation: CREATE_SUB_MUTATION_RECURRING_ONLY,
      variables: {
        returnUrl,
        test,
        planName: PLANS_DATA[planName].planName,
        amount: PLANS_DATA[planName].price,
      },
    });

You can't basically show the confirmation URL in your app, Shopify won't trust app developers to take sensitive info like payment details, so must open the confirmation URL into a new tab, where the merchant is viewing a Shopify payment page(made by shopify) that contains the payment details to be entered and on confirm the page will redirect the merchant to the return URL as you specified before.

For testing purposes

you can send a test param within the query to allow you to test without entering any payment details

const CREATE_SUB_MUTATION_RECURRING_ONLY = gql`
  mutation RecurringSubscription(
    $returnUrl: URL!
    $test: Boolean!
    $planName: String!
    $amount: Decimal!
  ) {
    appSubscriptionCreate(
      test: $test
      name: $planName
      returnUrl: $returnUrl
      lineItems: [
        {
          plan: {
            appRecurringPricingDetails: {
              price: { amount: $amount, currencyCode: USD }
              interval: EVERY_30_DAYS
            }
          }
        }
      ]
    ) {
      userErrors {
        field
        message
      }
      confirmationUrl
      appSubscription {
        id,
        currentPeriodEnd
      }
    }
  }
`;

Now to test just pass true to test

    result = await graphQlClient?.mutate({
      mutation: CREATE_SUB_MUTATION_RECURRING_ONLY,
      variables: {
        returnUrl,
        test,
        planName: PLANS_DATA[planName].planName,
        amount: PLANS_DATA[planName].price,
      },
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文