0.2.2 • Published 8 months ago

react-native-apple-pay-token v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago