Skip to content

Commit

Permalink
Merge pull request #151 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Release version 3.9.0
  • Loading branch information
jjholmes927 committed Feb 7, 2023
2 parents 0fd5d64 + 039c7a7 commit eccdb6d
Show file tree
Hide file tree
Showing 11 changed files with 597 additions and 136 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ pids
*.seed
*.pid.lock

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand Down
182 changes: 91 additions & 91 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gocardless-nodejs",
"version": "3.8.0",
"version": "3.9.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 <[email protected]>",
"repository": {
Expand Down
22 changes: 22 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ 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 { VerificationDetailService } from './services/verificationDetailService';
import { WebhookService } from './services/webhookService';

export class GoCardlessClient {
Expand Down Expand Up @@ -61,8 +63,10 @@ export class GoCardlessClient {
private _redirectFlows: RedirectFlowService;
private _refunds: RefundService;
private _scenarioSimulators: ScenarioSimulatorService;
private _schemeIdentifiers: SchemeIdentifierService;
private _subscriptions: SubscriptionService;
private _taxRates: TaxRateService;
private _verificationDetails: VerificationDetailService;
private _webhooks: WebhookService;

constructor(token: string, environment = Environments.Live, options = {}) {
Expand Down Expand Up @@ -94,8 +98,10 @@ export class GoCardlessClient {
this._redirectFlows = undefined;
this._refunds = undefined;
this._scenarioSimulators = undefined;
this._schemeIdentifiers = undefined;
this._subscriptions = undefined;
this._taxRates = undefined;
this._verificationDetails = undefined;
this._webhooks = undefined;
}

Expand Down Expand Up @@ -309,6 +315,14 @@ export class GoCardlessClient {
return this._scenarioSimulators;
}

get schemeIdentifiers(): SchemeIdentifierService {
if (!this._schemeIdentifiers) {
this._schemeIdentifiers = new SchemeIdentifierService(this._api);
}

return this._schemeIdentifiers;
}

get subscriptions(): SubscriptionService {
if (!this._subscriptions) {
this._subscriptions = new SubscriptionService(this._api);
Expand All @@ -325,6 +339,14 @@ export class GoCardlessClient {
return this._taxRates;
}

get verificationDetails(): VerificationDetailService {
if (!this._verificationDetails) {
this._verificationDetails = new VerificationDetailService(this._api);
}

return this._verificationDetails;
}

get webhooks(): WebhookService {
if (!this._webhooks) {
this._webhooks = new WebhookService(this._api);
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum Environments {
Sandbox = 'SANDBOX',
}

const CLIENT_VERSION = '3.8.0';
const CLIENT_VERSION = '3.9.0';
const API_VERSION = '2015-07-06';

export { Environments, CLIENT_VERSION, API_VERSION };
56 changes: 30 additions & 26 deletions src/services/creditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ interface CreditorListResponse extends Types.APIResponse {
}

interface CreditorCreateRequest {
// The first line of the creditor's address.

address_line1?: string;

// The second line of the creditor's address.

address_line2?: string;

// The third line of the creditor's address.

address_line3?: string;

// The city of the creditor's address.

city?: string;

// [ISO 3166-1 alpha-2
// code.](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)

Expand All @@ -37,17 +21,9 @@ interface CreditorCreateRequest {

creditor_type: Types.CreditorCreditorType;

// The creditor's name.
// The creditor's trading name.

name: string;

// The creditor's postal code.

postal_code?: string;

// The creditor's address region, county or department.

region?: string;
}

interface CreditorListRequest {
Expand Down Expand Up @@ -92,7 +68,7 @@ interface CreditorUpdateRequest {
// Resources linked to this Creditor.
links?: Types.CreditorUpdateRequestLinks;

// The creditor's name.
// The creditor's trading name.

name?: string;

Expand All @@ -105,6 +81,11 @@ interface CreditorUpdateRequest {
region?: string;
}

interface CreditorApplySchemeIdentifierRequest {
// Resources linked to this Creditor.
links: Types.CreditorApplySchemeIdentifierRequestLinks;
}

export class CreditorService {
private api: Api;

Expand Down Expand Up @@ -217,4 +198,27 @@ export class CreditorService {

return formattedResponse;
}

async applySchemeIdentifier(
identity: string,
requestParameters: CreditorApplySchemeIdentifierRequest
): Promise<CreditorResponse> {
const urlParameters = [{ key: 'identity', value: identity }];
const requestParams = {
path: '/creditors/:identity/actions/apply_scheme_identifier',
method: 'post',
urlParameters,
requestParameters,
payloadKey: null,
fetch: null,
};

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

return formattedResponse;
}
}
2 changes: 1 addition & 1 deletion src/services/instalmentScheduleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface InstalmentScheduleCreateWithDatesRequest {
// An explicit array of instalment payments, each specifying at least an
// `amount` and `charge_date`.

instalments: Types.InstalmentScheduleInstalments[];
instalments: Types.InstalmentScheduleInstalment[];

// Resources linked to this InstalmentSchedule.
links: Types.InstalmentScheduleCreateWithDatesRequestLinks;
Expand Down
4 changes: 4 additions & 0 deletions src/services/mandateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ interface MandateCreateRequest {
// For ACH customers only. Required for ACH customers. A string containing the
// IP address of the payer to whom the mandate belongs (i.e. as a result of
// their completion of a mandate setup flow in their browser).
//
// Not required for creating offline mandates where `authorisation_source` is
// set to telephone or paper.
//

payer_ip_address?: string;

Expand Down
129 changes: 129 additions & 0 deletions src/services/schemeIdentifierService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
'use strict';

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

interface SchemeIdentifierResponse
extends Types.SchemeIdentifier,
Types.APIResponse {}

interface SchemeIdentifierListResponse extends Types.APIResponse {
scheme_identifiers: Types.SchemeIdentifier[];
meta: Types.ListMeta;
}

interface SchemeIdentifierCreateRequest {
// The name which appears on customers' bank statements. This should usually be
// the merchant's trading name.

name: string;

// The scheme which this scheme identifier applies to.

scheme: Types.SchemeIdentifierScheme;
}

interface SchemeIdentifierListRequest {
// Cursor pointing to the start of the desired set.

after?: string;

// Cursor pointing to the end of the desired set.

before?: string;

// Number of records to return.

limit?: string;
}

export class SchemeIdentifierService {
private api: Api;

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

async create(
requestParameters: SchemeIdentifierCreateRequest,
idempotencyKey = '',
customHeaders: Types.JsonMap = {}
): Promise<SchemeIdentifierResponse> {
const urlParameters = [];
const requestParams = {
path: '/scheme_identifiers',
method: 'post',
urlParameters,
requestParameters,
payloadKey: 'scheme_identifiers',
idempotencyKey,
customHeaders,
fetch: async identity => this.find(identity),
};

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

return formattedResponse;
}

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

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

return formattedResponse;
}

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

for (const schemeidentifier of list.scheme_identifiers) {
yield schemeidentifier;
}

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

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

payloadKey: null,
fetch: null,
};

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

return formattedResponse;
}
}
Loading

0 comments on commit eccdb6d

Please sign in to comment.