11import { Configuration } from "./Configuration" ;
22import { 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" ;
66import * as types from "./types" ;
77
88export 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 }
0 commit comments