UNPKG

@paydock/client-sdk

Version:

Paydock client sdk

252 lines 12.5 kB
import { ApiInternal } from '../api/api-internal'; import { Container } from '../components/container'; import { EventEmitter } from '../helper/event-emitter'; import type { OnClickEventData } from './interfaces/on-click-event-data.interface'; import type { OnPaymentSuccessfulEventData } from './interfaces/on-payment-successful-event-data.interface'; import type { OnCloseEventData } from './interfaces/on-close-event-data.interface'; import type { OnPaymentInReviewEventData } from './interfaces/on-payment-in-review-event-data.interface'; import type { OnPaymentErrorEventData } from './interfaces/on-payment-error-event-data.interface'; import type { WalletCaptureRequest } from './interfaces/wallet-capture-request.interface'; import type { OnUnavailableEventData } from './interfaces/on-unavailable-event-data.interface'; import type { BaseGatewayConfig } from './interfaces/base-gateway-config.interface'; import type { ChargeWalletTokenMeta } from './interfaces/charge-wallet-token-meta.interface'; import type { BaseWalletMeta } from './interfaces/base-wallet-meta.interface'; import type { OnErrorEventData } from './interfaces/on-error-event-data.interface'; import type { OnShippingAddressChangeEventData } from './interfaces/on-shipping-address-change-event-data.interface'; import type { OnShippingOptionChangeEventData } from './interfaces/on-shipping-option-change-event-data.interface'; import type { OnShippingAddressChangeEventResponse } from './interfaces/on-shipping-address-change-event-response.interface'; import type { OnShippingOptionChangeEventResponse } from './interfaces/on-shipping-option-change-event-response.interface'; import type { ShippingEventToResponse } from './types/shipping-event-to-response.type'; declare abstract class BaseWalletButton<T extends BaseWalletMeta> { protected container: Container; protected api: ApiInternal; protected env: string; protected gatewayId: string; protected meta: T; protected eventEmitter: EventEmitter; protected chargeWalletTokenMeta?: ChargeWalletTokenMeta; private onShippingOptionsChangeHandlerRegistered; constructor(selector: string, publicKeyOrAccessToken: string, gatewayId: string, meta: T, requiredMetaFields: string[]); private getApiAuthType; /** * Current method can change environment. By default environment = sandbox. * Also we can change domain alias for this environment. By default domain_alias = paydock.com * Bear in mind that you must set an environment before calling `button.load()`. * * @example * button.setEnv('production', 'paydock.com'); * @param {string} env - sandbox, production * @param {string} [alias] - Own domain alias */ setEnv(env: string, alias?: string): void; /** * Callback for onClick method. * * @callback OnClickCallback * @param {OnClickEventData} data * @return {Promise<string>} walletToken string result */ /** * Registers a callback function to be invoked when the wallet button gets clicked. * **Note:** is mandatory to handle this event to perform the wallet initialization (and optionally any validation logic). * The event handler needs to return the wallet token string in order for the Wallet charge processing to proceed, or throw an error in case of failure or validation errors. * **Note:** this callback may be called multiple times as the customer closes the payment checkout and re-clicks the button. * It's the merchant's responsibility to handle this situation and evaluate in each case if generating a new WalletCharge Token is required or the previous one can be used in each case, depending on order data and updates. * In case a new one needs to be generated, remember it will need to be preceded by a `setMeta` call. * * @example * button.onClick(async (data) => { * const responseData = await fetch('https://your-server.com/init-wallet-charge'); * return responseData.walletToken; * }); * * @param {OnClickCallback} handler - Function to be called when the wallet button is clicked. */ onClick(handler: (data: OnClickEventData) => Promise<string>): () => void; /** * Callback for onPaymentSuccessful method. * * @callback OnPaymentSuccessfulCallback * @param {OnPaymentSuccessfulEventData} data */ /** * If the payment was successful, the function passed as parameter will be called. * Important: Do not perform thread blocking operations in callback such as window.alert() calls. * * @example * button.onPaymentSuccessful((data) => { * console.log('Payment successful!'); * }); * * @example * button.onPaymentSuccessful().then((data) => console.log('Payment successful!')); * * @param {OnPaymentSuccessfulCallback} [handler] - Function to be called when the payment was successful. */ onPaymentSuccessful(handler?: (data: OnPaymentSuccessfulEventData) => void): Promise<unknown> | (() => void); /** * Callback for onPaymentInReview method. * * @callback OnPaymentInReviewCallback * @param {OnPaymentInReviewEventData} data */ /** * If the payment was left in fraud review, the function passed as parameter will be called. * Important: Do not perform thread blocking operations in callback such as window.alert() calls. * * @example * button.onPaymentInReview((data) => { * console.log('Payment in fraud review'); * }); * * @example * button.onPaymentInReview().then((data) => console.log('Payment in fraud review')); * * @param {OnPaymentInReviewCallback} [handler] - Function to be called when the payment was left in fraud review status. */ onPaymentInReview(handler?: (err: OnPaymentInReviewEventData) => void): Promise<unknown> | (() => void); /** * Callback for onPaymentError method. * * @callback OnPaymentErrorCallback * @param {OnPaymentErrorEventData} data */ /** * If the payment was not successful, the function passed as parameter will be called. * Important: Do not perform thread blocking operations in callback such as window.alert() calls. * * @example * button.onPaymentError((err) => { * console.log('Payment not successful'); * }); * * @example * button.onPaymentError().then((err) => console.log('Payment not successful')); * * @param {OnPaymentErrorCallback} [handler] - Function to be called when the payment was not successful. */ onPaymentError(handler?: (err: OnPaymentErrorEventData) => void): Promise<unknown> | (() => void); /** * Callback for onCheckoutClose method. * * @callback OnCheckoutCloseCallback * @param {OnCloseEventData} data */ /** * Registers a callback function to be invoked when the wallet checkout closes. * * @example * button.onCheckoutClose(() => { * console.log('Wallet checkout closes'); * }); * * @param {OnCheckoutCloseCallback} handler - Function to be called when the wallet checkout closes. */ onCheckoutClose(handler?: (err: OnCloseEventData) => void): Promise<unknown> | (() => void); /** * Callback for onShippingAddressChange method. * * @callback OnShippingAddressChangeCallback * @param {OnShippingAddressChangeEventData} data * @return {Promise<OnShippingAddressChangeEventResponse>} Address update result */ /** * If shipping address data is updated, the function passed as parameter will be called. * Use this method to listen for shipping address selection or input from customer when shipping is enabled. * The event handler needs to return a new token in case a backend to backend wallet update call was executed. * In addition, if any error occured, an error string must be supplied. * By default, the event handler will be processed successfuly if neither token nor error is returned. * * @example * button.onShippingAddressChange((data) => { * const responseData = await fetch('https://your-server.com/update-shipping-info'); * return { error: null, token: responseData.walletToken }; * }); * * @param {OnShippingAddressChangeCallback} [handler] - Function to be called when the shipping address data is updated. */ onShippingAddressChange(handler?: (data: OnShippingAddressChangeEventData) => Promise<OnShippingAddressChangeEventResponse>): () => void; /** * Callback for onShippingOptionsChange method. * * @callback OnShippingOptionsChangeCallback * @param {OnShippingOptionChangeEventData} data * @return {Promise<OnShippingOptionChangeEventResponse>} Address update result */ /** * If shipping options data is updated, the function passed as parameter will be called. * Use this method to listen for shipping option selection from customer when shipping is enabled. * The event handler needs to return a new token in case a backend to backend wallet update call was executed. * In addition, if any error occured, an error string must be supplied. * By default, the event handler will be processed successfuly if neither token nor error is returned. * * @example * button.onShippingOptionsChange((data) => { * const responseData = await fetch('https://your-server.com/update-shipping-info'); * return { error: null, token: responseData.walletToken }; * }); * * @param {OnShippingOptionsChangeCallback} [handler] - Function to be called when the shipping options data is updated. */ onShippingOptionsChange(handler?: (data: OnShippingOptionChangeEventData) => Promise<OnShippingOptionChangeEventResponse>): () => void; /** * Callback for onUnavailable method. * * @callback OnUnavailableCallback * @param {OnUnavailableEventData} data */ /** * Registers a callback function to be invoked when the wallet is not available in the current context. * * @example * button.onUnavailable(() => { * console.log('Wallet not available'); * }); * * @param {OnUnavailableCallback} handler - Function to be called when the wallet is not available in the current context. */ onUnavailable(handler?: (err: OnUnavailableEventData) => void): Promise<unknown> | (() => void); /** * Callback for onError method. * * @callback OnErrorCallback * @param {OnErrorEventData} data */ /** * Registers a callback function to be invoked when an error that is not related to payment execution occurs. * For example, if the amount of the wallet token injected via the `onClick` event handler does not match the amount provided via the initial `meta` or `setMeta` method. * * @example * button.onError((error) => { * console.log('WalletButtonExpress error', error); * }); * * @param {OnErrorCallback} handler - Function to be called when the WalletButton has an error. */ onError(handler?: (err: OnErrorEventData) => void): Promise<unknown> | (() => void); /** * Add docs on each child class */ abstract load(): void; /** * Add docs on each child class */ abstract setMeta(meta: object): void; protected getGatewayWalletConfig<T>(): Promise<BaseGatewayConfig<T>>; protected executeWalletCallback<T, U extends { request_type: string; }>(data: U): Promise<T>; protected executeWalletCapture<T>(data: WalletCaptureRequest): Promise<T>; protected handleMerchantOnExpressButtonClickEvent(): Promise<void>; protected handleMerchantOnShippingChangedEvent<T extends OnShippingAddressChangeEventData | OnShippingOptionChangeEventData>(eventData: T): Promise<ShippingEventToResponse<T>>; protected setWalletToken(token: string, opts?: { skipApiAuth: boolean; }): void; protected handleCheckoutClose(): void; protected handleOnUnavailable(): void; protected handleOnError(error?: Error): void; protected eventDataFromApiError(err: any): OnPaymentErrorEventData['data']; protected validateRequiredMetaFields(requiredMetaFields: string[]): void; } export { BaseWalletButton }; //# sourceMappingURL=base.wallet-button-express.d.ts.map