Giter VIP home page Giter VIP logo

trustly-client's Introduction

Trustly Client

Dependency Status

Node.js client for trusty integrations. Right now it doesn´t includes the withdrawal, feel free to submit a pull request. You can use callback style or promises.

##Getting started

Install the module with: npm install trustly-client

    var client = require('trustly-client');
    var tClientKP = client(configuration);
    //Promise style
    tClientKP.init()
    .then(function () {
        return tClientKP.deposit({
            NotificationURL: 'http://127.0.0.1:4343/notification',
            EndUserID: '[email protected]',
            MessageID: '111112111221',
            Locale: 'es_ES',
            Amount: '1.00',
            Currency: 'EUR',
            SuccessURL: 'http://127.0.0.1:4343/success',
            FailURL: 'http://127.0.0.1:4343/fail',
            HoldNotifications: 1
        });
    })
    .then(function (response) {
        console.log(util.inspect(response, false, 20, true));
    })
    .fail(function (error) {
        console.log(util.inspect(error, false, 20, true));
    });
    //Callback style
    tClientKP.init(function(){
        tClientKP.deposit({
            NotificationURL: 'http://127.0.0.1:4343/notification',
            EndUserID: '[email protected]',
            MessageID: '111112111221',
            Locale: 'es_ES',
            Amount: '1.00',
            Currency: 'EUR',
            SuccessURL: 'http://127.0.0.1:4343/success',
            FailURL: 'http://127.0.0.1:4343/fail',
            HoldNotifications: 1
        },function(err, response){
            if (err){
                console.log(util.inspect(err, false, 20, true));
            }
            console.log(util.inspect(response, false, 20, true));
        });
    })

You should init, and it is a asyncronous process. This init loads your private and the trustly public keys, neccesary for all the request and responses, creation and verification.

Documentation

Basically to initialize, you should pass, the config object composed by:

  • [required] 'privateKeyPath': Path to you private key
  • [required] 'username': Your trustly api username
  • [required] 'password': Your trustly api password
  • [optional] 'publicKeyPath': Path to a public key (for the general cases you don't need it, i package the trusty public key)
  • [optional] 'endpoint': By default it is autoselected depending of the environment, you can always send the endpoint you want.
  • [optional] 'environment': By default i fill with development

The module have this 3 basic methods:

  • 'deposit' : Create a deposit request.
  • 'refund' : Create a refund request.
  • 'createNotificationResponse' : Helper that verifies the data from truistly using the keys, and returns the data you need to response to every notification, returns an object.

The 2 basic methods are: deposit, refund. They uses the parameters described in trusty documentation. here (trustly docs)

Then you have a method to handle the notifications: 'createNotificationResponse'. Accepts a Json string or a Json with the notification, and returns you the correct data, then you simply need to send as a reponse in you notification listener. (see test/test-notification-server.js you have an example about it)

Also there are other functions to sign, verify the data, compose the request. Feel free to explore the code.

Errors

It will return always the same structure if an error happens:

    var error = {
        lastRequest: self._lastRequest,
        lastResponse: self._lastResponse,
        trustlyError: null,
        clientError: null
    };

Always you will have last request and response. If clientError is filled, mean all errors except trustly errors. If trustlyError is filled, it will catch all information about the trustly error in this format (Example):

    trustlyError = { 
        method: 'Deposit',
        uuid: 'dba2d98c-6c4e-4b9e-aa46-90027793aa14',
        message: 'ERROR_DUPLICATE_MESSAGE_ID',
        code: 637 
    };

Note: method and uuid can be null if the request contains a malformed JSON More information about the errors here (trustly docs)

Release History

####(1.1.3 Lastest)

  • Working for Deposit, Refund and management of notifications.
  • Better management of the errors.
  • Correct and fix refund.

####(1.1.1)

  • Fix problems with notifications some example updates.

####(1.1.0)

  • Correct notifications handling, remove "handleNotification" is replaced by "createNotificationResponse", more correct, and added an express server as example.

####(1.0.1 - 1.0.4)

  • Updates in packages.
  • Update the load method.
  • Added callback example.
  • Fix paths, problems with the keys.

####(1.0.0)

  • Firsts steps. Basic usage finishes: Deposit, refund and handleNotification functions.
  • Sign, verify and compose requests, and responses done.

License

Licensed under the MIT license. 2015

trustly-client's People

Contributors

danibram avatar

Watchers

 avatar  avatar

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.