npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

payu-blik-pl

1.0.18 • Public • Published

A simple and lightweight PayU BLIK payment facility

Installation

npm install payu-blik-pl

Usage

To use, simply require module, create connector and call payWithBLIK() method

Create a connector

var PayUBlikModule = require('payu-blik-pl');
// these is the minimal set of configuration options, you MUST provide your clientId and secret that was given to you when you registered to PayU
var initOptions = {
    clientId: 111111,
  clientSecret: '7261414absecrete1d3080a8c0751928',
  clientSecondKey: 'zzz305d1e4a1507931d0eae070fbbxxx', 
  apiNotificationURL: "https://your.eshop.com/notify"
};
var payConnector = PayUBlikModule.createPayUConnector(initOptions);
// from now on you can request BLIK payments
 

Invoke BLIK payments

// prepare order data, i.e. what is being paid for and how much
var orderData = {
    "currencyCode": "PLN",
    "totalAmount": "31000",
    "description": "Transakcja testowa",
    "notifyUrl": "https://your.eshop.com/notify",
    "customerIp": "127.0.0.1",
    "products": [
        {
            "name": "Wireless Mouse for Laptop",
            "unitPrice": "21000",
            "quantity": "1"
        }
    ]
}
//...
// make a BLIK payment
 
// this is the BLIK code that is entered by the customer
var BLIKCode = 712898;
 
var customerEmail = 'test@test.pl';
var customerExternalId = 'myCRMId1'
payConnector.payWithBLIK( BLIKCode, customerEmail, customerExternalId, orderData).then(response=>{
  // here one can check on the response if the payment was a success 
    console.log('There was a valid response', response);
}).catch(error=>{
  // this is called when any business related error has happened (such as unauthorized payment attempt)
    console.log('Failed to hanle payment', error);
});

Response structure

// sample success response
{ 
  status: { 
    message: 'Created', 
    code: 201 
  },
  body:{ 
    orderId: 'XJVLWS4WSS190531GUEST000P01',
    status: { statusCode: 'SUCCESS' } 
  } 
}

Notification signature validation

// get signature header
var signatureHeader = req.header('OpenPayu-Signature');
// get message body
var messageBody = req.body;
// validate if the notification is original and valid
var isValid = payConnector.validateNotificationSignature(signatureHeader, messageBody);

Changelog

  • v1.0.18 - added token expiration handling
  • v1.0.16 - functional fixes
  • v1.0.10 - added method for notification signature validation
  • v1.0.9 - added transaction id
  • v1.0.7 - added buyer email
  • v1.0.6 - readme fixes
  • v1.0.5 - single item blik payment added
  • v1.0.3 - readme fixes
  • v1.0.2 - readme fixes
  • v1.0.1 - initial fixes
  • v1.0.0 - initial version

Keywords

install

npm i payu-blik-pl

Downloadsweekly downloads

30

version

1.0.18

license

LGPL

last publish

collaborators

  • avatar
Report a vulnerability