Getting Started
Este contenido aún no está disponible en tu idioma.
-
Install the plugin
Ventana de terminal npm i @capgo/capacitor-payVentana de terminal pnpm add @capgo/capacitor-payVentana de terminal yarn add @capgo/capacitor-payVentana de terminal bun add @capgo/capacitor-pay -
Sync native projects
Ventana de terminal npx cap syncVentana de terminal pnpm cap syncVentana de terminal yarn cap syncVentana de terminal bunx cap sync
Native prerequisites
-
Apple Pay (iOS)
- Create an Apple Pay merchant ID in the Apple Developer portal.
- Generate and upload the payment processing certificate required by your gateway.
- Enable the Apple Pay capability in Xcode and make sure your provisioning profile includes it.
- Update
Info.plistwith a usage description if your gateway requires network access to validate payments.
-
Google Pay (Android)
- Sign in to the Google Pay Business Console.
- Configure your payment gateway parameters or set up direct tokenization for testing.
- If you plan to use production cards, switch
environmenttoPRODUCTIONand register test cards for QA. - Confirm that Google Play services are available on the device (required by Google Pay).
Refer to the guides under docs/ in the plugin repository for step-by-step screenshots.
Check availability
import { Pay } from '@capgo/capacitor-pay';
const availability = await Pay.isPayAvailable({ apple: { supportedNetworks: ['visa', 'masterCard', 'amex'] }, google: { isReadyToPayRequest: { allowedPaymentMethods: [ { type: 'CARD', parameters: { allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'], allowedCardNetworks: ['VISA', 'MASTERCARD'], }, }, ], }, },});
if (!availability.available) { console.warn('Native pay unavailable:', availability);}Request payment (Apple Pay)
const appleResult = await Pay.requestPayment({ apple: { merchantIdentifier: 'merchant.com.example.app', countryCode: 'US', currencyCode: 'USD', supportedNetworks: ['visa', 'masterCard'], paymentSummaryItems: [ { label: 'Starter Plan', amount: '9.99' }, { label: 'Capgo Store', amount: '9.99' }, ], requiredShippingContactFields: ['name', 'emailAddress'], },});
const token = appleResult.apple?.paymentData;Request payment (Google Pay)
const googleResult = await Pay.requestPayment({ google: { environment: 'test', paymentDataRequest: { apiVersion: 2, apiVersionMinor: 0, allowedPaymentMethods: [ { type: 'CARD', parameters: { allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'], allowedCardNetworks: ['VISA', 'MASTERCARD'], billingAddressRequired: true, billingAddressParameters: { format: 'FULL' }, }, tokenizationSpecification: { type: 'PAYMENT_GATEWAY', parameters: { gateway: 'example', gatewayMerchantId: 'exampleMerchantId', }, }, }, ], merchantInfo: { merchantName: 'Capgo Store', }, transactionInfo: { totalPriceStatus: 'FINAL', totalPrice: '9.99', currencyCode: 'USD', countryCode: 'US', }, }, },});
const paymentData = googleResult.google?.paymentData;Handling responses
- Tokenize the returned payload with your payment processor and confirm the transaction server-side.
- Surface a fallback path (card entry, invoice) if native pay is unavailable or the user cancels the sheet.
- Cache the availability result so you do not display the buttons on unsupported devices.