GithubHelp home page GithubHelp logo

jop_pay's Introduction

cordova-plugin-upi

Cordova plugin to pay via UPI supported apps via intent based

Supported Platform:

  • Android

Installations:

cordova plugin add https://github.com/richie777cfc/jop_pay

After installation, the upi plugin would be avilable in "window" object.

Methods:

  • Fetch UPI supported apps.
pspAppsResponseList = function(apps) {
    console.log("UPI supported apps" + JSON.stringify(apps));
}
failureCallback = function(err) {
    console.log("Issue in fetching UPI supported apps " + err);
}

function getPspAppsList() {
    window["UPI"].supportedApps(pspAppsResponseList, failureCallback);
}
  • Start a transaction you can start a transaction either by passing upistring or parsed value as given below.
appid = "com.google.android.apps.nbu.paisa.user"

upistring = "upi://pay?mc=4121&pa=jptest.npysvjimjztqaq@yestransact&pn=BUS1007&tr=unPQB2ZFnzvrT2mvfGHH&am=1";

paymentstring = appid + "|" + upistring;

function launchPspAppForUpiPayment(upivalue) {
    var appConfig = upivalue.split("|")[0]
    var upiconfig = upivalue.split("|")[1]
    window["UPI"].acceptPayment(upiconfig, appConfig, launchPspAppForUpiPaymentSuccess, launchPspAppForUpiPaymentFailure);
}

launchPspAppForUpiPaymentSuccess = function(apps) {
    console.log("Payment success");
}
launchPspAppForUpiPaymentFailure = function(err) {
    console.log("Payment failed");
}

launchPspAppForUpiPayment(paymentstring);

Responses:

Sample response of successful payment

{
  "ApprovalRefNo": "932413452",
  "Status": "SUCCESS",
  "message": "txnId=764900774.690841&responseCode=00&Status=SUCCESS&txnRef=417855597.31908274&ApprovalRefNo=932413452",
  "responseCode": "00",
  "status": "SUCCESS",
  "txnId": "764900774.690841",
  "txnRef": "417855597.31908274",
  "appId": "com.phonepe.app.preprod",
  "appName": "PhonePe Preprod",
}

Sample response of failure payment

{
  "Status": "FAILURE",
  "message": "txnId=901818401.3087038&responseCode=ZD&Status=FAILURE&txnRef=654595701.7025663",
  "responseCode": "ZD",
  "status": "FAILURE",
  "txnId": "901818401.3087038",
  "txnRef": "654595701.7025663",
  "appId": "com.phonepe.app.preprod",
  "appName": "PhonePe Preprod",
}

InAppBrowser integration:

  • Integration with InAppBrowser
// Code for opening the InAppBrowser. Use below options. URL to be replaced with relevant URL.
var options = "closebuttoncolor=#000000,lefttoright=yes,hideurlbar=yes,fullscreen=yes,hardwareback=no,toolbarcolor=#145a7b,zoom=no,useWideViewPort=no,hidenavigationbuttons=yes,footer=no,message=Hello,toolbar=no,location=no";
let browser = cordova.InAppBrowser.open('https://www.google.com/','_blank', options)
browser.addEventListener('message', messCalls); //Event listener for messages.

function messCalls(params) {
  if (params.data.eventtype && params.data.eventtype == "webjs") {
    eval(params.data.type + "()");
    //if there are params then pass the same to function.
  }
}


//Sample code for PSP app list
pspAppsResponseList = function(apps) {
    // Below code is to send the response back to the InAppBrowser URL.
    browser.executeScript({
          code: "pspAppsResponseList("+JSON.stringify(apps)+")"});
}

failureCallback = function(err) {
    alert("Issue in fetching UPI supported apps " + err);
}

function getPspAppsList() {
    window["UPI"].supportedApps(pspAppsResponseList, failureCallback);
}
  • Sending message from InAppBrowser
// Sample request format which will need to be written in inappbrowser url.
// eventtype will be webjs which client end needs to read for function execution
function getPspAppsList() {
  var messageObj = {eventtype: "webjs", type: "getPspAppsList", params: ""};
  var stringifiedMessageObj = JSON.stringify(messageObj);
  window.webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);
}

//Response to be sent to client in below method.
function pspAppsResponseList(pspApps) {
  console.log(pspApps)
}

Release Notes:

1.0.0:

Initial Release of cordova plugin for upi transaction

jop_pay's People

Contributors

richie777cfc avatar

Watchers

 avatar

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.