npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mobilpay-node

v0.2.0

Published

MobilPay Gateway library

Downloads

797

Readme

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: '',
  serviceType: 1, // default value 
});

serviceType can take one of the following values:

  • 1 (Standard payment)
  • 3 (Payment with prefilled card data)

serviceType with value 2 is not yet implemented (Payment with CVV only)

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',
  }
});

If the serviceType is 3, the paymentRequest from above should contain:

  tokenId: 'token id from mobilpay',
  panMasked: 'pan masked from mobilpay'

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
  });

Retrieve session id

In order to cancel a payment, you need a sessionId. MobilPay.getSessionId() method will return a promise that is resolved with an object that contains property sessionId:

MobilPay.getSessionId({
  username: 'mobilpay.username',
  password: 'mobilpay.password'
  })
  .then(response => {
    console.log(response); // { sessionId: 'unique user session identifier'}
    const { sessionId } = response;
  })
  .catch(err => {
    // handle error case
    console.log(err)
  })

Cancel a payment

MobilPay.creditInvoice({
  sessionId: sessionId,
  orderId: '', // payment request id you want to credit
  amount: 10 // must be equal or less than the initial amount
})
  .then(response => console.log(response))
  .catch(err => console.log(err))