react-native-apple-pay-token
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

react-native-apple-pay-token

React Native module to handle Apple Pay tokens

Installation

Before using these functions, make sure you have installed and properly configured the react-native-apple-pay package in your React Native project.

yarn add react-native-apple-pay

Configuration

Before using these functions, you must configure your Info.plist file by setting the ApplePayMerchantIdentifier variable to your Apple Pay merchant identifier.

Follow these steps:

  1. Open your Xcode project.
  2. Locate your Info.plist file in the project navigator.
  3. Add the following key-value pair to your Info.plist file, replacing YOUR_MERCHANT_IDENTIFIER with your actual Apple Pay merchant identifier:
<key>ApplePayMerchantIdentifier</key>
<string>YOUR_MERCHANT_IDENTIFIER</string>

Usage

Import the necessary functions from react-native-apple-pay to use them in your code. Here are the available functions:

getApplePayToken

This function is used to obtain an Apple Pay token for a specific transaction.

Parameters

  • tiket (number): The ticket or item price.
  • tax (number): The tax amount for the transaction.
  • total (number): The total amount for the transaction. Returns
  • A Promise that resolves to an Object containing the Apple Pay token.

Example

import { getApplePayToken } from 'react-native-apple-pay';

const tiket = 100.0;
const tax = 10.0;
const total = tiket + tax;

getApplePayToken(tiket, tax, total)
  .then((token) => {
    // Handle the Apple Pay token
    console.log('Apple Pay Token:', token);
  })
  .catch((error) => {
    // Handle errors
    console.error('Error:', error);
  });

canMakePayments

This function checks if the device is capable of making payments using Apple Pay.

Returns A Promise that resolves to a boolean value, indicating whether Apple Pay payments can be made on the device.

Example

import { canMakePayments } from 'react-native-apple-pay';

canMakePayments()
  .then((canMake) => {
    if (canMake) {
      // Apple Pay is available
      console.log('Apple Pay is available on this device.');
    } else {
      // Apple Pay is not available
      console.log('Apple Pay is not available on this device.');
    }
  })
  .catch((error) => {
    // Handle errors
    console.error('Error:', error);
  });

canSetupCards

This function checks if the device is capable of setting up cards for Apple Pay.

Returns A Promise that resolves to a boolean value, indicating whether Apple Pay card setup is supported on the device.

Example

import { canSetupCards } from 'react-native-apple-pay';

canSetupCards()
  .then((canSetup) => {
    if (canSetup) {
      // Card setup is available
      console.log('Apple Pay card setup is available on this device.');
    } else {
      // Card setup is not available
      console.log('Apple Pay card setup is not available on this device.');
    }
  })
  .catch((error) => {
    // Handle errors
    console.error('Error:', error);
  });

navigateToSetup

This function navigates the user to the Apple Pay card setup screen.

Returns A Promise that resolves once the user has been navigated to the card setup screen.

Example

import { navigateToSetup } from 'react-native-apple-pay';

navigateToSetup()
  .then(() => {
    // User has been navigated to the card setup screen
    console.log('Navigated to Apple Pay card setup.');
  })
  .catch((error) => {
    // Handle errors
    console.error('Error:', error);
  });

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.20latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.20
0.2.10
0.2.00
0.1.00

Package Sidebar

Install

npm i react-native-apple-pay-token

Weekly Downloads

0

Version

0.2.2

License

MIT

Unpacked Size

32.8 kB

Total Files

15

Last publish

Collaborators

  • den1ska