Validating user payment status when app runs createShopifyAuth flow

TG3
New Member
1 0 0

Hi,

 

I'm using the following flow to build a public app, but using a one time purchase model instead of a subscription model:

https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react

 

The issue:

- a user installs and pays for the app and everything works fine and dandy.

- later on, due to an app update or some internal shopify trigger, the app re-runs the "createShopifyAuth" method when a user tries to open the embedded app.

https://github.com/Shopify/shopify-demo-app-node-react/blob/master/server.js#L33

In my app, since I'm using AppPurchaseOneTime, I've replaced:

await getSubscriptionUrl(ctx, accessToken, shop);

with my own custom:

await getOneTimePurchaseUrl(ctx, accessToken, shop);

which functions the same, but with a different graphql mutation.

 

The problem here is, since I'm using the AppPurchaseOneTime instead of a subscription, if a user has already paid for the app, I don't want to redirect them to the billing page again during that flow, because it seems that the billing page doesn't recognize whether or not a user has previously paid for the app or not, and will force them to buy it again. Once the user has bought my app that's it, they have it forever and I don't want to bother them with the billing page ever again.

 

Now, I could (and have) created a validation check just before the getOneTimePurchaseUrl that:

- fetches all the user's payments using: https://shopify.dev/docs/admin-api/rest/reference/billing/applicationcharge#index-2020-07

- filters for any payment with a status of "active"

- if found, it simply runs ctx.redirect('/')

- else, it runs my getOneTimePurchaseUrl method and redirects them to the billing page

- and my app's client side code also validates the same way

 

Is this the best solution to handle this situation, or is there something I'm missing in the redirect flow that automatically handles it for us?

0 Likes