Add a new state for the new payment method: const [isPaycometNewMethodSelected, setIsPaycometNewMethodSelected] = useState('');
Update the handlePaymentMethodSelected adding the new method: Code Block |
---|
| const handlePaymentMethodSelected = (newFdAccountId?: string) => {
if (!newFdAccountId) {
payment.setCheckoutPaymentMethodId('');
return;
}
// ... rest of the code
setIsPaycometNewMethodSelected(''); // New line
}; |
Clear our new method in the useEffect logic that already exist: Code Block |
---|
| // when checkout payment method have been updated from payment context
// the flags to show add new credit card or add gift card
// have to be updated.
useEffect(() => {
// ... rest of the code
setIsPaycometNewMethodSelected('');
}
}, [setCheckoutPaymentMethodId, checkoutPaymentMethodId]); |
Update the placeOrder function to deal with the new method: Adjust the processOrderWithAccount function for the new method like this Sodexo example: Code Block |
---|
| // ... rest of the code
const isPaymentWithVoucher =
paymentAccount.paymentMethodBrand === PaymentMethodBrand.SODEXO_VOUCHER ||
paymentAccount.paymentMethodBrand === PaymentMethodBrand.CHEQUE_GOURMET_VOUCHER;
if (payment.checkoutPaymentMethodId === CASH_ACCOUNT_IDENTIFIER || isPaymentWithVoucher) {
const paymentDetails: IPayment = {
cashPayment: true,
fullName,
paymentMethodBrand: paymentAccount?.paymentMethodBrand ?? undefined,
};
if (payment.isVrPayment) {
// The GraphQL endpoint for VR Payment expects this object even
// for Cash orders, otherwise the order creation fails
paymentDetails.vrPaymentInput = {
merchantAccount: '',
pspReference: '',
storePaymentMethod: true,
};
}
return commitOrder({
...commitInput,
creditType: CASH_ACCOUNT_IDENTIFIER,
payment: paymentDetails,
});
} |
Adjust the handleOrderCommit to place the order with the new method: Code Block |
---|
| // Add new condition here as the isPaymentWithVoucher from the Sodexo example
const isPaymentWithVoucher = isPaymentWithSodexoVoucher || isPaymentWithChequeGourmetVoucher;
if (
(showAddPaymentMethod ||
isAdyenBlikMethodSelected ||
reloadAddPaymentMethod ||
isPayPalRegistration) &&
!(selectedPaymentMethod?.cash || isPaymentWithVoucher || payment.isFreeOrderPayment)
) {
await placeOrder();
} else {
await placeOrderWithAccount();
} |
|