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

@dimski/przelewy24

v1.0.2

Published

Library for Przelewy24

Downloads

32

Readme

P24 (Przelewy24) Node.js SDK

This Node.js SDK provides a convenient way to interact with Przelewy24 (P24) payment gateway in your Node.js applications.

Installation

Install the package using npm:

npm install @dimski/przelewy24

Usage

Initialize P24 instance

const { P24 } = require('@dimski/przelewy24');
// or
import { P24 } from "@dimski/przelewy24";

const p24 = new P24({
  prod: false,  // Set to true for production environment
  merchantId: YOUR_MERCHANT_ID,
  posId: YOUR_POS_ID,
  apiKey: YOUR_API_KEY,
  crc: YOUR_CRC_KEY,
  defaultValues: {
    currency: 'PLN',
    country: 'PL',
    language: 'pl',
  },
});

Test access to the Przelewy24 API

try {
  await p24.testAccess();
  console.log('Connection to Przelewy24 API successful.');
} catch (error) {
  console.error('Connection to Przelewy24 API failed:', error.message);
}

Get available payment methods

// Specify the configuration for getting payment methods
const paymentMethodsConfig = {
  lang: 'pl',  // Language code ('en' for English, 'pl' for Polish, etc.)
  amount: 1000, // Optional: Amount for which payment methods are requested
  currency: 'PLN', // Optional: Currency code
};

// Get available payment methods
try {
  const paymentMethods = await p24.getPaymentMethods(paymentMethodsConfig);
  console.log('Available payment methods:', paymentMethods);
} catch (error) {
  console.error('Failed to retrieve payment methods:', error.message);
}

Validate IP

const exampleIP = '91.216.191.182';
const isValidIP = p24.validateIP(exampleIP);

if (isValidIP) {
  console.log(`IP ${exampleIP} is valid.`);
} else {
  console.error(`IP ${exampleIP} is not within the valid IP range.`);
}

Register a transaction

const transactionData = await p24.registerTransaction({
  sessionId: 'unique_session_id',
  amount: 1000,
  description: 'Test transaction',
  email: '[email protected]',
  urlReturn: 'https://yourdomain.com/return',
  urlStatus: 'https://yourdomain.com/status',
  currency: 'PLN',
});

console.log('Transaction token:', transactionData.token);

Verify the transaction notification

// Example transaction notification data
const notificationData = {
  sessionId: 'unique_session_id',
  amount: 1000,
  originAmount: 1000,
  currency: 'PLN',
  orderId: 123456,
  methodId: 1,
  statement: 'Payment for Order #123456',
  sign: 'generated_sign_from_przelewy24',
};

// Verify the transaction notification
const isNotificationValid = p24.verifyTransactionNotification(notificationData);

if (isNotificationValid) {
  console.log('Transaction notification is valid.');
} else {
  console.error('Transaction notification is not valid. Possible tampering detected.');
}

Verify transaction

// Example: Verify transaction
const verifyData = {
  sessionId: 'unique_session_id',
  orderId: 123456,
  amount: 1000,
  currency: 'PLN',
};

const isTransactionVerified = await p24.verifyTransaction(verifyData);

if (isTransactionVerified) {
  console.log('Transaction verified successfully.');
} else {
  console.log('Transaction verification failed.');
}

Verify the notification and transaction using one method

// Example data for notification verification and transaction verification
const verificationData = {
  sessionId: 'unique_session_id',
  amount: 1000,
  originAmount: 1000,
  currency: 'PLN',
  orderId: 123456,
  methodId: 1,
  statement: 'Payment for Order #123456',
  sign: 'generated_sign_from_przelewy24',
  // Add additional properties required for transaction verification
  // ...
};

// Verify the notification and transaction
const isVerificationSuccessful = await p24.verifyNotificationAndTransaction(verificationData);

if (isVerificationSuccessful) {
  console.log('Notification and transaction verification successful.');
} else {
  console.error('Verification failed. Possible tampering or unsuccessful transaction.');
}

Refund

// Example data for initiating a refund
const refundData = {
  requestId: 'unique_request_id',
  refundsUuid: 'unique_refund_uuid',
  urlStatus: 'https://your-callback-url.com/refund-status',
  refunds: [
    {
      orderId: 123456,          // Order ID for the transaction to be refunded
      sessionId: 'unique_session_id',
      amount: 500,               // Amount to be refunded in grosz (e.g., 500 grosz = 5 PLN)
      description: 'Refund for Order #123456',
      // Add additional properties required for each refund
      // ...
    },
    // Add more refund objects if needed
    // ...
  ],
};

// Initiate the refund
try {
  const refundResponse = await p24.refund(refundData);
  console.log('Refund initiated successfully:', refundResponse);
} catch (error) {
  console.error('Refund failed:', error.message);
}

Verify the refund notification

// Example data for verifying a refund notification
const refundNotificationData = {
  orderId: 123456,               // Order ID for the refunded transaction
  sessionId: 'unique_session_id',
  requestId: 'unique_request_id',
  refundsUuid: 'unique_refund_uuid',
  amount: 500,                   // Amount refunded in grosz (e.g., 500 grosz = 5 PLN)
  currency: 'PLN',
  timestamp: 1634750000,         // Timestamp of the refund notification
  status: 1,                     // Status of the refund (1: Success, 2: Rejected)
  sign: 'valid_signature',       // Signature received with the refund notification
};

// Verify the refund notification
const isVerified = p24.verifyRefundNotification(refundNotificationData);

if (isVerified) {
  console.log('Refund notification is valid.');
} else {
  console.error('Refund notification verification failed.');
}

Documentation

For detailed documentation on the available methods and configurations, refer to the official Przelewy24 API documentation.

License

This SDK is open-source and released under the MIT License.