Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit 7a6e916

Browse files
author
Santiago Montiu
committed
[feat] include new standing_orders and direct_debits methods. fix tests and retests
1 parent 10ef79b commit 7a6e916

File tree

6 files changed

+180
-2
lines changed

6 files changed

+180
-2
lines changed

src/v1/DataAPIClient.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ApiError } from "./APIError";
22
import { Constants } from "./Constants";
33
import { IAccount } from "./interfaces/data/IAccount";
44
import { IBalance } from "./interfaces/data/IBalance";
5+
import { IDirectDebit } from "./interfaces/data/IDirectDebit";
6+
import { IStandingOrder } from "./interfaces/data/IStandingOrder";
57
import { IInfo } from "./interfaces/data/IInfo";
68
import { IJWT } from "./interfaces/auth/IJWT";
79
import { IMe } from "./interfaces/data/IMe";
@@ -158,6 +160,28 @@ export class DataAPIClient {
158160
return await DataAPIClient.callAPI<IBalance>(accessToken, `${Constants.API_URL}/data/v1/accounts/${accountId}/balance`);
159161
}
160162

163+
/**
164+
* Call to /accounts/account_id/direct_debits API
165+
*
166+
* @param accessToken
167+
* @param accountId
168+
* @returns {Promise<IResult<IDirectDebit>>}
169+
*/
170+
public static async getDirectDebits(accessToken: string, accountId: string): Promise<IResult<IDirectDebit>> {
171+
return await DataAPIClient.callAPI<IDirectDebit>(accessToken, `${Constants.API_URL}/data/v1/accounts/${accountId}/direct_debits`);
172+
}
173+
174+
/**
175+
* Call to /accounts/account_id/standing_orders API
176+
*
177+
* @param accessToken
178+
* @param accountId
179+
* @returns {Promise<IResult<IStandingOrder>>}
180+
*/
181+
public static async getStandingOrders(accessToken: string, accountId: string): Promise<IResult<IStandingOrder>> {
182+
return await DataAPIClient.callAPI<IStandingOrder>(accessToken, `${Constants.API_URL}/data/v1/accounts/${accountId}/standing_orders`);
183+
}
184+
161185
/**
162186
* Call to /cards API.
163187
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Customer's direct debits and associated data - for use with /accounts endpoint
3+
* Docs: https://docs.truelayer.com/#retrieve-direct-debits
4+
*
5+
* @interface IDirectDebit
6+
*/
7+
export interface IDirectDebit {
8+
/** Unique identifier of the direct debit in a request. It may change between requests. */
9+
direct_debit_id: string;
10+
/** Name of the service or user returned by the Provider */
11+
name: string;
12+
/** This can either be Active or Inactive */
13+
status: string;
14+
/** Date of the latest payment */
15+
previous_payment_timestamp: string;
16+
/** Amount of the latest paymentt */
17+
previous_payment_amount: number;
18+
/** ISO 4217 alpha-3 currency code */
19+
currency: string;
20+
/** A collection of additional Provider specific transaction metadata * @type {IMeta} */
21+
meta?: IMeta;
22+
/** Date and time the request was made */
23+
timestamp: string;
24+
}
25+
26+
/**
27+
* Direct debit meta
28+
*
29+
* @interface IMeta
30+
*/
31+
export interface IMeta {
32+
/** Provider mandate identification */
33+
provider_mandate_identification: string;
34+
/** Provider account identifier */
35+
provider_account_id: string;
36+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Customer's standing orders - for use with /accounts endpoint
3+
* Docs: https://docs.truelayer.com/#retrieve-standing-orders
4+
*
5+
* @interface IStandingOrder
6+
*/
7+
export interface IStandingOrder {
8+
/** Frequency of the standing order.
9+
* Possible values:
10+
* EvryDay - every day
11+
* EvryWorkgDay - every working day
12+
* IntrvlDay:XX - every XX calendar day
13+
* IntrvlMnthDay:XX:YY - every XXth month on the YYth day of the month
14+
* IntrvlWkDay:XX:YY - every XXth week, on the YYth day of the week
15+
* QtrDay - quarterly -
16+
* WkInMnthDay:XX:YY - every month, on the XXth week of the month and on the YYth day of the week. */
17+
frequency: string;
18+
/** This can either be Active or Inactive */
19+
status: string;
20+
/** Date and time the request was made */
21+
timestamp: string;
22+
/** ISO 4217 alpha-3 currency code */
23+
currency: string;
24+
/** A collection of additional Provider specific transaction metadata * @type {IMeta} */
25+
meta?: IMeta;
26+
/** The date on which the next payment for the standing order schedule will be made */
27+
next_payment_date: string;
28+
/** Amount of the next payment for the standing order **/
29+
next_payment_amount: number;
30+
/** The date on which the first payment for the standing order schedule will be or was made */
31+
first_payment_date: string;
32+
/** Amount of the first payment for the standing order */
33+
first_payment_amount: number;
34+
/** The date on which the next payment for a Standing Order schedule will be made */
35+
final_payment_date: string;
36+
/** Amount of the last payment for the standing order */
37+
final_payment_amount: number;
38+
/** Reference of the standing order set by the user */
39+
reference: string;
40+
/** Date of the latest payment */
41+
previous_payment_timestamp: string;
42+
/** Amount of the latest payment */
43+
previous_payment_amount: number;
44+
}
45+
46+
/**
47+
* Direct debit meta
48+
*
49+
* @interface IMeta
50+
*/
51+
export interface IMeta {
52+
/** Provider account identifier */
53+
provider_account_id: string;
54+
}

test/integration/integration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as TrueLayer from "./../../index";
66
import { StatusAPIClient } from "../../src/v1/StatusAPIClient";
77

88
// Get access token from environment variable
9-
const access_token: string = process.env.access_token;
9+
const access_token: string = process.env.access_token || '';
1010

1111
if (DataAPIClient.validateToken(access_token)) {
1212

test/unit/data.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test("buildRequestOptions() - returns well formed request options - all params",
4242
});
4343

4444
// Get access token from environment variable
45-
const access_token: string = process.env.access_token;
45+
const access_token: string = process.env.access_token || '';
4646

4747
// Only run the below stubbed tests with a valid access token
4848
if (DataAPIClient.validateToken(access_token)) {
@@ -101,6 +101,22 @@ if (DataAPIClient.validateToken(access_token)) {
101101
t.deepEqual(actual, expected);
102102
});
103103

104+
test.serial("stubbed request body for /Accounts/{id}/DirectDebits endpoint is correctly parsed", async (t) => {
105+
const expected = fixtures.accountDirectDebitResponse;
106+
mock.stub(request, "get").returns(JSON.stringify(expected));
107+
const actual = await DataAPIClient.getDirectDebits(access_token, "test_account_id");
108+
t.plan(1);
109+
t.deepEqual(actual, expected);
110+
});
111+
112+
test.serial("stubbed request body for /Accounts/{id}/StandingOrders endpoint is correctly parsed", async (t) => {
113+
const expected = fixtures.accountStandingOrderResponse;
114+
mock.stub(request, "get").returns(JSON.stringify(expected));
115+
const actual = await DataAPIClient.getStandingOrders(access_token, "test_account_id");
116+
t.plan(1);
117+
t.deepEqual(actual, expected);
118+
});
119+
104120
test.serial("stubbed request body for /Cards endpoint is correctly parsed", async (t) => {
105121
const expected = fixtures.cardsResponse;
106122
mock.stub(request, "get").returns(JSON.stringify(expected));

test/unit/fixtures.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ICardBalance } from "../../src/v1/interfaces/data/ICardBalance";
1111
import { ICardTransaction } from "../../src/v1/interfaces/data/ICardTransaction";
1212
import { IProviderInfo } from '../../src/v1/interfaces/auth/IProviderInfo';
1313
import { IStatusInfo } from "../../src/v1/interfaces/status/IStatusInfo";
14+
import { IStandingOrder } from "../../src/v1/interfaces/data/IStandingOrder";
15+
import { IDirectDebit } from "../../src/v1/interfaces/data/IDirectDebit";
1416

1517
export class Fixtures {
1618

@@ -386,6 +388,52 @@ export class Fixtures {
386388
]
387389
};
388390

391+
// Expected /Accounts/{id}/StandingOrders json response
392+
public readonly accountStandingOrderResponse: IResult<IStandingOrder> =
393+
{
394+
results: [
395+
{
396+
currency: "GBP",
397+
frequency: "DD",
398+
next_payment_date: "2017-10-12T07:17:54.8144949Z",
399+
next_payment_amount: 123,
400+
first_payment_date: "2017-10-12T07:17:54.8144949Z",
401+
status: "Active",
402+
first_payment_amount: 123,
403+
final_payment_date: "2017-10-12T07:17:54.8144949Z",
404+
final_payment_amount: 123,
405+
timestamp: "2017-10-12T07:17:54.8144949Z",
406+
reference: "Savings",
407+
previous_payment_timestamp: "2017-10-12T07:17:54.8144949Z",
408+
previous_payment_amount: 123,
409+
meta: {
410+
provider_account_id: "234234-123"
411+
}
412+
}
413+
]
414+
};
415+
416+
// Expected /Accounts/{id}/DirectDebits json response
417+
public readonly accountDirectDebitResponse: IResult<IDirectDebit> =
418+
{
419+
results: [
420+
{
421+
direct_debit_id: "123",
422+
name: "Netflic",
423+
status: "Active",
424+
previous_payment_timestamp: "2017-10-12T07:17:54.8144949Z",
425+
previous_payment_amount: 123,
426+
currency: "GBP",
427+
timestamp: "2017-10-12T07:17:54.8144949Z",
428+
meta: {
429+
provider_mandate_identification: "Lacsitos",
430+
provider_account_id: "234234-123"
431+
}
432+
}
433+
]
434+
};
435+
436+
// Expected /Cards/{id}/Transactions json response
389437
public readonly cardTransactionsResponse: IResult<ICardTransaction> =
390438
{
391439
results: [

0 commit comments

Comments
 (0)