diff options
author | Florian Dold <florian@dold.me> | 2023-02-23 00:52:10 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-23 00:52:17 +0100 |
commit | 7985b0a33ffc3e258da5d73f4056384c38e626fe (patch) | |
tree | 68908cb8ac2d49551f22bb4745bdf541156b8be5 /packages/taler-wallet-core | |
parent | 7879efcff70ea73935e139f4522aedadfe755c04 (diff) | |
download | wallet-core-7985b0a33ffc3e258da5d73f4056384c38e626fe.tar.xz |
taler-harness: deployment tooling for tipping
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/bank-api-client.ts | 60 |
1 files changed, 60 insertions, 0 deletions
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<void> { + 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<any> { + 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()); + } +} |