- 26 May 2024
- 1 Minute to read
- Print
- DarkLight
Implement Payment Method with Payment Flow Footer
- Updated on 26 May 2024
- 1 Minute to read
- Print
- DarkLight
You may implement a new Payment Method with Flow and Payment Flow Footer:
Create an Apex class implements IPaymentHandler interface
Add the following 2 methods in the new Apex class
InitializePaymentResult initialize (PaymentContext context);
HandlePaymentResult handle(Payment payment, PaymentContext context);
- Provide the following property values in method initialize:
- action.type
- action.actionTypeName
- action.componentName(= name of flow)
- payment.totalAmount
Sample of method initialize:
global virtual InitializePaymentResult initialize (PaymentContext context) {
InitializePaymentResult result = new InitializePaymentResult();
result.payment = new Payment();
result.payment.totalAmount = context.totalAmount;
result.action = new PaymentAction();
result.action.type = PaymentAction.ActionType.ScreenFlow;
result.action.actionTypeName = String.valueOf(result.action.type);
result.action.componentName = 'default_payment_flow';
return result;
}
- The method handle should return the result of payment or the error message.
Sample of method handle:
global virtual HandlePaymentResult handle(Payment payment, PaymentContext context) {
HandlePaymentResuLt result = new HandlePaymentResult();
result.success = validatePayment (payment, context);
// provide value for error
// result.success = false;
// result.message = 'test error';
return result;
}
private Boolean validatePayment (Payment payment, PaymentContext context) {
return true;
}
Create new Payment Method:
Setup -> Custom Metadata Types -> Payment Method -> Manage Payment method -> NewAdd the new Apex class name to Handler and save
Create a new Flow:
Setup -> Flows -> New FlowSet input and output variables.
Add a Screen component in the flow, drag and drop custom component Custom Flow Footer to the bottom of the Screen component, the API Name is PaymentFlowFooter.
Remove the tick from Show Footer in Configure Footer, then save the flow with the new Apex class name (same as what you filled in Handler of new Payment Method), and activate the flow.
- If payment failed, then on the flow modal text of the error will appear and Web_Order__c will not be created. Customer can read the failed message and close modal.
- If payment succeeded, Web_Order__c will be created and lookup field Payment__c.Web_Order__c will be populated.
- If result.action.type = PaymentAction.ActionType.None, then after clicking “Place Order” button, Web_Order__c will be just created, and the lookup field Payment__c.Web_Order__c will be populated.