Giter Club home page Giter Club logo

node-przelewy24's Introduction

Przelewy24 for NodeJS

Build

NodeJS Library for Przelewy24. This library is written in Typescript to provide best typesafety.

This library provides an elegant way to create/verify transactions easily.

Note: Now this library uses the new REST API availiable in here.

Previous legacy API support is still availiable in v1.1.1 Future versions will support new REST API only, If you use legacy API please use that version

Documentation

Documentation can be in read here.

Installation

npm install --save @ingameltd/node-przelewy24

Typescript

Importing

import {
  P24,
  Order,
  Currency,
  Country,
  Language,
  NotificationRequest,
  Verification
} from "@ingameltd/node-przelewy24";

Initialization

  • merchantId : ID given by P24
  • posId : Given by P24(often this referes to Merchant ID)
  • apiKey : API Key from p24 panel(Klucz do raportów)
  • crcKey : CRC value obtained from p24 panel
const p24 = new P24(
  merchantId, 
  posId,
  apiKey,
  crcKey, 
  { 
    sandbox: false // enable or disable sandbox
  }
);

Testing access to P24

const result = await p24.testAccess();
console.log(result); // true on success or an error being throw P24Error

Get payment link

Prepare following details to initiate a payment

const order: Order = {
  sessionId: "c837e1a3-c5a3-4e89-adf1-05faffd8913b",
  amount: 1000, // Transaction amount expressed in lowest currency unit, e.g. 1.23 PLN = 123
  currency: Currency.PLN,
  description: "test order",
  email: "[email protected]",
  country: Country.Poland,
  language: Language.PL,
  urlReturn: "http://myawesomeapp.com/continue",
  urlStatus: "http://myawesomeapp.com/p24callback", // callback to get notification
  timeLimit: 15, // 15min
  encoding: Encoding.UTF8,
}
const result = await p24.createTransaction(order)
console.log(result) // prints a valid url to pay the payment or throws an error

Verify Notification

P24 system will send you a notification to the urlStatus provided in transaction order. You need to verify this Notification request before actually Verify Transaction

const verify: NotificationRequest = req.body
const res = p24.verifyNotification(verify)
console.log(res) // true when the Notification is valid

Verifies a transaction with P24

To accept the payment to your merchant account, after validating the Notification request, you need to verify the transaction with P24 system. If you don't do that the funds will not be transferred into your account.

// extract all information from callback request
const verifyRequest: Verification = {
    amount: 1000,
    currency: Currency.PLN,
    orderId: 3030,
    sessionId: 'c837e1a3-c5a3-4e89-adf1-05faffd8913b'
}

const res = await p24.verifyTransaction(verifyRequest)
console.log(res) // true on success otherwise P24Error

Refund a requst

To refund the customer you need to open up a refund request

const ref = {
  refundsUuid: '94c1fb0b-f40f-4201-b2a0-f4166839d06c',
  requestId: 'afa379ac-c3ca-43d0-892f-e7a3f13ee4cc',
  refunds: [
    {
        amount: 1000,
        description: 'test',
        orderId: 3030,
        sessionId: 'c837e1a3-c5a3-4e89-adf1-05faffd8913b'
    }
  ],
}

const result = await p24.refund(ref)
console.log(result) // returns a SuccessResponse<RefundResult[]> where you can find about each refund request in array

Validate IP

Library provides method to validate IP addresses with P24 backends

const valid = Przelewy24.isIpValid("127.0.0.1");
console.log(valid); // output false if IP is not from p24

node-przelewy24's People

Contributors

dependabot[bot] avatar kasvith avatar kuba-orlik avatar niezgoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-przelewy24's Issues

Incorrect CRC value

Hello,

I was running the library successfully until I implemented the code as a GCP/Firebase function. On GCP, my transactions are not getting registered and I am getting 400 response code (Incorrect CRC value). A have verified correctness of my CRC dependent data: sessionId, merchantId, amount, currency, crc.

Any thoughts on what I am doing wrong?

Regards,
Adam

Incorrect CRC value

Hi, I face a problem with incorrect CRC value despite I checked few times and crc is correct. The problem occurs when i try to pass transaction amount via request.query to order object. When I put description the same way and the amount is just written in order object everything works just fine.

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.