Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ typings/

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Build outputs
dist/
41 changes: 32 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,31 @@ To initialise the client, you must provide:
- The environment that this token is for (see [here](https://github.com/gocardless/gocardless-nodejs/blob/master/src/constants.ts) for a list of available environments).
- Any additional options (see [here](#available-client-options) for a list of supported options).

<!-- prettier-ignore -->
```js
const gocardless = require('gocardless-nodejs/client');
const constants = require('gocardless-nodejs/constants');

import gocardless from 'gocardless-nodejs';
import { Environments } from 'gocardless-nodejs/constants';

// Initialise the client.
// Initialize the client
const client = gocardless(
process.env.GC_ACCESS_TOKEN,
constants.Environments.Sandbox,
{ raiseOnIdempotencyConflict: true },
Environments.Sandbox,
{ raiseOnIdempotencyConflict: true }
);
```

TypeScript:

```typescript
import gocardless, { GoCardlessClient } from 'gocardless-nodejs';
import { Environments } from 'gocardless-nodejs/constants';
import type { Payment } from 'gocardless-nodejs/types';

const client: GoCardlessClient = gocardless(
process.env.GC_ACCESS_TOKEN,
Environments.Sandbox
);

const payment: Payment = await client.payments.find('PM123');
```

### The Basics
Expand All @@ -42,7 +55,7 @@ For a full list of available resources, visit the [GoCardless API reference](htt

<!-- prettier-ignore -->
```js
const uuidv4 = require('uuid/v4');
import { v4 as uuidv4 } from 'uuid';

// Create a new payment.
const payment = await client.payments.create(
Expand All @@ -51,7 +64,7 @@ const payment = await client.payments.create(
currency: "GBP",
links: { mandate: "MD123" },
},
{ uuidv4() },
uuidv4(),
);

// List the first three payments past a certain date.
Expand Down Expand Up @@ -86,3 +99,13 @@ for await (const payment of client.payments.all()) {
### Available client options

- `raiseOnIdempotencyConflict`: set to `true` to raise exceptions on [idempotency](https://developer.gocardless.com/api-reference/#making-requests-idempotency-keys) conflicts. Defaults to `false`.


### CommonJS backwards compatibility

We provide a CommonJS implementation for backwards compatibility. For CommonJS, change the imports to:

```js
const gocardless = require('gocardless-nodejs');
const { Environments } = require('gocardless-nodejs/constants');
```
3 changes: 3 additions & 0 deletions dist-cjs-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions dist-esm-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 16 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
module.exports = {
export default {
preset: 'ts-jest',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.ts$': [
'ts-jest',
{
useESM: true,
tsconfig: {
esModuleInterop: false,
},
},
],
},
};
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 65 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gocardless-nodejs",
"version": "7.1.0",
"version": "7.2.0-beta1",
"description": "Node.js client for the GoCardless API - a powerful, simple solution for the collection of recurring bank-to-bank payments",
"author": "GoCardless Ltd <client-libraries@gocardless.com>",
"repository": {
Expand All @@ -19,6 +19,65 @@
"api",
"direct debit"
],
"type": "module",
"main": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/types/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/types/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./client": {
"import": {
"types": "./dist/types/client.d.ts",
"default": "./dist/esm/client.js"
},
"require": {
"types": "./dist/types/client.d.ts",
"default": "./dist/cjs/client.js"
}
},
"./constants": {
"import": {
"types": "./dist/types/constants.d.ts",
"default": "./dist/esm/constants.js"
},
"require": {
"types": "./dist/types/constants.d.ts",
"default": "./dist/cjs/constants.js"
}
},
"./webhooks": {
"import": {
"types": "./dist/types/webhooks.d.ts",
"default": "./dist/esm/webhooks.js"
},
"require": {
"types": "./dist/types/webhooks.d.ts",
"default": "./dist/cjs/webhooks.js"
}
},
"./errors": {
"import": {
"types": "./dist/types/errors.d.ts",
"default": "./dist/esm/errors.js"
},
"require": {
"types": "./dist/types/errors.d.ts",
"default": "./dist/cjs/errors.js"
}
},
"./types": {
"types": "./dist/types/types/Types.d.ts"
},
"./package.json": "./package.json"
},
"scripts": {
"test": "jest",
"lint": "eslint src/**/*.ts",
Expand Down Expand Up @@ -47,8 +106,11 @@
"ts-jest": "29.4.1",
"typescript": "^5.0.2"
},
"main": "index.js",
"types": "types/Types.d.ts",
"files": [
"dist/",
"LICENSE.txt",
"README.md"
],
"engines": {
"node": ">=18.0"
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs';
import nock from 'nock';
import * as fs from 'node:fs';
import * as nock from 'nock';
import { Api } from './api';
import { Environments } from '../constants';
import * as GoCardlessErrors from '../errors';
Expand Down
16 changes: 7 additions & 9 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
'use strict';

import os = require('os');
import process = require('process');
import _ = require('lodash');
import * as os from 'os';
import * as process from 'process';
import * as _ from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import * as url from 'url';
import got, { Agents, OptionsOfJSONResponseBody } from 'got';
import qs from 'qs';
import * as qs from 'qs';

import { Environments, CLIENT_VERSION, API_VERSION } from '../constants';
import * as GoCardlessErrors from '../errors';
import { Environments, CLIENT_VERSION, API_VERSION } from '../constants.js';
import * as GoCardlessErrors from '../errors.js';
import {
ApiRequestSignatureHelper,
ApiRequestSigningOptions,
ApiRequestSigningOptionsInternal,
} from '../apiRequestSigning';
} from '../apiRequestSigning.js';

export interface APIOptions {
proxy?: Agents;
Expand Down
2 changes: 1 addition & 1 deletion src/apiRequestSigning.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'node:fs';
import * as fs from 'node:fs';
import { ApiRequestSignatureHelper, ApiRequestSigningOptionsInternal } from './apiRequestSigning';

const privateKeyPem = fs.readFileSync('src/fixtures/private_key.pem', 'utf8');
Expand Down
94 changes: 46 additions & 48 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
'use strict';

import { Environments } from './constants';
import { Api, APIOptions } from './api/api';
import { BalanceService } from './services/balanceService';
import { BankAccountDetailService } from './services/bankAccountDetailService';
import { BankAccountHolderVerificationService } from './services/bankAccountHolderVerificationService';
import { BankAuthorisationService } from './services/bankAuthorisationService';
import { BankDetailsLookupService } from './services/bankDetailsLookupService';
import { BillingRequestService } from './services/billingRequestService';
import { BillingRequestFlowService } from './services/billingRequestFlowService';
import { BillingRequestTemplateService } from './services/billingRequestTemplateService';
import { BillingRequestWithActionService } from './services/billingRequestWithActionService';
import { BlockService } from './services/blockService';
import { CreditorService } from './services/creditorService';
import { CreditorBankAccountService } from './services/creditorBankAccountService';
import { CurrencyExchangeRateService } from './services/currencyExchangeRateService';
import { CustomerService } from './services/customerService';
import { CustomerBankAccountService } from './services/customerBankAccountService';
import { CustomerNotificationService } from './services/customerNotificationService';
import { EventService } from './services/eventService';
import { ExportService } from './services/exportService';
import { FundsAvailabilityService } from './services/fundsAvailabilityService';
import { InstalmentScheduleService } from './services/instalmentScheduleService';
import { InstitutionService } from './services/institutionService';
import { LogoService } from './services/logoService';
import { MandateService } from './services/mandateService';
import { MandateImportService } from './services/mandateImportService';
import { MandateImportEntryService } from './services/mandateImportEntryService';
import { MandatePdfService } from './services/mandatePdfService';
import { NegativeBalanceLimitService } from './services/negativeBalanceLimitService';
import { OutboundPaymentService } from './services/outboundPaymentService';
import { PayerAuthorisationService } from './services/payerAuthorisationService';
import { PayerThemeService } from './services/payerThemeService';
import { PaymentService } from './services/paymentService';
import { PaymentAccountService } from './services/paymentAccountService';
import { PaymentAccountTransactionService } from './services/paymentAccountTransactionService';
import { PayoutService } from './services/payoutService';
import { PayoutItemService } from './services/payoutItemService';
import { RedirectFlowService } from './services/redirectFlowService';
import { RefundService } from './services/refundService';
import { ScenarioSimulatorService } from './services/scenarioSimulatorService';
import { SchemeIdentifierService } from './services/schemeIdentifierService';
import { SubscriptionService } from './services/subscriptionService';
import { TaxRateService } from './services/taxRateService';
import { TransferredMandateService } from './services/transferredMandateService';
import { VerificationDetailService } from './services/verificationDetailService';
import { WebhookService } from './services/webhookService';
import { Environments } from './constants.js';
import { Api, APIOptions } from './api/api.js';
import { BalanceService } from './services/balanceService.js';
import { BankAccountDetailService } from './services/bankAccountDetailService.js';
import { BankAccountHolderVerificationService } from './services/bankAccountHolderVerificationService.js';
import { BankAuthorisationService } from './services/bankAuthorisationService.js';
import { BankDetailsLookupService } from './services/bankDetailsLookupService.js';
import { BillingRequestService } from './services/billingRequestService.js';
import { BillingRequestFlowService } from './services/billingRequestFlowService.js';
import { BillingRequestTemplateService } from './services/billingRequestTemplateService.js';
import { BillingRequestWithActionService } from './services/billingRequestWithActionService.js';
import { BlockService } from './services/blockService.js';
import { CreditorService } from './services/creditorService.js';
import { CreditorBankAccountService } from './services/creditorBankAccountService.js';
import { CurrencyExchangeRateService } from './services/currencyExchangeRateService.js';
import { CustomerService } from './services/customerService.js';
import { CustomerBankAccountService } from './services/customerBankAccountService.js';
import { CustomerNotificationService } from './services/customerNotificationService.js';
import { EventService } from './services/eventService.js';
import { ExportService } from './services/exportService.js';
import { FundsAvailabilityService } from './services/fundsAvailabilityService.js';
import { InstalmentScheduleService } from './services/instalmentScheduleService.js';
import { InstitutionService } from './services/institutionService.js';
import { LogoService } from './services/logoService.js';
import { MandateService } from './services/mandateService.js';
import { MandateImportService } from './services/mandateImportService.js';
import { MandateImportEntryService } from './services/mandateImportEntryService.js';
import { MandatePdfService } from './services/mandatePdfService.js';
import { NegativeBalanceLimitService } from './services/negativeBalanceLimitService.js';
import { OutboundPaymentService } from './services/outboundPaymentService.js';
import { PayerAuthorisationService } from './services/payerAuthorisationService.js';
import { PayerThemeService } from './services/payerThemeService.js';
import { PaymentService } from './services/paymentService.js';
import { PaymentAccountService } from './services/paymentAccountService.js';
import { PaymentAccountTransactionService } from './services/paymentAccountTransactionService.js';
import { PayoutService } from './services/payoutService.js';
import { PayoutItemService } from './services/payoutItemService.js';
import { RedirectFlowService } from './services/redirectFlowService.js';
import { RefundService } from './services/refundService.js';
import { ScenarioSimulatorService } from './services/scenarioSimulatorService.js';
import { SchemeIdentifierService } from './services/schemeIdentifierService.js';
import { SubscriptionService } from './services/subscriptionService.js';
import { TaxRateService } from './services/taxRateService.js';
import { TransferredMandateService } from './services/transferredMandateService.js';
import { VerificationDetailService } from './services/verificationDetailService.js';
import { WebhookService } from './services/webhookService.js';

export class GoCardlessClient {
private _api: Api;
Expand Down
4 changes: 1 addition & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

enum Environments {
Live = 'LIVE',
Sandbox = 'SANDBOX',
}

const CLIENT_VERSION = '7.1.0';
const CLIENT_VERSION = '7.2.0-beta1';
const API_VERSION = '2015-07-06';

export { Environments, CLIENT_VERSION, API_VERSION };
2 changes: 0 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

class GoCardlessException extends Error {}

class MalformedResponseError extends GoCardlessException {
Expand Down
Loading