Adobe Commerce 2.3 reached end of support in September 2022.
Adobe Commerce only. Learn more.

applyStoreCreditToCart mutation

The applyStoreCreditToCart mutation applies store credit to the specified cart. Store credit must be enabled on the store to run this mutation.

Store credit is an amount that the merchant applies to a customer account as a result of a refund or similar transaction. If gift cards are enabled for a store, then a customer receives store credit when redeeming a gift card. No matter how the customer obtains store credit, these funds can be used to pay for purchases.

The amount returned in the current_balance indicates how much store credit at the time you run the applyStoreCreditToCart mutation. This amount is not decreased until you place the order.

If the amount of available store credit equals or exceeds the grand total of the quote, set the payment method to free in the setPaymentMethodOnCart mutation.

Syntax

1
2
3
4
5
6
7
mutation {
  applyStoreCreditToCart(
    input: ApplyStoreCreditToCartInput
  ) {
    ApplyStoreCreditToCartOutput
  }
}

Example usage

In the following example, the customer starts with $10 of store credit. The subtotal of the items in the cart before applying the store credit plus shipping and tax is $34.64. The grand total on the cart after applying the store credit is $24.64.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mutation {
  applyStoreCreditToCart(
    input: {
      cart_id: "4HHaKzxpKM2ZwD0IcheRfcPNBWS3OvRM"
    }
  ) {
    cart {
      applied_store_credit {
        applied_balance {
          currency
          value
        }
        current_balance {
          currency
          value
        }
      }
      prices {
        grand_total {
          currency
          value
        }
      }
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "data": {
    "applyStoreCreditToCart": {
      "cart": {
        "applied_store_credit": {
          "applied_balance": {
            "currency": "USD",
            "value": 34.64
          },
          "current_balance": {
            "currency": "USD",
            "value": 10
          }
        },
        "prices": {
          "grand_total": {
            "currency": "USD",
            "value": 24.64
          }
        }
      }
    }
  }
}

Input attributes

The ApplyStoreCreditToCartInput object must contain the following attributes.

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart

Output attributes

The ApplyStoreCreditToCartOutput object returns the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
id ID! The ID of the cart
is_virtual Boolean! Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.

Errors

Error Description
Could not find a cart with ID \"xxxxx\" The ID provided in the cart_id field is invalid or the cart does not exist for the customer.
The cart isn't active The cart with the given cart ID is unavailable, because the items have been purchased and the cart ID becomes inactive.
Field ApplyStoreCreditToCartInput.cart_id of required type String! was not provided The value specified in the ApplyStoreCreditToCartInput.cart_id argument is empty.