$ npm install @adrianha/react-native-midtrans --save
- Navigate to ios/
- Run
pod install
- 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/app/build.gradle
Add this.
repositories {
jcenter()
// Add the midtrans repository into the list of repositories
maven { url "http://dl.bintray.com/pt-midtrans/maven" }
maven { url "https://jitpack.io" }
}
- In
android/app/build.gradle
Add this line on dependencies
// For using the Midtrans Sandbox
implementation 'com.midtrans:uikit:1.23.0-SANDBOX' // change the number to the latest version
// For using the Midtrans Production
implementation 'com.midtrans:uikit:1.23.0' // change the number to the latest version
For see the version. https://github.com/veritrans/veritrans-android/releases
- Create Midtrans instance
import Midtrans from '@adrianha/react-native-midtrans';
const midtrans = new Midtrans({
clientKey: 'YOUR_CLIENT_KEY',
baseUrl: 'MERCHANT_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('PAYMENT_SNAP_TOKEN');
console.log({ result });
} catch (e) {
console.log(e);
}