{"id":20937133,"url":"https://github.com/danibram/trustly-client","last_synced_at":"2025-05-13T22:31:03.319Z","repository":{"id":33429474,"uuid":"37074781","full_name":"danibram/trustly-client","owner":"danibram","description":"A node client to comunicate with trustly.","archived":false,"fork":false,"pushed_at":"2021-07-23T09:53:37.000Z","size":1723,"stargazers_count":6,"open_issues_count":14,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T13:36:46.132Z","etag":null,"topics":["client","nodejs","payment","payment-integration","trustly"],"latest_commit_sha":null,"homepage":"https://github.com/danibram/trustly-client","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danibram.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-08T15:17:18.000Z","updated_at":"2021-07-23T09:53:40.000Z","dependencies_parsed_at":"2022-08-28T22:01:58.898Z","dependency_job_id":null,"html_url":"https://github.com/danibram/trustly-client","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danibram%2Ftrustly-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danibram%2Ftrustly-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danibram%2Ftrustly-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danibram%2Ftrustly-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danibram","download_url":"https://codeload.github.com/danibram/trustly-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225260810,"owners_count":17446112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","nodejs","payment","payment-integration","trustly"],"created_at":"2024-11-18T22:32:57.833Z","updated_at":"2024-11-18T22:33:16.640Z","avatar_url":"https://github.com/danibram.png","language":"TypeScript","funding_links":["https://www.paypal.me/danibram"],"categories":[],"sub_categories":[],"readme":"# Trustly Client\n\n[![npm version](https://img.shields.io/npm/v/trustly-client.svg?style=flat-square)][npm-home-module][![GitHub license](https://img.shields.io/npm/dt/trustly-client.svg?style=flat-square)][npm-home-module][![Support link][paypal-badge]][paypal-link]\n\nNode.js client for trustly integrations. Rewrite completely to Typescript and updated to use lasts libraries.\n\n## Quickstart\n\n### Installation\n\nInstall the module with: `npm install trustly-client` or `yarn add trustly-client`\n\n### Usage\n\nIn versions **\u003e3.0.0** all validations are removed and you are free to pass every parameter you like. For older changelog go to the tags **\u003c3.0.0**\n\n```javascript\n// In Vanilla javascript\nvar client = require('trustly-client').default // Import it\nvar tClientKP = client(configuration) // Fill the configuration\n\ntClientKP // Ready to use\n    .deposit(\n        {\n            NotificationURL: 'http://127.0.0.1:4343/notification',\n            EndUserID: 'john.doe@example.com',\n            MessageID: '111112111221',\n        },\n        {\n            Locale: 'es_ES',\n            Amount: '1.00',\n            Currency: 'EUR',\n            SuccessURL: 'http://127.0.0.1:4343/success',\n            FailURL: 'http://127.0.0.1:4343/fail',\n        }\n    )\n    .then(function (response) {\n        console.log(util.inspect(response, false, 20, true))\n    })\n    .catch(function (error) {\n        console.log(util.inspect(error, false, 20, true))\n    })\n\n// In Typescript\nimport client from 'trustly-client' // Import it\nlet tClient = client(configuration) // Fill the configuration\n\ntClientKP // Ready to use\n    .deposit(\n        {\n            NotificationURL: 'http://127.0.0.1:4343/notification',\n            EndUserID: 'john.doe@example.com',\n            MessageID: '111112111221',\n        },\n        {\n            Locale: 'es_ES',\n            Amount: '1.00',\n            Currency: 'EUR',\n            SuccessURL: 'http://127.0.0.1:4343/success',\n            FailURL: 'http://127.0.0.1:4343/fail',\n        }\n    )\n    .then(function (response) {\n        console.log(util.inspect(response, false, 20, true))\n    })\n    .catch(function (error) {\n        console.log(util.inspect(error, false, 20, true))\n    })\n```\n\n## Documentation\n\n### Initialization\n\nAfter import the library you must configure it with your data:\n\n```javascript\nimport client from 'trustly-client' // Import it\nlet tClient = client({\n    username: '', // required\n    password: '', // required\n    privateKeyPath: '', // required\n    publicKeyPath: '', // optional\n    endpoint: '', // optional\n    environment: '', // optional (But required in production, see below!)\n}) // Fill the configuration\n```\n\nThis configuration is an object and this is the structure:\n\n-   [required] 'privateKeyPath': Path to you private key\n-   [required] 'username': Your trustly api username\n-   [required] 'password': Your trustly api password\n-   [optional] 'publicKeyPath': Path to a public key (for the general cases you don't need it, i package the trusty public key)\n-   [optional] 'endpoint': By default is selected depending of the environment between \"\" and \"\".\n-   [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\n\n### Usage\n\nThis are the methods availables, every method accepts `data` and `params` and are the same that you have to send to trustly.\n\n-   **'deposit'** : Create a deposit request.\n-   **'refund'** : Create a refund request.\n-   **'selectAccount'** : Create a select account request.\n-   **'charge'** : Create a charge request.\n-   **'withdraw'** : Create a withdraw request.\n-   **'approveWithdrawal'** : Create a approve withdrawal request.\n-   **'denyWithdrawal'** : Create a deny withdrawal request.\n-   **'accountPayout'** : Create a account payout request.\n\n-   **'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.\n-   **'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:\n\n        ```\n        {\n            \"result\": {\n                \"signature\": \"R9+hjuMqbsH0Ku ... S16VbzRsw==\",\n                \"uuid\": \"258a2184-2842-b485-25ca-293525152425\",\n                \"method\": \"credit\",\n                \"data\": {\n                    \"status\": \"...\"\n                }\n            },\n            \"version\":\"1.1\"\n        }\n        ```\n\n    In the oficial docs you have all you need to manage the data [trustly official doc](https://trustly.com/en/developer/api#/notifications)\n\n-   **'verifyAndParseNotification'** : Helper to verify and parse Json the notification response\n-   **'composeNotificationResponse'** : Helper to compose the notification response, its accepts also custom data to send it back. You can use both (**verifyAndParseNotification**,**composeNotificationResponse**) as replacement of **createNotificationResponse**.\n\n```javascript\nconsole.log('- Notification is comming. √')\ntClient\n    .createNotificationResponse(req.body)\n    .then(function (data) {\n        console.log(util.inspect(data, false, 20, true))\n        res.send(data)\n    })\n    .catch(function (error) {\n        console.log('_Error')\n        console.log(util.inspect(error, false, 20, true))\n    })\n\n// -------------------- OR ----------------------//\n\nconsole.log('- Notification is comming. √')\ntClient\n    .verifyAndParseNotification(req.body)\n    .then(function (notification) {\n        return composeNotificationResponse(notification, {\n            status: 'OK',\n            ...aditionalData,\n        })\n    })\n    .then(function (data) {\n        console.log(util.inspect(data, false, 20, true))\n        res.send(data)\n    })\n    .catch(function (error) {\n        console.log('_Error')\n        console.log(util.inspect(error, false, 20, true))\n    })\n```\n\nAll trustly methods (deposit, refund, selectAccount, charge, withdraw, approveWithdrawal, denyWithdrawal) uses the parameters described in trusty documentation. [here (trustly docs)](https://trustly.com/en/developer/api#/introduction).\nIf is something missing please make a pull request or write an issue.\n\nMethod **'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](https://github.com/danibram/trustly-client/blob/master/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.\n\nAlso 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.\n\n## Error Management\n\nManaging 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:\n\n```javascript\nvar error = {\n    lastRequest: self._lastRequest,\n    lastResponse: self._lastResponse,\n    trustlyError: null,\n    clientError: null,\n}\n```\n\nIt seems to long but sometimes you must understand the request and the response.\n\nIf _clientError_ is filled, means that the error not comes from trustly.\nIf _trustlyError_ is filled, it will catch all information about the trustly error in this format (Example):\n\n```javascript\ntrustlyError = {\n    method: 'Deposit',\n    uuid: 'dba2d98c-6c4e-4b9e-aa46-90027793aa14',\n    message: 'ERROR_DUPLICATE_MESSAGE_ID',\n    code: 637,\n}\n```\n\n_Note: method and uuid can be null if the request contains a malformed JSON_\nMore information about the errors [here (trustly docs)](https://trustly.com/en/developer/api#/errormessages)\n\n## Release History\n\nSee [CHANGELOG.md](https://github.com/danibram/trustly-client/blob/master/CHANGELOG.md)\n\n## License\n\nLicensed under the MIT license. 2021\n\n[npm-home-module]: https://www.npmjs.com/package/trustly-client\n[paypal-badge]: https://img.shields.io/badge/❤%20support-paypal-blue.svg?style=flat-square\n[paypal-link]: https://www.paypal.me/danibram\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanibram%2Ftrustly-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanibram%2Ftrustly-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanibram%2Ftrustly-client/lists"}