Skip to content

Commit d879b1f

Browse files
committed
Payment.search accept query (find by batchId or recipientId)
1 parent 1ea8c25 commit d879b1f

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

lib/Payment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Configuration } from "./Configuration";
2-
import { Recipient } from './Recipient';
2+
import { Recipient } from "./Recipient";
33
import * as types from "./types";
44

55
// tslint:disable:function-name
@@ -87,13 +87,13 @@ export class Payment {
8787
* @hidden
8888
*/
8989
static async search(
90-
batchId: string,
90+
query: { [key: string]: string },
9191
page: number = 1,
9292
pageSize: number = 10,
9393
term: string = "",
9494
) {
9595
const data = await Configuration.gateway().payment.search(
96-
batchId,
96+
query,
9797
page,
9898
pageSize,
9999
term,

lib/PaymentGateway.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Configuration } from "./Configuration";
22
import { Gateway } from "./Gateway";
3-
import { Payment } from './Payment';
4-
import { buildURL } from './util';
5-
import * as querystring from 'querystring';
3+
import { Payment } from "./Payment";
4+
import { buildURL } from "./util";
5+
import * as querystring from "querystring";
66
import * as types from "./types";
77

88
export class PaymentGateway {
@@ -32,9 +32,11 @@ export class PaymentGateway {
3232
* @param paymentId Payment Rails payment id (e.g. "P-aabccc")
3333
*/
3434
async find(paymentId: string) {
35-
const endPoint = buildURL('payments', paymentId);
35+
const endPoint = buildURL("payments", paymentId);
3636

37-
const result = await this.gateway.client.get<types.Payment.Result>(endPoint);
37+
const result = await this.gateway.client.get<types.Payment.Result>(
38+
endPoint,
39+
);
3840

3941
return Payment.factory(result.payment);
4042
}
@@ -53,9 +55,12 @@ export class PaymentGateway {
5355
* @param body Payment information
5456
*/
5557
async create(batchId: string, body: any) {
56-
const endPoint = buildURL('batches', batchId, 'payments');
58+
const endPoint = buildURL("batches", batchId, "payments");
5759

58-
const result = await this.gateway.client.post<types.Payment.Result>(endPoint, body);
60+
const result = await this.gateway.client.post<types.Payment.Result>(
61+
endPoint,
62+
body,
63+
);
5964

6065
return Payment.factory(result.payment);
6166
}
@@ -72,9 +77,12 @@ export class PaymentGateway {
7277
* @param body Payment update information
7378
*/
7479
async update(paymentId: string, batchId: string, body: any) {
75-
const endPoint = buildURL('batches', batchId, 'payments', paymentId);
80+
const endPoint = buildURL("batches", batchId, "payments", paymentId);
7681

77-
const result = await this.gateway.client.patch<{ ok: boolean }>(endPoint, body);
82+
const result = await this.gateway.client.patch<{ ok: boolean }>(
83+
endPoint,
84+
body,
85+
);
7886

7987
return true;
8088
}
@@ -88,7 +96,7 @@ export class PaymentGateway {
8896
* @param batchId Payment Rails payment id (e.g. "B-xx999bb")
8997
*/
9098
async remove(paymentId: string, batchId: string) {
91-
const endPoint = buildURL('batches', batchId, 'payments', paymentId);
99+
const endPoint = buildURL("batches", batchId, "payments", paymentId);
92100

93101
const result = await this.gateway.client.remove<{ ok: boolean }>(endPoint);
94102

@@ -97,26 +105,29 @@ export class PaymentGateway {
97105

98106
/**
99107
* Search for payments in a given batch
100-
* @param batchId Payment Rails payment id (e.g. "B-xx999bb")
108+
* @param query Object containing either search key, usually either "recipientId" or "batchId"
101109
* @param page Page number (1 based)
102110
* @param pageSize Page size (0...1000)
103111
* @param term Any search terms to look for
104112
*/
105113
async search(
106-
batchId: string,
114+
query: { [key: string]: string },
107115
page: number = 1,
108116
pageSize: number = 10,
109117
term: string = "",
110118
) {
111119
// tslint:disable-next-line:max-line-length
112-
const endPoint = buildURL('batches', batchId, 'payments');
113-
const query = querystring.stringify({
120+
const endPoint = buildURL("payments");
121+
const urlQuery = querystring.stringify({
122+
...query,
114123
page,
115124
pageSize,
116125
search: term,
117126
});
118127

119-
const result = await this.gateway.client.get<types.Payment.ListResult>(`${endPoint}?${query}`);
128+
const result = await this.gateway.client.get<types.Payment.ListResult>(
129+
`${endPoint}?${urlQuery}`,
130+
);
120131

121132
return result.payments.map(p => Payment.factory(p));
122133
}

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)