# Loyalty Accounts

## <mark style="color:red;">How to Create Loyalty Accounts & Transfer Store Credit</mark>

This document provides a comprehensive guide on how to create loyalty accounts within a sales channel and transfer store credit between these accounts.

Before creating a loyalty account, make sure the user for whom you intend to create a loyalty account already has a registered account in the sales channel.

Registered accounts can be viewed in Omnitron on the **Sales Channels > Users** page.

<figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-2371bb87aac4ec69b2b631bb1527ac7e6faec860%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">Enabling Loyalty Money Dynamic Setting</mark>

The first step is to enable the **LOYALTY\_MONEY\_ENABLED** dynamic setting for making loyalty money enabled for payment transactions.

To enable loyalty money for payment transactions, follow these steps:

1. Follow the **Sales Channels > Sales Channel Settings** sidebar and click the **Dynamic Settings** page.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-6d3401f15bebab9bffe5b018ff04753e1e94ef52%2Fimage%20(115).png?alt=media" alt=""><figcaption></figcaption></figure>
2. Among the existing dynamic settings, locate the **LOYALTY\_MONEY\_ENABLED** setting and click on it.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-db6b172684e8f279eeb93d1a3576a9738f6e67b2%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
3. Set its Value to **Yes**, click the **Save** button. This will enable the loyalty money transaction for the relevant sales channel.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-597ea12a14ebddc4fb69222e8c9edfc1a2551a5e%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">Creating Loyalty Accounts</mark>

To create loyalty accounts, follow these steps:

1. Follow the **Sales Channels > Sales Channel Settings** sidebar and click the **Loyalty Accounts** page.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-29b82ae3398e592fb6b42092e6316982b8b4d06d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
2. Click the **+ New Loyalty Account** button located in the upper right corner of the page.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-a120da2d5662a7991253431f3dd7a799ba724ccb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
3. When you click the add button, a form will open for entering account details. The fields in this form and their explanations are as follows:

   * **Account ID:** This field is optional and can be left blank.
   * **User PK:** This field will automatically populate after selecting the next field, User Email.
   * **User Email:** After typing the complete user’s email address that is registered in the sales channel, this address will be filtered. Select the filtered email address.
   * **Balance:** Enter the amount of store credit to be assigned to the loyalty account.
   * **Debit Card Allowed:** Choose whether the balance assigned to the account will go into a negative value when it runs out. *(To avoid any potential balance issues, it is recommended to select “Yes”.)*
   * **Currency:** Enter the currency for the loyalty account.

   NOTE: Multiple accounts for the same user cannot be created with the same currency. However, you can create multiple accounts for the same user with different currencies.\\
4. After entering all fields correctly (these cannot be edited later), click the **OK** button to create the account.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-b2b6e2b9a9a7859f01e011a1857b923766c2bc19%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## <mark style="color:red;">Transferring Store Credit Between Accounts</mark>

Store credit can be transferred between the loyalty accounts that you have created. The recommended scenario is to create a primary account for distributing store credit and then transfer from this primary account to customer accounts.

{% hint style="warning" %}
Store credit can only be transferred between accounts with the same currency. Accounts with different currencies would not be displayed during the transfer process.
{% endhint %}

To transfer store credit between loyalty accounts, follow these steps:

1. Filter and locate the loyalty account from which you want to make the transfer, as created in the previous step. Click on the corresponding row to go to the **Loyalty Account Detail** page.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-6963612ec6785a664e2675e8217d5990ed07803c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
2. At the top of this page, you will find summary information about the account on the **Account Information** section. From here, you can check the account balance.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-66998d10c83d95b1289c7335fafaa898b1def3e8%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
3. In the second section of the page, you will find the **Create Transfer** section, where the transfer will take place.
   * **Transfer To (Account ID):** Select the loyalty account to which the transfer will be made from the list.
   * **Transfer Amount:** Enter the amount of store credit you want to transfer in the specified currency.
4. Click the **Save** button to complete the transfer.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-3a8bf99b2fff3eb2b65a66bd63b096b69ee02b56%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
5. When you click **Save**, you will see a notification message at the top of the page. The transfer is completed successfully once the message disappears, and the transfer transaction will be reflected in the **Account Activities** section at the bottom of the page.

   <figure><img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-7758e3ccb90e5d1b9c265251e62f1ebae335f97b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
To enable the transfer process, there must be at least one transfer transaction in the loyalty account. This transaction can be either incoming or outgoing transfer. All previous transactions are listed in the **Account Activities** section at the bottom of the page.

<img src="https://2911598027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlQinVPnOffBiOp126ldR%2Fuploads%2Fgit-blob-bf57166225c8c7219dd6e8a7ccefab3e2ec5b4c4%2Fimage.png?alt=media" alt="" data-size="original">
{% endhint %}

## <mark style="color:red;">Understanding the Flow of Partial Loyalty Money Usage</mark>

After selecting a payment method with LoyaltyMoneyRule, we will examine the steps to understand if the request to LoyaltyMoneyUsagePage does not work as expected. Follow the all steps outlined in this page to perform these actions, then review the relevant scenarios.

### Example Scenario 1: LoyaltyMoney Partial Usage Request

#### **`GET` Sending Request to LoyaltyMoney Usage Page**

A request is sent to the LoyaltyMoneyUsagePage with the intention of using LoyaltyMoney for a partial amount of the order.

**Path:** `https://{storefront_url}/orders/checkout/?page=LoyaltyMoneyUsagePage`

**Request Body**

```json
{}
```

**Response**

```json
{
    "context_list": [
        {
            "page_context": {
                "balance": "50.00"     // ( The total amount in the user's loyalty account )
            },
            "page_name": "LoyaltyMoneyUsagePage",
            "page_slug": "loyaltymoneyusagepage"
        }
    ],
    "template_name": "orders/checkout.html",
    "errors": null,
    "pre_order": {...}
}
```

***

#### **`POST` Loyalty Money Usage**

A request is sent to the LoyaltyMoneyUsagePage, specifying the amount of LoyaltyMoney the user intends to use.

**Path:** `https://{storefront_url}/orders/checkout/?page=LoyaltyMoneyUsagePage`

**Request Body**

```json
{
    "loyalty_amount_to_use": "10.00"    //(The Loyalty amount the user wishes to use on the shop. )
}
```

**Response**

```json
{
    "context_list": [
        {
            "page_context": {},
            "page_name": "EmptyPage",
            "page_slug": "emptypage"
        }
    ],
    "template_name": "orders/checkout.html",
    "errors": null,
    "pre_order": {...}
}
```

***

#### **`POST` Complete Loyalty Money Payment**

A request is sent to the LoyaltyMoneyPage for the completion of the order with LoyaltyMoney as the payment method.

**Path:** `https://{storefront_url}/orders/checkout/?page=LoyaltyMoneyPage`

**Request Body**

```json
{
    "agreement": true
}
```

**Response**

```json
{
    "context_list": [
        {
            "page_context": {
                "redirect_url": "/orders/completed/IjcwMjExMjMyMTA5MTci:1mRByT:tTgDsJbIKXyxJZyIZwHIBqtShvw/",
                "order_id": 303,
                "new_user": false,
                "token": "138ddd19a0436166354cccbacb4cbb0473104193",
                "campaigns": []
            },
            "page_name": "ThankYouPage",
            "page_slug": "thankyoupage"
        }
    ],
    "template_name": "orders/checkout.html",
    "errors": null,
    "pre_order": {...}
}
```

### Example Scenario 2: Full Amount LoyaltyMoney Usage

**LoyaltyMoney Usage Request:**

* A request is made to the LoyaltyMoneyUsagePage to use LoyaltyMoney for a portion of the order amount.
* Consequently, the CreditCard payment option becomes selectable again.

**CreditCard Flow:**

* Progress is made up to the InstallmentSelectionPage.

**LoyaltyMoney Usage Request (Full Amount):**

* A request is sent to the LoyaltyMoneyUsagePage to pay the entire order amount using LoyaltyMoney.
* Consequently, the CreditCard payment option becomes inactive, and an error occurs when attempting to send a request to the InstallmentSelectionPage, returning an error message.
