Implement a Front-Commerce payment method
Choose the payment workflow wisely
Payment can be handled synchronously or asynchronously.
If Front-Commerce allows both strategies to work, we highly recommend you to implement an asynchronous payment method (using IPN) whenever it is possible.
This will prevent your payments from being rejected later within the provider process without your backend application knowing about it.
In this guide, we'll implement an asynchronous Front-Commerce payment method.
Implement the server logic
Front-Commerce allows you to implement your own payment method. New embedded payment methods have to be registered from a GraphQL module. Let’s create a new "PWAy" payment module for a fictive payment provider.
Handle a sublist of payment methods
You may need to dynamically set the list of payment methods displayed for your module.
This is achieved by registering a replacement handler
export default createGraphQLRuntime({
contextEnhancer: ({ loaders }) => {
/* ... */
loaders.Payment.registerEmbeddedPaymentMethod(
/* ... */
);
loaders.Payment.registerMultiplePaymentMethods({
isMethodToReplace: (method) => method.code === METHOD_CODE,
getReplacementMethods: async () => {
try {
// custom call to fetch the allowed payment methods list
const paymentMethods = call(/* ... */);
return paymentMethods.map((method) => ({
// this is the method code provided to the checkout workflow
// note that all payment methods must have a common prefix
code: `${prefix}_${method.id}`,
// the displayed payment method name on the checkout page
title: method.description,
// this method is called following the onAuthorize call in the AdditionalDataComponent (see bellow) instead of the default method defined with registerEmbeddedPaymentMethod
callback: (paymentData, orderId, orderPaymentDetails) =>
return loader.order(paymentData, orderId, orderPaymentDetails);
})),
} catch (error) {
// handle the error here
return [];
}
},
});
/* ... */
},
});
Display the new payment method on the UI with additional information
While payment methods provided by Front-Commerce don't need any additional information, you may require some, for example, if you want to let users enter a comment related to the payment method/checkout.
See the payment workflows specificities for changes to the current example for each workflow.