Capacitor plugin for Apple Pay
npm install @jackobo/capacitor-apple-pay
npx cap sync
async function payWithApplePay() {
await CapacitorApplePay.addListener('validateMerchant', async (event: ValidateMerchantEvent) => {
const merchantSession = await validateMerchantWithYourServer(event.validationURL);
await CapacitorApplePay.completeMerchantValidation({
merchantSession: merchantSession
})
});
await CapacitorApplePay.addListener('authorizePayment', async (event: AuthorizePaymentEvent) => {
try {
const success = await processPaymentWithYourServer(event.payment);
if(success) {
await CapacitorApplePay.paymentAuthorizationSuccess();
} else {
await CapacitorApplePay.paymentAuthorizationFail();
}
} finally {
await CapacitorApplePay.removeAllListeners();
}
}
await CapacitorApplePay.addListener('cancel', async () => {
await CapacitorApplePay.removeAllListeners();
});
await CapacitorApplePay.startPayment(paymentRequestObject);
}
canMakePayments()
addListener('validateMerchant', ...)
addListener('authorizePayment', ...)
addListener('cancel', ...)
startPayment(...)
completeMerchantValidation(...)
paymentAuthorizationSuccess()
paymentAuthorizationFail()
removeAllListeners()
- Interfaces
- Type Aliases
canMakePayments() => Promise<CanMakePaymentsResult>
Checks if Apple Pay is available
Returns: Promise<CanMakePaymentsResult>
addListener(eventName: 'validateMerchant', handler: ValidateMerchantEventHandler) => Promise<PluginListenerHandle>
Subscribe to the validateMerchant event
Param | Type |
---|---|
eventName |
'validateMerchant' |
handler |
ValidateMerchantEventHandler |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'authorizePayment', handler: AuthorizePaymentEventHandler) => Promise<PluginListenerHandle>
Subscribe to the authorizePayment event
Param | Type |
---|---|
eventName |
'authorizePayment' |
handler |
AuthorizePaymentEventHandler |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'cancel', handler: CancelPaymentEventHandler) => Promise<PluginListenerHandle>
Subscribe to the cancel event (when the payment is canceled by the user by closing Apple Pay payment sheet)
Param | Type |
---|---|
eventName |
'cancel' |
handler |
CancelPaymentEventHandler |
Returns: Promise<PluginListenerHandle>
startPayment(request: PaymentRequest) => Promise<void>
Starts the payment process
Param | Type |
---|---|
request |
PaymentRequest |
completeMerchantValidation(request: CompleteMerchantValidationRequest) => Promise<void>
You call this from your code after you performed merchant validation with your server.
Param | Type |
---|---|
request |
CompleteMerchantValidationRequest |
paymentAuthorizationSuccess() => Promise<void>
You call this from your code after the payment processing was successful
paymentAuthorizationFail() => Promise<void>
You call this from your code after when the payment processing failed
removeAllListeners() => Promise<void>
Unsubscribe from all events
Response returned by the canMakePayments method
Prop | Type | Description |
---|---|---|
canMakePayments |
boolean |
It is true if Apple Pay is available |
Prop | Type |
---|---|
remove |
() => Promise<void> |
The validateMerchant event payload
Prop | Type | Description |
---|---|---|
validationURL |
string |
The URL that your backend needs to use in order to perform merchant validation with Apple |
authorizePayment event payload
Prop | Type |
---|---|
payment |
any |
The payload for startPayment method
Prop | Type |
---|---|
merchantId |
string |
countryCode |
string |
currencyCode |
string |
supportedNetworks |
PaymentNetwork[] |
merchantCapabilities |
MerchantCapability[] |
total |
PaymentRequestTotal |
Prop | Type | Description |
---|---|---|
label |
string |
The text that appears next to the amount. Usually this is your merchant name |
amount |
string |
The amount formatted as string yourAmount.toFixed(2) |
type |
'final' | 'pending' |
Defaults to final if not specified |
completeMerchantValidation method request
Prop | Type | Description |
---|---|---|
merchantSession |
string |
Contains the merchant session obtained from your server in the merchant validation process |
validateMerchant event callback
(event: ValidateMerchantEvent): void
authorizePayment event callback
(event: AuthorizePaymentEvent): void
cancel event callback
(): void
All available payment networks
'amex' | 'bancomat' | 'bancontact' | 'cartesBancaires' | 'chinaUnionPay' | 'dankort' | 'discover' | 'eftpos' | 'electron' | 'elo' | 'girocard' | 'interac' | 'jcb' | 'mada' | 'maestro' | 'masterCard' | 'mir' | 'privateLabel' | 'visa' | 'vPay'
Merchant capabilities
'supports3DS' | 'supportsCredit' | 'supportsDebit' | 'supportsEMV'