$ npm install @adrianha/react-native-midtrans --save
$ react-native link @adrianha/react-native-midtrans
- Add
pod 'ReactNativeMidtrans', :path => '../node_modules/@adrianha/react-native-midtrans'
on yourPodfile
- Run
pod install
- Run your project (
Cmd+R
)
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜@adrianha/react-native-midtrans
and addReactNativeMidtrans.xcodeproj
- In XCode, in the project navigator, select your project. Add
libReactNativeMidtrans.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)
- Open up
android/build.gradle
- Add
maven { url "http://dl.bintray.com/pt-midtrans/maven" }
onallproject.repositories
scope - Add
maven { url "https://jitpack.io" }
onallproject.repositories
scope
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.adrianha.midtrans.ReactNativeMidtransPackage;
to the imports at the top of the file - Add
new ReactNativeMidtransPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':@adrianha/react-native-midtrans' project(':@adrianha/react-native-midtrans').projectDir = new File(rootProject.projectDir, '../node_modules/@adrianha/react-native-midtrans/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':@adrianha/react-native-midtrans')
- Create Midtrans instance
import Midtrans from '@adrianha/react-native-midtrans';
const midtrans = new Midtrans({
clientKey: 'CLIENT_KEY',
baseUrl: 'BASE_URL',
/** iOS only: Midtrans.ENVIRONMENT_SANDBOX | Midtrans.ENVIRONMENT_PRODUCTION */
environment: Midtrans.ENVIRONMENT_SANDBOX,
/** android only */
colorTheme: {
primaryColor: '#000000',
},
});
- Pay with SNAP token
try {
const result = await midtrans.startPaymentWithSnapToken('SNAP_TOKEN');
console.log({ result });
} catch (e) {
console.log(e);
}