@easypaypt/checkout-sdk
Version:
SDK for easypay's Checkout
204 lines • 7.89 kB
TypeScript
/**
* Represents the object returned by the Checkout creation API call.
* @see https://api.prod.easypay.pt/docs#tag/Checkout/paths/~1checkout/post
*/
export interface CheckoutManifest {
id: string;
session: string;
config: null | {
language?: string;
logoUrl?: string;
hideDetails?: boolean;
allowClose?: boolean;
sdkVersion?: string;
backgroundColor?: string;
accentColor?: string;
errorColor?: string;
inputBackgroundColor?: string;
inputBorderColor?: string;
inputBorderRadius?: number;
inputFloatingLabel?: boolean;
buttonBackgroundColor?: string;
buttonBorderRadius?: number;
buttonBoxShadow?: boolean;
fontFamily?: string;
baseFontSize?: number;
};
}
/** The possible types of Checkout payments. */
export declare type CheckoutType = 'single' | 'frequent' | 'subscription';
/** The possible payment methods. */
export declare type CheckoutMethod = 'cc' | 'mbw' | 'mb' | 'dd' | 'vi' | 'ap' | 'gp';
/** The possible payment status values. */
export declare type PaymentStatus = 'authorised' | 'deleted' | 'enrolled' | 'error' | 'failed' | 'paid' | 'pending' | 'success' | 'tokenized' | 'voided';
/** Represents information sent when the Checkout process succeeds. */
export interface CheckoutOutput {
/** The Checkout session's id. */
id: string;
/** The Checkout payment type. */
type: CheckoutType;
/** Information about the payment. */
payment: {
/** The payment's id. */
id: string;
/** The chosen payment method. */
method: CheckoutMethod;
/** The status of the payment. */
status: PaymentStatus;
/** How much is being paid. Not used in frequent payments. */
value?: number;
/** Multibanco entity. Not used in other methods. */
entity?: string;
/** Multibanco reference. Not used in other methods. */
reference?: string;
/** Multibanco expiration date. Not used in other methods. */
expirationDate?: string;
/** SEPA Direct Debit mandate. Used only in Direct Debit. */
sddMandate?: {
/** Name of the account holder. */
accountHolder: string;
/** The billing entity for the payments. */
billingEntity: string;
/** Country code prefix to the phone number. */
countryCode: string;
/** The customer's e-mail address. */
email: string;
/** The IBAN. */
iban: string;
/** The mandate's ID. */
id: string;
/** The maximum number of debits allowed for this Direct Debit. */
maxNumDebits: string;
/** The customer's name. May be different from the account holder's name. */
name: string;
/** The customer's phone number. */
phone: string;
/** The authorization reference. */
referenceAdc: string;
};
};
}
/** Represents an error that happened during a Checkout session. */
export interface CheckoutError {
/** The error code. */
code: 'checkout-expired' | 'already-paid' | 'checkout-canceled' | 'generic-error';
}
/** Represents a payment error that happened during a Checkout session. */
export interface CheckoutPaymentError {
/** The error code. */
code: 'payment-failure' | 'generic-error';
/** The payment method for which the error happened. */
paymentMethod: CheckoutMethod;
/** On `payment-failure` errors, the Checkout that had already been created. */
checkout?: CheckoutOutput;
}
/**
* The possible options to configure the Checkout SDK.
*/
export interface CheckoutOptions {
/** The id of the HTML element where the Checkout should be inserted. */
id?: string;
/** The callback to call on Checkout successful completion. */
onSuccess?: (successInfo: CheckoutOutput) => void;
/** The callback to call on Checkout errors. */
onError?: (error: CheckoutError) => void;
/** The callback to call on Payment errors. */
onPaymentError?: (error: CheckoutPaymentError) => void;
/** The callback to call on Checkout close. */
onClose?: () => void;
/** Whether the SDK should use testing APIs. */
testing?: boolean;
/** The Checkout iframe URL which to include. Used to debug only. Will override the testing URL. */
iframeUrl?: string;
/** Wether the Checkout should be a popup or an inline element */
display?: string;
/** Wether the Checkout should have the customer details form hidden */
hideDetails?: boolean;
/** Which language should the Checkout be displayed in*/
language?: string;
/** The logo url of the merchant */
logoUrl?: string;
/** The background color of the iframe */
backgroundColor?: string;
/** The accent color of the checkout */
accentColor?: string;
/** The error color of the checkout */
errorColor?: string;
/** The checkout inputs background color */
inputBackgroundColor?: string;
/** The checkout inputs border color */
inputBorderColor?: string;
/** The checkout inputs border radius */
inputBorderRadius?: number;
/** The checkout inputs floating label */
inputFloatingLabel?: boolean;
/** The checkout buttons background color */
buttonBackgroundColor?: string;
/** The checkout buttons border radius */
buttonBorderRadius?: number;
/** The checkout buttons box shadow */
buttonBoxShadow?: boolean;
/** The checkout font family text*/
fontFamily?: string;
/** The checkout font size text*/
baseFontSize?: number;
}
/**
* Encapsulates a Checkout instance created by startCheckout.
* Stores useful parameters and allows cleanup when unmount() is called.
*/
export declare class CheckoutInstance {
private manifest;
private givenOptions;
private static PROD_URL;
private static TEST_URL;
private static LOGTAG;
private options;
private dialog;
private style;
private hostElement;
private originUrl;
private messageHandler;
private clickHandler;
private successfulPaymentInteraction;
/**
* The class constructor. Sets up the iframe contents and event listener.
*/
constructor(manifest: CheckoutManifest, givenOptions: CheckoutOptions);
private mapOptionsToManifest;
/**
* Validates the necessary parameters for Checkout initialization and gives helpful messages for integrators.
*/
private validateParameters;
/**
* Encodes a Manifest for iframe consumption. Supports both Node and browser environments.
*/
private encodeManifest;
/**
* Handles messages sent from the Checkout iframe. If the origin and contents are as expected,
* pass them on to the event handlers that were configured in startCheckout.
*
* If the Checkout becomes finished successfuly, automatically removes the event listener.
* If the Checkout gets an error or if it is closed without a successful payment, the event listener is not removed.
*/
private handleMessage;
private handleClick;
/**
* Creates popup modal in the DOM to host the Checkout iframe.
*
* If the user clicks close on Checkout, automatically closes the popup.
*/
private createPopupDOMTree;
/**
* Used to cleanup Checkout by removing the DOM contents and event listener.
*/
unmount(): void;
}
/**
* Used to configure and populate the Checkout form.
*
* Returns an instance of the CheckoutInstance class, which can be used to manage
* the running Checkout (in particular, to unmount it).
*/
export declare function startCheckout(manifest: CheckoutManifest, options?: CheckoutOptions): CheckoutInstance;
//# sourceMappingURL=index.d.ts.map