Giter Site home page Giter Site logo

mobilpay-node's Introduction

mobilpay-node

dependencies Status devDependencies Status

About

this is a lightweight NodeJs library to integrate MobilPay payment gateway in your projects. Bare in mind that it's still under development and does't support all the payment options. So, feel free to contribute ;)

Usage

var mobilpay = require('mobilpay-node');
var constants = mobilpay.constants;

Bare in mind that you need to extract the public key from the public certificate provided by Mobilpay

openssl x509 -pubkey -noout -in PUBLIC_CERTIFICATE_FILE.cer > PUBLIC_KEY.pem

Create Mobilpay instance

// create Mobilpay instance
var MobilPay = new mobilpay.Mobilpay({
  signature: '',
  sandbox: true,
  publicKeyFile: '',
  privateKeyFile: '',
});

Create a new payment request

var paymentRequest = MobilPay.createRequest({
  amount: parseFloat(Math.round(Math.random() * 10000)/100).toFixed(2),
  customerId: '12345',
  billingAddress: {
    type: constants.ADDRESS_TYPE_PERSON,
    firstName: 'Damian',
    lastName: 'Gardner',
    email: '[email protected]',
    address: '4793 College Street, Cluj-Napoca, Cluj',
    mobilePhone: '0722222222'
  },
  shippingAddress: {
    type: constants.ADDRESS_TYPE_PERSON,
    firstName: 'Damian',
    lastName: 'Gardner',
    email: '[email protected]',
    address: '4793 College Street, Cluj-Napoca, Cluj',
    mobilePhone: '0722222222'
  },
  confirmUrl: 'http://mysite.local/confirm',
  returnUrl: 'http://mysite.local/return',
  params: {
    test1: 'test param 1',
    test2: 'test param 2',
  }
});

Prepare redirect data

MobilPay.prepareRedirectData(paymentRequest)
  .then(function(result) {

    console.log(
      'Redirect URL: ' + result.url,
      'env_key: ' + result.envKey,
      'data: ' + result.data
    );

  })
  .catch(function(err) {
    console.log(err);
  });

With the prepared data render a form and display it to the client

<form name="frmPaymentRedirect" method="post" action="{{ redirectUrl }}">
    <input type="hidden" name="env_key" value="{{ envKey }}"/>
    <input type="hidden" name="data" value="{{ data }}"/>
    <p>
        You will be redirected to a secure page on mobilpay.ro
    </p>
    <p>
        Click to continue <input type="submit" value="Submit">
    </p>
</form>

Mobilpay will POST notifications to your confirm URL which can be something like this http://mysite.local/confirm. to handle these notifications you'll need to add this pice of code your route handler

mobilPay.handleGatewayResponse({
  envKey: 'content from env_key POST body',
  data: 'content from data POST body'
  })
  .then(function(data) {
    // check the response and send back an acknowledge message
    var response = new mobilpay.MerchantResponse({
      message: data.response.crc
    });

    // send response.toXml() as response
  })
  .catch(function(err) {
    // handle error case
  });

mobilpay-node's People

Contributors

robi-richter avatar

Watchers

 avatar  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.