Payment Providers
::: Customize Payment :::
You can add multiple payment method types to a shop such as CARD
& INVOICE
but before you can start accepting payment you need to add a payment adapter by implementing the IPaymentAdapter and registering it to the global Payment director that implements the IPaymentDirector.
Below is an example implementation of Pre-Paid INVOICE
payment provider type that will require a manual confirmation of order payment
import type { IPaymentAdapter } from '@unchainedshop/core-payment';
import {
PaymentDirector,
PaymentAdapter,
PaymentProviderType,
PaymentError,
} from '@unchainedshop/core-payment';
const ShopPayment: IPaymentAdapter = {
key: 'ch.Shop.payment',
label: 'Shop Payment',
version: '1.0.0',
initialConfiguration: PaymentConfiguration = [],
typeSupported: (type: PaymentProviderType): boolean => {
return type === PaymentProviderType.INVOICE;
},
actions: (params): IPaymentActions => {
const { context, paymentContext } = params;
const { order } = paymentContext;
const { modules } = context;
return {
configurationError: (transactionContext?: any): PaymentError => {
return null;
},
isActive: (transactionContext?: any): boolean => {
return true;
},
isPayLaterAllowed: (transactionContext?: any): boolean => {
return false;
},
charge: async (transactionContext?: any):Promise<PaymentChargeActionResult | false> => {
return false;
},
register: async (transactionContext?: any): boolean => {
return {
token: '',
};
},
sign: async (transactionContext?: any): Promise<string> => {
return null;
},
validate: async (token?: any): Promise<boolean> => {
return false;
},
cancel: async (transactionContext?: any): Promise<boolean> => {
return false;
},
confirm: async (transactionContext?: any) => {
return false;
},
};
},
};