UNPKG

@moneygraph/sdk

Version:

AI-native SDK for global payouts powered by StratosPay

123 lines (122 loc) 3.68 kB
/** * Accept Payments Module * * For merchants to accept payments via cards, widget embed, or popup checkout. * Uses public key (pk_test_* or pk_live_*) for client-side operations. */ import type { ApiClient } from '../api/client'; export interface PaymentCustomer { first_name: string; last_name: string; email: string; phone?: string; phone_iso2?: string; ip_address: string; } export interface BillingAddress { country: string; state?: string; city: string; address: string; postal_code: string; } export interface CardDetails { card_number: string; cvv: string; expire: string; } export interface PaymentParams { title: string; description: string; external_reference: string; amount: number; currency: string; customer: PaymentCustomer; billing_address: BillingAddress; image?: string; callback_url?: string; metadata?: Record<string, any>; plan_id?: string; account_id?: string; } export interface CardPaymentParams extends PaymentParams { card: CardDetails; } export interface WidgetConfig extends PaymentParams { public_key: string; onsuccess?: (data: PaymentResult) => void; onerror?: (data: PaymentError) => void; onclose?: () => void; } export type PaymentStatus = 'success' | 'pending' | 'declined' | 'blocked' | 'requires_action'; export interface PaymentResult { id: string; status: PaymentStatus; amount: number; currency: string; external_reference: string; message?: string; action_url?: string; } export interface PaymentError { code: string; message: string; } export declare const TEST_CARDS: { readonly VISA_SUCCESS: "4917484589897107"; readonly MASTERCARD_SUCCESS: "5555555555554444"; readonly DISCOVER_SUCCESS: "6011000990139424"; readonly CARD_BLOCKED: "6011000991300009"; readonly INSUFFICIENT_FUNDS: "6011111111111117"; readonly DO_NOT_HONOUR: "378282246310005"; readonly PENDING: "374245455400126"; readonly REQUIRES_3DS: "4263982640269299"; readonly REQUIRES_3DS_ALT: "5425233430109903"; readonly REQUIRES_CONFIRMATION: "4000000000001976"; readonly BLOCKED_COUNTRIES: readonly ["AF", "KP"]; readonly MIN_AMOUNT: 10; readonly MAX_AMOUNT: 100; }; export declare class PaymentsModule { private client; private publicKey; private mode; constructor(client: ApiClient, publicKey: string, mode: 'sandbox' | 'live'); /** * Charge a card directly (server-side only, requires PCI compliance) */ chargeCard(params: CardPaymentParams): Promise<PaymentResult>; /** * Verify a payment by reference */ verifyPayment(externalReference: string): Promise<PaymentResult>; /** * Generate configuration for the embed widget * Use with: <script src="https://stratospay.com/embed.js"></script> */ generateWidgetConfig(params: Omit<PaymentParams, 'public_key'>): WidgetConfig; /** * Generate configuration for the popup checkout * Use with: <script src="https://stratospay.com/popup.js"></script> */ generatePopupConfig(params: Omit<PaymentParams, 'public_key'>): WidgetConfig; /** * Generate a unique external reference */ generateReference(prefix?: string): string; /** * Get the widget script URL */ getWidgetScriptUrl(): string; /** * Get the popup script URL */ getPopupScriptUrl(): string; /** * Generate inline script for widget initialization */ generateWidgetScript(config: WidgetConfig): string; private mockChargeCard; private mockPayments; private mockVerifyPayment; }