Open cocoahero opened 5 years ago
Hi @cocoahero, this behaviour is intentional for security reasons to protect private business information. You should be checking if the product is available for sale and managing product availability earlier in the customer's journey to prevent them from starting a checkout with a product that is out of sale.
I will let @rebeccajfriedman handle the second part!
No matter how many times we check inventory status before initiating a checkout, there will always be a chance for inventory to go out of stock before a checkout is initiated. We deal with this all the time due to high volume flash sales. Allowing the checkout process to continue is extremely poor UX.
I could see the potential for abuse in an open, public API, but the storefront API is authenticated. Returning a simple “insufficient inventory” error on checkout creation is no different than querying the product variant’s availableForSale
field.
Additionally,
CheckoutUserError
has a handy error codenotEnoughInStock
that could be easily used here. However, thecheckoutCompleteWithTokenizedPaymentV2
mutation used to complete the Apple Pay checkout only returns the genericUserError
, which is next to impossible to parse to know what the error actually was.
CheckoutUserErrors
is available on checkoutCompleteWithTokenizedPaymentV2
as of version 3.3.2.
@cocoahero Thanks for elaborating on this. I see where you're coming from, so let me take this away and get back to you. Leaving this issue open for now!
Hey @cocoahero we've added the ability to track inventory, and it will be available in the Storefront API as of April 2020 as ProductVariant.quantityAvailable
!
Check out the Storefront API ProductVariant API reference for 2020-04
.
Note that this field will require the new unauthenticated_read_product_inventory
scope as per the settings in the private app.
This SDK will be updated shortly after the full release in early April. I'll leave this issue open until it's shipped to the SDK, but please let us know if you don't think this will help address your flash sale issue.
@morganmccunn this is great news, thank you! 🎉
In our app, for both Apple Pay and Web based checkouts, when we create the checkout using the
checkoutCreate
mutation and have line items that represent sold out products, the checkout creation still succeeds.For web checkouts, the user is then presented with a web view that tells them that the products are out of stock. For Apple Pay checkouts, the user is presented with a payment sheet as if everything was normal. It is not until payment is authorized that the Storefront API returns an error.
Ideally, the apps should be able to know that there are inventory issues as soon as possible.
Additionally,
CheckoutUserError
has a handy error codenotEnoughInStock
that could be easily used here. However, thecheckoutCompleteWithTokenizedPaymentV2
mutation used to complete the Apple Pay checkout only returns the genericUserError
, which is next to impossible to parse to know what the error actually was.