Storefront.Checkout object's appliedGiftCards return wrong amountUsed value calculations

New Member
8 0 0

TLDR: When querying a checkout after it has been completed, the amount used for each gift card returns the wrong value.

SDK Version: 5.0.0

Summary

Ultimately what I'm trying to do is after completing a checkout, I want to show an order confirmation screen to the user that shows a break down of the amount used for each gift card. Seeing that the Storefront.Order object doesn't have any information about applied gift cards I figured I could use the checkout object I'm already using to poll for successful completion of checkout. Using the most up to date instance of the Storefront.Checkout object that comes back when polling for successful completion, I check the appliedGiftCards array on the Storefront.Checkout object and the amount used for each gift card has the wrong value.

Steps to Reproduce

1. Create checkout with `checkoutCreate` mutation
2. Add gift cards via `checkoutGiftCardsAppend` mutation - gift cards will cover entire cost of checkout total
3. Trigger Apple Pay flow
4. Complete checkout with `checkoutCompleteWithTokenizedPaymentV3` mutation
5. Poll for checkout completion using `.node(id: checkoutId) { .onCheckout { $0} }` query, with retry polling condition:

let retry = Graph.RetryHandler<Storefront.QueryRoot>(endurance: infinitePollingEnabled ? .infinite : .finite(10), interval: 1) { (response, error) -> Bool in
return (response?.node as? Storefront.Checkout)?.order == nil
}


Full Query:

static func query(checkoutId: GraphQL.ID) -> Storefront.QueryRootQuery {
        return Storefront.buildQuery { $0
            .node(id: checkoutId) { $0
                .onCheckout { $0
                    .ready()
                    .appliedGiftCards{ $0
                        .id()
                        .amountUsedV2 { $0
                            .amount()
                            .currencyCode()
                        }
                        .lastCharacters()
                    }
                    .shippingLine { $0
                        .title()
                        .priceV2 { $0
                            .amount()
                            .currencyCode()
                        }
                    }
                    .order { $0
                        .shopifyOrderFragment()
                    }
                }
            }
        }
    }


6. Grab storefront checkout object instance once checkout has successfully completed, look at the appliedGiftCards array and the amountUsed for each gift card is incorect .

Concrete Examples

Example 1:
I add the following gift cards to the checkout.
Before Completing Checkout:
1. Gift Card 8egb - Amount Used: $10
2. Gift Card 89fe - Amount Used: $20
3. GiftCard a879 - Amount Used: $7.89
Checkout total: $37.89

After Completing Checkout:
1. Gift Card 8eg - Amount Used: $0
2. Gift Card 89fe - Amount Used: $0
3. GiftCard a879 - Amount Used - $37.89
Checkout total: $37.89

What Shopify.com shows for this order:

xanderbuck7_0-1598999027212.png

Example 2:
I add the following gift cards to the checkout.
Before Completing Checkout:
1. Gift Card 9f71 - Amount Used: $20
2. Gift Card 3h6g - Amount Used: $10
3. GiftCard 3f5d - Amount Used: $7.89
Checkout total: $37.89

After Completing Checkout:
1. Gift Card 9f71 - Amount Used: $0
2. Gift Card 3h6g - Amount Used: $0
3. GiftCard 3f5d - Amount Used - $2.11
Checkout total: $37.89

(One thing to note here is for this example it almost looks like it's displaying the balance left in the gift card rather than the amount used, since the two $0 gift cards technically now have $0 balance and the last gift card was a $10 gift card and would have $2.11 balance. I double checked and I'm using amountUsed property and not balance in my code.)

What Shopify.com shows for this order:

API Example.
Using the Storefront graphql api query the checkout object used in example 1 above, it returns the following:

{
  "data": {
    "node": {
      "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC80NDQ4MjcwOGRhZmI3Y2E3ZWFmZjkxZTk1ZTkwZWU3OT9rZXk9ZmM4ZmY4ODQxM2Q1MWY1ZjIyNzIxYzI0ZDc1ZWQwY2Q=",
      "ready": true,
      "currencyCode": "USD",
      "paymentDueV2": {
        "amount": "0.0"
      },
      "totalPriceV2": {
        "amount": "37.89"
      },
      "subtotalPriceV2": {
        "amount": "30.0"
      },
      "totalTaxV2": {
        "amount": "2.89"
      },
      "order": {
        "orderNumber": 29836
      },
      "shippingLine": {
        "title": "Standard Shipping",
        "priceV2": {
          "amount": "5.0"
        }
      },
      "appliedGiftCards": [
        {
          "balanceV2": {
            "amount": "0.0"
          },
          "amountUsedV2": {
            "amount": "0.0"
          },
          "presentmentAmountUsed": {
            "amount": "0.0"
          }
        },
        {
          "balanceV2": {
            "amount": "0.0"
          },
          "amountUsedV2": {
            "amount": "0.0"
          },
          "presentmentAmountUsed": {
            "amount": "0.0"
          }
        },
        {
          "balanceV2": {
            "amount": "6701.11"
          },
          "amountUsedV2": {
            "amount": "37.89"
          },
          "presentmentAmountUsed": {
            "amount": "37.89"
          }
        }
      ]

 

Weirdly enough if I don't query this checkout object for a while (few minutes to an hour) it will return briefly the correct amount used calculations. If I query it right after, the wrong calculations show up again. Take a look at the these two queries, notice that the ready flag is set to true when its the wrong calculations, and set to false when it returns the correct amount used calculations.

{
  "data": {
    "node": {
      "id": "Z2lkOi8vc2hvcGlmeS9DaGVja291dC80NDQ4MjcwOGRhZmI3Y2E3ZWFmZjkxZTk1ZTkwZWU3OT9rZXk9ZmM4ZmY4ODQxM2Q1MWY1ZjIyNzIxYzI0ZDc1ZWQwY2Q=",
      "ready": false,
      "currencyCode": "USD",
      "paymentDueV2": {
        "amount": "0.0"
      },
      "totalPriceV2": {
        "amount": "37.89"
      },
      "subtotalPriceV2": {
        "amount": "30.0"
      },
      "totalTaxV2": {
        "amount": "2.89"
      },
      "order": {
        "orderNumber": 29836
      },
      "shippingLine": {
        "title": "Standard Shipping",
        "priceV2": {
          "amount": "5.0"
        }
      },
      "appliedGiftCards": [
        {
          "balanceV2": {
            "amount": "0.0"
          },
          "amountUsedV2": {
            "amount": "10.0"
          },
          "presentmentAmountUsed": {
            "amount": "10.0"
          }
        },
        {
          "balanceV2": {
            "amount": "0.0"
          },
          "amountUsedV2": {
            "amount": "20.0"
          },
          "presentmentAmountUsed": {
            "amount": "20.0"
          }
        },
        {
          "balanceV2": {
            "amount": "6636.16"
          },
          "amountUsedV2": {
            "amount": "7.89"
          },
          "presentmentAmountUsed": {
            "amount": "7.89"
          }
        }
      ],

 

0 Likes
Highlighted
New Member
8 0 0

Any thoughts @vix 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
503 98 91

Hi @xanderbuck7 

 

Going to set aside some time this week to look into this. I'll let you know any updates when I have one. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
New Member
8 0 0

@vix Thank you so much! Let me know what you find. 

0 Likes
Highlighted
New Member
8 0 0

@vix Any luck with this?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
503 98 91

Hi @xanderbuck7 

 

This is currently in our backlog, I don't have a timeline I can guarantee but we are aware and will be resolving. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
Shopify Staff
Shopify Staff
503 98 91

Hi @xanderbuck7 

Is this only replicable after order creation or can you replicate throughout the checkout journey? 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
New Member
8 0 0

Hi @vix,

The only place throughout the checkout journey where I've been able to reproduce invalid gift card amount calculations is the following scenario:

1. Add a gift card A that covers the complete subtotal.

2. Add gift card B to checkout, no amount will be used from this gift card since gift card A covers the whole subtotal.

3. Remove gift card A and you will see that the calculation for gift card B's amount is incorrect (in my tests, the amount used on gift card B stays at $0). 

 

Besides that, as you are aware, after an order is created, if I try to reload the checkout and look at what amount was used on the gift cards, this has incorrect value for amountUsed. So far the checkout object is the only place I've found where I can access gift card information, as you can imagine, this is pretty important to display this information on an order confirmation screen so we can provide a breakdown of what the user has spent.

 

 

 

 

 

0 Likes
Highlighted
New Member
8 0 0

Also @vix, I really appreciate you taking the time to look it this. Thank you again  

0 Likes