@exerp/odin-dropin
Version:
ODIN Payment Drop-in Facade
80 lines (78 loc) • 4.04 kB
TypeScript
import { OdinPayErrorPayload as CoreOdinPayErrorPayload, OdinPaySubmitPayload as CoreOdinPaySubmitPayload, BillingFieldsConfig as CoreBillingFieldsConfig, OdinPayBillingInformation as CoreOdinPayBillingInformation, FieldCustomization as CoreFieldCustomization, CardPaymentMethodDetails as CoreCardPaymentMethodDetails, AchPaymentMethodDetails as CoreAchPaymentMethodDetails, PaymentMethodSpecificDetails as CorePaymentMethodSpecificDetails } from '../../core/dist/types/components/exerp-odin-cc-form/exerp-odin-cc-form';
import { LogLevel } from './utils/logger';
/**
* Payload for the `onChangeValidation` callback, mirroring OdinPay.js v2's `fieldInformation` object.
*/
export interface OdinFieldValidationEvent {
/** The type of event, typically "FIELD_VALIDATION". */
type: string;
/** The name of the field being validated (e.g., "cardNumber", "postalCode"). */
fieldName: string;
/** The CSS selector for the field's container. */
selector: string;
/** Indicates if the field is currently valid. */
isValid: boolean;
/** An error code if the field is invalid (e.g., "INVALID", "REQUIRED", "MAX_LENGTH_EXCEEDED"). */
errorCode?: string;
}
/**
* Represents a set of CSS-like style properties for OdinPay.js v2 theme.
* Allows for standard CSS properties and pseudo-selector keys.
*/
export interface OdinV2ThemeStyleObject {
[key: string]: string | number | {
[pseudoSelector: string]: string | number;
};
}
/**
* Configuration object for the OdinPay.js v2 theme.
* This is a flat object where keys are CSS properties or pseudo-selectors.
*/
export type OdinV2ThemeConfig = OdinV2ThemeStyleObject;
interface OdinDropinInitializationParams {
odinPublicToken: string;
countryCode: "US" | "CA";
paymentMethodType?: "CARD" | "BANK_ACCOUNT";
/**
* Optional configuration to enable and customize billing fields.
* Fields can be enabled with `true` (using default label/placeholder)
* or with a `FieldCustomization` object ({ label?: string; placeholder?: string; }).
* Example: { name: true, addressLine1: { label: 'Street Address' } }
* postalCode/cardInformation can only receive customization.
*/
billingFieldsConfig?: CoreBillingFieldsConfig;
onSubmit: (result: CoreOdinPaySubmitPayload) => void;
onError: (error: CoreOdinPayErrorPayload) => void;
logLevel?: LogLevel;
/**
* Optional callback function invoked by OdinPay.js v2 during user interaction
* with input fields, providing real-time validation status for individual fields.
*
* @param event - An `OdinFieldValidationEvent` object containing details about the validated field.
* @since 2.0.0
*/
onChangeValidation?: (event: OdinFieldValidationEvent) => void;
/**
* Optional theme configuration object for OdinPay.js v2.
* This object should follow the flat structure specified by OdinPay.js v2,
* allowing CSS properties and pseudo-selectors.
* Border styling is NOT part of this theme and must be applied via external CSS
* to the field container divs.
* @since 2.0.0
*/
theme?: OdinV2ThemeConfig;
}
export declare class OdinDropin {
private params;
private odinCcFormComponent;
private eventListenersAttached;
private currentLogLevel;
private onChangeValidationCallback?;
private themeConfig?;
constructor(params: OdinDropinInitializationParams);
mount(selectorOrElement: string | HTMLElement): void;
private handleOdinSubmit;
private handleOdinError;
unmount(): void;
}
export type { CoreOdinPayErrorPayload as OdinPayErrorPayload, CoreBillingFieldsConfig as BillingFieldsConfig, CoreOdinPayBillingInformation as OdinPayBillingInformation, CoreFieldCustomization as FieldCustomization, CoreOdinPaySubmitPayload as OdinSubmitPayload, CoreCardPaymentMethodDetails as CardPaymentMethodDetails, CoreAchPaymentMethodDetails as AchPaymentMethodDetails, CorePaymentMethodSpecificDetails as PaymentMethodSpecificDetails, LogLevel, };