Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Business problem

...

For the food aggregator workflow we have the following diagramsequence of events:

...

Known issues

  1. Fulfillment service aggregating all fees into delivery fee
    This is part of the first implementation that we can see here :

    Code Block
    languagetypescript
        const deliveryFees = input.charges?.fees?.reduce((acc, fee) => {
          if (fee.type === PartnerFeeType.DELIVERY_FEE) {
            acc = fee.total?.amount ?? 0;
          }
          return acc;
        }, 0);
  2. DMP never receive the fees associated with the order
    Although DMP calculates the delivery fee in the WL during the quote workflow, this information is does not persisted persist when the order is created. Besides that, no information regarding the other fees is received by it, as we can see in the create delivery webhook documentation.

...

A simple solution is fixing the delivery fee in fulfillment calculation and altering the delivery integration to receive this information. Fixing the calculation is important since the fees returned for the POS will be used by them to create the delivery later (to be confirmed).

IMPORTANT CONSIDERATIONS:

  1. The proposed solution assumes that the POS will send the fee breakdown, either on the commitOrder endpoint or the submitOrder. This was proposed by Winrest and the ground work is already laid off in partners API given the list of fees it receives.

  2. The exact fee structure may change to include new fields in the near future, so this feature should be implemented after

    Jira Legacy
    serverSystem JIRA
    serverId255417eb-03fa-3e2f-a6ba-05d325fec50d
    keyIBFEC-1467
    is done.

  3. Although the POC focuses on aggregators, the changes will work for WL orders as well, since the create delivery process is the same.

Let’s split the solution into three steps:

  1. Fix the fee calculation in the fulfillment service

  2. Send fee information in partners service

  3. Receive and persist fee information in DMP

  4. Display fee breakdown in expeditor tablet, including printed tickets

...

For the first problem, we’ll need to map all the possible received fees (including new values to come) into the fee fields of the RBI Order. Taking Take delivery and service fee fees as examples:

intl-fulfillment-service/src/modules/channel-partner/channel-partner.service.ts

...

Note

Altering this request will change the payload sent to all delivery providers in used by international. If any of them have servers configured in strict mode, the integration could break. Ideally, we can use LaunchDarkly to configure which integrations will receive the new field.

Code Block
languagetypescript
public async createDelivery(input: CreateDeliveryRequestDto): Promise<CreateDeliveryResponseDto> {
   ...
   const mapRbiFees = (fees: FeesDto | undefined) => {
     return {
       deliveryFee: mapToMoney(fees?.baseDeliveryFee, IsoCountryCode2Char.ES),
       serviceFee: mapToMoney(fees?.serviceFee, IsoCountryCode2Char.ES),
     };
   };

   const payload: IWebhookCreateDelivery = {
       callbackUrl: `https://${partnersApi.host}/api/${partnersApi.version}/delivery/create/callback`,
       ...
       fees: mapRbiFees(input.fees),
  };
}

After configuring a mock the webhook to hit a local Mockoon server, I could confirm the new fees would indeed be sent to the delivery provider:

...

The create delivery request sent by partners-service is received by DMP /orders endpoint, which creates and an OrderResponseDTO object in Dynamo DB. First, we need to include the fee field in the three relevant DTOs: OrderResponseDto, DeliveryWebhookRbiDto and DeliveryWebhookDto.

...

Code Block
languagetypescript
export class FeesDto {
  @Type(() => Amount)
  @ValidateNested()
  @IsObject()
  @ApiProperty({ description: 'Delivery fee charged in the order', type: Amount })
  deliveryFee: Amount;

  @Type(() => Amount)
  @ValidateNested()
  @IsObject()
  @ApiProperty({ description: 'Service fee charged in the order', type: Amount })
  serviceFee: Amount;
}

export class OrderResponseDto {
  ...
  
  @ApiProperty({ description: 'Fees charged in the order', type: FeesDto })
  fees?: FeesDto;
}

export class DeliveryWebhookRbiDto {
  ...
  
  @ApiProperty({ description: 'Fees charged in the order', type: FeesDto })
  fees?: FeesDto;
}
export class DeliveryWebhookDto {
  ...
  
  @ApiProperty({ description: 'Fees charged in the order', type: FeesDto })
  fees?: FeesDto;
}

After the above it’s is done, it’s a matter of adjusting the relevant formatter methods used by the webhook.

...

We’ll have to align with the UI/UX team to find the best way to display the new information, but as long as the backend is returning it, the expeditor tablet has only to adjust the Order interface and create the new react components responsible for showing the fees.

...

  1. Display fee breakdown in order detail

    1. remove the old delivery fee calculation code

  2. Validate if the order ticket is printed with the fees

  3. Create/update e2e order tests to include the new scenario