aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/http-client/bank-revenue.ts
blob: 99ff7145782d0b2b5f9d33be25a8114a4604de89 (plain)
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
import { HttpRequestLibrary, makeBasicAuthHeader, readSuccessResponseJsonOrThrow } from "../http-common.js";
import { createPlatformHttpLib } from "../http.js";
import { TalerRevenueApi, codecForMerchantIncomingHistory } from "./types.js";
import { UserAndPassword } from "./utils.js";

export class TalerRevenueHttpClient {
  httpLib: HttpRequestLibrary;

  constructor(
    private baseUrl: string,
    private username: string,
    httpClient?: HttpRequestLibrary,
  ) {
    this.httpLib = httpClient ?? createPlatformHttpLib();
  }

  /**
   * https://docs.taler.net/core/api-bank-revenue.html#get-$BASE_URL-history
   * 
   * @returns 
   */
  async getHistory(auth: string): Promise<TalerRevenueApi.MerchantIncomingHistory> {
    const url = new URL(`history`, this.baseUrl);
    const resp = await this.httpLib.fetch(url.href, {
      method: "GET",
      headers: {
        Authorization: makeBasicAuthHeader(this.username, auth),
      }
    });
    return readSuccessResponseJsonOrThrow(resp, codecForMerchantIncomingHistory());
  }
}