Code Monkey home page Code Monkey logo

node-przelewy24's Introduction

Przelewy24 for NodeJS

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.

Documentation

Documentation can be in read here.

Installation

npm install --save @kasvith/node-przelewy24

Typescript

Importing

import { Przelewy24, PaymentOptions, ShoppingDetail, TransactionVerification } from '@kasvith/node-przelewy24';

Initialization

const p24 = new Przelewy24(MERCHANT_ID, POS_ID, 'SALT', TEST_MODE);

Testing connection

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

Get payment link

Prepare following details to initiate a payment

// prepare payment options(required)
const paymentParam: PaymentOptions = {
        p24_amount: 1250, // 12.50PLN -> 1250
        p24_country: CountryCode.Poland, // set country codes
        p24_currency: CurrencyType.PLN, // set currency
        p24_description: 'a fancy item', // set description
        p24_email: '[email protected]', // customer's email
        p24_session_id: 'kdsfksfklfklfffl', // a unique id from merchant's system
        p24_url_return: 'http://myawesomeapp.com/payment_success?order=abc', // return user to following url after a valid transaction
        p24_url_status: 'http://myawesomeapp.com/p24callback'
    };

// prepare shopping details(optional)
const shoppingDetails: ShoppingDetail[] = [
        { name: 'a book', price: 13, quantity: 4 },
        { name: 'a pen', price: 13, quantity: 1 },
        ...
    ];

const result = await p24.getPaymentLink(new Payment(paymentParam, shoppingDetails));
console.log(result) // prints a valid url to pay the payment or throws an error

Verifies a payment

Verifies a payment on p24 system. Once a sucessfull payment happen, http://myawesomeapp.com/p24callback is triggered with a POST request containing all the details for verify a transaction. When this happens the transaction becomes valid. TransactionVerification model is used to verify a transaction.

// extract all information from callback request
const {
    p24_merchant_id,
    p24_pos_id,
    p24_session_id,
    p24_amount,
    p24_currency,
    p24_order_id
} = req.body;

const verification: TransactionVerification = {
    p24_merchant_id: p24_merchant_id,
    p24_pos_id: p24_pos_id,
    p24_session_id: p24_session_id,
    p24_amount: p24_amount,
    p24_currency: p24_currency,
    p24_order_id: p24_order_id,
    p24_sign: p24_sign
}

const result = await p24.verifyTransaction(verification)
console.log(result) // true on success or throws an error

Validate IP

Library provides method to validate IP addresses with P24 backends

const valid = Przelewy24.isIpValid('127.0.0.1')
console.log(valid)

node-przelewy24's People

Contributors

kasvith avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.