> ## Documentation Index
> Fetch the complete documentation index at: https://pro-docs.bglobale.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Gift Cards

## Overview

Global‑e cartridges support:

* Purchasing Gift Cards as regular products
* Using Gift Cards on Global-e checkout

The cartridges contain needed functionality and demo implementation based on using SFCC custom objects.

## Purchase of Gift Cards

Gift Cards can be added to the basket and purchased like any other regular product.

Here is how to configure a gift card:

1. In SFCC Business Manager, create a new product.
2. For this product, check the product custom attribute **Is Globale Gift Card** which identifies the product as a Gift Card.

   <Frame>
     <img src="https://mintcdn.com/globale-pro/CL-c3MAJ9f_-Karr/images/uuid-78e33075-d5bf-bac6-4607-4e5d8b465ca3.png?fit=max&auto=format&n=CL-c3MAJ9f_-Karr&q=85&s=964df53901a3b1b7c6e09b68c85bbc2b" width="481" height="52" data-path="images/uuid-78e33075-d5bf-bac6-4607-4e5d8b465ca3.png" />
   </Frame>

   The product can be configured as a single or as a master with variation products that will be used as different amounts of Gift Card.

   <Frame>
     <img src="https://mintcdn.com/globale-pro/XlQTHMO1JRS1wjIN/images/uuid-c06164fc-13a8-0405-f2de-ba59234fe73b.png?fit=max&auto=format&n=XlQTHMO1JRS1wjIN&q=85&s=53b61b86b9a5429c15ee8fb2b6674fd9" width="1073" height="64" data-path="images/uuid-c06164fc-13a8-0405-f2de-ba59234fe73b.png" />
   </Frame>

A Gift Certificate is created on the SFCC instance after successful checkout:

<Frame>
  <img src="https://mintcdn.com/globale-pro/CL-c3MAJ9f_-Karr/images/uuid-6ca0251d-ab65-25e0-9f95-e62c4a941a52.png?fit=max&auto=format&n=CL-c3MAJ9f_-Karr&q=85&s=e2e1ac203c2daea2307400dcbe889f93" width="1865" height="826" data-path="images/uuid-6ca0251d-ab65-25e0-9f95-e62c4a941a52.png" />
</Frame>

This is how the gift card looks on the SFCC storefront:

<Frame>
  <img src="https://mintcdn.com/globale-pro/InyJH_3UfDszuirD/images/uuid-ff10868a-7e47-fe30-d440-7906f2f4bb25.png?fit=max&auto=format&n=InyJH_3UfDszuirD&q=85&s=025c78fa78a2ab5fed95abb833c63c48" width="664" height="250" data-path="images/uuid-ff10868a-7e47-fe30-d440-7906f2f4bb25.png" />
</Frame>

Native Gift Certificate purchase page for SiteGenesis:

<Frame>
  <img src="https://mintcdn.com/globale-pro/y93-IIIj3CQONbcg/images/uuid-ef47cde6-5328-15b9-1455-76995bc0ae07.png?fit=max&auto=format&n=y93-IIIj3CQONbcg&q=85&s=f970b10c05e5ad327c794244d6fe3468" width="1188" height="916" data-path="images/uuid-ef47cde6-5328-15b9-1455-76995bc0ae07.png" />
</Frame>

Gift Certificate on the cart page:

<Frame>
  <img src="https://mintcdn.com/globale-pro/CL-c3MAJ9f_-Karr/images/uuid-65d3fff1-5d96-4b24-5227-b313423faadd.png?fit=max&auto=format&n=CL-c3MAJ9f_-Karr&q=85&s=4a6f97ce1ac4b8e3bdc2d5f8e56dcac1" width="1199" height="582" data-path="images/uuid-65d3fff1-5d96-4b24-5227-b313423faadd.png" />
</Frame>

Gift Certificate on the Global-e checkout page:

<Frame>
  <img src="https://mintcdn.com/globale-pro/XEWVV0QvTmDap1kq/images/uuid-18ca4c49-3dbc-9656-3166-c50b891a9861.png?fit=max&auto=format&n=XEWVV0QvTmDap1kq&q=85&s=7e89cd92ed5f7175aa6aabb6211d6e85" width="1376" height="497" data-path="images/uuid-18ca4c49-3dbc-9656-3166-c50b891a9861.png" />
</Frame>

## Using Gift Cards

**“Validate” API call**

1. The customer enters all card data and clicks **Apply** to apply for a Gift Certificate.

   Note: the count of fields for card data is configurable on the Global-e side and can be configured according to the project’s needs. There can be one field with Card ID, two fields with Card ID and Card PIN, etc.

   <Frame>
     <img src="https://mintcdn.com/globale-pro/9HlUmFRUSCFTWThI/images/uuid-9f5c1767-94fa-350f-c728-b7c715a757b4.png?fit=max&auto=format&n=9HlUmFRUSCFTWThI&q=85&s=ee3dde979225cdd32a56ffb96689dc4e" width="1367" height="835" data-path="images/uuid-9f5c1767-94fa-350f-c728-b7c715a757b4.png" />
   </Frame>
2. Global-e sends a ‘Validate’ request to SFCC.

   The request payload is parsed and SFCC checks if the card exists.

   * If the card is not valid SFF responds with an error message.

     <Frame>
       <img src="https://mintcdn.com/globale-pro/XEWVV0QvTmDap1kq/images/uuid-0f8c44db-7352-f797-cbc0-04d2f7563cef.png?fit=max&auto=format&n=XEWVV0QvTmDap1kq&q=85&s=c3dd5f82f3d071f55ec65ffaf5fac6f5" width="697" height="461" data-path="images/uuid-0f8c44db-7352-f797-cbc0-04d2f7563cef.png" />
     </Frame>
   * If the card is valid:

     * The card balance is converted to checkout currency.
     * The UI of the Gift Cards section notifies the customer about the successful card application.
     * The totals section is reloaded with information about how much money will be compensated from the Gift Card.

     <Frame>
       <img src="https://mintcdn.com/globale-pro/XlQTHMO1JRS1wjIN/images/uuid-ca91dea4-fd9d-39b4-23e5-786411c9b665.png?fit=max&auto=format&n=XlQTHMO1JRS1wjIN&q=85&s=0b7e0a3968c77e8e51865dea98c49107" width="1308" height="721" data-path="images/uuid-ca91dea4-fd9d-39b4-23e5-786411c9b665.png" />
     </Frame>

If the amount of the card covers the order's total amount, the customer can create an order without any additional payments.

<Frame>
  <img src="https://mintcdn.com/globale-pro/AfesHL0ivXu6Xccj/images/uuid-31250d2e-fe0c-749d-a42d-1cb81d2b3604.png?fit=max&auto=format&n=AfesHL0ivXu6Xccj&q=85&s=22470e6953983a1f57d61c6d08c6f08f" width="1286" height="715" data-path="images/uuid-31250d2e-fe0c-749d-a42d-1cb81d2b3604.png" />
</Frame>

If the amount of the card covers only part of the order's total amount - the user should select a payment method to pay the rest.

<Frame>
  <img src="https://mintcdn.com/globale-pro/9HlUmFRUSCFTWThI/images/uuid-a9dee6ae-993b-4665-65b0-b10fe6ed3b61.png?fit=max&auto=format&n=9HlUmFRUSCFTWThI&q=85&s=380ff22f22658ed71185667e0f1c2358" width="372" height="250" data-path="images/uuid-a9dee6ae-993b-4665-65b0-b10fe6ed3b61.png" />
</Frame>

**“Redeem” API call**

After the customer clicks on ‘PAY AND PLACE ORDER' and receives a successful validation on the Global-e side, a 'Redeem’ request is sent from Global-e to SFCC.

When an order is created on the Global-e side (and before it is created on the SFCC side) Global-e sends a “Redeem” request to SFCC. This redemption request will be detected as “PENDING” in the “redeemResponseJSON”, and real redemption for SFCC Gift Certificate will take place after the Global-e Payment Update request, and it will be detected as “REDEEMED” in the “redeemResponseJSON”.

<Frame>
  <img src="https://mintcdn.com/globale-pro/CL-c3MAJ9f_-Karr/images/uuid-6f3536bb-2045-7139-d6f6-98575d1e4fe8.png?fit=max&auto=format&n=CL-c3MAJ9f_-Karr&q=85&s=04eafe1961fd5ba5914658f93d02f1e1" width="1711" height="402" data-path="images/uuid-6f3536bb-2045-7139-d6f6-98575d1e4fe8.png" />
</Frame>

If the 'Redeem' for the card fails - an error message is displayed to the user and the order is not created on the SFCC side.

<Frame>
  <img src="https://mintcdn.com/globale-pro/AfesHL0ivXu6Xccj/images/uuid-24c4f7be-8279-f0f3-f3e5-c2e219b905a5.png?fit=max&auto=format&n=AfesHL0ivXu6Xccj&q=85&s=fdb9fedbc7738c006792931470dad839" width="466" height="250" data-path="images/uuid-24c4f7be-8279-f0f3-f3e5-c2e219b905a5.png" />
</Frame>

If the 'Redeem' for the card was successful - the confirmation page is displayed to the user and the order is created on the SFCC side.

**Refund’ API call**

A Refund request is sent from Global-e to SFCC if a refund is created on the Global-e side. For example: if the order is set to ‘Cancelled' on the Global-e side.

If `RedeemTransactionResult` has the status **PENDING**, it will be changed to **REFUNDED**. If `RedeemTransactionResult` has the status **REDEEMED**, a new SFCC Gift Certificate will be created with the refund amount, and the `RedeemTransactionResult` status will change to **REFUNDEDTONEW**.

<Frame>
  <img src="https://mintcdn.com/globale-pro/y93-IIIj3CQONbcg/images/uuid-ef208783-2f1a-66e3-7e26-7be97d6a553e.png?fit=max&auto=format&n=y93-IIIj3CQONbcg&q=85&s=515dcbe3a512e65a2ee2712d0c661373" width="1889" height="682" data-path="images/uuid-ef208783-2f1a-66e3-7e26-7be97d6a553e.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/globale-pro/b-PlqzQu3R4_02Jo/images/uuid-47b59ffe-82f4-2f97-3934-effc04b1fa96.png?fit=max&auto=format&n=b-PlqzQu3R4_02Jo&q=85&s=6b5ba406fa297dfd4b0521a2fd14bb9e" width="1754" height="509" data-path="images/uuid-47b59ffe-82f4-2f97-3934-effc04b1fa96.png" />
</Frame>

**Used ’Gift Cards’ details**

Information about used cards is added to the payload of ‘Send Order To Merchant' and 'Payment Notification’ requests

## Required customization

**Purchase**

To enable the ability to buy Gift Cards as regular products via Global-e checkout changes need to be made to the code.

The following steps should be implemented:

1. SFCC hook

   In the project’s extended cartridge (or depending on used SFCC architecture in ‘int\_globale\_sfra'/’int\_globale\_sitegenesis') a hook handler should be added for the SFCC hook that is triggered during the payment update.

   **Path**: ./hooks.json

   ```
   {
       "hooks": [
           {
               "name": "globale.onAfterPaymentUpdate",
               "script": "./cartridge/scripts/globale/hooks/onAfterPaymentUpdate.js"
           }
       ]
   }
   ```
2. Hook’s handler

   **Path**: ./cartridge/scripts/globale/hooks/onAfterPaymentUpdate.js

   The logic for creating gift cards should be added in the hook's handler.

   **Example**

   ```
   'use strict';

   exports.onAfterPaymentUpdate = function (order, payload) {
       var globaleHelpers = require('*/cartridge/scripts/helpers/globaleHelpers');
       var logger = globaleHelpers.getLogger();
       try {
         // create gift cards
         var giftCard = new (require('*/cartridge/models/globale/alternativePayments/GiftCardStrategy'))(payload);
         giftCard.create(order);
       } catch (e) {
           logger.error('onAfterPaymentUpdate: ERROR: {0}', logger.message(e));
       }
   };
   ```

**Using**

Demo implementation in Global-e cartridges was done based on SFCC custom objects with type 'DEMO\_GLOBALE\_GIFT\_CARDS'. The project’s development team should override demo implementation and add a ‘Gift Card' provider depending on the project’s needs.

**Gift Card Provider** should be overridden by path: **./scripts/globale/alternativePayments/providers/GiftCardProvider.js**

**To customize a Gift Certificate logic you can add the following hooks**

```
        {
            "name": "globale.onAfterGiftCertificateRefund",
            "script": "./cartridge/scripts/hooks/giftCertificate/onAfterGiftCertificateRefund.js"
        },
```

```
        {
            "name": "globale.onAfterGiftCertificateRedeem",
            "script": "./cartridge/scripts/hooks/giftCertificate/onAfterGiftCertificateRedeem.js"
        },
```

```
        {
            "name": "globale.onAfterGiftCertificateCreate",
            "script": "./cartridge/scripts/hooks/giftCertificate/onAfterGiftCertificateCreate.js"
        },
```

**order create - OCAPI flow**

```
        {
            "name": "onAfterGiftCertificateOrderCreate",
            "script": "./cartridge/scripts/hooks/giftCertificate/onAfterGiftCertificateOrderCreate.js"
        },
```

## Summary

The demo implementation (that is based on using SFCC custom objects.) was made with a simple structure as a test example which allows understanding of the main things that can be used in the scope of the ‘Gift Cards' feature.
