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

# Pay By Link

**Pay By Link** lets a merchant create an SFCC order on behalf of a shopper through the Global-e checkout and generate a payment link that the shopper completes later. It is typically used by customer service agents placing orders for shoppers.

<Note>
  This is an optional feature. It requires project code (a storefront control plus hooks) and an expiry job. See [Implementation](#implementation).
</Note>

## How it works

1. A customer service agent shops on the shopper's behalf — **Merchant Tools → Ordering → Customer Service Center → Find customer** — adds products to the basket, and proceeds to checkout.
2. On the Global-e checkout, a control (for example **Generate Payment Link**) lets the agent create the order on the SFCC side via `GlobalePayByLink-OrderCreate`.
3. When the agent triggers it, the order is created with order status **NEW/OPEN** and payment status **NOT PAID**. The response includes `gePayByLinkUrl` for the shopper.
4. The payment link is shared with the shopper. How it is delivered is up to the merchant — for example a manual step, or an automated email sent when the order is created.
5. When the shopper opens the link, they reach the checkout, complete the address and payment forms, and click **Place Order**. Global-e sends a **ValidateCart** request; for Pay By Link this checks the SFCC **order status** (specifically that it has not been `CANCELLED` due to expiry). If everything is fine the shopper sees the confirmation page; otherwise they see a Global-e-controlled error such as *"the link is expired"*.
6. Because the order already exists on the SFCC side, the subsequent Global-e **OrderCreate** request is skipped. All later requests (**SendOrderToMerchant**, **PaymentPerform**, and so on) are handled exactly as for any other order, with no extra customization.

## Limitations

Pay By Link works only with **single orders** and is **not compatible** with [Mixed Orders](/mixed-orders-sfcc).

## Implementation

### Generate the payment link

A payment link is generated by calling the `GlobalePayByLink-OrderCreate` endpoint (available in both the SFRA and SiteGenesis cartridges). For example, add a control to the checkout template for authenticated agent sessions:

```html theme={null}
<isif condition="${session.userName !== 'storefront' && session.userAuthenticated}">
    <div class="pay-by-link-button-wrapper"
        data-create-order-url="${URLUtils.https('GlobalePayByLink-OrderCreate').toString()}">
        <button type="submit" class="btn btn-block btn-primary">Generate Payment Link</button>
    </div>
    <div class="pay-by-link-message" hidden></div>
</isif>
```

Wire up the click handler in the Global-e script loader:

```javascript theme={null}
GeScriptLoader.prototype.initEvents = function () {
    // ...
    if (document.querySelector('.pay-by-link-button-wrapper')) {
        document.querySelector('.pay-by-link-button-wrapper')
            .addEventListener('click', this.onPayByLinkHandler, false);
    }
    // ...
};
```

```javascript theme={null}
GeScriptLoader.prototype.onPayByLinkHandler = function (data) {
    try {
        var payByLink = document.querySelector('.pay-by-link-button-wrapper');
        var geIframe = document.querySelector('#gle_iframe');
        Helpers.makeJsonAjaxCall(payByLink.dataset.createOrderUrl + '?cartToken=' + geIframe.dataset.cartToken, 'POST', JSON.stringify(data))
            .then(function (response) {
                response = JSON.parse(response);
                if (response.success && response.orderCreateResult && response.orderCreateResult.gePayByLinkUrl) {
                    document.querySelector('.pay-by-link-message').hidden = false;
                    document.querySelector('.pay-by-link-message').innerHTML = response.orderCreateResult.gePayByLinkUrl;
                } else {
                    document.querySelector('.pay-by-link-message').hidden = false;
                    document.querySelector('.pay-by-link-message').innerHTML = response.errorMessage || response.orderCreateResult.errorMessage;
                }
            })
            .catch(function (e) {
                document.querySelector('.pay-by-link-message').innerHTML = e;
                console.warn(e);
            });
    } catch (e) {
        console.warn(e);
    }
};
```

The click handler posts to `GlobalePayByLink-OrderCreate` with the cart token from the checkout iframe (`#gle_iframe` `data-cart-token`). On success, surface `response.orderCreateResult.gePayByLinkUrl` to the agent.

### Cancel expired orders

Unpaid Pay By Link orders should be cancelled after they expire. The cartridges provide the job step type **`custom.GlobaleCancelExpiredPayByLinkOrders`**, which cancels orders still in **OPEN/NEW** and **NOT PAID** status once they pass the expiry time. Create a Business Manager job that runs this step on a schedule.

The expiry window (`autoCancelOrdersTime`) is read from the **Pay By Link Configurations** Merchant Account Setting (`sfccPayByLinkConfigurations`). See [Configuration](/configuration-sfcc) for Global-e settings.

## Customization (hooks)

Pay By Link behaviour can be extended through these hooks (see the [Hooks reference](/hooks-sfcc) for details):

| Hook | Purpose |
| - | - |
| [`globale.getUrlParameters`](/hooks-sfcc#globalegeturlparameters) | The OOTB handler detects whether an order is placed by an agent (the Pay By Link scenario). |
| [`globale.onPayByLinkAfterCreateOrder`](/hooks-sfcc#globaleonpaybylinkaftercreateorder) | Runs after the order is created. |
| [`globale.onPayByLinkAfterPlaceOrder`](/hooks-sfcc#globaleonpaybylinkafterplaceorder) | Runs after the order is placed. |
| [`globale.onBeforeOrderValidate`](/hooks-sfcc#globaleonbeforeordervalidate) | Runs before Pay By Link order validation. |
| [`globale.onAfterOrderValidate`](/hooks-sfcc#globaleonafterordervalidate) | Runs after Pay By Link order validation. |

## See also

* [Mixed Orders](/mixed-orders-sfcc) (mutually exclusive with Pay By Link)
* [Order lifecycle](/order-lifecycle-sfcc) · [Checkout flow](/checkout-flow-sfcc)
* [Jobs overview](/jobs-sfcc)
