The Heidelpay SDK NodeJS provides convenient access to the Heidelpay API from applications written in server-side JavaScript.
See the Node API docs.
Install the package with:
npm install --save @heidelpay/nodejs-sdk
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-...');
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);
});
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);
}
Apache 2.0