Questions:
N/D
Technical Refinement
Goal
The main objective is to allow the customers to use promo codes at checkout to receive benefits coming from offers.
Front-end refinement
From what we understand the current feature at checkout allow promo code just to type CBA offers and this feature is deprecated. More infos: https://rbidigital.slack.com/archives/C04FZ5HTH35/p1693855082030399.
As CBA feature is deprecated we need to change the promo code field to accept loyalty promo codes. (here more details on how to configure the promo code on sanity and voucherify: /wiki/spaces/CG/pages/984973325- OBS.: The documentation explain how configure promo codes to CBA offers and Loyalty Offers, So follow just the loyalty steps.)
After the config, we will have the config offer like this:
OBS.: On In-App Benefits there is just one item. If there are more itens, the discount will be the first item.
intl-whitelabel-app
1 - TASK: Create new promo code flow to loyalty
Create 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
Attention points:
We need to apply (dispatch) the personalised offer on some contexts:
actions.loyalty.setSelectedOffer(personalizedOffer)
actions.loyalty.setAppliedOffers
actions.loyalty.applyOffer
actions.loyalty.setCmsOffers
OBS.: It’s possible we need to apply the offer in another contexts too.
When we click on remove in offer info (after applied the offer), we need to remove the offer on all contexts.
When the customers reload the page, the offer must continue applied.
Verify need for other validations
With this update, the frontend is prepared to apply the promo code to loyalty.
2 - TASK: Updated action Remove button
We will need to update the button action to remove the applied offer on
loyalty.offers.cmsOffers
path:
intl-whitelabel-app/workspaces/frontend/src/state/global-state/models/loyalty/offers/offers.slice.ts
removeCmsOffers: (state, { payload }: PayloadAction<LoyaltyOffer>) => { state.cmsOffers = state.cmsOffers.filter(offer => offer._id !== payload._id); },
path:
intl-whitelabel-app/workspaces/frontend/src/pages/cart/your-cart/cart-offer.tsx
const onRemove = () => { ... dispatch(actions.loyalty.removeCmsOffers(selectedLoyaltyOffer)); };
OBS.: Change also:
path:
intl-whitelabel-app/workspaces/frontend/src/state/global-state/models/loyalty/loyalty.actions.ts
3 - TASK: Hide CBA Options
We will need to hide the CBA option to ensure that anything CBA option shows.
Then, we will create a new attribute to hide this option;
This attribute value can be the opposite of the value of feature flag (flag created on task 1)
4 - TASK: Apply discount again if not used
5 - TASK: Clean the applied offer when finished the order
When finished the order, we need to clean the offers on cookies, sessions and etc.
path:
intl-whitelabel-app/workspaces/frontend/src/pages/order-confirmation/order-confirmation.tsx
Back-end
After applied the whitelabel will do a call to backend to calculate the discount value:
First, it will call the PriceOrder mutation on intl-gateway or intl-graphql
This mutation will call the backend:
intl-partners-service
repository.on this repository, will call:
public async price(@Body() payload: PriceOrderRequestDto): Promise<OrderResponseDto>
path: intl-partners-service/src/modules/orders/orders.controller.ts
after:
public async price(input: IPriceOrderRequest): Promise<IOrder>
path:
intl-partners-service/src/modules/orders/orders.service.ts
on this file is where calculate the order and is generated the rbiOrderId.
Currently for some reason, the calc is wrong in 2 aspects:
Setting up wrong offers;
Missing configOffer calc;
intl-partners-service
When the frontend call the backend, the first method ran is:
public async price(@Body() payload: PriceOrderRequestDto): Promise<OrderResponseDto>
path:
intl-partners-service/src/modules/orders/orders.controller.ts
after:
public async price(input: IPriceOrderRequest): Promise<IOrder>
path:
intl-partners-service/src/modules/orders/orders.service.ts
on this file is where calculate the order and is generated the rbiOrderId.
On
price(input: IPriceOrderRequest)
on fileorders.service.ts
, there is a call method namedthis.cartTotalService.calculate(input.cart)
.Inside this method is calc the some type offers, for example System Wide offers, but there isn’t the calc relative Offer configs.
The method that calc relative the system wide offer is
getSystemWideOfferIncentiveDiscountAndType(offerId: string): Promise<IRewardIncentive | undefined>
path:
@intl-sanity/loyalty/index.ts
Possible solution configOffer calc:
We will need to create a new method to get the config offers on
intl-sanity
repository:path:
intl-sanity/loyalty/index.ts
After it, we will need to update the
intl-sanity
lib onintl-partners-service
to have access at this new query.In the next, we can do the new method to calc this type offer that can be after
getSystemWideOfferIncentiveDiscountAndType
method:path:
intl-partners-service/src/modules/orders/cart-total.service.ts
Remembering that all these problems can occur because there is an error in the offer settings somewhere.
Screenshots
N/A
POC
FRONTEND (WHITELABEL)
INTL-PARTNERS-SERVICE: https://github.com/rbilabs/intl-partners-service/tree/poc/IBFEC-934-loyalty-promo-code-at-checkout
Impact Analysis
N/A
Dependencies
N/A
Unit Test
N/A
Useful Links
N/A
Add Comment