npm package: @heidelpay/nodejs-sdk
Description: Heidelpay SDK NodeJS
Author: Heidelpay
Latest version: 1.3.1
Deprecated: This package is no longer supported. Please switch to @unzer/nodejs-sdk.

# Heidelpay SDK NodeJS

![License](https://img.shields.io/npm/l/@heidelpay/nodejs-sdk.svg)
[![Version](https://img.shields.io/npm/v/@heidelpay/nodejs-sdk.svg)](https://www.npmjs.com/package/@heidelpay/nodejs-sdk)
[![Download](https://img.shields.io/npm/dw/@heidelpay/nodejs-sdk.svg)](https://www.npmjs.com/package/@heidelpay/nodejs-sdk)

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

# **Documentation**

See the [Node API docs](https://docs.heidelpay.com/v1.0/docs/nodejs-sdk).

# **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
``` js
var Heidelpay = require('@heidelpay/nodejs-sdk').default;

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

Or using ES module

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

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

Or using TypeScript:

``` ts
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)
```js
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