@paydock/client-sdk
Version:
Paydock client sdk
85 lines • 4.39 kB
TypeScript
import type { ApiInternal } from '../../api/api-internal';
import type { SERVICE_TYPES } from '../../api/api-service-internal';
import type { Container } from '../../components/container';
import type { EventEmitter } from '../../helper/event-emitter';
import { ERROR_OPERATION } from '../enum/error-operation.enum';
import { SERVICE_GROUP } from '../enum/service-group.enum';
import type { IOpenWalletProvider, OpenWalletMeta } from '../interfaces';
import type { CreateOTTData, CreateOTTResponse, WalletType } from '../types';
import type { OnShippingAddressChangeEventData } from '../types/on-shipping-address-change-event-data.interface';
import type { OnShippingOptionChangeEventData } from '../types/on-shipping-option-change-event-data.interface';
import type { ShippingEventToResponse } from '../types/shipping-event-to-response.type';
/**
* Abstract base class for wallet-specific OpenWallet service implementations.
*
* Provides shared functionality for OTT creation, shipping event handling,
* error/unavailable emission, and DOM cleanup. Concrete implementations
* (e.g. Apple Pay, Google Pay) extend this class and implement {@link load} and {@link setMeta}.
*
* @implements {IOpenWalletProvider}
*/
export declare abstract class OpenWalletService implements IOpenWalletProvider {
protected api: ApiInternal;
protected eventEmitter: EventEmitter;
protected walletType: WalletType;
protected serviceId: string;
protected container: Container;
protected serviceType: SERVICE_TYPES;
/** The service group identifier used in OTT creation requests. */
protected readonly serviceGroup = SERVICE_GROUP.WALLET;
/**
* @param api - API client for backend communication.
* @param eventEmitter - Shared event emitter for wallet lifecycle events.
* @param walletType - The wallet type identifier (e.g. `'apple'`, `'google'`).
* @param serviceId - The service ID for the wallet configuration.
* @param container - The DOM container that holds the wallet button.
* @param serviceType - The service type from the API configuration.
*/
constructor(api: ApiInternal, eventEmitter: EventEmitter, walletType: WalletType, serviceId: string, container: Container, serviceType: SERVICE_TYPES);
/**
* Loads and renders the wallet button. Must be implemented by each wallet service.
*/
abstract load(): Promise<void>;
/**
* Updates the wallet metadata. Must be implemented by each wallet service.
*
* @param meta - The updated metadata.
*/
abstract setMeta(meta: OpenWalletMeta): void;
/**
* Creates a One-Time Token (OTT) by sending the payment data to the API.
* Emits {@link EVENT.SUCCESS} on success or {@link EVENT.ERROR} on failure.
*
* @param data - The payment data including amount, shipping, billing, card info, and ref token.
* @returns A promise resolving to the OTT response.
*/
protected createOTT(data: CreateOTTData): Promise<CreateOTTResponse>;
/**
* Delegates a shipping change event to the merchant's registered handler
* and returns the merchant's response.
*
* @param eventData - The shipping address or option change event data.
* @returns A promise resolving to the merchant's shipping update response.
* @throws {Error} If no handler is registered or the handler returns no result.
*/
protected handleMerchantOnShippingChangedEvent<T extends OnShippingAddressChangeEventData | OnShippingOptionChangeEventData>(eventData: T): Promise<ShippingEventToResponse<T>>;
/**
* Emits the {@link EVENT.UNAVAILABLE} event when the wallet is not available.
*
* @param reason - A human-readable description of why the wallet is unavailable.
*/
protected handleOnUnavailable(reason?: string): void;
/**
* Emits the {@link EVENT.ERROR} event and logs the error to the console.
*
* @param error - The error that occurred.
* @param operation - The operation that failed. Defaults to {@link ERROR_OPERATION.WALLET_OPERATION}.
*/
protected handleOnError(error: Error, operation?: ERROR_OPERATION): void;
/**
* Removes the wallet button element from the DOM.
* Call this to clean up resources when the button is no longer needed.
*/
destroy(): void;
}
//# sourceMappingURL=open-wallet.service.d.ts.map