Host Card Emulation Through React Native

Host Card Emulation Through React Native

react-native-card-emulation Host card emulation through react native

react-native-card-emulation

Host card emulation through react native

Installation

npm install react-native-card-emulation

Usage

import CardEmulation from "react-native-card-emulation";

// ...

1. Initialize the module

componentDidMount() {
  // ...
  CardEmulation.initialize();
}

2. Add event listeners

componentDidMount() {
    // ...

    CardEmulation.initialize();

    const eventEmitter = new NativeEventEmitter(CardEmulation);
    eventEmitter.addListener('ReadRecord', () => {
      // Call api to get record info
      // Api should return: PAN, expity, serviceCode, User name

      console.log('Read record event received on js')

      const pan = "1212121212121212";
      const expiry = "2104";
      const serviceCode = "101";
      const name = "BASTOLA/SANT";

      CardEmulation.setReadRecordData(pan, expiry, serviceCode, name);
    });

    eventEmitter.addListener('ComputeCryptoChecksum', () => {
      // Call api to compute cryptograhic checksum
      // Api should return cvv for Track1, cvv for Track2 and ATC

      console.log('Compute cryptographic checksum event received on js')

      const cvvT1 = "FBC7";
      const cvvT2 = "B892";
      const atc = "0001";

      CardEmulation.setCryptographicData(cvvT1, cvvT2, atc);
    });

    eventEmitter.addListener('PaymentStarted', () => {
      console.log('Payment Started');
    });

    eventEmitter.addListener('PaymentSuccessful', () => {
      console.log('Payment Successful');
    });

    eventEmitter.addListener('PaymentFailed', () => {
      console.log('Payment Failed');
    });

    eventEmitter.addListener('IncrementATC', () => {
      // Call an Api to increment atc

      console.log('Increment ATC');

      CardEmulation.atcIncremented();
    });
  }

Android setup

1. Add this on AndroidManifest.xml

<uses-permission android:name="android.permission.NFC" />

<uses-feature
  android:name="android.hardware.nfc"
  android:required="true" />

<application>

// ...
  <service
    android:name="com.reactnativecardemulation.apdu.ApduService"
    android:exported="true"
    android:permission="android.permission.BIND_NFC_SERVICE">
    <intent-filter>
      <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />

      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

    <meta-data
      android:name="android.nfc.cardemulation.host_apdu_service"
      android:resource="@xml/apdu_config" />
  </service>

</application>

2. Create a new file apdu_config.xml on android/app/src/main/res/xml and paste this code.

<?xml version="1.0" encoding="utf-8"?>
<host-apdu-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:apduServiceBanner="@mipmap/ic_launcher"
    android:description="@string/apdu_description"
    android:requireDeviceUnlock="false">

    <aid-group
        android:category="payment"
        android:description="@string/aid_group_description">
        <aid-filter
            android:name="325041592E5359532E4444463031"
            android:description="@string/aid_ppse_description" />
        <aid-filter
            android:name="A0000000041010"
            android:description="@string/aid_mastercard_description" />
    </aid-group>

</host-apdu-service>

3. Add this on android/app/src/main/res/values/strings.xml

<!-- HCE Configuration -->
<string name="apdu_description">Contactless Pay</string>
<string name="aid_group_description">Contactless Pay is the best.</string>
<string name="aid_ppse_description">Proximity Payment System Environment (PPSE)</string>
<string name="aid_mastercard_description">MasterCard</string>

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Download Details:

Author: bastolaxantos

Source Code: https://github.com/bastolaxantos/react-native-card-emulation

react-native react mobile-apps

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Native Mobile App Development

Skenix is providing React Native Development Services with qualified React Native App Developers. Get the best React Native App Development Services.

How React Native Is Shaping Mobile App Development

Are you a mobile app developer looking for more efficient tools for your projects? Mobile app development is getting tougher and tougher as the market continues to grow. As a developer, you need to develop Apps which meet the demands of your users. To achieve this, adopt the right tools, like the React Native development framework.

Top React Native Mobile App Development Companies in USA

Looking for top React Native mobile app development company in USA for Startups & Enterprise? Find out the top list of React Native mobile app development company in USA.

Which is the best React Native app development company in New York?

Hire top react native app development company in New York to build and develop custom react native mobile apps for Android & iOS with the latest features.