Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Questions:

...

  • Create a feature flag;

  • The first step to use the loyalty promo code at checkout will be to change the validation promo code flow.

    • On promo code component field, we will need to add a feature flag:

      • When this flag is enabled: The promo code flow will be LOYALTY OFFER

      • When this flag is disabled: The promo code flow will be CBA OFFER (current flow)

  • We will create a new hook to contain all the rules of this flow

    • We can use the same hook used to offer page flow.

      • intl-whitelabel-app/workspaces/frontend/src/state/loyalty/hooks/use-redeem-promo-codes.ts

...

  • Currently, we already sent the sanityId offer to the backend (intl-partners-service);

  • Then, we need to send the discount information to Winrest;

    • With the sanityId that we have, we will find the discount values by getOffers(sanityId: string)

      • path: intl-partners-service/src/modules/orders/cart-total.service.ts

  • We will add a new attribute orderDiscounts on the webhook payload;

  • We will send it to Winrest always in percentage (requested to Winrest, 'cause will be easier for them);

  • The orderDiscounts object would be in each cart object;

  • If the discount is amount type, we will transform it to percentage type;

    • E.g: If the total cart is 10 euros and amount discount is 5 euros;

      • We will calculate the discount:

        Code Block
        discount = (100 * 5) / 100;
        discount = 50%;
    • So the payload will be:

      Code Block
      languagejson
      "orderDiscounts": [
        {
          "type": "percentage",
          "value": 50
        }
      ]

...

titlePayload JSON

...

languagejson

...

1 - TASK: Create a method to calculate the percentage offer;

  • Create a feature flag;

  • Create a method to calculate the percentage offer.

    • path: intl-partners-service/src/modules/orders/orders.service.ts

    • We will send the discount values per cart item to Winrest, but the calculation of the discount percentage will be based on the cart total, which will be easier to calculate and in the end will have the same result if we calculate the discount per item.

    • The method will receive two params:

      • appliedOffers: IAppliedOffer[] | null | undefined

        • Offer applied on the cart;

          Image Added
      • total: number | undefined

        • total cart value;

    • The method return will be:

      • Promise<IOrderDiscounts[] | undefined>

        • Where the IOrderDiscounts.type will be always a percentage;

    • To discover the discount values we will need to use the method getOffers

      • path: intl-partners-service/src/modules/orders/cart-total.service.ts

      • This method is private, so we will update it to public;

    • If the discount offer is a type amount we will calculate the percentage over the total cart value;

      • E.g: If the total cart is 10 euros and amount discount is 5 euros;

        • We will calculate the discount:

          Code Block
          discount = Math.round((5 * 100) / 10)
          discount = 50%; 
      • So the payload will be:

        Code Block
        languagejson
        "orderDiscounts": [
          {
            

...

      • "

...

      • type": "

...

      • percentage",

...

      • 
            

...

      • "

...

      • value": 

...

      • 50
          

...

      • }
        ]
Expand
titlePayload JSON
Code Block
languagejson
{
  "menuSelectionscallbackUrl": [
    "https://euw3-dev-plk-partners-api.rbictg.com/api/v1/orders/84b5f1df-28df-4e6f-a871-a2783602436f/price/callback",
  "cart": {
     {"menuSelections": [
      {
        "externalReferenceId": "800852800853",

           "id": "item_67167f9f5b02e-bee8-4dd1-a5fa-222b79516a98",
            "menuSelections": [],
  
         "price": {
              "amountexternalReferenceId": 679"800852",

             "currencyid": "EUR"
            }item_67167",
            "quantitymenuSelections": 1[],
            "orderDiscountsprice": [{
              {
"amount": 679,
               "typecurrency": "percentageEUR",
            },
   "value": 50        "quantity": 1,
     }       "orderDiscounts": [
    ]          {
},           {             "externalReferenceId"type": "940151percentage",
                "idvalue": "item_50929",50
              }
 "menuSelections": [],          ]
  "price": {       },
       "amount": 0,  {
            "currencyexternalReferenceId": "EUR940151",
            },
"id": "item_50929",
            "quantitymenuSelections": 1[],
            "orderDiscountsprice": [{
              {
"amount": 0,
               "typecurrency": "percentage",EUR"
            },
            "valuequantity": 501,
            "orderDiscounts": [
}             ] {
         },       "type": "percentage",
   {             "externalReferenceIdvalue": "940180",50
             "id": "item_66018", }
            ]
    "menuSelections": [],     },
       "price": {  {
            "amountexternalReferenceId": 1500"940180",

             "currencyid": "EURitem_66018",
            }"menuSelections": [],
            "quantityprice": 1,{
              "orderDiscountsamount": [1500,
              {
"currency": "EUR"
            },
            "quantity": 1,
            "orderDiscounts": [
              {
                "type": "percentage",
                "value": 50
              }
            ]
          },
          {
            "externalReferenceId": "940325",
            "id": "45adf5bb-2f3d-4c40-a735-cf59d5a661ef",
            "menuSelections": [],
            "price": {
              "amount": 0,
              "currency": "EUR"
            },
            "quantity": 1,
            "orderDiscounts": [
              {
                "type": "percentage",
                "value": 50
              }
            ]
          }
        ],
        "price": {
          "amount": 1100,
          "currency": "EUR"
        },
        "quantity": 1,
        "orderDiscounts": [
          {
            "type": "percentage",
            "value": 50
          }
        ]
      }
    ]
  },
  "channel": "WHITELABEL_IN_STORE",
  "fees": [],
  "id": "84b5f1df-28df-4e6f-a871-a2783602436f",
  "instructions": [],
  "serviceMode": "TAKEOUT",
  "storeId": "1111"
}

1 - TASK: Create a method to calculate the percentage offer;

...

Create a feature flag;

Create a method to calculate the percentage offer.

...

path: intl-partners-service/src/modules/orders/orders.service.ts

...

We will send the discount values per cart item to Winrest, but the calculation of the discount percentage will be based on the cart total, which will be easier to calculate and in the end will have the same result if we calculate the discount per item.

...

The method will receive two params:

  • appliedOffers: IAppliedOffer[] | null | undefined

    • Offer applied on the cart;

      Image Removed
  • total: number | undefined

    • total cart value;

...

The method return will be:

  • Promise<IOrderDiscounts[] | undefined>

    • Where the IOrderDiscounts.type will be always a percentage;

...

To discover the discount values we will need to use the method getOffers

  • path: intl-partners-service/src/modules/orders/cart-total.service.ts

  • This method is private, so we will update it to public;

If the discount offer is a type amount we will calculate the percentage over the total cart value;

E.g: If the total cart is 10 euros and amount discount is 5 euros;

We will calculate the discount:

...

84b5f1df-28df-4e6f-a871-a2783602436f",
  "instructions": [],
  "serviceMode": "TAKEOUT",
  "storeId": "1111"
}

2 - TASK: Update the calculated total card;

...