UNPKG

@paydock/client-sdk

Version:

Paydock client sdk

1,498 lines (1,477 loc) 156 kB
import { Observable } from 'rxjs'; import { MicroAgent } from '@newrelic/browser-agent/loaders/micro-agent'; declare class ApiCharge { protected api: Api; constructor(api: Api); /** * Current method allows to work with charge related endpoints * * @example * api.charge().preAuth('payload', cb); * * @param {object} payload - Payload for pre authorization. * @param {number} payload.amount - Charge amount. * @param {string} payload.currency - Charge currency. * @param {string} payload.token - Payment source token. * @param {string} [payload._3ds.redirect_url] - Redirect url after 3d secure processing. * @param {listener} [cb] */ preAuth(payload: PreAuthBody, cb?: (data: any) => void): void | Promise<PreAuthResponse>; } interface PreAuthResponse { _3ds: { token: string; id: string; }; status: string; } interface PreAuthBody { token: string; amount: string | number; currency: string; _3ds?: { redirect_url?: string; }; } declare type Configs = IConf[]; interface IConf { env: string; url: string; } interface IEnvironment { getConf(): IConf; getEnv(): string; setEnv(env: string, alias?: string): void; } declare class Env implements IEnvironment { private alias; private configs; private env; constructor(configs: Configs, defaultEnv?: string); setEnv(env: string, alias?: string): void; getEnv(): string; getConf(): IConf; private isValidMode; } type HttpRequestMethod = 'DELETE' | 'GET' | 'OPTIONS' | 'POST' | 'PUT'; type HttpRequestUrl = string | URL; type AgentPrototype = Pick<(typeof MicroAgent)['prototype'], 'addPageAction' | 'noticeError'>; type AgentMethodNames = keyof AgentPrototype; type AgentMethodParameters<T extends AgentMethodNames> = Parameters<AgentPrototype[T]>; declare class InstrumentationAgent extends MicroAgent { private static agent; private static available; private static initialized; private constructor(); static get instance(): InstrumentationAgent; isAvailable(): boolean; call: <T extends "addPageAction" | "noticeError">(method: T, ...args: AgentMethodParameters<T>) => void; } interface CustomEventDTO { environment: string; appId?: never; timestamp?: never; [x: string]: unknown; } interface ReportBaseContext { environment: string; sdkVersion: string | null; description?: string; [x: string]: SerializableValue | undefined; } type SerializableValue = string | number | symbol | object | null; type ReportErrorFn = (repository: ErrorRepository, error: string | Error, ctx: ReportBaseContext & ({ className: string; classMethod: string; functionName?: never; } | { className?: never; classMethod?: never; functionName: string; })) => void; declare class ErrorRepository { private readonly agent; constructor(); createError(...args: Parameters<InstrumentationAgent['noticeError']>): Promise<void>; } type ReportEventFn = (repository: EventRepository, actionName: string, ctx: ReportBaseContext & CustomEventDTO) => void; declare class EventRepository { private readonly agent; constructor(); createEvent(...args: Parameters<InstrumentationAgent['addPageAction']>): Promise<void>; } declare enum API_AUTH_TYPE { PUBLIC_KEY = 0, TOKEN = 1 } declare class ApiBase { protected env: Env; auth: string; authType: API_AUTH_TYPE; constructor(auth: string, authType?: API_AUTH_TYPE); /** * Current method can change environment. By default environment = sandbox. * Also we can change domain alias for this environment. By default domain_alias = paydock.com * * @example * widget.setEnv('production'); * @param {string} env - sandbox, production * @param {string} [alias] - Own domain alias */ setEnv(env: string, alias?: string): ApiBase; requestObservable<Req extends object, Res>(method: 'GET' | 'POST', url: string, requestBody: Req): Observable<Res>; private makeRequest; private onRequestLoad; private onRequestError; setAuthType(): API_AUTH_TYPE; getClient(method: Extract<HttpRequestMethod, 'GET' | 'POST'>, link: string): { config: XMLHttpRequest; send: (body: any, cb?: (data) => void, errorCb?: (data: any) => any) => void; }; getClientPromise<Req extends object, Res>(method: Extract<HttpRequestMethod, 'GET' | 'POST'>, link: string): { config: XMLHttpRequest; send: (body: Req) => Promise<Res>; }; parser({ text, status }: { text: string; status: number; }, cb: any, errorCb: any): any; parserPromise<Res>({ text, status, }: { text: string; status: number; }): Promise<Res>; reportEvent: ReportEventFn; reportError: ReportErrorFn; protected newApiRequest(method: Extract<HttpRequestMethod, 'GET' | 'POST'>, link: string): XMLHttpRequest; protected get ctx(): { sdkVersion: string; className: string; environment: string; }; } /** * Interface for browser details response. * @interface BrowserDetails * * @param {string} [name] * @param {string} [java_enabled] * @param {string} [language] * @param {string} [screen_height] * @param {string} [screen_width] * @param {string} [time_zone] * @param {string} [color_depth] * */ interface BrowserDetails { name: string; java_enabled: string; language: string; screen_height: string; screen_width: string; time_zone: string; color_depth: string; } /** * Class Api include method for working with paydock api * @constructor * * @param {string} publicKey - PayDock users public key * @example * var api = new Api('publicKey'); * * **/ declare class Api extends ApiBase { publicKey: String; /** @constructs */ constructor(publicKey: string); /** * Method for getting browser details * * @example * api.getBrowserDetails(); * * @return {BrowserDetails} Browser details object */ getBrowserDetails(): BrowserDetails; /** * Current method allows to work with charge related endpoints * * @example * api.charge(); */ charge(): ApiCharge; } /** * List of available form field validators dedicated to cards and their definition * * @const CARD_VALIDATORS * * @type {Record<string, string>} * * @param {string} CVV=cardCvvValidation * Asserts that CVV contains zero or more digits and is a number * @param {string} EXPIRY_DATE=expireDateValidation * Asserts value is a date in the future with format MM/YY * @param {string} HOLDER_NAME=cardHoldernameValidation * Asserts value is a name that respects the ITU-T T.50 standard (@see https://www.itu.int/rec/T-REC-T.50/en) * @param {string} NUMBER=cardNumberValidation Asserts the value matches a known card scheme and as a the correct length. E.g., matches a 13, 16 or 19 digit bank card, **or**, a 13 to 25 digit Vii Gift card * @param {string} PIN=cardPinValidation Asserts the value is a number with exactly 4 digits */ declare const CARD_VALIDATORS: { readonly CVV: "cardCvvValidator"; readonly EXPIRY_DATE: "expireDateValidation"; readonly HOLDER_NAME: "cardHoldernameValidator"; readonly NUMBER: "cardNumberValidator"; readonly PIN: "cardPinValidator"; }; type CardValidatorValue = typeof CARD_VALIDATORS[keyof typeof CARD_VALIDATORS]; /** * List of available generic form field validators and their definition * * @const GENERIC_VALIDATORS * * @type {Record<string, string>} * * @param {string} REQUIRED=required * Asserts the input or form field has a value defined truthy value */ declare const GENERIC_VALIDATORS: { readonly REQUIRED: "required"; }; type GenericValidatorValue = typeof GENERIC_VALIDATORS[keyof typeof GENERIC_VALIDATORS]; declare const FORM_FIELD: { CARD_NAME: string; CARD_NUMBER: string; EXPIRE_MONTH: string; EXPIRE_YEAR: string; CARD_CCV: string; CARD_PIN: string; ACCOUNT_NAME: string; ACCOUNT_BSB: string; ACCOUNT_NUMBER: string; ACCOUNT_ROUTING: string; ACCOUNT_HOLDER_TYPE: string; ACCOUNT_BANK_NAME: string; ACCOUNT_TYPE: string; FIRST_NAME: string; LAST_NAME: string; EMAIL: string; PHONE: string; PHONE2: string; ADDRESS_LINE1: string; ADDRESS_LINE2: string; ADDRESS_STATE: string; ADDRESS_COUNTRY: string; ADDRESS_CITY: string; ADDRESS_POSTCODE: string; ADDRESS_COMPANY: string; }; declare const STYLE: { BACKGROUND_COLOR: string; BACKGROUND_ACTIVE_COLOR: string; TEXT_COLOR: string; BORDER_COLOR: string; ICON_SIZE: string; BUTTON_COLOR: string; ERROR_COLOR: string; SUCCESS_COLOR: string; FONT_SIZE: string; FONT_FAMILY: string; }; declare const VAULT_DISPLAY_STYLE: { BACKGROUND_COLOR: string; TEXT_COLOR: string; BORDER_COLOR: string; BUTTON_COLOR: string; FONT_SIZE: string; FONT_FAMILY: string; }; declare const TEXT: { TITLE: string; TITLE_H1: string; TITLE_H2: string; TITLE_H3: string; TITLE_H4: string; TITLE_H5: string; TITLE_H6: string; FINISH: string; TITLE_DESCRIPTION: string; SUBMIT_BUTTON: string; SUBMIT_BUTTON_PROCESSING: string; }; declare const ELEMENT: { SUBMIT_BUTTON: string; TABS: string; }; declare const SUPPORTED_CARD_TYPES: { AMEX: string; AUSBC: string; DINERS: string; DISCOVER: string; JAPCB: string; LASER: string; MASTERCARD: string; SOLO: string; VISA: string; VISA_WHITE: string; EFTPOS: string; EFTPOS_WHITE: string; }; interface IIcons { paypal_checkout_button?: string; afterpay_checkout_button?: string; zipmoney_checkout_button?: string; } interface IFormPropertyOption { card_name?: string; card_number?: string; expire_month?: string; expire_year?: string; card_ccv?: string; card_pin?: string; account_name?: string; account_bsb?: string; account_number?: string; account_routing?: string; account_holder_type?: string; account_bank_name?: string; first_name?: string; last_name?: string; email?: string; phone?: string; phone2?: string; address_line1?: string; address_line2?: string; address_state?: string; address_country?: string; address_city?: string; address_postcode?: string; address_company?: string; } interface IFormValues extends IFormPropertyOption { } interface IFormLabels extends IFormPropertyOption { } interface IFormPlaceholders extends IFormPropertyOption { } interface IFormElement { field: string; label?: string; placeholder?: string; value?: string; } type ValidatorFieldsMapKey = CardValidatorValue | GenericValidatorValue; type ValidatorFieldsMap = Partial<Record<ValidatorFieldsMapKey, string[]>>; interface IFormValidation { form_valid?: boolean; invalid_fields?: string[]; invalid_showed_fields?: string[]; validators?: ValidatorFieldsMap; } interface IStyles$1 { background_color?: string; background_active_color?: string; text_color?: string; border_color?: string; button_color?: string; icon_size?: string; error_color?: string; success_color?: string; font_size?: string; font_family?: string; } interface ITexts { title?: string; title_h1?: string; title_h2?: string; title_h3?: string; title_h4?: string; title_h5?: string; title_h6?: string; finish_text?: string; title_description?: string; submit_button?: string; submit_button_processing?: string; } interface ICommonParams { sdk_version?: string; sdk_type?: string; } interface ISRCParams extends ICommonParams { public_key?: string; service_id?: string; meta?: string; } interface IWalletParams extends IStyles$1, ITexts, ICommonParams { token: string; credentials: string; currency: string; amount: number; gateway_mode: string; } interface IParams extends IStyles$1, ITexts, ICommonParams { access_token?: string; public_key?: string; token?: string; configuration_token?: string; configuration_tokens?: string; ref_id?: string; supported_card_types?: string; validate_card_types?: boolean; fields_validation?: boolean; hidden_elements?: string; icons?: string; form_values?: string; form_labels?: string; form_placeholders?: string; query_token?: string; limit?: number; widget_id?: string; gateway_id?: string; gateway_ids?: string; payment_source_types?: string; element_styles?: string; use_country_phone_mask?: boolean; phone_mask_preferred_countries?: string; phone_mask_default_country?: string; phone_mask_only_countries?: string; language?: string; vault_display_token?: string; sdk_origin?: boolean; hide_ui_errors?: boolean; } interface ICountryPhoneMask { preferred_countries?: string[]; default_country?: string; only_countries?: string[]; } interface IPayPalMeta { brand_name?: string; cart_border_color?: string; reference?: string; email?: string; hdr_img?: string; logo_img?: string; pay_flow_color?: string; first_name?: string; last_name?: string; address_line?: string; address_line2?: string; address_city?: string; address_state?: string; address_postcode?: string; address_country?: string; phone?: string; hide_shipping_address?: boolean; } interface IBamboraMeta { customer_storage_number?: string; tokenise_algorithm?: number; } interface IZipmoneyMeta { first_name: string; last_name: string; phone?: string; tokenize?: boolean; email: string; gender?: string; date_of_birth?: string; charge: { amount: number; currency?: string; reference?: string; shipping_type?: string; items: Array<{ name: string; amount: number; quantity: number; type?: string; reference?: string; item_uri?: string; image_url?: string; }>; shipping_address?: { first_name?: string; last_name?: string; line1: string; line2?: string; country: string; postcode: string; city: string; state: string; }; billing_address: { first_name?: string; last_name?: string; line1: string; line2?: string; country: string; postcode: string; city: string; state: string; }; }; statistics: { account_created?: string; sales_total_number?: number; sales_total_amount?: number; sales_avg_value?: number; sales_max_value?: number; refunds_total_amount?: number; previous_chargeback?: boolean; currency?: string; last_login?: string; }; hide_shipping_address?: boolean; } interface IAfterpayMeta { amount: number; currency: string; email: string; first_name: string; last_name: string; address_line: string; address_line2: string; address_city: string; address_state: string; address_postcode: string; address_country: string; phone: string; } interface VaultDisplayStyle { background_color?: string; text_color?: string; border_color?: string; button_color?: string; font_size?: string; font_family?: string; } interface IApplePayShippingOption { id: string; label: string; detail: string; amount: string; type?: 'ELECTRONIC' | 'GROUND' | 'NOT_SHIPPED' | 'OVERNIGHT' | 'PICKUP' | 'PRIORITY' | 'SAME_DAY'; } interface IGooglePayShippingOption { id: string; label: string; detail?: string; type?: 'ELECTRONIC' | 'GROUND' | 'NOT_SHIPPED' | 'OVERNIGHT' | 'PICKUP' | 'PRIORITY' | 'SAME_DAY'; } interface IPayPalShippingOption { id: string; label: string; amount: string; currency: string; type: 'SHIPPING' | 'PICKUP'; } type IShippingOption = IApplePayShippingOption | IGooglePayShippingOption | IPayPalShippingOption; declare enum WALLET_TYPE { GOOGLE = "google", APPLE = "apple", FLYPAY = "flypay", FLYPAY_V2 = "flypayV2", PAYPAL = "paypal", AFTERPAY = "afterpay" } interface ApplePayStyles { button_type?: 'add-money' | 'book' | 'buy' | 'check-out' | 'continue' | 'contribute' | 'donate' | 'order' | 'pay' | 'plain' | 'reload' | 'rent' | 'set-up' | 'subscribe' | 'support' | 'tip' | 'top-up'; button_style?: 'black' | 'white' | 'white-outline'; } interface GooglePayStyles { button_type?: 'book' | 'buy' | 'checkout' | 'donate' | 'order' | 'pay' | 'plain' | 'subscribe'; button_size_mode?: 'static' | 'fill'; button_color?: 'default' | 'black' | 'white'; } interface AfterpayStyles { button_type?: 'black' | 'mint' | 'white'; height?: string; } type WalletStyles = { apple?: ApplePayStyles; google?: GooglePayStyles; afterpay?: AfterpayStyles; } | object; type WalletRawDataInitialization = { apple?: ApplePayRawDataInitialization; google?: GooglePayRawDataInitialization; } | object; type ApplePayRawDataInitialization = ApplePayJS.ApplePayPaymentRequest; type GooglePayRawDataInitialization = google.payments.api.IsReadyToPayPaymentMethodSpecification | google.payments.api.PaymentMethodSpecification; interface IWalletMeta { amount_label?: string; country?: string; pay_later?: boolean; hide_message?: boolean; standalone?: boolean; show_billing_address?: boolean; request_payer_name?: boolean; request_payer_email?: boolean; request_payer_phone?: boolean; request_shipping?: boolean; shipping_options?: IShippingOption[]; merchant_name?: string; raw_data_initialization?: WalletRawDataInitialization; access_token?: string; refresh_token?: string; style?: WalletStyles; wallets?: WALLET_TYPE[]; client_id?: string; apple_pay_capabilities?: Array<'credentials_available' | 'credentials_status_unknown' | 'credentials_unavailable'>; } declare class Link { protected env: Env; protected linkResource: string; protected params: IParams; protected widgetId: string; constructor(linkResource: string); getNetUrl(): string; getUrl(): string; setParams(params: IParams | IWalletParams | ISRCParams): void; concatParams(params: IParams): void; getParams(): IParams; setEnv(env: string, alias?: string): void; getEnv(): string; getBaseUrl(): string; } declare class Container { protected selector: string; constructor(selector: string); isExist(): boolean; getStyles<T>(allowValue: string[]): T | {}; on(name: any, cb: (event: MouseEvent) => void): void; getAttr<T>(allowValue: string[]): T | {}; getElement(): Element; getSelector(): string; private convertConfigs; } declare class IFrame { protected container: Container; constructor(container: Container); load(link: string, options?: { title?: string; }, iframeClass?: string): void; loadFromHtml(content: string, options?: { title?: string; }, iframeClass?: string): void; remove(): void; show(): void; hide(saveSize?: boolean): void; isExist(): boolean; getElement(): HTMLIFrameElement; setStyle(property: string, value: string): void; setIframeHeight(iframeElement: HTMLIFrameElement, iFrameDocument: Document, selector: string): void; private setStyles; } /** * List of available payment source types * * @type {object} * @param {string} CARD=card * @param {string} BANK_ACCOUNT=bank_account * @param {string} CHECKOUT=checkout */ declare const PAYMENT_TYPE: { CARD: string; GIFT_CARD: string; BANK_ACCOUNT: string; CHECKOUT: string; BSB: string; }; /** * Purposes * @type {object} * @param {string} PAYMENT_SOURCE=payment_source * @param {string} CARD_PAYMENT_SOURCE_WITH_CVV=card_payment_source_with_cvv * @param {string} CARD_PAYMENT_SOURCE_WITHOUT_CVV=card_payment_source_without_cvv * */ declare enum PURPOSE { PAYMENT_SOURCE = "payment_source", CARD_PAYMENT_SOURCE_WITH_CVV = "card_payment_source_with_cvv", CARD_PAYMENT_SOURCE_WITHOUT_CVV = "card_payment_source_without_cvv" } interface IGeneral { purpose: PURPOSE; predefined_fields: IPredefinedFields; defined_form_fields?: string[]; webhook_destination?: string; success_redirect_url?: string; error_redirect_url?: string; meta?: IPayPalMeta; label?: string; dynamic_fields_position?: boolean; } interface IPredefinedFields { gateway_id: string; type?: string; card_scheme?: string; card_processing_network?: string; } /** * Class Configuration include methods for creating configuration token * @constructor * * @example * var config = new Configuration('gatewayId'); // short * * var config = new Configuration('gatewayId', 'bank_account', 'paymentSource'); // extend * * var config = new Configuration('not_configured'); // without gateway * * @param {string} [gatewayID=default] - gateway ID. By default or if put 'default', it will use the selected default gateway. If put 'not_configured', it won’t use gateway to create downstream token. * @param {string} paymentType - Type of payment source which shows in widget form. Available parameters [PAYMENT_TYPE]{@link PAYMENT_TYPE} * @param {string} purpose - Param which describes payment purpose. By default uses Available parameters [PURPOSE]{@link PURPOSE} */ declare class Configuration { private configs; private env; static createEachToken(accessToken: string, configs: Configuration[]): Promise<string[]>; private static addTokenInBase64; /** @constructs */ constructor(gatewayID?: string, paymentType?: string, purpose?: PURPOSE); /** * Destination, where customer will receive all successful responses. * Response will contain “data” object with “payment_source” or other parameters, in depending on 'purpose' * * @example * config.setWebHookDestination('http://google.com'); * * @param {string} url - Your endpoint for post request. */ setWebHookDestination(url: string): void; /** * URL to which the Customer will be redirected to after the success finish * * @example * config.setSuccessRedirectUrl('google.com/search?q=success'); * * @param {string} url */ setSuccessRedirectUrl(url: string): void; /** * URL to which the Customer will be redirected to if an error is triggered in the process of operation * * @example * config.setErrorRedirectUrl('google.com/search?q=error'); * * @param {string} url */ setErrorRedirectUrl(url: string): void; /** * Set list with widget form field, which will be shown in form. Also you can set the required validation for these fields * * @example * config.setFormFields(['phone', 'email', 'first_name*']); * * @param {string[]} fields - name of fields which can be shown in a widget. * If after a name of a field, you put “*”, this field will be required on client-side. * (For validation, you can specify any fields, even those that are shown by default: card_number, expiration, etc... ) [FORM_FIELD]{@link FORM_FIELD} */ setFormFields(fields: string[]): void; /** * Method for setting meta information for checkout page * * @example * config.setMeta({ brand_name: 'paydock', reference: '15', email: 'wault@paydock.com' }); * * @param {IPayPalMeta | IZipmoneyMeta | IAfterpayMeta | IBamboraMeta} object - * data which can be shown on checkout page [IPayPalMeta]{@link IPayPalMeta} [IZipmoneyMeta]{@link IZipmoneyMeta} [IAfterpayMeta]{@link IAfterpayMeta} [IBamboraMeta]{@link IBamboraMeta} */ setMeta(meta: IPayPalMeta | IZipmoneyMeta | IAfterpayMeta | IBamboraMeta): void; /** * Current method can change environment. By default environment = sandbox. * Also we can change domain alias for this environment. By default domain_alias = paydock.com * * @example * config.setEnv('production'); * @param {string} env - sandbox, production * @param {string} [alias] - Own domain alias */ setEnv(env: string, alias?: string): void; /** * Title for tab which can be set instead of default * * @example * config.setLabel('custom label'); * * @param {string} label - Text label for tab */ setLabel(label: string): void; getEnv(): string; /** * createToken - method which exactly create payment one time token * * @example * config.createToken('582035346f65cdd57ee81192d6e5w65w4e5', * function (data) { * console.log(data); * }, function (error) { * console.log(error); * }); * * @param {string} accessToken - Customer access token or public key which provided for each client * @param {createToken~requestCallback} cb - The callback that handles the success response. * @param {createToken~requestCallback} errorCb - The callback that handles the failed response. */ createToken(accessToken: string, cb: (token: string) => void, errorCb?: (error: any) => void): void; getDefaultGateway<T>(accessToken: string, method: HttpRequestMethod, url: HttpRequestUrl): Promise<T>; private send; getConfigs(): IGeneral; private getUrl; private getDefaultGatewayUrl; setGiftCardSchemeData(giftCardScheme: any, processingNetwork: any): void; } /** * Current constant include available type of element for styling * @const STYLABLE_ELEMENT * @type {object} * @param {string} INPUT=input. * These states are available: [STYLABLE_ELEMENT_STATE.ERROR]{@link STYLABLE_ELEMENT_STATE}, [STYLABLE_ELEMENT_STATE.FOCUS]{@link STYLABLE_ELEMENT_STATE}. * These styles are available [IElementStyleInput]{@link IElementStyleInput} * @param {string} SUBMIT_BUTTON=submit_button * These states are available: [STYLABLE_ELEMENT_STATE.HOVER]{@link STYLABLE_ELEMENT_STATE}. * These styles are available [IElementStyleSubmitButton]{@link IElementStyleSubmitButton} * @param {string} LABEL=label. * These styles are available [IElementStyleLabel]{@link IElementStyleLabel} * @param {string} TITLE=title. * These styles are available [IElementStyleTitle]{@link IElementStyleTitle} * @param {string} TITLE_DESCRIPTION=title_description. * These styles are available [IElementStyleTitleDescription]{@link IElementStyleTitleDescription} * */ declare const STYLABLE_ELEMENT: { INPUT: string; SUBMIT_BUTTON: string; LABEL: string; TITLE: string; TITLE_DESCRIPTION: string; }; /** * Current constant include available states of element for styling * @const STYLABLE_ELEMENT_STATE * @type {object} * @param {string} ERROR=error client|server validation. This state applies to: input * @param {string} FOCUS=focus focus. This state applies to: input * @param {string} HOVER=hover focus. This state applies to: submit_button * */ declare const STYLABLE_ELEMENT_STATE: { ERROR: string; FOCUS: string; HOVER: string; }; interface IElementStyleInput { color?: string; border?: string; border_radius?: string; background_color?: string; height?: string; text_decoration?: string; font_size?: string; font_family?: string; padding?: string; margin?: string; transition?: string; line_height?: string; font_weight?: string; } interface IElementStyleSubmitButton { color?: string; border?: string; border_radius?: string; background_color?: string; text_decoration?: string; font_size?: string; font_family?: string; padding?: string; margin?: string; transition?: string; line_height?: string; font_weight?: string; opacity?: string; } interface IElementStyleLabel { color?: string; text_decoration?: string; font_size?: string; font_family?: string; line_height?: string; font_weight?: string; padding?: string; margin?: string; } interface IElementStyleTitle { color?: string; text_decoration?: string; font_size?: string; font_family?: string; line_height?: string; font_weight?: string; padding?: string; margin?: string; } interface IElementStyleTitleDescription { color?: string; text_decoration?: string; font_size?: string; font_family?: string; line_height?: string; font_weight?: string; padding?: string; margin?: string; } declare const ERROR_CATEGORY: { readonly CONFIGURATION: "configuration"; readonly IDENTITY: "identity_access_management"; readonly INTERNAL: "internal"; readonly PROCESS: "process"; readonly RESOURCE: "resource"; readonly VALIDATION: "validation"; }; type ErrorCategory = (typeof ERROR_CATEGORY)[keyof typeof ERROR_CATEGORY]; declare const ERROR_CAUSE: { readonly ABORTED: "aborted"; readonly ACCESS_FORBIDDEN: "access_forbidden"; readonly ALREADY_EXISTS: "already_exists"; readonly CANCELED: "canceled"; readonly INVALID_CONFIGURATION: "invalid_configuration"; readonly INVALID_INPUT: "invalid_input"; readonly NOT_FOUND: "not_found"; readonly NOT_IMPLEMENTED: "not_implemented"; readonly RATE_LIMITED: "rate_limited"; readonly SERVER_BUSY: "server_busy"; readonly SERVICE_UNREACHABLE: "service_unreachable"; readonly UNAUTHORIZED: "unauthorized"; readonly UNKNOWN: "unknown_error"; readonly UNPROCESSABLE_ENTITY: "unprocessable_entity"; }; type ErrorCause = (typeof ERROR_CAUSE)[keyof typeof ERROR_CAUSE]; interface ErrorDetails { cause: ErrorCause; contextId: string; message: string; timestamp: string; } interface IEventError { cause: ErrorCause; category: ErrorCategory; retryable: boolean; details: ErrorDetails; } /** * * Class MultiWidget include method for for creating iframe url * @constructor * * @param {string} accessToken - PayDock users access token or public key * @param {(Configuration | string | Configuration[] | string[])} conf - exemplar[s] Configuration class OR configuration token * * @example * var widget = new MultiWidget('accessToken','configurationToken'); // With a pre-created configuration token * * var widget = new MultiWidget('accessToken',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens * * var widget = new MultiWidget('accessToken', new Configuration('gatewayId')); With Configuration * * var widget = new MultiWidget('accessToken',[ With Configurations * Configuration('gatewayId'), * Configuration('gatewayId', 'bank_account') * ]); */ declare class MultiWidget { protected link: Link; protected configs: Configuration[]; protected configTokens: string[]; protected accessToken: string; protected event: IFrameEvent; constructor(accessToken: string, confTokens: string[]); constructor(accessToken: string, confToken: string); constructor(accessToken: string, configs: Configuration[]); constructor(accessToken: string, conf: Configuration); /** * Object contain styles for widget * * @example * widget.setStyles({ * background_color: 'rgb(0, 0, 0)', * border_color: 'yellow', * text_color: '#FFFFAA', * button_color: 'rgba(255, 255, 255, 0.9)', * font_size: '20px' * fort_family: 'fantasy' * }); * @param {IStyles} fields - name of styles which can be shown in widget [STYLE]{@link STYLE} */ setStyles(styles: IStyles$1): void; /** * Method to set a country code mask for the phone input. * * @example * widget.usePhoneCountryMask(); * * @example * widget.usePhoneCountryMask({ * default_country: 'au', * preferred_countries: ['au', 'gb'], * only_countries: ['au', 'gb', 'us', 'ua'] * }); * * @param {object} [options] - Options for configure the phone mask. * @param {string} [options.default_country] - Set a default country for the mask. * @param {Array.<string>} [options.preferred_countries] - Set list of preferred countries for the top of the select box . * @param {Array.<string>} [options.only_countries] - Set list of countries to show in the select box. */ usePhoneCountryMask(options?: ICountryPhoneMask): void; setStyle(param: string, value: string): void; /** * Method for set different texts inside the widget * * @example * widget.setTexts({ * title: 'Your card', * finish_text: 'Payment resource was successfully accepted', * title_description: '* indicates required field', * submit_button: 'Save', * submit_button_processing: 'Load...', * }); * * @param {ITexts} fields - name of text items which can be shown in widget [TEXT]{@link TEXT} */ setTexts(texts: ITexts): void; setText(param: string, value: string): void; setElementStyle(element: string, state: string, styles: IElementStyleInput | IElementStyleSubmitButton | IElementStyleLabel): any; setElementStyle(element: string, styles: IElementStyleInput | IElementStyleSubmitButton | IElementStyleLabel | IElementStyleTitle | IElementStyleTitleDescription): any; /** * The method to set the predefined values for the form fields inside the widget * * @example * widget.setFormValues({ * email: 'predefined@email.com', * card_name: 'Houston' * }); * * @param { Object } fieldValues - Key of object is one of [FORM_FIELD]{@link FORM_FIELD}, The object value is what we are expecting */ setFormValues(fieldValues: IFormValues): void; setFormValue(key: string, value: string): void; /** * The method to set custom form field labels * * @example * widget.setFormPlaceholders({ * card_name: 'Card Holder Name', * email: 'Email For Receipt' * }) * * @param { Object } fieldLabels - Key of object is one of [FORM_FIELD]{@link FORM_FIELD}, The object value is what we are expecting */ setFormLabels(fieldLabels: IFormLabels): void; setFormLabel(key: string, label: string): void; /** * The method to set custom form fields placeholders * * @example * widget.setFormPlaceholders({ * card_name: 'Input your card holder name...', * email: 'Input your email, like test@example.com' * }) * * @param { Object } fieldPlaceholders - Key of object is one of [FORM_FIELD]{@link FORM_FIELD}, Value of object is expected placeholder */ setFormPlaceholders(fieldPlaceholders: IFormPlaceholders): void; setFormPlaceholder(key: string, placeholder: string): void; /** * The method to set the full configuration for the all specific form elements (label, placeholder, value) * You can also use the other method for the partial configuration like: setFormValues, setFormPlaceholder, setFormLabel * * @example * widget.setFormElements([ * { * field: 'card_name', * placeholder: 'Input your card holder name...', * label: 'Card Holder Name', * value: 'Houston', * }, * { * field: 'email', * placeholder: 'Input your email, like test@example.com', * label: 'Email For Receipt', * value: 'predefined@email.com', * }, * ]) * * @param { string } elements - The list of elements * @param { string } elements[].field - Field name of the element [FORM_FIELD]{@link FORM_FIELD} * @param { string } elements[].placeholder - Set custom form field placeholder * @param { string } elements[].label - Set custom labels near form field * @param { string } elements[].value - Set predefined values for the form field */ setFormElements(elements: IFormElement[]): void; setFormElement(element: IFormElement): void; /** * The method to change the widget icons * * @deprecated */ setIcons(icons: IIcons): void; setIcon(key: string, value: string): void; /** * Using this method you can set hidden elements inside widget * * @example * widget.setHiddenElements(['submit_button', 'email']); * * @param {string[]} elements - list of element which can be hidden [ELEMENT]{@link ELEMENT} || [FORM_FIELD]{@link FORM_FIELD} */ setHiddenElements(elements: string[]): void; /** * Current method can set custom ID to identify the data in the future * * @example * widget.setRefId('id'); * * @param {string} refId - custom id */ setRefId(refId: string): void; /** * Current method can add visual validation from gateway to widget's form fields * * @example * widget.useGatewayFieldValidation(); */ useGatewayFieldValidation(): void; /** * Current method can set icons of supported card types * * @example * * widget.setSupportedCardIcons(['mastercard', 'visa'], validateCardNumberInput); * * @param {string[]} elements - [SUPPORTED_CARD_TYPES]{@link SUPPORTED_CARD_TYPES} * @param {boolean} validateCardNumberInput - [validateCardNumberInput=false] - using this param you allow validation for card number input on supported card types */ setSupportedCardIcons(elements: string[], validateCardNumberInput?: boolean): void; /** * Current method can hide prevent the widget from showing the error messages * * @example * widget.hideUiErrors('id'); */ hideUiErrors(): void; /** * Current method can change environment. By default environment = sandbox. * Also we can change domain alias for this environment. By default domain_alias = paydock.com * * @example * widget.setEnv('production', 'paydock.com'); * @param {string} env - sandbox, production * @param {string} [alias] - Own domain alias */ setEnv(env: string, alias?: string): void; getEnv(): void; /** * Method for creating iframe url * * @example * widget.loadIFrameUrl(function (url) { * console.log(url); * }, function (errors) { * console.log(errors); * }); */ loadIFrameUrl(cb: (url: string) => void, errorCb?: (error: any) => void): void; /** * Method for setting a custom language code * * @example * config.setLanguage('en'); * @param {string} code - ISO 639-1 */ setLanguage(code: any): void; getLink(): Link; protected handleErrorEvent(event: EventTypes, error: IEventError, purpose: PURPOSE): void; } interface ITriggerData { configuration_token?: string; tab_number?: number; elements?: string; form_values?: string; } /** * Interface for classes that represent a trigger data. * @interface ITriggerData * * @param {string} [configuration_token] * @param {string} [tab_number] * @param {string} [elements] * @param {string} [form_values] * */ /** * List of available triggers * * @type {object} * @param {string} SUBMIT_FORM=submit_form * @param {string} CHANGE_TAB=tab * @param {string} HIDE_ELEMENTS=hide_elements * @param {string} SHOW_ELEMENTS=show_elements * @param {string} REFRESH_CHECKOUT=refresh_checkout * @param {string} UPDATE_FORM_VALUES=update_form_values * @param {string} INIT_CHECKOUT=init_checkout */ declare const TRIGGER: { SUBMIT_FORM: string; CHANGE_TAB: string; HIDE_ELEMENTS: string; SHOW_ELEMENTS: string; REFRESH_CHECKOUT: string; UPDATE_FORM_VALUES: string; INIT_CHECKOUT: string; }; declare class Trigger { protected iFrame: IFrame; constructor(iFrame: IFrame); push(triggerName: string, data?: ITriggerData): void; } interface IEventMetaData extends IEventData$1 { configuration_token: string; type: string; account_name?: string; account_number?: string; card_number_last4?: string; card_number_length?: number; card_scheme?: string; gateway_type?: string; } interface IEventFinishData extends IEventData$1 { payment_source: string; payment_source_token?: string; } /** * Interface of data from validation event. * * @interface IFormValidation * * @param {string} event The name of the event. * @param {string} message_source A system variable that identifies the event source. * @param {string} purpose A system variable that states the purpose of the event. * @param {string} [ref_id] Custom unique value that identifies result of processed operation. * @param {boolean} [form_valid] Indicates wether or not the form is valid. * @param {Array<string>} [invalid_fields] Names of form fields with invalid data. * @param {Array<string>} [invalid_showed_fields] Names of invalid form fields which are already displaying the error. * @param {Partial<Record<CardValidatorValue | GenericValidatorValue, Array<string>>>} [validators] Object containing validator identifiers as keys and the fields subject to that validator as an array of form field names. * See list of available [Generic Vallidators]{@link GENERIC_VALIDATORS} and [Card Validators]{@link CARD_VALIDATORS}, */ /** * Contains basic information associated with the event and additional meta data * specific to the event. E.g., card info, gateway info, etc. * * @interface IEventMetaData * * @param {string} event The name of the event. * @param {string} purpose A system variable that states the purpose of the event. * @param {string} message_source A system variable that identifies the event source. * @param {string} [ref_id] Custom unique value that identifies result of processed operation. * @param {string} configuration_token Token received from our API with widget data * @param {string} type Payment type 'card', 'bank_account' * @param {string} gateway_type Gateway type * @param {string} [card_number_last4] Last 4 digit of your card * @param {string} [card_scheme] Card scheme, e.g., (Visa, Mastercard and American Express (AmEx)) * @param {number} [card_number_length] Card number length * @param {string} [account_name] Bank account account name * @param {string} [account_number] Bank account account number * */ /** * Interface of data from event. * @interface IEventAfterLoadData * * @param {string} event The name of the event. * @param {string} purpose A system variable that states the purpose of the event. * @param {string} message_source A system variable that identifies the event source. * @param {string} [ref_id] Custom unique value that identifies result of processed operation. * */ /** * Interface of data from event. * @interface IEventFinishData * * @param {string} event The name of the event. * @param {string} purpose A system variable that states the purpose of the event. * @param {string} message_source A system variable that identifies the event source. * @param {string} [ref_id] Custom unique value that identifies result of processed operation. * @param {string} payment_source One time token. Result from this endpoint [API docs](https://docs.paydock.com/#tokens) * */ /** * List of available event's name * @const EVENT * * @type {object} * @param {string} AFTER_LOAD=afterLoad * @param {string} SUBMIT=submit * @param {string} FINISH=finish * @param {string} VALIDATION=validation * @param {string} VALIDATION_ERROR=validationError * @param {string} SYSTEM_ERROR=systemError * @param {string} META_CHANGE=metaChange * @param {string} RESIZE=resize */ /** * List of available event's name * @const VAULT_DISPLAY_EVENT * * @type {object} * @param {string} AFTER_LOAD=afterLoad * @param {string} SYSTEM_ERROR=system_error * @param {string} CVV_SECURE_CODE_REQUESTED=cvv_secure_code_requested * @param {string} CARD_NUMBER_SECURE_CODE_REQUESTED=card_number_secure_code_requested * @param {string} ACCESS_FORBIDDEN=access_forbidden * @param {string} SESSION_EXPIRED=systemError * @param {string} SYSTEM_ERROR=session_expired * @param {string} OPERATION_FORBIDDEN=operation_forbidden */ /** * Class HtmlMultiWidget include method for working with html * @constructor * @extends MultiWidget * * @param {string} selector - Selector of html element. Container for widget * @param {string} publicKey - PayDock users public key * @param {(Configuration | string | Configuration[] | string[])} conf - exemplar[s] Configuration class OR configuration token * @example * var widget = new MultiWidget('#widget', 'publicKey','configurationToken'); // With a pre-created configuration token * * var widget = new MultiWidget('#widget', 'publicKey',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens * * var widget = new MultiWidget('#widget', 'publicKey', new Configuration('gatewayId')); With Configuration * * var widget = new MultiWidget('#widget', 'publicKey',[ With Configurations * Configuration(), // default gateway_id, * Configuration('not_configured'), // without gateway, * Configuration('gatewayId'), * Configuration('gatewayId', 'bank_account') * ]); */ declare class HtmlMultiWidget extends MultiWidget { protected container: Container; protected iFrame: IFrame; protected triggerElement: Trigger; protected validationData: IFormValidation; /** @constructs */ constructor(selector: string, publicKey: string, conf: any); /** * Loads the widget. * * Calling this method results in an iframe element being inserted and rendered in the DOM. */ load(): void; /** * Registers a form validation callback for validation events. */ protected afterLoad(): void; /** * Listen to events of widget * * @example * * ```javascript * widget.on('form_submit', function (data) { * console.log(data); * }); * ``` * * @example * * ```javascript * widget.on('form_submit').then(function (data) { * console.log(data); * }); * ``` * * @typedef {(data: IEventData | IEventMetaData | IEventFinishData | IFormValidation) => void} EventListenerCallback * * @param {string} eventName - The name of the event that should be listened. Available event names [EVENT]{@link EVENT}. * @param {EventListenerCallback} [cb] - A function to be invoked whenever the event occurs. * * @return {Promise<IEventData | IEventMetaData | IEventFinishData | IFormValidation> | void} */ on(eventName: string): Promise<IEventData$1 | IEventMetaData | IEventFinishData | IFormValidation>; on(eventName: string, cb: (data: IEventData$1 | IEventMetaData | IEventFinishData | IFormValidation) => void): any; /** * Registers callback that will be invoked for every trigger. * * @param {'submit_form' | 'tab'} triggers - The Widget element identifier that caused the trigger. * @param {ITriggerData} data - Data that will be sent to the widget when the trigger occurs. */ trigger(triggerName: string, data?: ITriggerData): void; /** * Gets a reference to the form current validation state. * * !Warning: do not directly modify the values of the returned object. * * @return {IFormValidation} Form validation object */ getValidationState(): IFormValidation; /** * Checks if a given form is valid. * * A form is valid if all form fields are valid. * * @return {boolean} Indicates wether or not form is valid. */ isValidForm(): boolean; /** * Using this method you can check if a specific form field is invalid * * @param {string} field - Field name * @return {boolean} Field is invalid */ isInvalidField(field?: string): boolean; /** * Checks if a given form field is displaying an error. * * @param {string} field - The form field name * * @return {boolean} Indicates wether or not the Error message is being displayed on the associated field. */ isFieldErrorShowed(field?: string): boolean; /** * Checks if a given form field is valid or invalid by name. * * @param {string} field - The form field name * @param validator - The name of the validator. * * @return {boolean} Indicates wether or not the field is invalid based on validator intepretation. */ isInvalidFieldByValidator(field: string, validator: ValidatorFieldsMapKey): boolean; /** * Hides the widget. * * E.g., use this method to hide the widget after it loads. * * @param {boolean} [saveSize=false] Wether the original iframe element size should be saved before being hidden. */ hide(saveSize: boolean): void; /** * Shows the widget. * * E.g., use this method to show the widget after it was explicitly hidden. */ show(): void; /** * Reloads the widget. */ reload(): void; /** * Hides the specified Widget elements by their identifier. * * @example * * ```javascript * widget.hideElements(['submit_button', 'email']); * ``` * * @param {string[]} elements - List of element which can be hidden [ELEMENT]{@link ELEMENT} || [FORM_FIELD]{@link FORM_FIELD} */ hideElements(elements: string[]): void