Document Status | Status |
---|
colour | BlueGreen |
---|
title | IN REVIEWREVIEWED |
---|
|
|
---|
Document Owner(s) | Capovilla, Evandro |
---|
Reviewers | |
---|
✅ 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: |
...
Expand |
---|
title | https://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 loopOrder
Frontend->DB: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 |
---|
title | https://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.
New payment method support
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 |
---|
title | src/svgs/mbway/index.tsx |
---|
|
Code Block |
---|
import { SVGIconComponent } from '../types';
export const endered: SVGIconComponent = ({ title = '', ...props }) => (
//svg code
); |
|
...
Expand |
---|
title | src/themes/types/icon.ts |
---|
|
|
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 |
---|
|
Code Block |
---|
commitInput = {
...commitInput,
payment: {
paymentRequestCreatedAtpaymentRequestTimeLimit: 1627383253213, //timestamp
...commitInput.paymemt
}
} |
|
...
Expand |
---|
title | src/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 |
---|
title | intl-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 |
---|
title | src/functions/graphql/generated/graphql.ts |
---|
|
Code Block |
---|
export enum CartPaymentType {
...
MBWay = 'MBWay',
} |
|
Expand |
---|
title | src/functions/graphql/providers/payments.ts |
---|
|
Code Block |
---|
export interface IPaycometPaymentSaleEvent extends IBaseSale {
...
paymentRequestCreatedAtpaymentRequestTimeLimit?: number;
} |
|
Expand |
---|
title | src/functions/graphql/providers/payments.ts |
---|
|
Code Block |
---|
paycometSale = {
...
paymentRequestCreatedAtpaymentRequestTimeLimit: payment?.paymentRequestCreatedAtpaymentRequestTimeLimit,
}; |
|
Expand |
---|
title | src/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 |
---|
title | Update 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 |
---|
title | src/outcome/dtos/outcome.dto.ts |
---|
|
Code Block |
---|
export enum TypePayment {
...
MBWay = 'MBWay'
} |
|
...
Expand |
---|
title | Initiate 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 |
---|
title | src/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 |
---|
title | src/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 |
---|
title | src/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 |
---|
title | src/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 |
---|
|
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.
...