Versions Compared

Key

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

Document Status

Status
colourBlueGreen
titleIN REVIEWREVIEWED

Document Owner(s)

Capovilla, Evandro

Reviewers

Table of Contents

✅ Proposed Solution

...

Info

Remember that waiting for payment is a feature for all payment methods, but for it to be displayed, two conditions must be met:

  • The order must not be paid yet. (PRICE_SUCESSFUL and PAYMENT_REQUIRED)

  • The request must contain the paymentRequestCreatedAt paymentRequestTimeLimit property in the payment property.

...

Expand
titlehttps://sequencediagram.org/ - Create Payment Request
Code Block
title Create Payment Request

participant Frontend
participant Graphql/Fulfillment
participant DB
participant Payment Service
participant PSP Service
participant Paycomet External

Frontend->Graphql/Fulfillment: Initiate Payment
Graphql/Fulfillment->Payment Service: Initiate Payment
Payment Service->PSP Service:Initiate Payment
PSP Service->Paycomet External:Payments Endpoint
PSP Service<-Paycomet External:Result
Payment Service<-PSP Service:Result
Payment Service->DB: Update Order \n(PaymentRequestTimeLimit)
Payment Service<-DB: Order Updated
DB<-Payment Service: Create Payment in Payment Table
DB->Payment Service: Payment Created
Graphql/Fulfillment<-Payment Service:Result
Frontend<-Graphql/Fulfillment:Result

group Commit Order
Frontend->Frontend:Order >Graphql/Fulfillment:     Commit Order\n(SaveCommitOnly)
Frontend<-Graphql/Fulfillment: Commit Order Result
end

loop
Frontend->DB:Order Polling
Frontend<-DB:Order Result
end

For this communication, it is necessary to transmit two important pieces of information to the Paycomet service: the amount and the cellphone. The cellphone will be used by Paycomet to create a request in the user's MBWay account. Once the data reaches the Paycomet service, we will create a payload as mentioned below for the /payments endpoint of Paycomet.

...

Expand
titlehttps://sequencediagram.org/ - Retrieve Payment Status

title Payment Status

participant Frontend
participant Graphql/Fulfillment
participant DB
participant Payment Service
participant PSP Service
participant Paycomet External

Frontend->Frontend:Order Polling
PSP Service<-Paycomet External:Payment Status
Payment Service<-PSP Service:Payment Status
DB<-Payment Service: Update Order
Frontend<-DB:Order Result

Development

This section includes some code examples that will be developed. The examples serve as a guide for development, and good practices as well as testing should be adopted.

New payment method support

This first stage involves adding the main foundation for the new payment method. Since this task is repeated for all new payment methods, I will only provide the reference for each stage. This should be the first part of the frontend development; without it, it will not be possible to continue with the development of the subsequent screens.

...

Add new payment method icon

ref: https://github.com/rbilabs/ctg-components-library/pull/399 This task involves adding the icon to be used later by the whitelabel

Expand
titlesrc/svgs/mbway/index.tsx
Code Block
import { SVGIconComponent } from '../types';

export const endered: SVGIconComponent = ({ title = '', ...props }) => (
//svg code
);

...

Expand
titlesrc/themes/types/icon.ts
Code Block
mbway: string;

ref: https://github.com/rbilabs/ctg-components-library/pull/399

Create a new feature flag

This task aims to create the feature flag in both launchdarkly and whitelabel

https://rbictg.atlassian.net/wiki/spaces/IBC/pages/4362960979/Technical+refinement+-+Front+end#Task-1%3A-Create-a-new-feature-flag

...

Add the new payment method in the payment state and structure

This task aims to create the mbway in payment state and structure

https://rbictg.atlassian.net/wiki/spaces/IBC/pages/4362960979/Technical+refinement+-+Front+end#Task-2%3A-Add-the-new-payment-method-in-the-payment-state-and-structure

...

Add the new method in payment-method structure and payment list

This task aims to add mbway to the payment dropdown

https://rbictg.atlassian.net/wiki/spaces/IBC/pages/4362960979/Technical+refinement+-+Front+end#Task-3%3A-Add-the-new-method-in-payment-method-structure

...

Adjust the receipt email to show the correct message for the new payment method

https://This task aims to adjust the email to include mbway as a payment method

https://rbictg.atlassian.net/wiki/spaces/IBC/pages/4449861673/Technical+refinement+-+Frontend#Task-6%3A-Adjust-the-receipt-email-to-show-the-correct-message-for-the-new-payment-method

...

This task covers the order commit, where we will add a new field called paymentRequestCreatedAt paymentRequestTimeLimit, which will be responsible for recording when the payment request was generated. This field will be used in the future on the "Waiting for Payment" screen. It is important to remember that saveCommitOnly must be enabled for the order commit in the backend to be activated.

Expand
titleCommit Order
Code Block
commitInput = {
  ...commitInput,
  payment: {
    paymentRequestCreatedAtpaymentRequestTimeLimit: 1627383253213, //timestamp
    ...commitInput.paymemt
  }
}
Info

Even though we are just requesting a payment, we must place the order so that we can receive the transaction data in the psp-service notification endpoint. Without this, the order will never be completed.

Payment Pending Tracking

...

Tracking Page

This task involves handling the information for the "Waiting for Payment" screen when the payment request is made. Therefore, a generic screen should be developed that can be used by other future payment methods. Additionally, this screen should be displayed when the user closes the app and returns to the homepage, as long as there is still an active payment to be completed.

...

Expand
titlesrc/pages/mbway/index.tsx
Code Block
const pendingPage = () => {
  const { orderId } = useParams();
  const MBWayPendingPayment = LocalStorage.getItem(StorageKeys.PENDING_PAYMENT);
  
  let data;
  if(MBWayPendingPayment && MBWayPendingPayment.id === orderId){
    data = MBWayPendingPayment;
  } else {
    try{
      const orders = GetUserOrders(); 
      // map the order list to show only the latest information needed
      data = orders[0];
    }
  }
  
  return (
    <MBWayComponent data={data} />
  )
}

Backend

Packages

This task aims to add mbway to the payment method enums

Expand
titleintl-apis-psp-service
Code Block
export declare enum PaymentMethodType {
    ...
    MBWay = 'MBWay'
}

...

Commit Order Graphql/Fulfillment

This task aims to add mbway to the payment method enums and modify the commit order to accept this new payment method, in addition to including the new field: paymentRequestTimeLimit

Expand
titlesrc/functions/graphql/generated/graphql.ts
Code Block
export enum CartPaymentType {
  ...
  MBWay = 'MBWay',
}
Expand
titlesrc/functions/graphql/providers/payments.ts
Code Block
export interface IPaycometPaymentSaleEvent extends IBaseSale {
  ...
  paymentRequestCreatedAtpaymentRequestTimeLimit?: number;
}
Expand
titlesrc/functions/graphql/providers/payments.ts
Code Block
paycometSale = {
  ...
  paymentRequestCreatedAtpaymentRequestTimeLimit: payment?.paymentRequestCreatedAtpaymentRequestTimeLimit,
};
Expand
titlesrc/functions/graphql/utils/make-payment.ts
Code Block
private mapPaymentMethod(
    params: IPaycometPaymentSaleEvent,
  ): {
    paymentMethodType: string;
    paymentMethod: string;
  } {
    ...

    return {
      paymentMethodType: params.paymentRequestCreatedAtpaymentRequestTimeLimit &&
                           params.paymentMethodType ? 'MBWay' : 'scheme',
      paymentMethod: JSON.stringify({
        type: 'scheme',
        subtype: 'onetime',
      }),
    };
  }

...

Create a new request to Graphql/Fulfillment to handle MB Way on Initiate Endpoint

Implementation example: https://github.com/rbilabs/intl-whitelabel-graphql/pull/1150/files This task aims to add the paycometCaptureContext field to the initiatePayment endpoint

Expand
titleUpdate the Graphql Initiate Endpoint
Code Block
input PaycometCaptureContextInput {
  amount: number!
  rbiOrderId: String!
  cellphone: number
  method: string!
}

input InitiatePaymentInput {
  storeId: String!
  paymentMethodType: String!
  cybersourcePaSetup: CybersourcePaSetupInput
  cybersourceCaptureContext: CybersourceCaptureContextInput
  paycometCaptureContext: PaycometCaptureContextInput
}

Implementation example: https://github.com/rbilabs/intl-whitelabel-graphql/pull/1150

Create a new endpoint in Paycomet PSP Service

This task aims to create the initiatePayment endpoint on paycomet psp and also its functionality.

Expand
titlesrc/outcome/dtos/outcome.dto.ts
Code Block
export enum TypePayment {
  ...
  MBWay = 'MBWay'
}

...

Expand
titleInitiate Payment Service
Code Block
public async initiatePaymentMBWay(
    region: string,
    request: InitiateRequestDto,
  ): Promise<InitiateResult> {
    try{
      const result = this.createPaymentMBWayRequest(request);
      // Add log about payment initiation attempt
      if(result.errorCode === TransactionStatus.SUCCESSFUL){
        return this.handleSuccesful(region, request, result);
      }
      return this.handleFailure(region, request, result);
    } catch(error){
      return this.handleFailure(region, request, error);
    }
}

Update the

...

makePayment endpoint in Paycomet PSP Service

Expand
titlesrc/components/order-details/payment/payment.service.ts
Code Block
private isOneTimePayment(paymentMethod: PaymentMethod): paymentMethod is OneTimeSchemeDto {
return (
    (paymentMethod.type === PaymentMethodType.Scheme ||
    paymentMethod.type === PaymentMethodType.MBWay) &&
    paymentMethod.subtype === SchemePaymentMethodType.OneTime
  );
}
Expand
titlesrc/paycomet-core/paycomet-helper.ts
Code Block
public getPaymentLinkId(
  ...
): TypePayment | undefined {
  if (!methodId) {
    const paymentLink = transaction?.payment?.history.find(
      (order) =>
        ... ||
        order.methodId === TransactionMethodId.APPLEPAYLINK ||
        order.methodId === TransactionMethodId.MBWAY ||,
    );

    methodId = Number(paymentLink?.methodId);
  }
}
Expand
titlesrc/paycomet-core/commons.types.ts
Code Block
export enum TransactionMethodId {
  APPLEPAYLINK = 1,
  MBWAY = 38
}

Admin App

Adding mbway within the translation enum so that the Admin App knows this new payment method and selects the correct translation.

Expand
titlesrc/components/order-details/order-details-card.tsx

ref: https://github.com/rbilabs/intl-admin-app/blob/6068cb1f1023cb5a588bd3a87e7cc3587d226397/src/components/order-details/order-details-card.tsx#L60-L86

Code Block
const paymentMethodType = order?.cart?.payment?.type;

if (paymentMethodType === 'MBWay') {
      return formatMessage({ id: paymentMethodBrandTranslationMap(paymentMethodType) });
    }
    
if (paymentMethodBrand) {
      return formatMessage({ id: paymentMethodBrandTranslationMap(paymentMethodBrand) });
    }

DOP

Adding mbway within the translation enum so that the DOP knows this new payment method and selects the correct translation

Expand
titlesrc/utils/orders.ts

ref: https://github.com/rbilabs/ctg-fz-portal/blob/75b71352d4049a2797c8e752def79807d40a4e07/workspaces/frontend/src/utils/orders.ts#L8-L26

Code Block
export const paymentMethodTranslation: Record<string, keyof LocalizedDictionary> = {
  MBWAY: `${pathPaymentTranslations}.mbway`,
};

Expeditor Tablet

Adding the mbway inside the enum so that the expeditor tablet knows this new payment method.

Expand
titlesrc/constants/paymentMethod.ts

ref: https://github.com/rbilabs/intl-expeditor-tablet/blob/b02805ed57a3d13dd4bc83dbdeac190ad2d2a106/workspaces/frontend/src/constants/paymentMethod.ts#L3-L19

Code Block
export enum PaymentMethod {
  ...,
  MBWAY = "MBWAY",
}

...