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

acceloro-discord

v0.1.0

Published

A library for handling Polish online payments.

Downloads

2

Readme

node-polish-payments

A library for handling Polish online payments.

Contact

If you have questions or want to get in touch, you can use the details below:

Installation

Install the library using npm:

npm install node-polish-payments
npm install axios

Examples of use (Paybylink)

Payment (Transfer/Blik)

Initialization

const {
  PaybylinkTransfer,
  PaybylinkGenerateTransferSignature,
} = require('node-polish-payments');

const paybylinkSignature = new PaybylinkGenerateTransferSignature(
  'secretKey',
  shopId
);
const paybylinkTransfer = new PaybylinkTransfer('secretKey', shopId);

Configuration of transfer options

paybylinkTransfer.options.price = 5; // (REQUIRED)
paybylinkTransfer.options.control = ''; // (OPTIONAL)
paybylinkTransfer.options.description = ''; // (OPTIONAL)
paybylinkTransfer.options.email = ''; // (OPTIONAL)
paybylinkTransfer.options.notifyURL = ''; // (OPTIONAL)
paybylinkTransfer.options.returnUrlSuccess = ''; // (OPTIONAL)
paybylinkTransfer.options.returnUrlSuccessTidPass = true; // (OPTIONAL)
paybylinkTransfer.options.hideReceiver = true; // (OPTIONAL)
paybylinkTransfer.options.customFinishNote = 'Your custom note'; // (OPTIONAL)

Create a transfer

const createTransfer = await paybylinkTransfer.createTransfer();

if (createTransfer.data && createTransfer.data.url) {
  // After creating the payment correctly in JSON, we get { url: '', transactionId: '' }
  const transactionUrl = createTransfer.data.url;
  const transactionId = createTransfer.data.transactionId;
  console.log(
    `TRANSACTION CREATED\nID: ${transactionId}\nURL: ${transactionUrl}`
  );
} else {
  // If you receive an error, it will be in the format: { errorCode: 404, error: "Here some error" }
  // 400 Error decoding data into JSON format
  // 401 Wymanage fields not specified
  // 402 Field size invalid
  // 403 Invalid query signature
  // 404 Store id not found
  // 500 Internal error during transaction generation
  // 200 All ok transaction has been generated.
  console.log('ERROR: ', createTransfer);
}

Example of validation of sent notification (EXPRESS.JS)

const bodyParser = require('body-parser');
const express = require('express');
const app = express();

app.use(bodyParser.json());

app.post('/', (req, res) => {
  const signature = paybylinkSignature.generate(req.body);
  if (signature === req.body.signature) {
    res.set('Content-Type', 'text/plan');
    return res.send('OK');
  }
});

Payment (Paysafecard)

Initialization

const { PaybylinkPaysafecard } = require('node-polish-payments');
const paybylinkPaysafecard = new PaybylinkPaysafecard(userId, shopId, 'pin');

Configuration of Paysafecard options

paybylinkPaysafecard.options.amount = 10; // (REQUIRED)
paybylinkPaysafecard.options.return_ok =
  'http://yourwebsite.com/payment_success'; // (REQUIRED)
paybylinkPaysafecard.options.return_fail =
  'http://yourwebsite.com/payment_failure'; // (REQUIRED)
paybylinkPaysafecard.options.url = 'http://yourwebsite.com/payment_receive.php'; // (REQUIRED)
paybylinkPaysafecard.options.control = '123456'; // (REQUIRED)
paybylinkPaysafecard.options.description = ''; // (OPTIONAL)
paybylinkPaysafecard.options.get_pid = true; // (OPTIONAL)

Generate a Paysafecard payment

const payment = await paybylinkPaysafecard.generatePayment();
console.log(payment);

if (createTransfer.data && createTransfer.data.url) {
  // After creating the payment correctly in JSON, we get { url: '', transactionId: '' }
  const transactionUrl = createTransfer.data.url;
  const transactionId = createTransfer.data.transactionId;
  console.log(
    `TRANSACTION CREATED\nID: ${transactionId}\nURL: ${transactionUrl}`
  );
} else {
  // If you receive an error it will be in the format: { errorCode: code, error: "Here some error" }
  // 400 Error decoding data into JSON format
  // 401 Wymanage fields not specified
  // 402 Field size invalid
  // 403 Invalid query signature
  // 404 Store id not found
  // 500 Internal error during transaction generation
  // 200 All ok transaction has been generated.
  console.log(payment);
}

Example of validation of sent notification (EXPRESS.JS)

const axios = require('axios');

app.post('/', async (req, res) => {
  const allowedIpsUrl = 'https://paybylink.pl/psc/ips/';
  const clientIp = req.headers['cf-connecting-ip'] || req.ip;

  const userId = process.env.USER_ID;
  const shopId = process.env.SHOP_ID;

  try {
    if (req.body.userid !== userId || req.body.shopid !== shopId) {
      res.status(400).send('Invalid userId or shopId values.');
      return;
    }

    const response = await axios.get(allowedIpsUrl);
    const allowedIps = response.data.split(',').map(ip => ip.trim());

    if (allowedIps.includes(clientIp)) {
      if (req.body === 'TRUE') {
        res.send(req.body);
      } else {
        res.status(403).send('Transaction unsuccessful.');
      }
    } else {
      res.status(403).send('Invalid IP address.');
    }
  } catch (error) {
    console.error('Error:', error.message);
    res.status(500).send('An error occurred.');
  }
});

Payment (SMS PREMIUM)

Initialization

const { PaybylinkSms } = require('node-polish-payments');
const paybylinkSms = new PaybylinkSms(userId, serviceId);

Configuration of SMS options

paybylinkSms.code = 'your_sms_code'; // (REQUIRED)
paybylinkSms.number = 123456789; // (REQUIRED)

Check the SMS code

const checkCodeResult = await paybylinkSms.checkCode();
console.log(checkCodeResult);

Examples of use (COOMING SOON...)