Closed AlexanderProd closed 5 years ago
This happens with a paid Shopify store as well, therefore the error seems to be of different origin. The use of status code 402 is missleading though.
Re opening because I really have difficulties creating a checkout. According to #379 this can happen when you don't use the right token. I've tested tokens for 3 different stores though and the error still persists.
What are other problems that can lead to a checkout not being created?
I'm using it like this and initializeCheckout
is being called inside a react componentDidMount() method.
const createNewCheckout = () => this.state.store.client.checkout.create()
const fetchCheckout = id => this.state.store.client.checkout.fetch(id)
if (existingCheckoutID) {
try {
const checkout = await fetchCheckout(existingCheckoutID);
// Make sure this cart hasn’t already been purchased.
if (!checkout.completedAt) {
setCheckoutInState(checkout)
return
}
} catch (e) {
localStorage.setItem('shopify_checkout_id', null)
}
}
const newCheckout = await createNewCheckout()
setCheckoutInState(newCheckout)
Hey @AlexanderProd !
The error is because undefined.myshopify.com
is not a real store (or at least, not one that is operational).
It's worth noting that the credential set must be valid for the store you are executing API calls against – access tokens cannot be used globally across Shopify.
If you want to create a free store for testing purposes, I recommend creating a free account with our partner program. https://www.shopify.ca/partners
Once you've created a shop, you can follow the Getting Started guide to generate storefront credentials. Follow the steps for Via a private app.
Cheers!
@jamiemtdwyer I dont even understand why it says undefined.myshopify.com
. I've used the credentials for a real paid shopify store (storefront access token and the store name) as well as the credentials for the graphql shopify store found inside the js-buy-sdk
examples and also a test store created with the partner programm, In all cases everything works but I cant create a checkout.
To me, this points to the buy client not being initialized properly.
https://github.com/Shopify/js-buy-sdk#initializing-the-client
Perhaps the shop domain has not been passed in correctly, which is why the client is attempting to perform a request to undefined.myshopify.com
I'm not sure why you're having success with the other operations except checkout. There's nothing special about the checkout mutations. My advice would be to try to replicate this in the simplest environment possible, by simply initializing the client and creating a checkout, and see if that works.
It might be some kind of scoping issue, where your environment does not have access to the client you've initialized inside of the componentDidMount()
callback, i.e. this.state.store.client
is not initialized properly or does not point to your actual client.
Describe the bug I'm developing a shop that uses the
js-buy-sdk
, while developing I've been using the graphql store credentials that can be found in the storefront-api-examples repository.Now I've encountered this error though, which lead me to wonder if a paid Shopify store is required to use some functions of
js-buy-sdk
.Environment (please complete the following information):
v2.0.1
Bug Report Checklist