I’m working on a custom website that’s not built with Shopify but I want to use Shopify for handling payments. My site has a shopping cart built with JavaScript and jQuery. When someone clicks the checkout button, I want to send all their cart information to Shopify and redirect them straight to Shopify’s checkout page.
Basically I need to figure out how to take the items, quantities, and other cart details from my website and create a Shopify checkout session with that data. Then I need to get the checkout URL so I can redirect the customer there.
I’m pretty new to working with Shopify’s system so I’m not sure what API endpoints or methods I should be using for this. Any help would be great!
checkout permalinks might be easier for your usecase. you can construct urls like /cart/add
with variant ids and quantities as parameters, then redirect directly to /checkout
. way simpler than dealing with storefront api if you dont need custom checkout flows. just make sure your variant ids are correct or it’ll break.
I’ve done something similar for a client project where we had a React frontend that needed to integrate with Shopify’s checkout. You’ll want to use the Storefront API for this, specifically the checkoutCreate mutation. First, you need to get a Storefront access token from your Shopify admin with the right permissions. Then you can make a GraphQL request with your cart items formatted as line items - each needs a variant ID and quantity. The API will return a checkout object with a webUrl property that you can redirect customers to. One thing that caught me out initially was making sure the variant IDs match exactly what’s in your Shopify store, otherwise the checkout creation will fail. Also worth noting that you’ll need to handle inventory checking on your end since there’s a chance items could go out of stock between adding to cart and checkout creation.