npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trustly-client

v3.2.1

Published

Trustly client for node.js integrations.

Downloads

2,763

Readme

Trustly Client

npm versionGitHub licenseSupport link

Node.js client for trustly integrations. Rewrite completely to Typescript and updated to use lasts libraries.

Quickstart

Installation

Install the module with: npm install trustly-client or yarn add trustly-client

Usage

In versions >3.0.0 all validations are removed and you are free to pass every parameter you like. For older changelog go to the tags <3.0.0

// In Vanilla javascript
var client = require('trustly-client').default // Import it
var tClientKP = client(configuration) // Fill the configuration

tClientKP // Ready to use
    .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'
    })
    .then(function(response) {
        console.log(util.inspect(response, false, 20, true))
    })
    .catch(function(error) {
        console.log(util.inspect(error, false, 20, true))
    })

// In Typescript
import client from 'trustly-client' // Import it
let tClient = client(configuration) // Fill the configuration

tClientKP // Ready to use
    .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'
    })
    .then(function(response) {
        console.log(util.inspect(response, false, 20, true))
    })
    .catch(function(error) {
        console.log(util.inspect(error, false, 20, true))
    })

Documentation

Initialization

After import the library you must configure it with your data:

import client from 'trustly-client' // Import it
let tClient = client({
    username: '', // required
    password: '', // required
    privateKeyPath: '', // required
    publicKeyPath: '', // optional
    endpoint: '', // optional
    environment: '' // optional (But required in production, see below!)
}) // Fill the configuration

This configuration is an object and this is the structure:

  • [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 is selected depending of the environment between "" and "".
  • [optional] 'environment': By default is "development", and it does the http calls to trustly development environment (https://test.trustly.com/api/1), if you pass production it turns to https://trustly.com/api/1, so remember to change that variable when you go to production

Usage

This are the methods availables, every method accepts data and params and are the same that you have to send to trustly.

  • 'deposit' : Create a deposit request.

  • 'refund' : Create a refund request.

  • 'selectAccount' : Create a select account request.

  • 'charge' : Create a charge request.

  • 'withdraw' : Create a withdraw request.

  • 'approveWithdrawal' : Create a approve withdrawal request.

  • 'denyWithdrawal' : Create a deny withdrawal request.

  • 'accountPayout' : Create a account payout request.

  • 'request' : This creates a free request to trustly, use only for testing propouses, you have to pass this parameters (method, params, attributes), and it compose and sign the trustly structure.

  • 'createNotificationResponse' : Helper that: - Verify the signature and the data from trustly - Compose the data you need to send to trustly to answer the notifications, it will be returned as an output from this method. The output should be like:

    ```
    {
        "result": {
            "signature": "R9+hjuMqbsH0Ku ... S16VbzRsw==",
            "uuid": "258a2184-2842-b485-25ca-293525152425",
            "method": "credit",
            "data": {
                "status": "..."
            }
        },
        "version":"1.1"
    }
    ```

    In the oficial docs you have all you need to manage the data trustly official doc

All trustly methods (deposit, refund, selectAccount, charge, withdraw, approveWithdrawal, denyWithdrawal) uses the parameters described in trusty documentation. here (trustly docs). If is something missing please make a pull request or write an issue.

Method 'createNotificationResponse' accepts a Json string or a Json with the notification, and compose for you te correct response for Trustly. See tests/notification-server/test-notification-server.js, inside you have an already express server that you can deploy anywhere (dont forget to update with your configuration), and test the notifications.

Also it is exported helpers to sign, verify, interfaces, all configuration etc... So feel free to use it, if there is any doubt dont be shy, write an issue, a pull request or an email to me.

Error Management

Managing errors is the key of a client, so for that trustly client always send the lastRequest and lastResponse (If there it be), and also i parse the most important parts for you according to the documentation, the final structure, is:

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

It seems to long but sometimes you must understand the request and the response.

If clientError is filled, means that the error not comes from trustly. 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

See CHANGELOG.md

License

Licensed under the MIT license. 2017