Skip to content

Commit

Permalink
Bump version to v1.3.0
Browse files Browse the repository at this point in the history
• Add documentation about `available_refund_amount_insufficient` error
• Allow updating `retry_if_possible` field on subscriptions
• Added support for applying tax to transaction and surcharge fees.
   • Added `taxes` to payout_items.
   • Added `tax_currency` to payout.
   • Added `tax_rates` endpoint.
   • Added a `payout tax_exchange_rates_confirmed` webhook to know when the exchange rate has been finalised for all fees in the payout.
  • Loading branch information
gocardless-robot authored and Jason Lafferty committed Jul 14, 2020
1 parent fecd564 commit 2fcfb14
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 214 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ const constants = require('gocardless-nodejs/constants');
// Initialise the client.
const client = gocardless(
process.env.GC_ACCESS_TOKEN,
Constants.Environments.Sandbox,
constants.Environments.Sandbox,
{ raiseOnIdempotencyConflict: true },
);
```
Expand Down
360 changes: 185 additions & 175 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "gocardless-nodejs",
"version": "1.2.0",
"version": "1.3.0",
"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 Down
4 changes: 2 additions & 2 deletions src/api/api.ts
Expand Up @@ -131,9 +131,9 @@ export class Api {
Accept: 'application/json',
Authorization: `Bearer ${token}`,
'GoCardless-Version': '2015-07-06',
'GoCardless-Client-Version': '1.2.0',
'GoCardless-Client-Version': '1.3.0',
'GoCardless-Client-Library': 'gocardless-nodejs',
'User-Agent': `gocardless-nodejs/1.2.0 node/${this.processVersion} ${this.osPlatform}/${this.osRelease}`,
'User-Agent': `gocardless-nodejs/1.3.0 node/${this.processVersion} ${this.osPlatform}/${this.osRelease}`,
};

return { ...customHeaders, ...mandatoryHeaders };
Expand Down
11 changes: 11 additions & 0 deletions src/client.ts
Expand Up @@ -21,6 +21,7 @@ import { PayoutItemService } from './services/payoutItemService';
import { RedirectFlowService } from './services/redirectFlowService';
import { RefundService } from './services/refundService';
import { SubscriptionService } from './services/subscriptionService';
import { TaxRateService } from './services/taxRateService';

export class GoCardlessClient {
private _api: Api;
Expand All @@ -44,6 +45,7 @@ export class GoCardlessClient {
private _redirectFlows: RedirectFlowService;
private _refunds: RefundService;
private _subscriptions: SubscriptionService;
private _taxRates: TaxRateService;

constructor(token: string, environment = Environments.Live, options = {}) {
this._api = new Api(token, environment, options);
Expand All @@ -67,6 +69,7 @@ export class GoCardlessClient {
this._redirectFlows = undefined;
this._refunds = undefined;
this._subscriptions = undefined;
this._taxRates = undefined;
}

get bankDetailsLookups(): BankDetailsLookupService {
Expand Down Expand Up @@ -220,4 +223,12 @@ export class GoCardlessClient {

return this._subscriptions;
}

get taxRates(): TaxRateService {
if (!this._taxRates) {
this._taxRates = new TaxRateService(this._api);
}

return this._taxRates;
}
}
22 changes: 12 additions & 10 deletions src/services/instalmentScheduleService.ts
Expand Up @@ -46,11 +46,12 @@ interface InstalmentScheduleCreateWithDatesRequest {
// <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
// characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
// <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
// characters <p class='restricted-notice'><strong>Restricted</strong>: You can
// only specify a payment reference for Bacs payments (that is, when collecting
// from the UK) if you're on the <a
// href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
// packages</a>.</p>
// characters<br /> Note that this reference must be unique (for each merchant)
// for the BECS scheme as it is a scheme requirement. <p
// class='restricted-notice'><strong>Restricted</strong>: You can only specify a
// payment reference for Bacs payments (that is, when collecting from the UK) if
// you're on the <a href='https://gocardless.com/pricing'>GoCardless Plus, Pro
// or Enterprise packages</a>.</p>
payment_reference?: string;

// On failure, automatically retry payments using [intelligent
Expand Down Expand Up @@ -102,11 +103,12 @@ interface InstalmentScheduleCreateWithScheduleRequest {
// <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
// characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
// <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
// characters <p class='restricted-notice'><strong>Restricted</strong>: You can
// only specify a payment reference for Bacs payments (that is, when collecting
// from the UK) if you're on the <a
// href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
// packages</a>.</p>
// characters<br /> Note that this reference must be unique (for each merchant)
// for the BECS scheme as it is a scheme requirement. <p
// class='restricted-notice'><strong>Restricted</strong>: You can only specify a
// payment reference for Bacs payments (that is, when collecting from the UK) if
// you're on the <a href='https://gocardless.com/pricing'>GoCardless Plus, Pro
// or Enterprise packages</a>.</p>
payment_reference?: string;

// On failure, automatically retry payments using [intelligent
Expand Down
11 changes: 6 additions & 5 deletions src/services/paymentService.ts
Expand Up @@ -51,11 +51,12 @@ interface PaymentCreateRequest {
// <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
// characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
// <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
// characters <p class='restricted-notice'><strong>Restricted</strong>: You can
// only specify a payment reference for Bacs payments (that is, when collecting
// from the UK) if you're on the <a
// href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
// packages</a>.</p>
// characters<br /> Note that this reference must be unique (for each merchant)
// for the BECS scheme as it is a scheme requirement. <p
// class='restricted-notice'><strong>Restricted</strong>: You can only specify a
// payment reference for Bacs payments (that is, when collecting from the UK) if
// you're on the <a href='https://gocardless.com/pricing'>GoCardless Plus, Pro
// or Enterprise packages</a>.</p>
reference?: string;

// On failure, automatically retry the payment using [intelligent
Expand Down
11 changes: 6 additions & 5 deletions src/services/refundService.ts
Expand Up @@ -28,11 +28,12 @@ interface RefundCreateRequest {
// <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
// characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
// <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
// characters <p class='restricted-notice'><strong>Restricted</strong>: You can
// only specify a payment reference for Bacs payments (that is, when collecting
// from the UK) if you're on the <a
// href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
// packages</a>.</p>
// characters<br /> Note that this reference must be unique (for each merchant)
// for the BECS scheme as it is a scheme requirement. <p
// class='restricted-notice'><strong>Restricted</strong>: You can only specify a
// payment reference for Bacs payments (that is, when collecting from the UK) if
// you're on the <a href='https://gocardless.com/pricing'>GoCardless Plus, Pro
// or Enterprise packages</a>.</p>
reference?: string;

// Total expected refunded amount in minor unit (e.g. pence/cents/öre). If there
Expand Down
4 changes: 4 additions & 0 deletions src/services/subscriptionService.ts
Expand Up @@ -138,6 +138,10 @@ interface SubscriptionUpdateRequest {
// <p class="restricted-notice"><strong>Restricted</strong>: You need your own
// Service User Number to specify a payment reference for Bacs payments.</p>
payment_reference?: string;

// On failure, automatically retry payments using [intelligent
// retries](#success-intelligent-retries). Default is `false`.
retry_if_possible?: boolean;
}

interface SubscriptionPauseRequest {
Expand Down
87 changes: 87 additions & 0 deletions src/services/taxRateService.ts
@@ -0,0 +1,87 @@
'use strict';

import { Api } from '../api/api';
import * as Types from '../types/Types';

interface TaxRateResponse extends Types.TaxRate, Types.APIResponse {}

interface TaxRateListResponse extends Types.APIResponse {
tax_rates: Types.TaxRate[];
meta: Types.ListMeta;
}

interface TaxRateListRequest {
// Cursor pointing to the start of the desired set.
after?: string;

// Cursor pointing to the end of the desired set.
before?: string;

// The jurisdiction this tax rate applies to
jurisdiction?: string;
}

export class TaxRateService {
private api: Api;

constructor(api) {
this.api = api;
}

async list(
requestParameters: TaxRateListRequest
): Promise<TaxRateListResponse> {
const urlParameters = [];
const requestParams = {
path: '/tax_rates',
method: 'get',
urlParameters,
requestParameters,
payloadKey: null,
fetch: null,
};

const response = await this.api.request(requestParams);
const formattedResponse: TaxRateListResponse = {
...response.body,
__response__: response.__response__,
};

return formattedResponse;
}

async *all(
requestParameters: TaxRateListRequest
): AsyncGenerator<Types.TaxRate, void, unknown> {
let cursor = undefined;
do {
const list = await this.list({ ...requestParameters, after: cursor });

for (const taxrate of list.tax_rates) {
yield taxrate;
}

cursor = list.meta.cursors.after;
} while (cursor);
}

async find(identity: string): Promise<TaxRateResponse> {
const urlParameters = [{ key: 'identity', value: identity }];
const requestParams = {
path: '/tax_rates/:identity',
method: 'get',
urlParameters,

payloadKey: null,
fetch: null,
};

const response = await this.api.request(requestParams);
const formattedResponse: TaxRateResponse = {
...response.body['tax_rates'],
__response__: response.__response__,
};

return formattedResponse;
}
}

0 comments on commit 2fcfb14

Please sign in to comment.