UNPKG

@olo/pay-capacitor

Version:
281 lines (280 loc) 13.2 kB
import type { Plugin } from "@capacitor/core"; export interface OloPaySDKPlugin extends Plugin { /** * Initialize the Olo Pay SDK. The SDK must be initialized prior to calling other methods. * * This promise will only be rejected on iOS. If it is rejected the `code` property on the returned * error will be [`PromiseRejectionCode.missingParameter`](#promiserejectioncode) * * _**NOTE:**_ On iOS, this method will also initialize Apple Pay and a [`DigitalWalletReadyEvent`](#digitalwalletreadyevent) * will be emitted when it is ready to process payments. On Android, a separate initialization * call to `initializeGooglePay()` is required. * * @param options Initialization options */ initialize(options: AndroidInitializationOptions | iOSInitializationOptions): Promise<void>; /** * Used internally by the Olo Pay SDK Plugin. Calling this method manually * will result in a no-op */ initializeInternal(options: InternalInitOptions): Promise<void>; /** * _**ANDROID ONLY:** If this method is called on iOS the promise will be rejected_ * * Initialize digital wallets. This must be called after initializing the SDK. When digital wallets * are ready, a [`DigitalWalletReadyEvent`](#digitalwalletreadyevent) will be emitted. * * If the promise is rejected, possible values of the `code` property on the returned error will be one of: * - [PromiseRejectionCode.unimplemented (iOS)](#promiserejectioncode) * - [PromiseRejectionCode.missingParameter](#promiserejectioncode) * - [PromiseRejectionCode.sdkUninitialized](#promiserejectioncode) * * @param options Options for initializing digital wallets. _`countryCode` and `merchantName` are required options._ */ initializeGooglePay(options: GooglePayInitializationOptions): Promise<void>; /** * _**ANDROID ONLY:** If this method is called on iOS the promise will be rejected_ * * Call this to change the country and merchant name used for processing Google Pay payments. This will immediately * trigger a [`DigitalWalletReadyEvent`](#digitalwalletreadyevent) indicating digital wallets are not ready. When Google Pay * has been reinitialized and is ready to be used with the new parameters, another event will be emitted. * * _**NOTE:** If other options need to be changed besides country code and merchant name you can call * `initializeGooglePay()` instead, but it is more expensive than calling this method._ * * If the promise is rejected, possible values of the `code` property on the returned error will be one of: * - [PromiseRejectionCode.unimplemented (iOS)](#promiserejectioncode) * - [PromiseRejectionCode.missingParameter](#promiserejectioncode) * - [PromiseRejectionCode.sdkUninitialized](#promiserejectioncode) * - [PromiseRejectionCode.googlePayUninitialized](#promiserejectioncode) * * @param options Options for changing the country and merchant name. _`countryCode` and `merchantName` are required options._ */ changeGooglePayVendor(options: ChangeGooglePayVendorOptions): Promise<void>; /** * Launch the digital wallet flow and generate a payment method to be used with Olo's Ordering API. * * If the promise is rejected, the `code` property of the returned error object will be one of: * - [PromiseRejectionCode.sdkUninitialized](#promiserejectioncode) * - [PromiseRejectionCode.invalidParameter](#promiserejectioncode) * - [PromiseRejectionCode.missingParameter](#promiserejectioncode) * - [PromiseRejectionCode.applePayUnsupported (iOS)](#promiserejectioncode) * - [PromiseRejectionCode.googlePayNotReady (Android)](#promiserejectioncode) * - [PromiseRejectionCode.googlePayUninitialized (Android)](#promiserejectioncode) * - [PromiseRejectionCode.generalError](#promiserejectioncode) * * @param options Options for processing a digital wallet payment. _`amount` is a required option_ */ getDigitalWalletPaymentMethod(options: DigitalWalletPaymentRequestOptions): Promise<DigitalWalletPaymentMethodResult | undefined>; /** * Check if the Olo Pay SDK has been initialized */ isInitialized(): Promise<InitializationStatus>; /** * Check if digital wallets have been initialized. On iOS, digital wallets are initialized when the SDK is initialized, so this method * will behave the same as `isInitialized()`. On Android, a separate call to `initializeGooglePay()` is required to initialize digital wallets. */ isDigitalWalletInitialized(): Promise<InitializationStatus>; /** * Check if digital wallets are ready to be used. Events are emitted whenever the digital wallet status * changes, so listenting to that event can be used instead of calling this method, if desired. */ isDigitalWalletReady(): Promise<DigitalWalletStatus>; } /** * Used internally by the Olo Pay SDK Plugin */ export declare type InternalInitOptions = { version: string; buildType: string; }; /** Type alias representing options for a digital wallet payment method request */ export declare type DigitalWalletPaymentRequestOptions = GooglePayPaymentRequestOptions | ApplePayPaymentRequestOptions; /** * Type alias representing a digital wallet payment method result. The * object will either contain payment method data or error data. */ export declare type DigitalWalletPaymentMethodResult = { paymentMethod: PaymentMethod; error?: undefined; } | { paymentMethod?: undefined; error: DigitalWalletError; }; /** * Type representing a digital wallet error * | Property | Description | * | -------- | ----------- | * | `errorMessage` | Error message indicating what went wrong | * | `digitalWalletType` | Enum value indicating Apple Pay or Google Pay. If this is a Google Pay error, there are additional properties indicating the type of error that occurred. See `GooglePayError` | */ export declare type DigitalWalletError = { errorMessage: string; digitalWalletType: DigitalWalletType; } & (GooglePayError | null); /** * Type representing specific error types that can occur while processing a Google Pay transaction * | Property | Description | * | -------- | ----------- | * | `googlePayErrorType` | The type of error that occurred. See `GooglePayErrorType` | */ declare type GooglePayError = { googlePayErrorType: GooglePayErrorType; }; /** * Options for initializing the Olo Pay SDK * | Property | Description | Default | * | -------- | ----------- | ------- | * | `productionEnvironment` | `true` to use the production environment, `false` for the test environment. | `true` | */ declare type OloPayInitializationConfig = { productionEnvironment?: boolean; }; /** * Options for initializing Apple Pay * | Property | Description | * | -------- | ----------- | * | `applePayMerchantId` | The merchant id registered with Apple for Apple Pay | * | `applePayCompanyLabel` | The company name that will be displayed on the Apple Pay payment sheet | */ declare type ApplePayInitializationConfig = { applePayMerchantId: string; applePayCompanyLabel: string; }; /** Options for initializing the Android Olo Pay SDK. This is a type alias for code readability. */ export declare type AndroidInitializationOptions = OloPayInitializationConfig; /** Options for initializing the iOS Olo Pay SDK. This is a type alias for code readability */ export declare type iOSInitializationOptions = OloPayInitializationConfig & ApplePayInitializationConfig; /** * Options for intializing Google Pay * | Property | Description | Default | * | -------- | ----------- | ------- | * | `googlePayProductionEnvironment` | `true` to use the production environment, `false` for the test environment | `true` | * | `countryCode` | A two character country code for the vendor that will be processing the payment | - | * | `merchantName` | The merchant/vendor display name | - | * | `fullAddressFormat` | Determines what address fields are required to complete a Google Pay transaction. `true` includes name, street address, locality, region, country code, and postal code. `false` only includes name, country code, and postal code | `false` | * | `existingPaymentMethodRequired` | Whether an existing saved payment method is required for Google Pay to be considered ready | `true` | * | `emailRequired` | Whether Google Pay collects an email when processing payments | `false` | * | `phoenNumberRequired` | Whether Google Pay collects a phone number when processing payments | `false` | */ export declare type GooglePayInitializationOptions = { googlePayProductionEnvironment?: boolean; countryCode: string; merchantName: string; fullAddressFormat?: boolean; existingPaymentMethodRequired?: boolean; emailRequired?: boolean; phoneNumberRequired?: boolean; }; /** * Options for changing the country code or merchant name for Google Pay transactions * | Property | Description | * | -------- | ----------- | * | `countryCode` | A two character country code for the vendor that will be processing the payment | * | `merchantName` | The merchant/vendor display name | */ export declare type ChangeGooglePayVendorOptions = { countryCode: string; merchantName: string; }; /** * Options for requesting a payment method via Google Pay * | Property | Description | Default | * | -------- | ----------- | ------- | * | `amount` | The amount to be charged | - | * | `currencyCode` | A three character currency code for the transaction | 'USD' | * | `currencyMulitplier` | Multiplier to convert the amount to the currency's smallest currency unit (e.g. $2.34 * 100 = 234 cents) | 100 | * * _**IMPORTANT:** The amount charged will be equivalent to `amount * currencyCode` so ensure these are set properly_ */ export declare type GooglePayPaymentRequestOptions = { amount: number; currencyCode?: string; currencyMultiplier?: number; }; /** * Options for requesting a payment method via Apple Pay * | Property | Description | Default | * | -------- | ----------- | ------- | * | `amount` | The amount to be charged | - | * | `currencyCode` | A three character currency code for the transaction | 'USD' | * | `countryCode` | A two character country code | 'US' | */ export declare type ApplePayPaymentRequestOptions = { amount: number; countryCode?: string; currencyCode?: string; }; /** * Represents the status of digital wallets * | Property | Description | * | -------- | ----------- | * | `isReady` | `true` if digital wallets are ready to be used, `false` otherwise | */ export declare type DigitalWalletStatus = { isReady: boolean; }; /** * Represents the initialization status of digital wallets * | Property | Description | * | -------- | ----------- | * | `isInitialized` | `true` if the SDK has been initialized, `false` otherwise | */ export declare type InitializationStatus = { isInitialized: boolean; }; /** * Payment method used for submitting payments to Olo's Ordering API * | Property | Description | * | -------- | ----------- | * | `id` | The payment method id. This should be set to the token field when submitting a basket | * | `last4` | The last four digits of the card | * | `cardType` | The issuer of the card | * | `expMonth` | Two-digit number representing the card's expiration month | * | `expYear` | Four-digit number representing the card's expiration year | * | `postalCode` | Zip or postal code | * | `countryCode` | Two character country code | * | `isDigitalWallet` | `true` if this payment method was created by digital wallets (e.g. Apple Pay or Google Pay), `false` otherwise | * | `productionEnvironment` | Whether or not this payment method was created in the production environment | */ export declare type PaymentMethod = { id?: string; last4?: string; cardType?: string; expMonth?: number; expYear?: number; postalCode?: string; countryCode?: string; isDigitalWallet: boolean; productionEnvironment: boolean; }; /** Digital wallet types */ export declare enum DigitalWalletType { applePay = "applePay", googlePay = "googlePay" } /** Specific kinds of Google Pay Errors */ export declare enum GooglePayErrorType { /** Google Pay didn't succeed due to a network error */ networkError = "NetworkError", /** Google Pay didn't succeed due to developer error */ developerError = "DeveloperError", /** Google Pay didn't succeed due to an internal error */ internalError = "InternalError" } export declare enum PromiseRejectionCode { invalidParameter = "InvalidParameter", missingParameter = "MissingParameter", applePayUnsupported = "ApplePayUnsupported", sdkUninitialized = "SdkUninitialized", googlePayUninitialized = "GooglePayUninitialized", googlePayNotReady = "GooglePayNotReady", uninmplemented = "UNIMPLEMENTED", generalError = "generalError" } export declare type PromiseRejection = { code: string; message: string; }; export declare const DigitalWalletReadyEvent = "digitalWalletReadyEvent"; export {};