react-native-card-emulation Host card emulation through react native
Host card emulation through react native
npm install react-native-card-emulation
import CardEmulation from "react-native-card-emulation";
// ...
componentDidMount() {
// ...
CardEmulation.initialize();
}
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();
});
}
<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>
<?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>
<!-- 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>
See the contributing guide to learn how to contribute to the repository and the development workflow.
Author: bastolaxantos
Source Code: https://github.com/bastolaxantos/react-native-card-emulation
Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.
Skenix is providing React Native Development Services with qualified React Native App Developers. Get the best React Native App Development Services.
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.
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.
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.