Node.js SDK

Check out our Node.js SDK.

License Version Download

Installation

Install the package using npm or yarn

npm install @heidelpay/nodejs-sdk
yarn add @heidelpay/nodejs-sdk

Usage

Private key
The package needs to be configured with your private key. Make sure you have it first
var Heidelpay = require('@heidelpay/nodejs-sdk').default;

// Create new instance Heidelpay
var heidelpay = new Heidelpay('s-priv-xxxxxxxxxx');
import Heidelpay from '@heidelpay/nodejs-sdk';

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

Example

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-xxxxxxxxxx");

// New a card with pan number and exipry date
var card = new Card("4711100000000000", "01/2020");

// Set CVC
card.setCVC("123");

// Create customer object
var customer = new Customer("Test", "User");

heidelpay
  .createCustomer(customer)
  .then(function(newCustomer) {
    // Create payment type then authorize (Card)
    return heidelpay.createPaymentType(card);
  })
  .then(function(paymentType) {
    // Authorize with payment card
    console.log("PaymentType:", paymentType.getId());
    return paymentType.authorize({
      amount: 1.00,
      currency: "EUR",
      typeId: paymentType.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);
  });
var Heidelpay = require("@heidelpay/nodejs-sdk").default;
var Card = require("@heidelpay/nodejs-sdk").Card;
var Customer = require("@heidelpay/nodejs-sdk").Customer;

const authorizePayment = async (heidelpay, customer, card) => {
  try {
    // Create a new customer
    const newCustomer = await heidelpay.createCustomer(customer);
    console.log("customer Id:", newCustomer.getCustomerId());

    // Create payment type then authorize (Card)
    const paymentType = await heidelpay.createPaymentType(card);
    console.log("paymentType Id:", paymentType.getId());

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

// Create new instance Heidelpay
const heidelpay = new Heidelpay("s-priv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n");

// New a card with pan number and exipry date
const card = new Card("4711100000000000", "01/2022");

// Set CVC
card.setCVC("123");

// Create customer object
const customer = new Customer("Test", "User");

authorizePayment(heidelpay, customer, card);