UNPKG

@palta-brain/web-sdk

Version:
319 lines (318 loc) 9.02 kB
import { PrimerCheckout, UniversalCheckoutOptions } from '@primer-io/checkout-web'; import { AuthorizationResponseDetails } from 'paypal-checkout-components/modules/callback-data'; export type MerchantStrCustomerId = { type: string; value: string; }; export type MerchantUUIDCustomerId = { type: string; value: string; }; export type CustomerId = MerchantStrCustomerId | MerchantUUIDCustomerId; export type showPaymentFormData = { settings: PaymentFormSettings; primerOption: UniversalCheckoutOptions; braintreeOption: any; clientToken?: string; formWrapperSelector?: string; paymentWrapperSelector: string; primerCheckoutFormSelector: string; braintreeCheckoutFormSelector: string; payPalEnv?: string; }; export interface PaymentClientI { getPricePoints: (request: PricePointRequest) => Promise<PricePoint[]>; showPaymentForm: ({ settings, primerOption, braintreeOption, clientToken, formWrapperSelector, paymentWrapperSelector, primerCheckoutFormSelector, braintreeCheckoutFormSelector, }: showPaymentFormData) => Promise<ShowPaymentFormResponse>; updatePaymentForm: (settings: PaymentFormSettings) => Promise<void>; loadReCaptchaScript: (onReCaptchaReady?: () => void, onError?: () => void) => void; } export type clientTokenType = string | null | undefined; export type checkoutTraceId = string | null; declare global { namespace grecaptcha { namespace enterprise { function execute(siteKey: string, config: { action: string; }): Promise<string>; function ready(callback: () => void): Promise<string>; } } } export type FeatureType = 'timebased' | 'consumable'; export type ProductFeatureInfo = { ident: string; quantity: number; type: FeatureType; }; export type SubscriptionTypes = 'intro' | 'intro_next' | 'lifetime' | 'freebie'; export type StoreType = 1 | 2 | 3; export type PeriodTypes = 'second' | 'minute' | 'day' | 'week' | 'month' | 'year'; type Prettify<T> = { [K in keyof T]: T[K]; } & unknown; export type ProductInfo = { sku: string; features: ProductFeatureInfo[]; }; export type PricePointRequest = { customerId?: CustomerId | null; availabilityRules?: boolean | null; ident?: string[] | null; status?: string[] | null; countryCode?: string | null; platformCode?: string | null; requestContext?: Record<string, any> | null; }; export type PricePointResponse = { pricePoints: any[]; products: { [key: string]: object; }; }; type PricePointBase = { ident: string; storeType: StoreType; name: string; type: SubscriptionTypes; priority: number; currencyCode: string; parameters: Record<string, any>; productSku: string; product: ProductInfo; introBasePrice: string | null; introPeriodValue: number | null; introPeriodType: PeriodTypes | null; introTotalPrice: string | null; nextBasePrice: string | null; nextTotalPrice: string | null; nextPeriodValue: number | null; nextPeriodType: PeriodTypes | null; }; export type PricePoint = Prettify<PricePointBase & ({ type: 'intro'; introBasePrice: string; introPeriodValue: number; introPeriodType: PeriodTypes; introTotalPrice: string; } | { type: 'intro_next'; introBasePrice: string; introPeriodValue: number; introPeriodType: PeriodTypes; introTotalPrice: string; nextBasePrice: string; nextPeriodValue: number; nextPeriodType: PeriodTypes; nextTotalPrice: string; } | { type: 'lifetime'; introBasePrice: string; } | { type: 'freebie'; introPeriodValue: number; introPeriodType: PeriodTypes; })>; export declare enum PaymentMethodType { card = "card", paypal = "paypal", apple_pay = "apple_pay", google_pay = "google_pay" } export type PSPSession = { clientToken: string; paymentMethods: PaymentMethodType[]; }; export type createClientSessionResponse = { orderId: string; primer?: PSPSession; braintree?: PSPSession; status: string; price: string; currencyCode: string; }; export type BillingAddressType = { firstName?: string; lastName?: string; addressLine1?: string; addressLine2?: string; city?: string; state?: string; countryCode?: string; postalCode?: string; }; export type Customer = { id: CustomerId; billingAddress?: BillingAddressType; emailAddress?: string; mobileNumber?: string; }; export type PaymentClientSettingsType = { apiEndpoint: string; apiKey: string; reCaptchaEnabled?: boolean | null | undefined; reCaptchaSiteKey?: string | null | undefined; metadata: object; email: string; onError: (error: any, description: string) => void; onPaymentStatusChange: (status: PaymentStatusesType, paymentMethodType: string) => void; }; export type PaymentFormSettings = { ident: string; countryCode?: string; platformCode?: string; customerId?: CustomerId; customer: Customer; email?: string; orderId?: string; billingAddress?: BillingAddressType; mobileNumber?: string; }; export type createClientSessionRequest = { recaptchaToken?: string | null; customer: Customer; pricePointIdent: string; countryCode?: string; platformCode?: string; orderId?: string; metadata?: object; }; export type startCheckoutRequestType = { orderId: string; }; export type startCheckoutResponseType = { status: string; }; export type checkoutOnFailRequest = { orderId: string; }; export type checkoutOnSuccessRequest = { orderId: string; }; export declare enum IntegrationTypeEnum { Primer = "primer", Braintree = "braintree" } export type resumePaymentRequest = { integrationType: IntegrationTypeEnum; orderId: string; paymentToken: string; integrationPaymentId: string; }; export type createPaymentRequest = { integrationType: IntegrationTypeEnum; paymentToken: string; orderId: string; deviceData?: string; }; export declare enum CheckoutStateEnum { processing = "processing", completed = "completed", failed = "failed", cancelled = "cancelled" } export declare enum Intent { /** * Submits the transaction for authorization but not settlement. */ Authorize = "authorize", /** * Validates the transaction without an authorization (i.e. without holding funds). * Useful for authorizing and capturing funds up to 90 days after the order has been placed. * Only available for Checkout flow. */ Order = "order", /** * Payment will be immediately submitted for settlement upon creating a transaction. * `sale` can be used as an alias for this value. */ Capture = "capture" } export declare enum FlowType { /** * Used to store the payment method for future use, ie subscriptions */ Vault = "vault", /** * Used for one-time checkout */ Checkout = "checkout" } export declare enum ButtonSizeOption { /** * Recommended. Default. * 150 pixels by 25 pixels */ Small = "small", /** * 250 pixels by 35 pixels */ Medium = "medium", /** * 350 pixels by 40 pixels */ Large = "large", /** * Dynamic * Matches the width of the container element, height is decided dynamically based on width. * Minimum width is 150px, maximum width is 500px. */ Responsive = "responsive" } export interface AuthorizationResponse { /** * The payment method nonce. */ nonce: string; /** * The payment method type, always `PayPalAccount`. */ type: string; /** * Additional PayPal account details. */ details: AuthorizationResponseDetails; } export declare enum PaymentStatus { success = "success", error = "error" } export type createPaymentResponse = { status: PaymentStatus; integrationPaymentId: string; checkoutState: CheckoutStateEnum; requiredAction?: { name: string; clientToken: string; }; }; export type resumePaymentResponse = { integrationPaymentId: string; status: PaymentStatus; checkoutState: CheckoutStateEnum; requiredAction?: { name: string; clientToken: string; }; }; export type BraintreeCheckout = any; export type ShowPaymentFormResponse = PrimerCheckout | BraintreeCheckout | null; export type UpdateClientResponse = { orderId: string; primer?: PSPSession; braintree?: PSPSession; price: string; currencyCode: string; }; export type UpdateClientRequest = { metadata: object; orderId?: string; platformCode?: string; countryCode?: string; pricePointIdent: string; customer: Customer; primerClientToken?: string; braintreeClientToken?: string; }; export declare const threeDStatuses: string[]; export type PaymentStatusesType = 'PENDING' | 'ERROR' | 'COMPLETE' | 'FAIL'; export {};