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

Get which coupon code applied in checkout #1043

Closed Komal2905 closed 4 years ago

Komal2905 commented 4 years ago

I have applied coupon code in checkout which is "MoneyV2" based, and it is successfully applied I can see that in checkout detail. but what I could not find is that how to fetch which coupon has applied.

{node(id:"NODE_ID"){__typename,... on Checkout{id,webUrl,currencyCode,subtotalPrice,totalPrice,discountApplications(first:1){edges{node{__typename,... on DiscountCodeApplication{applicable,code,value{__typename,... on MoneyV2{amount},... on PricingPercentageValue{percentage}}},... on ManualDiscountApplication{title},... on ScriptDiscountApplication{title}}}}}}}

I am using following query and can see coupon code in

  discountApplications =     {
        edges =         (
                        {
                node =                 {
                    "__typename" = DiscountCodeApplication;
                    applicable = 1;
                    code = GET30;
                    value =                     {
                        "__typename" = MoneyV2;
                        amount = "48.0";
                    };
                };
            }
        );
    };
rebeccajfriedman commented 4 years ago

Hi @Komal2905 - it looks like the response you printed contains code = GET30;. This means that the coupon code was GET30. Hope this helps!

Komal2905 commented 4 years ago

@rebeccajfriedman though I am getting this response, I don't find any way to parse this. like discountApplications.edges.node.first.code - is this possible. or any way like this

dbart01 commented 4 years ago

The trouble is that you're attempting to use Storefront.DiscountApplication directly. It is a GraphQL interface, which translates into Swift as a protocol. Since not all discount applications can be treated the same way, you must disambiguate the type before consuming it in your application layer. Please take a look at the sample app example for a more in-depth example on how to work with discount applications.