wonder-payment
Version:
A lightweight and customizable wonder component for secure and user-friendly credit card input in payment forms.
82 lines (79 loc) • 2.41 kB
text/typescript
type WonderPaymentConfiguration = {
payfacData: string;
environment: "development" | "staging" | "production";
onPaymentCompleted?: () => void;
onPaymentFailed?: () => void;
placeholders?: Placeholders;
};
type PlaceholderKeys = "cardNumber" | "expiryDate" | "expiryMonth" | "expiryYear" | "securityCodeThreeDigits" | "securityCodeFourDigits";
type Placeholders = Partial<Record<PlaceholderKeys, string>>;
type SuccessResponse = {
resultCode: "Success";
message?: string;
} & Required<WonderPaymentPaymentMethods>;
type ErrorResponse = {
resultCode: "Error";
message: string;
} & Partial<WonderPaymentPaymentMethods>;
type WonderPaymentPaymentMethodsResponse = SuccessResponse | ErrorResponse;
type WonderPaymentPaymentMethods = {
amount: number;
clientKey: string;
currency: string;
enableStoreDetails: string;
formattedAmount: string;
locale: string;
minorUnitsAmount: number;
merchantName: string;
paymentMethods: PaymentMethodsResponse;
};
interface PaymentMethodsResponse {
paymentMethods?: PaymentMethod[];
storedPaymentMethods?: StoredPaymentMethod[];
}
type Issuer = {
disabled?: boolean;
id: string;
name: string;
};
type PaymentMethod = {
brand?: string;
brands?: string[];
configuration?: object;
fundingSource?: "debit" | "credit";
group?: PaymentMethodGroup;
issuers?: Issuer[];
name: string;
type: string;
};
type StoredPaymentMethod = PaymentMethod & {
bankAccountNumber: string;
bankLocationId: string;
expiryMonth?: string;
expiryYear?: string;
holderName?: string;
iban?: string;
id: string;
label?: string;
lastFour?: string;
networkTxReference?: string;
ownerName?: string;
shopperEmail?: string;
supportedRecurringProcessingModels: string[];
supportedShopperInteractions: string[];
};
type PaymentMethodGroup = {
name: string;
paymentMethodData: string;
type: string;
};
declare class WonderPayment {
private configuration;
private element;
constructor(config: WonderPaymentConfiguration);
mount(selector: HTMLElement | string): Promise<void>;
handleError(message: string): void;
handleSuccess(message: string): void;
setupPaymentMethods(environment: string, payfacData: string): Promise<WonderPaymentPaymentMethodsResponse>;
}
export { WonderPayment as default };