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

Apple Pay Discount gets invalidated #1054

Closed georgescumihai closed 4 years ago

georgescumihai commented 4 years ago

Version of the SDK: 3.7.0 through carthage

What is the expected behaviour? To be able to cancel the apple pay and start it again, without generating a new discount code.

What is happening instead?

I am able to pay with apple pay, I am able to apply a discount to the order and pay, but I have an issue when ever I apply a discount start the apple pay flow and tap "Cancel" on the apple pay modal. The discount code gets invalidated, If I try to pay again (Web or ApplePay), discount amount is not allocated to the total. I get this message when I try to pay with web checkout, after I canceled an order with discount through apple pay "MY_DISCOUNT_CODE discount code isn’t valid for the items in your cart". MY_DISCOUNT_CODE is the code discount code that I applied to the order.

I apply the discount code with .checkoutDiscountCodeApplyV2 mutation.

If I try only with web checkout I do not have this issue, I can close and open the webUrl from the iPhone, from computer browser, I do not get the code invalidated, I can open the apple pay flow and the discount is still applied.

My discount creation payload on the BE is :

{
"allocation_method": "across",
"customer_selection": "all",
"once_per_customer": True,
"target_selection": "all",
"target_type": "line_item",
"value": str(amount),
"value_type": "fixed_amount
"starts_at": start_date,
"title": disc_code
}
dbart01 commented 4 years ago

This is not an issue with the SDK but rather your application flow. It sounds like your discount code is single-use, which means it can be applied to a checkout once. It is extremely difficult to pinpoint the exact issue with your app without implementation on-hand but I'd suspect that you need to reuse checkouts across Apple Pay invocations.

georgescumihai commented 4 years ago

I am reusing the same checkout, and the discount code is invalidated.

I create the checkout, I can open the webUrl and the discount is there. If I open the apple pay, the discount is there, only after I cancel the apple pay and tap Cancel, the discount code is invalidated. After I tapped Cancel, if I refresh the page were I initially opened the webUrl, the discount code is invalidated.

So I am reusing the checkout.

LE: I apply the discount code once.

dbart01 commented 4 years ago

I'm not sure I can be of any use in debugging this issue without seeing the application but here are some things I'd recommend double-checking / looking into:

georgescumihai commented 4 years ago

Will try to see if I can provide a sample app,.

Does your checkout ID match across invocation of the Apple Pay modal?

Yes, they match, it is the exact same object.

Does your checkout ID match across Apple Pay and Web Checkout?

I have the Storefront.Checkout object, I open the webUrl variable from it and start the apple pay checkout by creating the PayCheckout from the StoreFront.Checkout, so if there isn't any things happening under the hood in the webpage, yes they the same ID.

Are you removing / updating the applied discount code after Apple Pay invocation?

No, the discount is applied before the Apple Pay invocation.

Are your discounts applied too early / too late in your checkout creation lifecycle?

I am not sure what this means, but the discount is applied before the checkout payment flow is started. Also from webCheckout, you can apply a discount, so this question is a bit confusing ?

dbart01 commented 4 years ago

No, the discount is applied before the Apple Pay invocation.

Are you overwriting / reapplying the same discount on an existing checkout with the discount already applied?

georgescumihai commented 4 years ago

I am not reapplying the same discount to any other checkout, even to the one that I applied it, it is only applied once. During tests, I tried to create a new discount code and apply it to the order, after the Apple Pay was canceled, but that usually failed with a checkoutError. I do not remember the outcome of removing the existing discount code, generate a new one and apply the new one after the previous discount code was removed. It was easier just to restart the process(create a new checkout, generate a new discount code and apply a new discount code), because it was always working.