Code Monkey home page Code Monkey logo

heidelpaynodejs's Introduction

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)

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

heidelpaynodejs's People

Contributors

kevinvn1709 avatar tuannat avatar vojis avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heidelpaynodejs's Issues

Absence of releases

There have currently been 42 commits to devel, including bugfixes and functionality additions, since the last official release of this package 14 months ago.

When can the next release be expected that officially makes these changes available?

Type definition of constructor not sufficient

We stumbled upon an error with an API change of you (I guess).

For the creation of a payment type we used the same Heidelpay SDK instance as for authorizing the payment, for example.
This, however, does not work anymore. We recognized that the instance for creating a payment type needs the public key, while authorizing utilizes the private key. The documentation of this is not sufficient and it is only recognizable in your code examples (https://docs.unzer.com/reference#testinput & https://docs.unzer.com/reference#paymentsauthorize).

The type definition of the SDK-Constructor is also not sufficient, as it only describes the private key as input parameter.

export default class Heidelpay {
    constructor(privateKey: string, locale?: string, env?: string);
 [...]

Npm package out of date

I see that this github repo has the latest changes needed to implement 3dsecure and further commits that are not in sync with the project:

https://www.npmjs.com/package/@heidelpay/nodejs-sdk

The last release of this npm is about 29 days ago, and this repo has changes that we need to implement some payments.

Is there any plan to make a release in npm?

Warm regards and thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.