diff options
Diffstat (limited to 'packages/taler-util/src/http-client/bank-wire.ts')
-rw-r--r-- | packages/taler-util/src/http-client/bank-wire.ts | 122 |
1 files changed, 116 insertions, 6 deletions
diff --git a/packages/taler-util/src/http-client/bank-wire.ts b/packages/taler-util/src/http-client/bank-wire.ts index a8c976a80..c002bd125 100644 --- a/packages/taler-util/src/http-client/bank-wire.ts +++ b/packages/taler-util/src/http-client/bank-wire.ts @@ -14,7 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { HttpRequestLibrary, makeBasicAuthHeader, readTalerErrorResponse } from "../http-common.js"; +import { + HttpRequestLibrary, + makeBasicAuthHeader, + readTalerErrorResponse, +} from "../http-common.js"; import { HttpStatusCode } from "../http-status-codes.js"; import { createPlatformHttpLib } from "../http.js"; import { @@ -26,16 +30,17 @@ import { opUnknownFailure, } from "../operation.js"; import { - LongPollParams, - PaginationParams, - TalerWireGatewayApi, codecForAddIncomingResponse, codecForIncomingHistory, codecForOutgoingHistory, codecForTransferResponse, -} from "./types.js"; + codecForBankWireTransferList, +} from "../types-taler-wire-gateway.js"; import { addLongPollingParam, addPaginationParams } from "./utils.js"; +import { LongPollParams, PaginationParams } from "../types-taler-common.js"; +import * as TalerWireGatewayApi from "../types-taler-wire-gateway.js"; + export type TalerWireGatewayResultByMethod< prop extends keyof TalerWireGatewayHttpClient, > = ResultByMethod<TalerWireGatewayHttpClient, prop>; @@ -85,7 +90,10 @@ export class TalerWireGatewayHttpClient { * https://docs.taler.net/core/api-bank-wire.html#post--transfer * */ - async transfer(auth: string, body: TalerWireGatewayApi.TransferRequest) { + async makeWireTransfer( + auth: string, + body: TalerWireGatewayApi.TransferRequest, + ) { const url = new URL(`transfer`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", @@ -113,6 +121,79 @@ export class TalerWireGatewayHttpClient { } /** + * https://docs.taler.net/core/api-bank-wire.html#get--transfers + * + */ + async getTransfers( + auth: string, + params?: { + status?: TalerWireGatewayApi.WireTransferStatus; + } & PaginationParams, + ) { + const url = new URL(`transfers`, this.baseUrl); + if (params) { + if (params.status) { + url.searchParams.set("status", params.status); + } + } + addPaginationParams(url, params); + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + }, + }); + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForBankWireTransferList()); + //FIXME: account should not be returned or make it optional + case HttpStatusCode.NoContent: + return opFixedSuccess({ + transfers: [], + debit_account: undefined, + }); + //FIXME: show more details in docs + case HttpStatusCode.BadRequest: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: + return opKnownHttpFailure(resp.status, resp); + //FIXME: show more details in docs + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + } + + /** + * https://docs.taler.net/core/api-bank-wire.html#get--transfers-$ROW_ID + * + */ + async getTransferStatus(auth: string, rowId?: number) { + const url = new URL(`transfers/${String(rowId)}`, this.baseUrl); + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + }, + }); + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForBankWireTransferList()); + //FIXME: account should not be returned or make it optional + case HttpStatusCode.BadRequest: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: + return opKnownHttpFailure(resp.status, resp); + //FIXME: show more details in docs + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + } + + /** * https://docs.taler.net/core/api-bank-wire.html#get--history-incoming * */ @@ -223,4 +304,33 @@ export class TalerWireGatewayHttpClient { return opUnknownFailure(resp, await readTalerErrorResponse(resp)); } } + + /** + * https://docs.taler.net/core/api-bank-wire.html#post--admin-add-kycauth + * + */ + async addKycAuth(auth: string, body: TalerWireGatewayApi.AddIncomingRequest) { + const url = new URL(`admin/add-kycauth`, this.baseUrl); + const resp = await this.httpLib.fetch(url.href, { + method: "POST", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + }, + body, + }); + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForAddIncomingResponse()); + //FIXME: show more details in docs + case HttpStatusCode.BadRequest: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Unauthorized: + return opKnownHttpFailure(resp.status, resp); + //FIXME: show more details in docs + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + } } |