aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/bank-integration.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-14 01:19:30 -0300
committerSebastian <sebasjm@gmail.com>2023-10-14 01:19:30 -0300
commit592ecda944bf5b32e86f6c42ee8e1f17d9c86451 (patch)
treeb4befbbe407f6e8c53bbf4307bcd412a918eb6c9 /packages/taler-util/src/http-client/bank-integration.ts
parent617ab78264bb3ef200e3568bb6cf9b60ddf5687a (diff)
downloadwallet-core-592ecda944bf5b32e86f6c42ee8e1f17d9c86451.tar.xz
complet bank api
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());
+ }
+
+}
+