Front-end
Say we have the following order:
With this improvements, we want to split the amount of the delivery fee into two fields:
delivery fee and management fee.
Similar to what we have in the current app (airtouch):
gastos de envio → delivery fee
otros gastos → management fee
Mapping of how delivery fee is set:
PriceOrder
Calls partner service API PriceOrder to get price related info including fees.
Persists taxes into the database
GetOrder
Retrieves order related info from the database, including fees
Backend
priceOrder
intl-whitelabel-app →
priceOrder
intl-whitelabel-graphql →
priceOrder
intl-fullfilment-service →
priceOrder
updateDeliveryEntry
intl-delivery-service
getFeeAndDiscountByBrand
( using intl-packages delivery lib or intl-delivery-service?)
Delivery fees are managed by the fee service ( intl-delivery-service):
getFeeAndDiscountByBrand
getFeeChargeByTier
It get the values from launchdarkly based on the service mode.
If catering , it uses
tiered-catering-delivery-fees
Otherwise, it uses
tiered-delivery-fees
Searches the tier list from highest to lowest key, stopping when requestedAmountCents exceeds that tier.
Said that, we can to analyze the following "return” to propose the management fee. Apart from that, looks like Launchdarkly existing configuration (variations) were thought to enable "free delivery” and we can leverage this approach.
return { baseDeliveryFee: fee, --> LD fee deliverySurchargeFee, --> LD expandedFees (based on delivery quotation value) discount, --> LD discount fee: fee + geographicalFee + serviceFee + smallCartFee + deliverySurchargeFee, geographicalFee, --> LD geographicalFee serviceFee, --> Calculated with LD serviceFeePercent of the requested amount smallCartFee, --> LD smallCartFee };
We may introduce a new fee named "management fee” to fulfill the current use-case or explore existing fees.
Going further in priceOrder (fulfillment), it reaches the applyQuote service
await this.quotesApi.applyQuote(applyQuoteParameters);
/api/v1/quotes/apply
return this.service.enqueueApplyQuoteNotification(request);
→SQS_APPLY_QUOTE_QUEUE_URL
/SNS_QUOTE_TOPIC_ARN
Here, the services are decoupled. Therefore, there is a lambda function that listens to the apply quote queue and handles it.
intl-delivery-service
on-apply-quote Lambda
return quoteService.applyQuote(message);
async applyQuote(request: ApplyQuoteRequestDto): Promise<ApplyQuoteResponseDto> {
getFees
As result, zeroed fees are being set. See cloud watch logs from lambda function.
*The quotedFee comes from partners. In Iberia, it comes from DMP, aka: intl-partners-delivery. But it depends on the market. DMP also uses launchdarkly to calculate the fee. It doesn’t get the other fees.
Once we get these fees (including the zeroed one), intl-delivery-service sends the result to
SNS: dev-plk-delivery-quote-outcome
SQS: aws-rbi-dev-plk-apply-delivery-service-quote
Lambda: sls-rbi-dev-plk-orders-delivery-service-apply-quote ( intl-orders-service)
Which get the message and updates the current order in the database (dynamodb)
Proposal:
Enhance this lambda function (dev-plk-delivery-on-apply-quote) to not overwrite discount and service fees with zeroes. It should keep the value from launchdarkly.
Configure launchdarkly to fit business needs enabling FE to show fees and discounts properly.
discount <> 0
serviceFee <> 0
fee <> 0
Configured webhooks*:
In partners service, create quote flow calls both in delivery : quote_create and quote_apply
The following flows are triggered whenever an order is updated in the database, so that the fee amounts are properly read by the API services and returned to the caller.
intl-data-service: Dynamodb order mutated (updated to createDelivery) from queue
ORDER_UPDATED_TOPIC_ARN
processMessage
intl-orders-service
processMessage
requestTransportation
createDelivery / Quote flows
Architecture
Problems detected in DEV:
Added 9 sauces of 2.00 in the cart
After resulting in 18, it multiplied by 9 again:
Button + reached limit of 5, and kept varying between 4 and 5 in upsell cart modal
Threshold issue:
During the initial analysis, we were informed that fees would not come to FE when threshold is reached, however the behavior looks the same of when threshold is not reached.
0 Comments