And if you will work on the web, you should check "Payment Request Button" 's docs.
Serve your application over HTTPS. This is a requirement both in development and in production. One way to get up and running is to use a service like ngrok.
In file android/app/src/main/AndroidManifest.xml, add the following XML elements under
manifest > application. These call the values set in strings.xml.
Optional1: If you get user information, set these:
Added metadata options to specify what, if any, billing info to require from Google Pay. Add the following entries to strings.xml in the Android project to enable additional data:
In file android/app/src/main/res/values/strings.xml add the these value.
First, you should check to be able to use Google Pay on device.
import{ Stripe, GooglePayEventsEnum }from'@capacitor-community/stripe';(async()=>{// Check to be able to use Google Pay on deviceconst isAvailable = Stripe.isGooglePayAvailable().catch(()=>undefined);if(isAvailable ===undefined){// disable to use Google Payreturn;}})();
This method return resolve(): void or
reject('Not implemented on Device.').
method isGooglePayAvailable()
isGooglePayAvailable() => Promise<void>
2. createGooglePay
You should connect to your backend endpoint, and get every key. This is "not" function at this Plugin. So you can use
HTTPClient ,
Axios , Ajax , and so on.
After that, you set these key to createGooglePay method.
(async()=>{// Connect to your backend endpoint, and get paymentIntent.const{ paymentIntent }=awaitthis.http.post<{
paymentIntent:string;}>(environment.api +'payment-sheet',{}).pipe(first()).toPromise(Promise);// Prepare Google Payawait Stripe.createGooglePay({
paymentIntentClientSecret: paymentIntent,// Web only. Google Pay on Android App doesn't need
paymentSummaryItems:[{
label:'Product Name',
amount:1099.00}],
merchantIdentifier:'merchant.com.getcapacitor.stripe',
countryCode:'US',
currency:'USD',});})();
Method of Google Pay notify any listeners. If you want to get event of payment process is 'Completed', you should add
GooglePayEventsEnum.Completed listener to
Stripe object:
// be able to get event of Google Pay
Stripe.addListener(GooglePayEventsEnum.Completed,()=>{console.log('GooglePayEventsEnum.Completed');});
The event name you can use is
GooglePayEventsEnum.
enum GooglePayEventsEnum
Members
Value
Loaded
"googlePayLoaded"
FailedToLoad
"googlePayFailedToLoad"
Completed
"googlePayCompleted"
Canceled
"googlePayCanceled"
Failed
"googlePayFailed"
📖 Reference
See the Stripe Documentation for more information. This plugin is wrapper, so there information seems useful for you.
Google Pay (Android)
This plugin use GooglePayLauncher on com.stripe:stripe-android:
import{ Stripe, GooglePayEventsEnum }from'@capacitor-community/stripe';(async()=>{// Check to be able to use Google Pay on deviceconst isAvailable = Stripe.isGooglePayAvailable().catch(()=>undefined);if(isAvailable ===undefined){// disable to use Google Payreturn;}
Stripe.addListener(GooglePayEventsEnum.Completed,()=>{console.log('GooglePayEventsEnum.Completed');});// Connect to your backend endpoint, and get paymentIntent.const{ paymentIntent }=awaitthis.http.post<{
paymentIntent:string;}>(environment.api +'payment-sheet',{}).pipe(first()).toPromise(Promise);// Prepare Google Payawait Stripe.createGooglePay({
paymentIntentClientSecret: paymentIntent,// Web only. Google Pay on Android App doesn't need
paymentSummaryItems:[{
label:'Product Name',
amount:1099.00}],
merchantIdentifier:'merchant.com.getcapacitor.stripe',
countryCode:'US',
currency:'USD',});// Present Google Payconst result =await Stripe.presentGooglePay();if(result.paymentResult === GooglePayEventsEnum.Completed){// Happy path}})();