aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/bank-wire.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/http-client/bank-wire.ts')
-rw-r--r--packages/taler-util/src/http-client/bank-wire.ts98
1 files changed, 98 insertions, 0 deletions
diff --git a/packages/taler-util/src/http-client/bank-wire.ts b/packages/taler-util/src/http-client/bank-wire.ts
new file mode 100644
index 000000000..9f2b859ed
--- /dev/null
+++ b/packages/taler-util/src/http-client/bank-wire.ts
@@ -0,0 +1,98 @@
+import { HttpRequestLibrary, makeBasicAuthHeader, readSuccessResponseJsonOrThrow } from "../http-common.js";
+import { createPlatformHttpLib } from "../http.js";
+import { TalerWireGatewayApi, codecForAddIncomingResponse, codecForIncomingHistory, codecForOutgoingHistory, codecForTransferResponse } from "./types.js";
+import { PaginationParams, UserAndPassword, addPaginationParams } from "./utils.js";
+
+/**
+ * The API is used by the exchange to trigger transactions and query
+ * incoming transactions, as well as by the auditor to query incoming
+ * and outgoing transactions.
+ *
+ * https://docs.taler.net/core/api-bank-wire.html
+ */
+export class TalerWireGatewayHttpClient {
+ httpLib: HttpRequestLibrary;
+
+ constructor(
+ private baseUrl: string,
+ private username: string,
+ httpClient?: HttpRequestLibrary,
+ ) {
+ this.httpLib = httpClient ?? createPlatformHttpLib();
+ }
+
+ /**
+ * https://docs.taler.net/core/api-bank-wire.html#post-$BASE_URL-transfer
+ *
+ */
+ async transfer(
+ auth: string,
+ body: TalerWireGatewayApi.TransferRequest,
+ ): Promise<TalerWireGatewayApi.TransferResponse> {
+ const url = new URL(`transfer`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ headers: {
+ Authorization: makeBasicAuthHeader(this.username, auth),
+ },
+ body
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForTransferResponse());
+ }
+
+ /**
+ * https://docs.taler.net/core/api-bank-wire.html#get-$BASE_URL-history-incoming
+ *
+ */
+ async getHistoryIncoming(
+ auth: string,
+ pagination?: PaginationParams
+ ): Promise<TalerWireGatewayApi.IncomingHistory> {
+ const url = new URL(`history/incoming`, this.baseUrl);
+ addPaginationParams(url, pagination)
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ headers: {
+ Authorization: makeBasicAuthHeader(this.username, auth),
+ }
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForIncomingHistory());
+ }
+ /**
+ * https://docs.taler.net/core/api-bank-wire.html#get-$BASE_URL-history-outgoing
+ *
+ */
+ async getHistoryOutgoing(
+ auth: string,
+ pagination?: PaginationParams
+ ): Promise<TalerWireGatewayApi.OutgoingHistory> {
+ const url = new URL(`history/outgoing`, this.baseUrl);
+ addPaginationParams(url, pagination)
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ headers: {
+ Authorization: makeBasicAuthHeader(this.username, auth),
+ }
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForOutgoingHistory());
+ }
+ /**
+ * https://docs.taler.net/core/api-bank-wire.html#post-$BASE_URL-admin-add-incoming
+ *
+ */
+ async addIncoming(
+ auth: string,
+ body: TalerWireGatewayApi.AddIncomingRequest,
+ ): Promise<TalerWireGatewayApi.AddIncomingResponse> {
+ const url = new URL(`admin/add-incoming`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ headers: {
+ Authorization: makeBasicAuthHeader(this.username, auth),
+ },
+ body
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForAddIncomingResponse());
+ }
+}
+