UNPKG

pay-connect

Version:

A module for integrating multiple payment gateways including PayPal, Stripe, GooglePay and Momo.

539 lines (525 loc) 16.2 kB
import { PayPalScriptOptions, PayPalButtonsComponentOptions } from '@paypal/paypal-js'; import * as _stripe_stripe_js from '@stripe/stripe-js'; import { Stripe } from 'stripe'; export { Stripe } from 'stripe'; import GooglePayButton from '@google-pay/button-element/dist/index'; declare class MomoGateway { startPayment(amount: number, orderId: string): Promise<string>; confirmPayment(paymentId: string): Promise<string>; cancelPayment(paymentId: string): Promise<string>; } interface BillingInfo { name: string; phone_number: string; address: string; city: string; postal_code?: string; } interface OrderData { subtotal: string; tax: string; discount: string; total: string; billing_info: BillingInfo; } interface SubscriptionData { plan_id: string; start_time?: string; quantity?: string; shipping_amount?: { currency_code: string; value: string; }; subscriber?: { name?: { given_name: string; surname: string; }; email_address?: string; shipping_address?: { name?: { full_name: string; }; address?: { address_line_1: string; address_line_2?: string; admin_area_2: string; admin_area_1: string; postal_code: string; country_code: string; }; }; }; application_context?: { brand_name?: string; locale?: string; shipping_preference?: string; user_action?: string; payment_method?: { payer_selected?: string; payee_preferred?: string; }; return_url?: string; cancel_url?: string; }; } interface PlanData { product_id: string; name: string; description: string; status: string; billing_cycles: Array<{ frequency: { interval_unit: string; interval_count: number; }; tenure_type: string; sequence: number; total_cycles: number; pricing_scheme: { fixed_price: { value: string; currency_code: string; }; }; }>; payment_preferences: { auto_bill_outstanding: boolean; setup_fee: { value: string; currency_code: string; }; setup_fee_failure_action: string; payment_failure_threshold: number; }; taxes: { percentage: string; inclusive: boolean; }; } interface ProductData { name: string; description: string; type: string; category: string; } interface PricingData { pricing_schemes: { billing_cycle_sequence: number; pricing_scheme: { fixed_price: { value: string; currency_code: string; }; pricing_model?: string; tiers?: { starting_quantity: string; ending_quantity?: string; amount: { value: string; currency_code: string; }; }[]; }; }[]; } declare class PayPalOrders { private options; private baseUrl; private generateAccessToken; constructor(options: PayPalScriptOptions, baseUrl: string, generateAccessToken: () => Promise<string>); createOrder(data: OrderData): Promise<{ jsonResponse: any; httpStatusCode: number; }>; captureOrder(orderID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; } declare class PayPalSubscriptions { private options; private baseUrl; private generateAccessToken; constructor(options: PayPalScriptOptions, baseUrl: string, generateAccessToken: () => Promise<string>); createPlan(data: PlanData): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getPlanList(): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getPlanDetails(planID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; updatePlan(planID: string, data: { op: string; path: string; value: any; }[]): Promise<{ jsonResponse: any; httpStatusCode: number; }>; updatePlanPricing(planID: string, data: PricingData): Promise<{ jsonResponse: any; httpStatusCode: number; }>; createSubscription(data: SubscriptionData): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getSubscriptionDetails(subscriptionID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; updateSubscription(subscriptionID: string, data: { op: string; path: string; value: any; }[]): Promise<{ jsonResponse: any; httpStatusCode: number; }>; cancelSubscription(subscriptionID: string, reason: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; activateSubscription(subscriptionID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; captureSubscription(subscriptionID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; suspendSubscription(subscriptionID: string, reason: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; reviseSubscription(subscriptionID: string, data: any): Promise<{ jsonResponse: any; httpStatusCode: number; }>; listSubscriptionTransactions(subscriptionID: string, startTime: string, endTime: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; } declare class PayPalPayments { private options; private baseUrl; private generateAccessToken; constructor(options: PayPalScriptOptions, baseUrl: string, generateAccessToken: () => Promise<string>); refundCapturedPayment(captureID: string, amount: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getCaptureDetails(captureID: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; } declare class PayPalProducts { private options; private baseUrl; private generateAccessToken; constructor(options: PayPalScriptOptions, baseUrl: string, generateAccessToken: () => Promise<string>); createProduct(data: ProductData): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getProductList(): Promise<{ jsonResponse: any; httpStatusCode: number; }>; getProductDetails(productId: string): Promise<{ jsonResponse: any; httpStatusCode: number; }>; updateProduct(productId: string, data: { op: string; path: string; value: string; }[]): Promise<{ jsonResponse: any; httpStatusCode: number; }>; } interface PaypalGatewayOptions extends PayPalScriptOptions { clientSecret?: string; } declare class PaypalGateway { private clientId; private clientSecret?; private options; private baseUrl; orders: PayPalOrders; subscriptions: PayPalSubscriptions; payments: PayPalPayments; products: PayPalProducts; constructor(options: PaypalGatewayOptions); private generateAccessToken; renderCheckoutButtons(containerId: string, options?: PayPalButtonsComponentOptions): Promise<void>; renderSubscriptionButtons(containerId: string, options?: PayPalButtonsComponentOptions): Promise<void>; } interface StripeGatewayOptions { secretKey: string; } declare const loadStripeClient: (publishableKey: string) => Promise<_stripe_stripe_js.Stripe | null>; declare class StripeGateway { private serverStripe; constructor(options: StripeGatewayOptions); createCharge(amount: number, currency: string, source: string): Promise<{ success: boolean; chargeId: string; amount: number; currency: string; source: Stripe.CustomerSource | null; error?: undefined; } | { success: boolean; error: any; chargeId?: undefined; amount?: undefined; currency?: undefined; source?: undefined; }>; retrieveCharge(chargeId: string): Promise<{ success: boolean; chargeId: string; amount: number; currency: string; status: Stripe.Charge.Status; error?: undefined; } | { success: boolean; error: any; chargeId?: undefined; amount?: undefined; currency?: undefined; status?: undefined; }>; refundCharge(chargeId: string): Promise<{ success: boolean; refundId: string; chargeId: string | Stripe.Charge | null; error?: undefined; } | { success: boolean; error: any; refundId?: undefined; chargeId?: undefined; }>; createSubscription(customerId: string, priceId: string): Promise<{ success: boolean; subscriptionId: string; status: Stripe.Subscription.Status; error?: undefined; } | { success: boolean; error: any; subscriptionId?: undefined; status?: undefined; }>; retrieveSubscription(subscriptionId: string): Promise<{ success: boolean; subscriptionId: string; status: Stripe.Subscription.Status; items: Stripe.ApiList<Stripe.SubscriptionItem>; error?: undefined; } | { success: boolean; error: any; subscriptionId?: undefined; status?: undefined; items?: undefined; }>; cancelSubscription(subscriptionId: string): Promise<{ success: boolean; subscriptionId: string; status: Stripe.Subscription.Status; error?: undefined; } | { success: boolean; error: any; subscriptionId?: undefined; status?: undefined; }>; retrieveCustomer(customerId: string): Promise<{ success: boolean; customerId: string; email: string | null; name: string | null | undefined; error?: undefined; } | { success: boolean; error: any; customerId?: undefined; email?: undefined; name?: undefined; }>; retrievePrice(priceId: string): Promise<{ success: boolean; priceId: string; unitAmount: number | null; currency: string; error?: undefined; } | { success: boolean; error: any; priceId?: undefined; unitAmount?: undefined; currency?: undefined; }>; createCustomer(email: string, name: string): Promise<{ success: boolean; customerId: string; email: string | null; name: string | null | undefined; error?: undefined; } | { success: boolean; error: any; customerId?: undefined; email?: undefined; name?: undefined; }>; createPrice(unitAmount: number, currency: string, productId: string): Promise<{ success: boolean; priceId: string; unitAmount: number | null; currency: string; error?: undefined; } | { success: boolean; error: any; priceId?: undefined; unitAmount?: undefined; currency?: undefined; }>; createProduct(name: string, description: string): Promise<{ success: boolean; productId: string; name: string; description: string | null; error?: undefined; } | { success: boolean; error: any; productId?: undefined; name?: undefined; description?: undefined; }>; listProducts(): Promise<{ success: boolean; products: Stripe.Product[]; error?: undefined; } | { success: boolean; error: any; products?: undefined; }>; createCheckoutSession(params: Stripe.Checkout.SessionCreateParams): Promise<{ success: boolean; sessionId: string; url: string | null; error?: undefined; } | { success: boolean; error: any; sessionId?: undefined; url?: undefined; }>; } type Environment = GooglePayButton["environment"] type ButtonType = GooglePayButton["buttonType"] type ButtonColor = GooglePayButton["buttonColor"] type ButtonSizeMode = GooglePayButton["buttonSizeMode"] type ButtonLocale = GooglePayButton["buttonLocale"] type ButtonRadius = GooglePayButton["buttonRadius"] type ExistingPaymentMethodRequired = GooglePayButton["existingPaymentMethodRequired"] type PaymentRequest = GooglePayButton["paymentRequest"] type OnPaymentDataChanged = GooglePayButton["onPaymentDataChanged"] type OnPaymentAuthorized = GooglePayButton["onPaymentAuthorized"] type OnReadyToPayChange = GooglePayButton["onReadyToPayChange"] type OnLoadPaymentData = GooglePayButton["onLoadPaymentData"] type OnCancel = GooglePayButton["onCancel"] type OnError = GooglePayButton["onError"] type OnClick = GooglePayButton["onClick"] type PaymentData = google.payments.api.PaymentData type IntermediatePaymentData = google.payments.api.IntermediatePaymentData type TransactionInfo = google.payments.api.TransactionInfo type TransactionState = google.payments.api.TransactionState type PaymentDataRequest = google.payments.api.PaymentDataRequest type PaymentDataError = google.payments.api.PaymentDataError type IsReadyToPayResponse = google.payments.api.IsReadyToPayResponse type PaymentDataRequestUpdate = google.payments.api.PaymentDataRequestUpdate type ReadyToPayChangeResponse = { isButtonVisible: boolean isReadyToPay: boolean paymentMethodPresent?: boolean } type PaymentsError = google.payments.api.PaymentsError type CallbackIntent = google.payments.api.CallbackIntent type ShippingOptionParameters = google.payments.api.ShippingOptionParameters type ShippingAddressParameters = google.payments.api.ShippingAddressParameters interface GooglePayOptions { environment: Environment paymentRequest: PaymentRequest buttonType?: ButtonType buttonColor?: ButtonColor buttonLocale?: ButtonLocale buttonSizeMode?: ButtonSizeMode buttonRadius?: ButtonRadius existingPaymentMethodRequired?: ExistingPaymentMethodRequired onCancel?: OnCancel onClick?: OnClick onError?: OnError onLoadPaymentData?: OnLoadPaymentData paymentDataCallbacks?: { onPaymentAuthorized?: OnPaymentAuthorized onPaymentDataChanged?: OnPaymentDataChanged } onReadyToPayChange?: OnReadyToPayChange } declare class GooglePayGateway { private options; constructor(options: GooglePayOptions); private handleLoadPaymentData; private handleCancel; private handleError; private handleClick; private onPaymentDataChanged; private getGoogleUnserviceableAddressError; private getGoogleDefaultShippingOptions; private calculateNewTransactionInfo; private onReadyToPayChange; private processPayment; private onPaymentAuthorized; renderButton(containerId: string): void; } interface GatewayConfig { paypal?: { options: PaypalGatewayOptions; }; stripe?: { options: StripeGatewayOptions; }; momo?: {}; googlePay?: GooglePayOptions; } interface Gateways { paypal?: PaypalGateway; stripe?: StripeGateway; momo?: MomoGateway; googlePay?: GooglePayGateway; } declare const initializeGateways: (config: GatewayConfig) => Gateways; export { type CallbackIntent, GooglePayGateway, type GooglePayOptions, type IntermediatePaymentData, type IsReadyToPayResponse, MomoGateway, type PaymentData, type PaymentDataError, type PaymentDataRequest, type PaymentDataRequestUpdate, type PaymentsError, PaypalGateway, type PaypalGatewayOptions, type ReadyToPayChangeResponse, type ShippingAddressParameters, type ShippingOptionParameters, StripeGateway, type StripeGatewayOptions, type TransactionInfo, type TransactionState, initializeGateways, loadStripeClient };