diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-10-17 12:04:44 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-10-17 12:04:44 +0200 |
commit | fba664f9a3c35dfeb5bc5ac28f0baea09ff9b8a0 (patch) | |
tree | 6d069afdecade1b13914f4d13020d0331c2f4036 /packages/taler-util/src/http-client/bank-integration.ts | |
parent | def5ecda6fc4015417779af0a829d3f8aad4dd83 (diff) | |
parent | aca3bc9423f15354913d0114cafbd4bd1782d801 (diff) |
Merge branch 'master' into age-withdrawHEADage-withdraw
Diffstat (limited to 'packages/taler-util/src/http-client/bank-integration.ts')
-rw-r--r-- | packages/taler-util/src/http-client/bank-integration.ts | 47 |
1 files changed, 47 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..cd6462417 --- /dev/null +++ b/packages/taler-util/src/http-client/bank-integration.ts @@ -0,0 +1,47 @@ +import { HttpRequestLibrary, readSuccessResponseJsonOrThrow } from "../http-common.js"; +import { createPlatformHttpLib } from "../http.js"; +import { + TalerBankIntegrationApi, + codecForBankWithdrawalOperationPostResponse, + 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()); + } + +} + |