Skip to main content

Apple Pay

Prerequisites

  • Please create a Tappay account and get the app ID from Tappay Dashboard.
  • Create Merchant ID and Apple Pay Certificate from Apple Developer.
  • Integrate your Merchant with Tappay Dashboard.
  • Please add the following config in your app.json
{
"expo": {
"plugins": [
[
"expo-tappay", {
"applePay":{
"enable":true,
"merchantId": "YOUR_MERCHANT_ID", // replace with your Merchant ID
}
// other payment methods...
}
]
]
}
}
ParameterTypeDescription
enablebooleanWhether to enable Apple Pay
merchantIdstringYour Apple Pay merchant identifier registered with Apple

Usage

Setup Tappay

This method configures the Tappay instance. This setup must be completed before any Apple Pay transaction can be processed.

ParameterTypeDescription
appIdnumberYour Tappay App ID
appKeystringYour Tappay App Key
serverTypeServerTypeYour Tappay Server Type

Server Type

  • sandbox: for testing
  • production: for production
import Tappay from "expo-tappay";

const tappay = new Tappay({
appId: 11340, // replace with your Tappay App ID
appKey: "app_whdEWBH8e8Lzy4N6BysVRRMILYORF6UxXbiOFsICkz0J9j1C0JUlCHv1tVJC", // replace with your Tappay App Key
serverType: "sandbox",
});

Checking Apple Pay Availability

Checks if Apple Pay is available and properly configured on the device

return: boolean


if (tappay.applePay.isAvailable) {
console.log("Apple Pay is available");
} else {
console.log("Apple Pay is not available");
}

Checking Apple Pay Can Make Payments

Checks if Apple Pay can make payments

return: boolean


if (tappay.applePay.canMakePayments()) {
console.log("Apple Pay can make payments");
} else {
console.log("Apple Pay cannot make payments");
}

Open Apple Pay Setup Screen

This method opens the Apple Pay setup screen.

return: void

tappay.applePay.showSetupView();

Start Apple Pay

Call startPayment() to initiate the Apple Pay payment flow.

Parameters:

ParameterTypeDescription
itemsCartItem[]Array of cart items to be processed for payment

return: void

tappay.applePay.startPayment(items);

Show Result

You must use showResult function to display the result in the user interface.

IMPORTANT: If showResult() is not called, the user interface will continue to show "Processing" and will not complete.

Transaction result status (true = success, false = failure)

return: void

tappay.applePay.showResult(boolean);

Listener

Receive Prime Listener

Event Type

return: EventSubscription

tappay.applePay.addRecievePrimeListener((event) => {
// Handle the result of getting the prime, check if it is successful or failed
});

Apple Pay Start Listener

Payload Type

return: EventSubscription

tappay.applePay.addStartListener((payload) => {
// Apple Pay transaction started
});

Apple Pay Cancel Listener

Payload Type

return: EventSubscription

tappay.applePay.addCancelListener((payload) => {
// Apple Pay transaction cancel
});

Apple Pay Finished Listener

Payload Type

return: EventSubscription

tappay.applePay.addFinishedListener((payload) => {
// Apple Pay transaction finished
});

Apple Pay Success Listener

Payload Type

return: EventSubscription

tappay.applePay.addSuccessListener((payload) => {
// Apple Pay transaction successful
});

Apple Pay Failed Listener

Payload Type

return: EventSubscription

tappay.applePay.addFailedListener((payload) => {
// Apple Pay transaction failed
});

Remove Listener

return: void

import ApplePay from "expo-tappay-apple-pay";
import { EventSubscription } from "expo-modules-core";


const subscription: EventSubscription = tappay.applePay.addRecievePrimeListener((data) => {});

subscription.remove();

Example

ApplePay Example

Type

Cart Item Type

KeyValueDescription
namestringProduct name to display in Apple Pay sheet
amountnumberProduct price in cents

Receive Prime Listener Event Type

  • OnSuccessReceivePrimeEvent
KeyValueDescription
successtrueIndicates the payment was successful
primestringThe payment token generated by Tappay
expiryMillisnumberThe expiration time of the payment token in milliseconds
totalAmountnumberThe total amount of the payment
clientIPstringThe client's IP address
  • OnFailureReceivePrimeEvent
KeyValueDescription
successfalseIndicates the payment failed
messagestringError message describing the failure

Apple Pay General Event Payload Type

KeyValueDescription
statusnumberThe status code of the event
messagestringA message describing the event

Apple Pay Transaction Event Payload Type

PropertyTypeDescription
statusnumberTransaction status code
amountnumberTransaction amount
messagestringTransaction message
descriptionstringDetailed transaction description

Version

  • TPDirect: v2.17.0