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

Highlighted
New Member
6 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
6 0 0

Any thoughts @vix 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
493 98 88

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
6 0 0

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

0 Likes
Highlighted
New Member
6 0 0

@vix Any luck with this?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
493 98 88

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