radiegtya / react-native-midtrans

Midtrans Mobile SDK for React Native
66 stars 30 forks source link
android javascript midtrans mobile payment payment-gateway react react-native sdk

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

Installation

npm install --save git+https://github.com/radiegtya/react-native-midtrans.git

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

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

var creditCardOptions = {
    saveCard:false,
    saveToken:false,
    paymentMode:"Normal",
    secure:false
    };
var userDetail = {
  fullName:"Ahmad", email:"ah@mad.com", 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

var optionColorTheme = {
  primary:'#c51f1f',
  primaryDark:'#1a4794',
  secondary:'#1fce38'
}
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.

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.