From 7985b0a33ffc3e258da5d73f4056384c38e626fe Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Feb 2023 00:52:10 +0100 Subject: taler-harness: deployment tooling for tipping --- packages/taler-wallet-core/src/bank-api-client.ts | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'packages/taler-wallet-core/src') diff --git a/packages/taler-wallet-core/src/bank-api-client.ts b/packages/taler-wallet-core/src/bank-api-client.ts index f807d2daa..de0d4b852 100644 --- a/packages/taler-wallet-core/src/bank-api-client.ts +++ b/packages/taler-wallet-core/src/bank-api-client.ts @@ -37,6 +37,7 @@ import { TalerErrorCode, } from "@gnu-taler/taler-util"; import { + createPlatformHttpLib, HttpRequestLibrary, readSuccessResponseJsonOrThrow, } from "@gnu-taler/taler-util/http"; @@ -277,3 +278,62 @@ export namespace BankAccessApi { ); } } + +export interface BankAccessApiClientArgs { + baseUrl: string; + username: string; + password: string; +} + +export interface BankAccessApiCreateTransactionRequest { + amount: AmountString; + paytoUri: string; +} + +export class BankAccessApiClient { + httpLib = createPlatformHttpLib(); + + constructor(private args: BankAccessApiClientArgs) {} + + async getTransactions(): Promise { + const reqUrl = new URL( + `accounts/${this.args.username}/transactions`, + this.args.baseUrl, + ); + const authHeaderValue = makeBasicAuthHeader( + this.args.username, + this.args.password, + ); + const resp = await this.httpLib.fetch(reqUrl.href, { + method: "GET", + headers: { + Authorization: authHeaderValue, + }, + }); + + const res = await readSuccessResponseJsonOrThrow(resp, codecForAny()); + logger.info(`result: ${j2s(res)}`); + } + + async createTransaction( + req: BankAccessApiCreateTransactionRequest, + ): Promise { + const reqUrl = new URL( + `accounts/${this.args.username}/transactions`, + this.args.baseUrl, + ); + const authHeaderValue = makeBasicAuthHeader( + this.args.username, + this.args.password, + ); + const resp = await this.httpLib.fetch(reqUrl.href, { + method: "POST", + body: req, + headers: { + Authorization: authHeaderValue, + }, + }); + + return await readSuccessResponseJsonOrThrow(resp, codecForAny()); + } +} -- cgit v1.2.3