premieroctet / react-native-wallet

A React-Native wrapper for Apple PassKit and Google Wallet API
17 stars 1 forks source link
android ios react-native wallet

🎟️ react-native-wallet

A module built with Expo Modules that provides wallet features for iOS and Android.

Uses PassKit on iOS, Google Wallet API on Android.

Installation

yarn add @premieroctet/react-native-wallet

Expo users

This module is not compatible with Expo Go. You will need to build a custom dev client.

Bare React Native users

You will need to install Expo Modules on your project.

Usage

import { Alert, Button, StyleSheet, View } from 'react-native';
import * as RNWallet from 'react-native-wallet';

export default function App() {
  const onAdd = async () => {
    try {
      const isAdded = await RNWallet.addPass('<PassUrlOrToken>');

      Alert.alert('Pass added', isAdded ? 'Yes' : 'No');
    } catch (error) {
      Alert.alert('Error', (error as Error).message);
    }
  };

  const onCheckPassExists = async () => {
    try {
      const passExists = await RNWallet.hasPass('<PassUrlOrToken>');

      Alert.alert('Pass exists', passExists ? 'Yes' : 'No');
    } catch (error) {
      Alert.alert('Error', (error as Error).message);
    }
  };

  const onRemovePass = async () => {
    try {
      await RNWallet.removePass('<PassUrlOrToken>');

      Alert.alert('Pass removed');
    } catch (error) {
      Alert.alert('Error', (error as Error).message);
    }
  };

  const onCanAddPasses = async () => {
    try {
      const canAddPasses = await RNWallet.canAddPasses();

      Alert.alert('Can add passes', canAddPasses ? 'Yes' : 'No');
    } catch (error) {
      Alert.alert('Error', (error as Error).message);
    }
  };

  return (
    <View style={styles.container}>
      <Button title="Check if can add passes" onPress={onCanAddPasses} />
      <Button title="Check if pass exists" onPress={onCheckPassExists} />
      <Button title="Remove pass" onPress={onRemovePass} />
      <RNWallet.RNWalletView
        buttonStyle={RNWallet.ButtonStyle.BLACK}
        buttonType={RNWallet.ButtonType.PRIMARY}
        onPress={onAdd}
      />
    </View>
  );
}

API

Methods

Props

Constants

The library exports a Constants object with the following properties:

Contributing

Contributions are very welcome!

To get started, fork and clone the repo, and install the dependencies in both root and example folders. Don't forget to install the pods in the example's ios folder.

To run the example app, run yarn start in the root folder, and yarn ios or yarn android in the example folder.

To updathe iOS code, run yarn open:ios, and edit the RNWallet pod files. To update the Android code, run yarn open:android and edit the react-native-wallet module.

Sponsors

This project is being developed by Premier Octet, a Web and mobile agency specializing in React and React Native developments.