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

barion-nodejs

v1.0.4

Published

A compact Node.js module to manage online e-money and card payments via the *Barion Smart Gateway*.

Downloads

4

Readme

#barion-nodejs

barion-nodejs is a compact Node.js module to manage online e-money and card payments via the Barion Smart Gateway. It allows you to accept credit card and e-money payments in just a few lines of code.

barion-nodejs lets you

  • Start an online immediate or reservation payment easily
  • Get details about a given payment
  • Finish an ongoing reservation payment completely or partially, with automatic refund support
  • Refund a completed payment transaction completely or partially

All with just a few simple pieces of code!

Installation

Using npm:

$ npm i -g npm
$ npm i --save barion-nodejs

In Node.js:

// Create barion object for the prod environment.
var barion = new (require('barion-nodejs'))();
// Create barion object for the test environment.
var barion = new (require('barion-nodejs'))(BarionTest);

// Import BarionError
var BarionError = barion.BarionError;

// Import the built-in requestbuilders
var BarionRequestBuilderFactory = barion.BarionRequestBuilderFactory;

Code Example

You can user the methods using simple Javascript objects and with the built-in request and object generators. We will give example for both.

Error handling

Money transfer

var moneySendOptionsWithObject = { UserName : "[email protected]", Password : "myweakpassword", Recipient : "[email protected]", Currency : "HUF", Amount : 100, Comment : "You are the best, pal!" };

barion.sendMoney(moneySendOptionsWithObject, function(err, data) { if(!err) { handleData(data); } else { handleError(err); } });

</details>

<details>
<summary>Send money using request builders</summary>
```javascript
var transferSendRequestBuilder =  new BarionRequestBuilderFactory.BarionTransferSendRequestBuilder();

var moneySendOptionsWithBuilder = transferSendRequestBuilder
    .setUsername("[email protected]")
    .setPassword("myweakpassword")
    .setRecipient("[email protected]")
    .setCurrency("HUF")
    .setAmount(100)
    .setComment("You are the best, pal!")
    .build();

barion.sendMoney(moneySendOptionsWithBuilder, function(err, data) {
    if(!err) {
        handleData(data);
    } else {
        handleError(err);
    }
});

Start payment

var paymentStartOptionsWithObject = { POSKey: "my_shops_pos_key_from_barion", PaymentType: "Immediate", GuestCheckOut: true, FundingSources: ["All"], PaymentRequestId: "request_id_generated_by_the_shop", Locale: "hu-HU", Currency: "HUF", Transactions: [ { POSTransactionId: "test_payment_id_from_shop", Payee: "[email protected]", Total: "1000", Items: [ { Name: "Test product", Description: "My favorite test product", Quantity: 1, Unit: "db", UnitPrice: 1000, ItemTotal: 1000 } ] } ] };

barion.startPayment(paymentStartOptionsWithObject, function (err, data) { if (!err) { handleData(data); } else { handleError(err); } });

</details>

<details>
<summary>Start payment using request builders</summary>
```javascript
var paymentStartRequestBuilder  = new BarionRequestBuilderFactory.BarionPaymentStartRequestBuilder();
var paymentTransactionBuilder   = new paymentStartRequestBuilder.BarionPaymentTransactionBuilder();
var itemBuilder                 = new paymentStartRequestBuilder.BarionItemBuilder();

var item = itemBuilder
    .setName('Test product')
    .setDescription('My favorite test product')
    .setQuantity(1)
    .setUnit('db')
    .setUnitPrice(1000)
    .setItemTotal(1000)
    .build();

var paymentTransaction = paymentTransactionBuilder
    .setPOSTransactionId('test_payment_id_from_shop')
    .setPayee('[email protected]')
    .setTotal(1000)
    .addItem(item)
    .build();

var paymentStartOptionsWithBuilder = paymentStartRequestBuilder
    .setPOSKey('my_shops_pos_key_from_barion')
    .setPaymentType('Immediate')
    .setGuestCheckout(true)
    .setFundingSources(["All"])
    .setPaymentRequestId('request_id_generated_by_the_shop')
    .setLocale('hu-HU')
    .setCurrency('HUF')
    .addTransaction(paymentTransaction)
    .build();

barion.startPayment(paymentStartOptionsWithBuilder, function (err, data) {
    if (!err) {
        handleData(data);
    } else {
        handleError(err);
    }
});

Get state of a payment

var getPaymentStateOptionsWithObject = { POSKey : "my_shops_pos_key_from_barion", PaymentId : "payment_id_in_the_barion_system" };

barion.getPaymentState(getPaymentStateOptionsWithObject, function(err, data) { if (!err) { handleData(data); } else { handleError(err); } });

</details>

<details>
<summary>Get state of a payment using request builders</summary>
```javascript
var getPaymentStateRequestBuilder = new BarionRequestBuilderFactory.BarionGetPaymentStateRequestBuilder();

var getPaymentStateOptionsWithBuilder = getPaymentStateRequestBuilder
    .setPOSKey('my_shops_pos_key_from_barion')
    .setPaymentId('payment_id_in_the_barion_system')
    .build();

barion.getPaymentState(getPaymentStateOptionsWithObject, function(err, data) {
    if (!err) {
        handleData(data);
    } else {
        handleError(err);
    }
});

Refund a payment

var paymentRefundOptionsWithObject = { POSKey : "my_shops_pos_key_from_barion", PaymentId : "payment_id_in_the_barion_system", TransactionsToRefund : [ { TransactionId : "barion_transaction_id", POSTransactionId : "test_payment_id_from_shop", AmountToRefund : 10 } ]
};

barion.refund(paymentRefundOptionsWithObject, function(err, data) { if (!err) { handleData(data); } else { handleError(err); } });

</details>

<details>
<summary>Refund a payment using request builders</summary>
```javascript
var paymentRefundRequestBuilder = new BarionRequestBuilderFactory.BarionPaymentRefundRequestBuilder();
var transactionToRefundBuilder = new paymentRefundRequestBuilder.BarionTransactionToRefundBuilder();

var refundTransaction = transactionToRefundBuilder
    .setTransactionId('barion_transaction_id')
    .setPOSTransactionId('test_payment_id_from_shop')
    .setAmountToRefund(10)
    .build();

var paymentRefundOptionsWithBuilder = paymentRefundRequestBuilder
    .setPOSKey('my_shops_pos_key_from_barion')
    .setPaymentId('payment_id_in_the_barion_system')
    .addTransactionToRefund(refundTransaction)
    .build();

barion.refund(paymentRefundOptionsWithBuilder, function(err, data) {
    if (!err) {
        handleData(data);
    } else {
        handleError(err);
    }
});

Request withdrawal

var withdrawBankTransferOptionsWithObject = { UserName : "[email protected]", Password : "myweakpassword", Currency : "HUF", Amount : 1000, RecipientName : "Partner Name", Comment : "Withdrawal", BankAccount : { Country : "HUN", Format : 1, AccountNumber : "bank_account_number" } };

barion.withdraw(withdrawBankTransferOptionsWithObject, function(err, data) { if (!err) { handleData(data); } else { handleError(err); } });

</details>

<details>
<summary>Request withdrawal using request builders</summary>
```javascript
var withdrawBankTransferRequestBuilder = new BarionRequestBuilderFactory.BarionWithdrawBankTransferRequestBuilder();
var bankAddressBuilder = new withdrawBankTransferRequestBuilder.BarionBankAccountBuilder();

var bankAccount = bankAddressBuilder
    .setCountry("HUN")
    .setFormat(1)
    .setAccountNumber("bank_account_number")
    .build();

var withdrawBankTransferOptionsWithBuilder = withdrawBankTransferRequestBuilder
    .setUsername("[email protected]")
    .setPassword("myweakpassword")
    .setCurrency("HUF")
    .setAmount(1000)
    .setRecipientName("Partner Name")
    .setComment("Withdrawal")
    .setBankAccount(bankAccount)
    .build();

barion.withdraw(withdrawBankTransferOptionsWithBuilder, function(err, data) {
    if (!err) {
        handleData(data);
    } else {
        handleError(err);
    }
});

API Reference

You can find the documentation here

Support

You can find support in the Barion Developers Facebook group.

License

The library is licensed under Apache 2.0 license.