Shopify / shopify-app-template-node

MIT License
867 stars 391 forks source link

Redirecting back to app after billing / how to get app name #1227

Closed JeaneC closed 1 year ago

JeaneC commented 1 year ago

I'm using appSubscriptionCreate to create a subscription which needs a returnUrl and according to shopify support this returnUrl needs to be back in my embedded app. Would be nice if this could be automatic (the user just returns back to the page they were at before billing).

I don't know how to get a return URL in the backend of the embedded app. I saw a function called getEmbeddedAppUrl somewhere, but this only seems to work well during the auth flow (where it's used) where the host and shop name are passed as query parameters.

I also thought about manually constructing the URL www.store.myshopify.com/admin/${APP_NAME}, but then I need an app name

mkevinosullivan commented 1 year ago

@JeaneC when you say you are using appSubscriptionCreate, I assume you are referring to the GraphQL mutation, so you're doing this manually?

There are mechanisms in the API library to allow you to do billing checks and requests that might help

Using those mechanisms, the user is returned to the main page of your app.

W.r.t. constructing the URL manually, note that www.store.myshopify.com/admin/${apiKey} will work, as the apiKey of your app is the unique identifier for the app.

JeaneC commented 1 year ago

🤦 .Thank you @mkevinosullivan for the pointer and fast response! I think I must've just missed these in the docs as I was learning a lot of things. I was doing it manually but no more!

juanpasolano commented 1 year ago

@mkevinosullivan, the guides appear to be out of date. I am wondering if there is no easier way to get the store and host, it seems they are used internally to check auth but not exposed anywhere in the shopify-api-js api. Is there a reason why getting this apparently basic information is not easily accessible?