voko-sdk
Version:
Process payments with ease
38 lines (37 loc) • 2.38 kB
TypeScript
import { PaymentMethod, MobileOperator, SupportedProvider, ProviderConfig, Environment, VokoErrorCode } from '../../core/types';
import { PaymentAdapter, PaymentRequest, PaymentStatusRequest, PaymentStatusResponse, WebhookVerificationResult } from '../../core/interfaces';
import { VokoError } from '../../core/errors';
import { HttpClient } from '../../utils/http-client';
import { Logger } from '../../utils/logger';
import { VokoPaymentResponse } from '../../core/models';
export declare abstract class BaseAdapter implements PaymentAdapter {
readonly config: ProviderConfig;
readonly provider: SupportedProvider;
protected readonly httpClient: HttpClient;
protected readonly logger: Logger;
protected readonly baseUrl: string;
constructor(config: ProviderConfig);
protected abstract getBaseUrl(environment: Environment): string;
protected abstract getPaymentEndpoint(): string;
protected abstract getStatusEndpoint(): string;
protected abstract transformRequest(request: PaymentRequest): Record<string, any>;
protected abstract transformResponse(providerResponse: any, originalRequest: PaymentRequest): VokoPaymentResponse;
protected abstract transformStatusResponse(providerResponse: any): PaymentStatusResponse;
protected abstract getAuthHeaders(): Record<string, string>;
protected abstract mapErrorCode(providerError: any): VokoErrorCode;
protected abstract verifyWebhookSignature(payload: string, signature?: string): boolean;
protected abstract getStatusRequestData(request: PaymentStatusRequest): Record<string, any>;
protected getContentHeaders(): Record<string, string>;
protected getStatusHttpMethod(): 'GET' | 'POST';
initiatePayment(request: PaymentRequest): Promise<VokoPaymentResponse>;
checkPaymentStatus(request: PaymentStatusRequest): Promise<PaymentStatusResponse>;
verifyWebhook(payload: string, signature?: string): Promise<WebhookVerificationResult>;
protected makeApiCall(endpoint: string, data: Record<string, any>, method?: 'GET' | 'POST'): Promise<any>;
private buildUrl;
private buildRequestHeaders;
protected handleError(error: any): VokoError;
protected generateTransactionId(): string;
protected parseWebhookPayload(payload: string): any;
getSupportedPaymentMethods(): PaymentMethod[];
getSupportedOperators(): MobileOperator[];
}