Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Billing API access in proxy requests #469

Closed
rkbhochalya opened this issue Oct 15, 2023 · 4 comments
Closed

Billing API access in proxy requests #469

rkbhochalya opened this issue Oct 15, 2023 · 4 comments
Labels

Comments

@rkbhochalya
Copy link

rkbhochalya commented Oct 15, 2023

I'm working on an app that handles proxy requests from the shop frontend. The authenticate.public.appProxy function is very handy in validating these requests.

However, I need access to the billing API in order to set a limit on the number of such requests based on the active plan. Ideally, UnauthenticatedAdminContext could provide this access. This would be beneficial, particularly for cases where I'm not handling an admin request from Shopify, such as in listing shops with their current plan in an internal dashboard.

Alternatively, having the ability to access the shopifyApi interface from the remix app would also be acceptable.

Any workarounds for this issue would be greatly appreciated.

@byrichardpowell
Copy link
Contributor

Hey @rkbhochalya 👋

Thanks for opening an issue, and sorry we are missing this functionality.

Please could you explain your use case? 2 questions to help me understand:

  1. I assume that you need billing.require(), but because this is a request from the storefront, you could not use billing.cancel() or billing.request()?
  2. What would you do if the shop does not have the correct billing setup? Would that be a 401 response?

I think we could add something here, but I need to look into it. E.g:

const {billing} = authenticate.public.appProxy(request)

await billing.require({
  plans: ["MONTHLY_PLAN"],
  isTest: true,
  onFailure: async () => throw new Response(401) ,
});

Would this work?

In the meantime, so you are unblocked, you can you the admin GraphQL API to perform the same check yourself. This is the query that the Remix template uses under the hood:

  query appSubscription($endCursor: String) {
    currentAppInstallation {
      activeSubscriptions {
        id
        name
        test
      }

      oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {
        edges {
          node {
            id
            name
            test
            status
          }
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  }

Just to set expectations, since there is a workaround and we haven't got many requests for this, it might be a while until we get to this.

Copy link
Contributor

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the Stale label Dec 23, 2023
Copy link
Contributor

github-actions bot commented Jan 6, 2024

We are closing this issue because it has been inactive for a few months.
This probably means that it is not reproducible or it has been fixed in a newer version.
If it's an enhancement and hasn't been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

@github-actions github-actions bot closed this as completed Jan 6, 2024
@tomoyanakano
Copy link

tomoyanakano commented Jul 30, 2024

I also need this function. In my case, it is required for validating app subscription for Theme App Extension.

const {billing} = authenticate.public.appProxy(request)

const { hasActivePayment, appSubscriptions } = await billing.check({
    plans: ['basic', 'standard', 'advanced'],
    isTest: process.env.NODE_ENV !== "production",
  });

if (appSubsctions[0].name == 'basic') {
  throw json({ message: "Forbidden", status: 403 });
}

return json({ message: "success", status: 200 })

As @byrichardpowell said, I think it is able to implement it by using admin.graphql but it is more easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants