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
...
We will use all methods created above (
mapOffersDiscounts
andcalculateTotalCart
):path:
intl-partners-service/src/modules/orders/orders.service.ts
On method
public async price(input: IPriceOrderRequest):
We will import the attribute
appliedOffers
on objectinput.cart
;We will protect the code with feature flag here;
We will calculate the total cart without possible discounts (
calculateTotalCart
) and use the methodmapOffersDiscounts
to create the object with percentage discount:Code Block language typescript let discountsOffer; if (FEATURE_FLAG && appliedOffers?.length) { const totalCart = this.cartTotalService.calculateTotalCart(input.cart); discountsOffer = await this.mapOffersDiscounts(appliedOffers, totalCart); }
We will add the variable
orderDiscounts
on attributeorderDiscounts
fromnewOrder
object;
4 - TASK: Send the new discount object to Winrest
We will need to send the new discount attribute to Winrest by webhook:
Then, we will add the new attribute on mapper
mapRbiCart
;So we will add the variable
discountsOffer
tomapRbiCart
:mapRbiCart(pricingCart, discountsOffer)
;In this method, we will add a new condition to send the discount values:
Code Block language typescript if (FEATURE_FLAG && orderDiscounts?.length && verifyDiscountTypes(cartEntry)) { result.orderDiscounts = orderDiscounts; }
Where,
verifyDiscountTypes
item type of the cart that there will be a discount because these items are already an items offer;Code Block language json const verifyDiscountTypes = (cartEntry: ICartEntry): boolean => { return ( cartEntry.type !== CartEntryType.offerDiscount && cartEntry.type !== CartEntryType.offerCombo && cartEntry.type !== CartEntryType.offerItem ); };
Screenshots
N/A
POC
FRONTEND (WHITELABEL)
BACKEND (INTL-PARTNERS-SERVICE)
...