react-native-datatrans
Getting started
git clone https://github.com/creadi/simpego-app-react-native.git
yarn add file:../DatatransPayment
react-native link react-native-datatrans
pod 'RNDatatransPayment', :path => '../node_modules/react-native-datatrans'
cd ios && pod install
To make TWINT work you have to do the following:
Set up a url scheme
https://developer.apple.com/documentation/uikit/core_app/communicating_with_other_apps_using_custom_urls
In Xcode navigate to Project targets > Info tab > Url Types
Add app url prefix scheme
Add the url scheme to the init options
When you initialize the library you need to add the twint property
const datatrans = new Datatrans({ ... twint: 'ch.shop' })
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜ Add Files to [your project's name]
- Go to
node_modules
➜ react-native-datatrans
and add RNDatatransPayment.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNDatatransPayment.a
to your project's Build Phases
➜ Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNDatatransPaymentPackage;
to the imports at the top of the file - Add
new RNDatatransPaymentPackage()
to the list returned by the getPackages()
method
- Append the following lines to
android/settings.gradle
:
include ':react-native-datatrans'
project(':react-native-datatrans').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-datatrans/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
compile project(':react-native-datatrans')
Usage
First initialize the app
import Datatrans from 'react-native-datatrans'
const datatrans = new Datatrans({ merchantId: '1100007268', twint: 'ch.shop', signature: '171127105041804302', testing: false })
You can pay in hidden mode by passing card number and the other checkout parameters
datatrans.payWithCard({
brand: 'Visa',
number: '4242424242424242',
expMonth: 12,
expYear: 2018,
cvv: '123',
name: 'Dani Lazarov',
amount: 199.99,
currencyCode: 'CHF',
country: 'Switzerland',
refNo: '20171207-test-4',
})
.then(res => console.log('Payment was successful', res)
.catch(err => console.error('There was an error', err)
Or open app in ui mode
datatrans.payWithCardUI({
amount: 200,
currencyCode: 'CHF',
country: 'Switzerland',
refNo: '20171207-test-4',
})
.then(res => console.log('Payment was successful', res)
.catch(err => console.error('There was an error', err)
Config parameters
options = {
merchantId: string,
twint: string,
signature: string,
testing: false
}
Payments parameters
options = {
brand: 'Visa' | 'Mastercard' | 'Diners' | 'Amex' | 'Jcb' | 'Myone' | 'Discover',
number: string,
expMonth: number,
expYear: number,
cvv: string,
name: string,
amount: number,
currencyCode: string,
country?: string,
refNo: string,
}