1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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());
}
}
|