diff options
Diffstat (limited to 'packages/taler-wallet-core/src/bank-api-client.ts')
-rw-r--r-- | packages/taler-wallet-core/src/bank-api-client.ts | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/packages/taler-wallet-core/src/bank-api-client.ts b/packages/taler-wallet-core/src/bank-api-client.ts index 33f12172b..94ca2271b 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 { + checkSuccessResponseOrThrow, createPlatformHttpLib, HttpRequestLibrary, readSuccessResponseJsonOrThrow, @@ -97,6 +98,9 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> => .property("taler_withdraw_uri", codecForString()) .build("WithdrawalOperationInfo"); +/** + * @deprecated Use BankAccessApiClient or WireGatewayApi + */ export namespace BankApi { // FIXME: Move to BankAccessApi?! export async function registerAccount( @@ -142,37 +146,6 @@ export namespace BankApi { return await registerAccount(bank, username, password); } - export async function adminAddIncoming( - bank: BankServiceHandle, - params: { - exchangeBankAccount: HarnessExchangeBankAccount; - amount: string; - reservePub: string; - debitAccountPayto: string; - }, - ) { - let url = new URL( - `taler-wire-gateway/${params.exchangeBankAccount.accountName}/admin/add-incoming`, - bank.bankAccessApiBaseUrl, - ); - await bank.http.postJson( - url.href, - { - amount: params.amount, - reserve_pub: params.reservePub, - debit_account: params.debitAccountPayto, - }, - { - headers: { - Authorization: makeBasicAuthHeader( - params.exchangeBankAccount.accountName, - params.exchangeBankAccount.accountPassword, - ), - }, - }, - ); - } - export async function confirmWithdrawalOperation( bank: BankServiceHandle, bankUser: BankUser, @@ -227,6 +200,9 @@ export namespace BankApi { } } +/** + * @deprecated use BankAccessApiClient + */ export namespace BankAccessApi { export async function getAccountBalance( bank: BankServiceHandle, @@ -288,6 +264,45 @@ export interface BankAccessApiCreateTransactionRequest { paytoUri: string; } +export class WireGatewayApiClientArgs { + accountName: string; + accountPassword: string; + wireGatewayApiBaseUrl: string; +} + +export class WireGatewayApiClient { + httpLib = createPlatformHttpLib(); + + constructor(private args: WireGatewayApiClientArgs) {} + + async adminAddIncoming(params: { + amount: string; + reservePub: string; + debitAccountPayto: string; + }): Promise<void> { + let url = new URL( + `admin/add-incoming`, + this.args.wireGatewayApiBaseUrl, + ); + const resp = await this.httpLib.fetch(url.href, { + method: "POST", + body: { + amount: params.amount, + reserve_pub: params.reservePub, + debit_account: params.debitAccountPayto, + }, + headers: { + Authorization: makeBasicAuthHeader( + this.args.accountName, + this.args.accountPassword, + ), + }, + }); + logger.info(`add-incoming response status: ${resp.status}`); + await checkSuccessResponseOrThrow(resp); + } +} + export class BankAccessApiClient { httpLib = createPlatformHttpLib(); |