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 { 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 { const url = new URL(`withdrawal-operation/${woid}`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", }); return readSuccessResponseJsonOrThrow(resp, codecForBankWithdrawalOperationPostResponse()); } }