aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/bank-integration.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/http-client/bank-integration.ts')
-rw-r--r--packages/taler-util/src/http-client/bank-integration.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/taler-util/src/http-client/bank-integration.ts b/packages/taler-util/src/http-client/bank-integration.ts
new file mode 100644
index 000000000..cdba66fa5
--- /dev/null
+++ b/packages/taler-util/src/http-client/bank-integration.ts
@@ -0,0 +1,44 @@
+import { HttpRequestLibrary, readSuccessResponseJsonOrThrow } from "../http-common.js";
+import { createPlatformHttpLib } from "../http.js";
+import { codecForBankWithdrawalOperationPostResponse } from "../taler-types.js";
+import { TalerBankIntegrationApi, codecForBankVersion, codecForBankWithdrawalOperationStatus } from "./types.js";
+
+export class TalerBankIntegrationHttpClient {
+ httpLib: HttpRequestLibrary;
+
+ constructor(
+ private baseUrl: string,
+ httpClient?: HttpRequestLibrary,
+ ) {
+ this.httpLib = httpClient ?? createPlatformHttpLib();
+ }
+
+ /**
+ * https://docs.taler.net/core/api-bank-integration.html#get-$BANK_API_BASE_URL-withdrawal-operation-$wopid
+ *
+ */
+ async getWithdrawalOperationById(woid: string, timeoutMs?: number): Promise<TalerBankIntegrationApi.BankWithdrawalOperationStatus> {
+ const url = new URL(`withdrawal-operation/${woid}`, this.baseUrl);
+ if (timeoutMs) {
+ url.searchParams.set("long_poll_ms", String(timeoutMs))
+ }
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET"
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForBankWithdrawalOperationStatus());
+ }
+
+ /**
+ * https://docs.taler.net/core/api-bank-integration.html#post-$BANK_API_BASE_URL-withdrawal-operation-$wopid
+ *
+ */
+ async completeWithdrawalOperationById(woid: string): Promise<TalerBankIntegrationApi.BankWithdrawalOperationPostResponse> {
+ const url = new URL(`withdrawal-operation/${woid}`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ });
+ return readSuccessResponseJsonOrThrow(resp, codecForBankWithdrawalOperationPostResponse());
+ }
+
+}
+