npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@olo/pay-capacitor

v3.0.0

Published

Olo Pay SDK Capacitor Plugin

Downloads

261

Readme

@olo/pay-capacitor

About Olo Pay

Olo Pay is an E-commerce payment solution designed to help restaurants grow, protect, and support their digital ordering and delivery business. Olo Pay is specifically designed for digital restaurant ordering to address the challenges and concerns that weʼve heard from thousands of merchants.

About the Capacitor Plugin

The Olo Pay Capacitor Plugin allows partners to easily add PCI-compliant Apple Pay and Google Pay functionality to their checkout flow and seamlessly integrate with the Olo Ordering API.

Use of the plugin is subject to the terms of the Olo Pay SDK License.

For more information about integrating Olo Pay into your payment solutions, refer to our Olo Pay Dev Portal Documentation (Note: requires an Olo Developer account).

Install

npm install @olo/pay-capacitor
npx cap sync

API Index

Getting Started

A basic high-level overview of the steps needed to integrate the Capacitor Plugin into your hybrid app is as follows:

  1. Initialize Olo Pay (see initialize(...)).
  2. [Android Only] Initialize Google Pay (see initializeGooglePay(...)).
  3. Wait for DigitalWalletReadyEvent to indicate digital wallet payments can be processed.
  4. Create a payment method (see getDigitalWalletPaymentMethod(...)).
  5. Submit the order to Olo's Ordering API.

Handling Promise Rejections

When calling functions on the Olo Pay SDK Plugin, there is a chance that the call will fail with the promise being rejected. When this happens the returned error object will always contain code and message properties indicating why the method call was rejected.

For convenience, the Olo Pay SDK exports a PromiseRejectionCode enum and a PromiseRejection type for handling promise rejection errors.

Example

try {
  const paymentMethodData = await getDigitalWalletPaymentMethod({ amount: 2.34 }});
  //Handle payment method data
} catch (error) {
  let rejection = error as PromiseRejection;
  if (rejection) {
    switch(rejection.code) {
      case PromiseRejectionCode.missingParameter: {
          // Handle missing parameter scenario
          break;
      }
      case PromiseRejectionCode.sdkUninitialized: {
          // Handle sdk not initialized scenario
          break;
      }
    }
  } else {
    // Some other error not related to a promise being rejected from the Olo Pay SDK
  }
}

Events

DigitalWalletReadyEvent

You can subscribe to this event to know when digital wallets are ready to process payments. It can be referenced using the DigitalWalletReadyEvent constant that is exported from the plugin or as a string with "digitalWalletReadyEvent". The event returns a DigitalWalletStatus object.

On iOS, if a device supports digital wallets, it will be ready (and this event will be emitted) as soon as the SDK is initialized.

On Android, this is emitted asynchronously after a call to initializeGooglePay(). Also note that this will be emitted whenever the status changes. Certain method calls, such as changeGooglePayVendor(), will cause this event to be emitted that changes the ready status to false and then asynchronously follow-up with another event that changes the status to true when the new vendor is ready to be used.

Example Code:

import { OloPaySDK, DigitalWalletReadyEvent } from '@olo/pay-capacitor'
 
let digitalWalletReadyEventListener = await OloPaySDK.addListener(DigitalWalletReadyEvent, (info: DigitalWalletStatus) => {
   // Handle event... 
});

// Don't forget to unsubscribe when you no longer need to listen to the event
digitalWalletReadyEventListener.remove();

Methods

initialize(...)

initialize(options: AndroidInitializationOptions | iOSInitializationOptions) => Promise<void>

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

NOTE: On iOS, this method will also initialize Apple Pay and a DigitalWalletReadyEvent will be emitted when it is ready to process payments. On Android, a separate initialization call to initializeGooglePay() is required.

| Param | Type | Description | | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | | options | OloPayInitializationConfig | iOSInitializationOptions | Initialization options |


initializeInternal(...)

initializeInternal(options: InternalInitOptions) => Promise<void>

Used internally by the Olo Pay SDK Plugin. Calling this method manually will result in a no-op

| Param | Type | | ------------- | ------------------------------------------------------------------- | | options | InternalInitOptions |


initializeGooglePay(...)

initializeGooglePay(options: GooglePayInitializationOptions) => 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 will be emitted.

If the promise is rejected, possible values of the code property on the returned error will be one of:

| Param | Type | Description | | ------------- | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | | options | GooglePayInitializationOptions | Options for initializing digital wallets. countryCode and merchantName are required options. |


changeGooglePayVendor(...)

changeGooglePayVendor(options: ChangeGooglePayVendorOptions) => 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 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:

| Param | Type | Description | | ------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | options | ChangeGooglePayVendorOptions | Options for changing the country and merchant name. countryCode and merchantName are required options. |


getDigitalWalletPaymentMethod(...)

getDigitalWalletPaymentMethod(options: DigitalWalletPaymentRequestOptions) => Promise<DigitalWalletPaymentMethodResult | undefined>

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:

| Param | Type | Description | | ------------- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | | options | DigitalWalletPaymentRequestOptions | Options for processing a digital wallet payment. amount is a required option |

Returns: Promise<DigitalWalletPaymentMethodResult>


isInitialized()

isInitialized() => Promise<InitializationStatus>

Check if the Olo Pay SDK has been initialized

Returns: Promise<InitializationStatus>


isDigitalWalletInitialized()

isDigitalWalletInitialized() => 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.

Returns: Promise<InitializationStatus>


isDigitalWalletReady()

isDigitalWalletReady() => Promise<DigitalWalletStatus>

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.

Returns: Promise<DigitalWalletStatus>


Type Aliases

AndroidInitializationOptions

Options for initializing the Android Olo Pay SDK. This is a type alias for code readability.

OloPayInitializationConfig

OloPayInitializationConfig

Options for initializing the Olo Pay SDK | Property | Description | Default | | -------- | ----------- | ------- | | productionEnvironment | true to use the production environment, false for the test environment. | true |

{ productionEnvironment?: boolean; }

iOSInitializationOptions

Options for initializing the iOS Olo Pay SDK. This is a type alias for code readability

OloPayInitializationConfig & ApplePayInitializationConfig

ApplePayInitializationConfig

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 |

{ applePayMerchantId: string; applePayCompanyLabel: string; }

InternalInitOptions

Used internally by the Olo Pay SDK Plugin

{ version: string; buildType: string; }

GooglePayInitializationOptions

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 |

{ googlePayProductionEnvironment?: boolean; countryCode: string; merchantName: string; fullAddressFormat?: boolean; existingPaymentMethodRequired?: boolean; emailRequired?: boolean; phoneNumberRequired?: boolean; }

ChangeGooglePayVendorOptions

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 |

{ countryCode: string; merchantName: string; }

DigitalWalletPaymentMethodResult

Type alias representing a digital wallet payment method result. The object will either contain payment method data or error data.

{ paymentMethod: PaymentMethod; error?: undefined; } | { paymentMethod?: undefined; error: DigitalWalletError }

PaymentMethod

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 |

{ id?: string; last4?: string; cardType?: string; expMonth?: number; expYear?: number; postalCode?: string; countryCode?: string; isDigitalWallet: boolean; productionEnvironment: boolean; }

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 |

{ errorMessage: string; digitalWalletType: DigitalWalletType; } & (GooglePayError | null)

GooglePayError

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 |

{ googlePayErrorType: GooglePayErrorType; }

DigitalWalletPaymentRequestOptions

Type alias representing options for a digital wallet payment method request

GooglePayPaymentRequestOptions | ApplePayPaymentRequestOptions

GooglePayPaymentRequestOptions

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

{ amount: number; currencyCode?: string; currencyMultiplier?: number; }

ApplePayPaymentRequestOptions

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' |

{ amount: number; countryCode?: string; currencyCode?: string; }

InitializationStatus

Represents the initialization status of digital wallets | Property | Description | | -------- | ----------- | | isInitialized | true if the SDK has been initialized, false otherwise |

{ isInitialized: boolean }

DigitalWalletStatus

Represents the status of digital wallets | Property | Description | | -------- | ----------- | | isReady | true if digital wallets are ready to be used, false otherwise |

{ isReady: boolean }

Enums

DigitalWalletType

| Members | Value | | --------------- | ------------------------ | | applePay | 'applePay' | | googlePay | 'googlePay' |

GooglePayErrorType

| Members | Value | Description | | -------------------- | ----------------------------- | -------------------------------------------------- | | networkError | 'NetworkError' | Google Pay didn't succeed due to a network error | | developerError | 'DeveloperError' | Google Pay didn't succeed due to developer error | | internalError | 'InternalError' | Google Pay didn't succeed due to an internal error |

PromiseRejectionCode

Describes all the reasons why a method could be rejected. Individual methods document which promise rejection codes are possible, and it's up to the developer to handle them.

| Members | Value | Description | | ------- | ----- | ----------- | | invalidParameter | 'InvalidParameter' | Promise rejected due to an invalid parameter | | missingParameter | 'MissingParameter' | Promise rejected due to a missing parameter | | sdkUninitialized | 'SdkUninitialized' | Promise rejected because the SDK isn't initialized | | applePayUnsupported | 'ApplePayUnsupported' | Promise rejected because the device doesn't support Apple Pay (iOS Only) | | googlePayUninitialized | 'GooglePayUninitialized' | Promise rejected because Google Pay hasn't been initialized yet (Android Only) | | googlePayNotReady | 'GooglePayNotReady' | Promise rejected because Google Pay isn't ready yet (Android Only) | | unimplemented | 'UNIMPLEMENTED' | Promise rejected because the method isn't implemented for the current platform | | generalError | 'generalError' | General purpose promise rejection |

Additional Types

PromiseRejection

When a promise is rejected, the error object returned is guaranteed to have these properties to understand what went wrong. There may be additional properties on the object, but code and message will always be available.

| Property | Description | | -------- | ----------- | | code | The code to indicate why the promise was rejected | | message| A message providing more context about why the promise was rejected. e.g. If the code is missingParameter the message will indicate which parameter is missing |

Changelog

v3.0.0 (July 26, 2024)

Breaking Changes

  • Removed OloPayInitializationConfig.freshInstall parameter used when initializing the SDK

Updates

Dependency Updates

v2.0.1 (July 18, 2023)

Dependency Updates

v2.0.0 (July 14, 2023)

Breaking Changes

v1.1.1 (May 22, 2023)

Updates

  • Fix crash if negative amount is passed in to getDigitalWalletPaymentMethod()

v1.1.0 (Feb 6, 2023)

Updates

  • Add isInitialized()
  • Add isDigitalWalletInitialized()
  • Add DigitalWalletReadyEvent constant and associated documentation
  • Add PromiseRejection type for improved error handling
  • Fix bug with American Express payment methods containing a cardType value incompatible with Olo's Ordering API
  • Fix bug with Google Pay errors not containing error key in returned data
  • Native code threading optimizations

v1.0.0 (Dec 19, 2022)

License

Olo Pay Software Development Kit License Agreement

Copyright © 2022 Olo Inc. All rights reserved.

Subject to the terms and conditions of the license, you are hereby granted a non-exclusive, worldwide, royalty-free license to (a) copy and modify the software in source code or binary form for your use in connection with the software services and interfaces provided by Olo, and (b) redistribute unmodified copies of the software to third parties. The above copyright notice and this license shall be included in or with all copies or substantial portions of the software.

Your use of this software is subject to the Olo APIs Terms of Use, available at https://www.olo.com/api-usage-terms. This license does not grant you permission to use the trade names, trademarks, service marks, or product names of Olo, except as required for reasonable and customary use in describing the origin of the software and reproducing the content of this license.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.