Skip to main content

Documentation Portal

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"
        },