Coder Social home page Coder Social logo

react-native-midtrans's Introduction

React Native Midtrans

By https://dumbways.id (Ega Radiegtya)

Originally Developed by my developer team @mucasali (Muchamad Sahli), and @uadacid (Pratamasetya)

This plugin already tested on Production at https://fifilio.com

React Native Midtrans is module for applicate Midtrans Payment Gateway, its use Midtrans Mobile SDK.

react-native-midtrans enable merchant to accept online payments in React Native apps. it use Midtrans Mobile user Interface SDK to make transactions on all the payment types supported by Midtrans. Watch the video for the default module example.

There are four parties involved in the payment process for making a payment.

  1. Merchant Server : The merchant backand implementation
  2. Customers
  3. Midtrans Backend (Payment Procesor)
  4. PaymentProject

Transaction Flow

  1. Checkout: Customer clicks the Checkout button on the Host application and the app makes a request to the Merchant Server
  2. Token request: Merchant Server makes a request to Veritrans server with Order Information.
  3. Token response: Midtrans responds with a valid transaction token to Merchant server
  4. Token response: Merchant server forwards the token to the Mobile SDK
  5. Get transaction options: Mobile SDK requests payment/merchant information based on the token
  6. Transaction options response: Mobile SDK renders the payment Options and payment information to make the payment
  7. Pay: Customers selects the payment method and the payment details and clicks “Pay”
  8. Charge: Mobile SDK sends the Charge request to the Veritrans Backend for payment Processing.
  9. Charge response: Mobile SDK receives the response from the Veritrans Backend and triggers the handler on Mobile App with success/failure/pending status
  10. Charge notification: Midtrans Backend sends a notification to the Merchant backend confirming the completion of transaction.

Prerequisites

  • Create a merchant account in MAP
  • In MAP, setup your merchant accounts settings, in particular Notification URL.
  • Setup your merchant server. A server side implementation is required for midtrans mobile SDK to work. You can check the server implementation reference, and walk through the API’s that you may need to implement on your backend server.
  • Minimum requirements for Android
  • compileSdkVersion 25
  • buildToolsVersion min 25.0.2
  • targetSdkVersion 25

Installation

  • Install the module
npm i --save react-native-midtrans

or

npm install --save git+https://github.com/radiegtya/react-native-midtrans.git
  • Link the library
react-native link react-native-midtrans
  • In your android/build.gradle add
android {
  .....
}
repositories {
    // Add the midtrans repository into the list of repositories
    maven { url "http://dl.bintray.com/pt-midtrans/maven" }
}

Usage

Lets require react-native-midtrans module

import PaymentMidtrans from 'react-native-midtrans'

Checkout Payment

PaymentMidtrans.checkOut(
	optionConect,
	transRequest,
	itemDetails,
	creditCardOptions,
  userDetail,
  optionColorTheme,
  optionFont,
	callback(res)
);

Props of Payment CheckOut

  • optionConect (Object)

    1. clientKey (String) clientKey from MAP (Merchant Admin Portal)
    2. urlMerchan (String) url Backend
    Example:
    const optionConect = {
    		clientKey: "VT-CLIENT-AAAAAAAAAAAAA",
    		urlMerchant : "http://example.com/payment"
    }
    

    Note: in merchant Server (backend) must be have route with name charge for handle request to Veritrans server with Order Information. for detail can visit here

  • transRequest (Object)

    1. transactionId (String) id of transaction
    2. totalAmount (Number) total amount be paied on checkOut
    Example:
    const transRequest = {
    		transactionId : "001",
    		totalAmount : 6000
    }
    
  • itemDetails (Arrray), holds infromation about ilist of tem purchased by user transaction required for Mandiri Bill and BCA KlikPay, Optional for another payment

    1. id (String) id of item
    2. price (Number) price of item
    3. qty (Number) qty of item
    4. name (String) name of item
Example:
var itemDetails = [
              {id:"001", price:1000, qty:4, name:"cimory"},
              {id:"002", price:2000, qty:2, name:"cofimix"}
            ];

Note: Sum of price must be equals with totalAmount in transRequest

  • creditCardOptions (Object)
    1. saveCard = save card to Snap (true or false)
    2. saveToken = save card token as 'one click' token (true or false)
    3. paymentMode = mode payment use credit Card ("Normal", "Two Click", "One Click")
    4. secure = using 3D secure (true, false)
var creditCardOptions = {
    saveCard:false,
    saveToken:false,
    paymentMode:"Normal",
    secure:false
    };
  • userDetail (Object)
    1. fullName = Full Name member (customer)
    2. email = Email customer
    3. phoneNumber = Phone Number Customer
    4. userId = User Id Customer
    5. address = Address Customer
    6. city = City Customer
    7. country = Country Customer
    8. zipCode = ZipCode Customer
var userDetail = {
  fullName:"Ahmad", email:"[email protected]", phoneNumber:"0850000000", userId:"U01", address:"kudus", city:"kudus", country:"IDN", zipCode:"59382"
};

*Note: value of country use ISO 3166-1 alpha-3, visit wikipedia to learn about ISO 3166-1 alpha-3

  • optionColorTheme (Object)
    1. primary = For top panels showing amount
    2. primaryDark = For bordered button, link button
    3. secondary = For text field.
var optionColorTheme = {
  primary:'#c51f1f',
  primaryDark:'#1a4794',
  secondary:'#1fce38'
}
  • optionFont (Object)
    1. defaultText = for default Text
    2. semiBoldText = for semi bold text
    3. boldText = for bold text
var font = {
  defaultText:"open_sans_regular.ttf", semiBoldText:"open_sans_semibold.ttf",
  boldText:"open_sans_bold.ttf"
}

*Note: open_sans_regular.ttf, open_sans_semibold.ttf, open_sans_bold.ttf is path of the custom font on the assets directory.

  • Callback (function) to return result of payment transaction;
var callback = (res)=>{console.log(res)};

Payment Result

TransactionResult is wrapper for UI flow finished transaction object. It contains:

status : either canceled, pending, success, failed or invalid based on payment API.

  • status canceled is value if transaction canceled. for example when selecting payment method users click back
  • status: pending will be only use on asynchronous transaction like bank transfer or internet banking.
  • status success / failed: For synchronous transaction you can immediately know the status of the transaction.
  • status invalid : There are unknown error happened.

react-native-midtrans's People

Contributors

radiegtya avatar uadacid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-midtrans's Issues

Expo/CRNA support

any plans to support expo? would be great if we don't even touch the native code

Error: Ambiguous resolution

error: bundling failed: ambiguous resolution: module C:\ReactProject\MyApp\index.js tries to require react-native, but there are several files providing this module. You can delete or fix them:

  • C:\ReactProject\MyApp\node_modules\react-native-midtrans\node_modules\react-native\package.json
  • C:\ReactProject\MyApp\node_modules\react-native\package.json

BUNDLE [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

Failed to registering transaction.

alt text

hi bro,
did i miss something on setup ? where?

and
const optionConect = {
clientKey: "xxxxx",
urlMerchant : "https://" <-- can you explain about this Merchant url?
}

and undefined response
alt text

thanks

Syntax error

\node_modules\react-native-midtrans\android\src\main\java\com\paymentproject\midtrans\MidtransPackage.java:20: error: method does not override or implement a method from a supertype
    @Override
    ^
1 error
:react-native-midtrans:compileReleaseJavaWithJavac FAILED

Problem when build version

hello, i want to ask about the library. when i build using react-native run-android, i got some trouble like this

`va:10: error: cannot find symbol
import com.facebook.react.ReactApplication;
^
symbol: class ReactApplication
location: package com.facebook.react
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:22: error: cannot find symbol
import com.facebook.react.modules.core.ChoreographerCompat;
^
symbol: class ChoreographerCompat
location: package com.facebook.react.modules.core
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:24: error: cannot find symbol
import com.facebook.react.modules.core.ReactChoreographer;
^
symbol: class ReactChoreographer
location: package com.facebook.react.modules.core
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:105: error: cannot find symbol
latestJSBundleLoader = JSBundleLoader.createAssetLoader(getReactApplicationContext(), latestJSBundleFile, false);
^
symbol: method createAssetLoader(ReactApplicationContext,String,boolean)
location: class JSBundleLoader
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:107: error: method createFileLoader in class JSBundleLoader cannot be applied to given types;
latestJSBundleLoader = JSBundleLoader.createFileLoader(latestJSBundleFile);
^
required: Context,String
found: String
reason: actual and formal argument lists differ in length
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:145: error: cannot find symbol
instanceManager.recreateReactContextInBackground();
^
symbol: method recreateReactContextInBackground()
location: variable instanceManager of type ReactInstanceManager
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:196: error: cannot find symbol
ReactApplication reactApplication = (ReactApplication) currentActivity.getApplication();
^
symbol: class ReactApplication
location: class CodePushNativeModule
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:196: error: cannot find symbol
ReactApplication reactApplication = (ReactApplication) currentActivity.getApplication();
^
symbol: class ReactApplication
location: class CodePushNativeModule
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:235: error: package ReactChoreographer does not exist
ReactChoreographer.getInstance().postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, new ChoreographerCompat.FrameCallback() {
^
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:235: error: package ChoreographerCompat does not exist
ReactChoreographer.getInstance().postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, new ChoreographerCompat.FrameCallback() {
^
C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java:235: error: cannot find symbol
ReactChoreographer.getInstance().postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, new ChoreographerCompat.FrameCallback() {
^
symbol: variable ReactChoreographer
Note: C:\Users\Test\Documents\Kerja\bmh-mobile\node_modules\react-native-code-push\android\app\src\main\java\com\microsoft\codepush\react\CodePushNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
11 errors
:react-native-code-push:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-code-push:compileReleaseJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.`

i am using

"react-native": "0.52.0",
"react-native-midtrans": "0.0.3",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.