@fightmegg/transferwise
Version:
Node TransferWise API client
132 lines (88 loc) • 3.99 kB
Markdown
[](https://www.npmjs.com/package/@fightmegg/transferwise)
[](https://www.npmjs.com/package/@fightmegg/transferwise)
[](https://circleci.com/gh/fightmegg/transferwise/tree/master)
> An open-source TransferWise API client for Node.JS
The TransferWise Node library provides convient access to the TransferWise API from applications written in server-side JavaScript.
See the [TransferWise API docs](https://api-docs.transferwise.com/#transferwise-api) for the offical docs, below is a list of methods supported by this library.
Install the package with:
```sh
npm install @fightmegg/transferwise
```
**NB: Requires Node >= 12**
```js
import TransferWise from '@fightmegg/transferwise';
const tw = new TransferWise({ token: ..., sandbox: true });
const profiles = await tw.profiles();
```
Currently only supports methods listed below. Aim to support all API methods _soon_.
**profiles**
```js
await tw.profiles();
```
**borderlessAccounts**
```js
await tw.borderlessAccounts("<profileId>");
```
**recipientAccounts**
```js
await tw.recipientAccounts.create("<accounts object>");
await tw.recipientAccounts.get("<accountId>");
await tw.recipientAccounts.delete("<accountId>");
await tw.recipientAccounts.list("<account url params>");
```
**quotes**
```js
await tw.quotes.temporary("<quote url params>");
await tw.quotes.create("<quote object>");
await tw.quotes.get("<quoteId>");
```
**transfers**
```js
await tw.transfers.create("<transfer object>");
await tw.transfers.cancel("<transfer object>");
await tw.transfers.get("<transferId>");
await tw.transfers.issues("<transferId>");
await tw.transfers.fund("<profileId>", "<transferId>");
await tw.transfers.deliveryEstimate("<transferId>");
await tw.transfers.list("<transfer url params>");
```
**simulation**
```js
await tw.simulation.transfers.processing("<transferId>");
await tw.simulation.transfers.fundsConverted("<transferId>");
await tw.simulation.transfers.outgoingPaymentSent("<transferId>");
await tw.simulation.transfers.bouncedBack("<transferId>");
await tw.simulation.transfers.fundsRefunded("<transferId>");
```
TransferWise signs all Webhook events, and it is recommended that you [verify this signature](https://api-docs.transferwise.com/#webhook-events-list-signature-header) . Luckily this library can do that for you.
Similarly to how `stripe node` works, you should only use the event returned from the method below.
```js
const event = tw.webhooks.constructEvent("<webhookMsg>", "<signature>");
```
Please note that you must pass the **raw** request body, exactly as recieved from TransferWise to the `constructEvent()` function; this will not work with a parsed (i.e., JSON) request body.
You can find an example of how to use this with [Express](https://expressjs.com/) below:
```js
app.post("/", bodyParser.raw({ type: "application.json" }), (req, res) => {
const sig = req.headers["x-signature"];
const event = tw.webhooks.constructEvent(req.body, sig);
// ...
});
```
Below is a series of issues that l have found out through various email chains with TransferWise API team.
**1. Create a Transfer**
When creating a transfer, the field **targetValue** will always be populated as `0` regardless, therefore you should only rely on this field in production.
**2. Simulate a Transfer**
When funding a transfer, the transfer state might show `processing`, however this state is misleading. When simulating, you will still need to simulate from `incoming_payment_waiting` to `processing`.
Run all tests:
```bash
$ npm test
```
This library is published to both the NPM and GitHub package registrys.