32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
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());
|
|
}
|
|
} |