Heidelpay SDK NodeJS

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;
var heidelpay = new Heidelpay('s-priv-...');
Or using ES module
import Heidelpay from '@heidelpay/nodejs-sdk';
const heidelpay = new Heidelpay('s-priv-...');
Or using TypeScript:
import Heidelpay from '@heidelpay/nodejs-sdk';
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;
var heidelpay = new Heidelpay('s-priv-...');
var card = new Card('471110xxxxxx0000', '01/xxxx');
card.setCVC('xxx');
var customer = new Customer('Rene', 'Fred');
heidelpay.createCustomer(customer).then(function(newCustomer) {
return heidelpay.createPaymentType(card);
}).then(function(paymentCard) {
return paymentCard.authorize({
amount: 100,
currency: 'EUR',
typeId: paymentCard.getId(),
returnUrl: 'https://www.google.at'
})
}).then(function(authorize) {
console.log('authorize', authorize.getId());
}).catch(function (error) {
console.log('error', error);
});
Using async / await (ES6 style)
import Heidelpay, {Card} from '@heidelpay/nodejs-sdk';
const heidelpay = new Heidelpay('s-priv-...');
const card = new Card('471110xxxxxx0000', '01/xxxx');
card.setCVC('xxx');
const customer = new Customer('Rene', 'Fred');
try {
const newCustomer = await heidelpay.createCustomer(customer);
const paymentCard = await heidelpay.createPaymentType(card);
const authorize = await paymentCard.authorize({
amount: 100,
currency: 'EUR',
typeId: paymentCard.getId(),
returnUrl: 'https://www.google.at'
});
} catch (error) {
console.log('error', error);
}
License
Apache 2.0