1.3.1 • Published 4 years ago

@heidelpay/nodejs-sdk v1.3.1

Weekly downloads
304
License
Apache-2.0
Repository
-
Last release
4 years ago

Heidelpay SDK NodeJS

License Version Download

The Heidelpay SDK NodeJS provides convenient access to the Heidelpay API from applications written in server-side JavaScript.

Documentation

See the Node API docs.

Installation

Install the package with:

npm install --save @heidelpay/nodejs-sdk

Usages

The package needs to be configured with your private key. Make sure you have it first

Using Common JS

var Heidelpay = require('@heidelpay/nodejs-sdk').default;

// Create new instance Heidelpay
var heidelpay = new Heidelpay('s-priv-...');

Or using ES module

import Heidelpay from '@heidelpay/nodejs-sdk';

// Create new instance Heidelpay
const heidelpay = new Heidelpay('s-priv-...');

Or using TypeScript:

import Heidelpay from '@heidelpay/nodejs-sdk';

// Create new instance Heidelpay
const heidelpay = new Heidelpay('s-priv-...');

Example

Using Promise

Authorize with a payment type (Card)

var Heidelpay = require('@heidelpay/nodejs-sdk').default;
var Card = require('@heidelpay/nodejs-sdk').Card;
var Customer = require('@heidelpay/nodejs-sdk').Customer;

// Create new instance Heidelpay var heidelpay = new Heidelpay('s-priv-...');

// New a card with pan number and exipry date var card = new Card('471110xxxxxx0000', '01/xxxx');

// Set CVC card.setCVC('xxx');

// Create customer object var customer = new Customer('Rene', 'Fred');

heidelpay.createCustomer(customer).then(function(newCustomer) { // Create payment type then authorize (Card) return heidelpay.createPaymentType(card); }).then(function(paymentCard) {
// Authorize with payment card return paymentCard.authorize({ amount: 100, currency: 'EUR', typeId: paymentCard.getId(), returnUrl: 'https://www.google.at' }) }).then(function(authorize) { // Authorize successful console.log('authorize', authorize.getId()); }).catch(function (error) { // Handle error console.log('error', error); });

## Using async / await (ES6 style)
```js
import Heidelpay, {Card} from '@heidelpay/nodejs-sdk';

// Create new instance Heidelpay
const heidelpay = new Heidelpay('s-priv-...');

// New a card with pan number and exipry date
const card = new Card('471110xxxxxx0000', '01/xxxx');

// Set CVC
card.setCVC('xxx');

// Create customer object
const customer = new Customer('Rene', 'Fred');

// Should wrap these code into async function (async/await syntax)
try {
  // Create a new customer
  const newCustomer = await heidelpay.createCustomer(customer);

  // Create payment type then authorize (Card)
  const paymentCard = await heidelpay.createPaymentType(card);

  // Authorize with payment card
  const authorize = await paymentCard.authorize({
    amount: 100,
    currency: 'EUR',
    typeId: paymentCard.getId(),
    returnUrl: 'https://www.google.at'
  });
} catch (error) {
  // Handle error
  console.log('error', error);
}

License

Apache 2.0

1.3.1

4 years ago

1.3.0

4 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

0.0.6

5 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago