Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
452 stars 199 forks source link

Checkout Creation Always Succeeds With Sold Out Line Items #970

Open cocoahero opened 5 years ago

cocoahero commented 5 years ago

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 code notEnoughInStock that could be easily used here. However, the checkoutCompleteWithTokenizedPaymentV2 mutation used to complete the Apple Pay checkout only returns the generic UserError, which is next to impossible to parse to know what the error actually was.

morganmccunn commented 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!

cocoahero commented 5 years ago

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.

rebeccajfriedman commented 5 years ago

Additionally, CheckoutUserError has a handy error code notEnoughInStock that could be easily used here. However, the checkoutCompleteWithTokenizedPaymentV2 mutation used to complete the Apple Pay checkout only returns the generic UserError, 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.

morganmccunn commented 5 years ago

@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!

morganmccunn commented 4 years ago

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.

cocoahero commented 4 years ago

@morganmccunn this is great news, thank you! 🎉