Skip to content

jackobo/capacitor-google-pay

Repository files navigation

@jackobo/capacitor-google-pay

Capacitor pluging for Google Pay Example:

Install

npm install @jackobo/capacitor-google-pay
npm install @types/googlepay --save-dev
npx cap sync

Usage

import {CapacitorGooglePay, PaymentErrorStatusCodeEnum} from "@jackobo/capacitor-google-pay";
async function pay() {
 await CapacitorGooglePay.initializeClient({
  environment: "TEST" //or PRODUCTION
 });

 const {result} = await CapacitorGooglePay.isReadyToPay(isReadyToPayRequest);
 if (!result) { // it means Google Pay is not available
  return;
 }

 try {
  const paymentData = await CapacitorGooglePay.startPayment(startPaymentRequest)
  await callYourServer(paymentData.paymentMethodData)
 } catch (err) {
  if (err?.code !== PaymentErrorStatusCodeEnum.Canceled) {
   //show error to user here
   console.log(err?.message);
  }
 }
}

API

initializeClient(...)

initializeClient(options: InitializeClientOptions) => Promise<void>

Initialize the Google Pay PaymentsClient object. You must call this at least once before calling any other methods of the plugin.

Param Type
options InitializeClientOptions

isReadyToPay(...)

isReadyToPay(request: IsReadyToPayRequest) => Promise<IsReadyToPayResponse>

Checks if the Google Pay is available.

Param Type
request IsReadyToPayRequest

Returns: Promise<IsReadyToPayResponse>


startPayment(...)

startPayment(request: StartPaymentRequest) => Promise<StartPaymentResponse>

Starts the payment process

Param Type
request PaymentDataRequest

Returns: Promise<PaymentData>


Type Aliases

InitializeClientOptions

It is used to initialize a PaymentClient object. This is basically a google.payments.api.PaymentOptions object but with the paymentDataCallbacks property omitted. Payment callbacks are not supported. See documentation https://developers.google.com/pay/api/web/reference/request-objects#PaymentOptions

Omit<google.payments.api.PaymentOptions, 'paymentDataCallbacks'>

Omit

Construct a type with the properties of T except for those in type K.

Pick<T, Exclude<keyof T, K>>

Pick

From T, pick a set of properties whose keys are in the union K

{ [P in K]: T[P]; }

Exclude

Exclude from T those types that are assignable to U

T extends U ? never : T

IsReadyToPayRequest

This is a google.payments.api.IsReadyToPayRequest object. See documentation https://developers.google.com/pay/api/web/reference/request-objects#IsReadyToPayRequest

google.payments.api.IsReadyToPayRequest

IsReadyToPayResponse

This is a google.payments.api.IsReadyToPayResponse. See documentation https://developers.google.com/pay/api/web/reference/response-objects#IsReadyToPayResponse

google.payments.api.IsReadyToPayResponse

StartPaymentRequest

This is a google.payments.api.PaymentDataRequest object. See documentation https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest

google.payments.api.PaymentDataRequest

StartPaymentResponse

This is a google.payments.api.PaymentData object. See documentation https://developers.google.com/pay/api/web/reference/response-objects#PaymentData

google.payments.api.PaymentData

About

A capacitor plugin for Google Pay

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published