From 8616c67de8de79a39298299eac9dc368749bfc7a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 4 Dec 2023 09:41:36 -0300 Subject: bank api sync --- packages/taler-util/src/http-client/bank-core.ts | 12 ++++- .../taler-util/src/http-client/bank-integration.ts | 3 +- packages/taler-util/src/http-client/types.ts | 53 ++++++++++++++++------ packages/taler-util/src/http-client/utils.ts | 2 - 4 files changed, 50 insertions(+), 20 deletions(-) (limited to 'packages') diff --git a/packages/taler-util/src/http-client/bank-core.ts b/packages/taler-util/src/http-client/bank-core.ts index 4557a34e4..2b67fc638 100644 --- a/packages/taler-util/src/http-client/bank-core.ts +++ b/packages/taler-util/src/http-client/bank-core.ts @@ -30,7 +30,7 @@ import { TalerBankConversionHttpClient } from "./bank-conversion.js"; import { TalerBankIntegrationHttpClient } from "./bank-integration.js"; import { TalerRevenueHttpClient } from "./bank-revenue.js"; import { TalerWireGatewayHttpClient } from "./bank-wire.js"; -import { AccessToken, PaginationParams, TalerCorebankApi, UserAndToken, codecForAccountData, codecForBankAccountCreateWithdrawalResponse, codecForBankAccountTransactionInfo, codecForBankAccountTransactionsResponse, codecForCashoutPending, codecForCashoutStatusResponse, codecForCashouts, codecForCoreBankConfig, codecForCreateTransactionResponse, codecForGlobalCashouts, codecForListBankAccountsResponse, codecForMonitorResponse, codecForPublicAccountsResponse, codecForRegisterAccountResponse, codecForWithdrawalPublicInfo } from "./types.js"; +import { AccessToken, PaginationParams, TalerCorebankApi, UserAndToken, WithdrawalOperationStatus, codecForAccountData, codecForBankAccountCreateWithdrawalResponse, codecForBankAccountTransactionInfo, codecForBankAccountTransactionsResponse, codecForCashoutPending, codecForCashoutStatusResponse, codecForCashouts, codecForCoreBankConfig, codecForCreateTransactionResponse, codecForGlobalCashouts, codecForListBankAccountsResponse, codecForMonitorResponse, codecForPublicAccountsResponse, codecForRegisterAccountResponse, codecForWithdrawalPublicInfo } from "./types.js"; import { addPaginationParams, makeBearerTokenAuthHeader } from "./utils.js"; @@ -103,6 +103,7 @@ export class TalerCoreBankHttpClient { case TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE: return opKnownFailure("payto-already-exists", resp); case TalerErrorCode.BANK_UNALLOWED_DEBIT: return opKnownFailure("insufficient-funds", resp); case TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT: return opKnownFailure("username-reserved", resp); + case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return opKnownFailure("user-cant-set-debt", resp); default: return opUnknownFailure(resp, body) } } @@ -425,8 +426,15 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#get--withdrawals-$WITHDRAWAL_ID * */ - async getWithdrawalById(wid: string) { + async getWithdrawalById(wid: string, wait?: { + old_state?: WithdrawalOperationStatus, + timeoutMs: number + }) { const url = new URL(`withdrawals/${wid}`, this.baseUrl); + if (wait) { + url.searchParams.set("long_poll_ms", String(wait.timeoutMs)) + url.searchParams.set("old_state", !wait.old_state ? "pending" : wait.old_state) + } const resp = await this.httpLib.fetch(url.href, { method: "GET", }); diff --git a/packages/taler-util/src/http-client/bank-integration.ts b/packages/taler-util/src/http-client/bank-integration.ts index d552d3b76..8131b36b6 100644 --- a/packages/taler-util/src/http-client/bank-integration.ts +++ b/packages/taler-util/src/http-client/bank-integration.ts @@ -6,6 +6,7 @@ import { TalerErrorCode } from "../taler-error-codes.js"; import { codecForTalerErrorDetail } from "../wallet-types.js"; import { TalerBankIntegrationApi, + WithdrawalOperationStatus, codecForBankWithdrawalOperationPostResponse, codecForBankWithdrawalOperationStatus, codecForIntegrationBankConfig @@ -47,7 +48,7 @@ export class TalerBankIntegrationHttpClient { * */ async getWithdrawalOperationById(woid: string, wait?: { - old_state?: "pending" | "selected" | "aborted" | "confirmed", + old_state?: WithdrawalOperationStatus, timeoutMs: number }) { const url = new URL(`withdrawal-operation/${woid}`, this.baseUrl); diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index d9cc8ec90..e25bd6ebd 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -274,6 +274,7 @@ export const codecForCoreBankConfig = (): Codec => .property("allow_conversion", codecForBoolean()) .property("allow_deletions", codecForBoolean()) .property("allow_registrations", codecForBoolean()) + .property("default_debit_threshold", codecForAmountString()) .property("currency_specification", codecForCurrencySpecificiation()) .property("currency", codecForString()) .build("TalerCorebankApi.Config"); @@ -358,6 +359,15 @@ export const codecForWithdrawalPublicInfo = (): Codec => buildCodecForObject() .property("username", codecForString(),) + .property("amount", codecForAmountString(),) + .property("selected_exchange_account", codecOptional(codecForPaytoString())) + .property("selected_reserve_pub", codecOptional(codecForString())) + .property("status", codecForEither( + codecForConstString("pending"), + codecForConstString("selected"), + codecForConstString("aborted"), + codecForConstString("confirmed"), + ),) .build("TalerCorebankApi.WithdrawalPublicInfo"); export const codecForBankAccountTransactionsResponse = @@ -408,20 +418,6 @@ export const codecForBankAccountCreateWithdrawalResponse = .property("withdrawal_id", codecForString()) .build("TalerCorebankApi.BankAccountCreateWithdrawalResponse"); -// export const codecForBankAccountGetWithdrawalResponse = -// (): Codec => -// buildCodecForObject() -// .property("amount", codecForAmountString()) -// .property("aborted", codecForBoolean()) -// .property("confirmation_done", codecForBoolean()) -// .property( -// "selected_exchange_account", -// codecOptional(codecForPaytoString()), -// ) -// .property("selected_reserve_pub", codecOptional(codecForString())) -// .property("selection_done", codecForBoolean()) -// .build("TalerCorebankApi.BankAccountGetWithdrawalResponse"); - export const codecForCashoutPending = (): Codec => buildCodecForObject() @@ -874,6 +870,8 @@ enum TanChannel { SMS = "sms", EMAIL = "email", } +export type WithdrawalOperationStatus = "pending" | "selected" | "aborted" | "confirmed" + export namespace TalerWireGatewayApi { export interface TransferResponse { @@ -1199,7 +1197,6 @@ export namespace TalerBankIntegrationApi { name: "taler-bank-integration"; } - export type WithdrawalOperationStatus = "pending" | "selected" | "aborted" | "confirmed" export interface BankWithdrawalOperationStatus { // Current status of the operation // pending: the operation is pending parameters selection (exchange and reserve public key) @@ -1292,6 +1289,9 @@ export namespace TalerCorebankApi { // If 'false' only the admin can allow_registrations: boolean; + // Default debt limit for newly created accounts + default_debit_threshold: AmountString; + // If 'true' account can delete themselves // If 'false' only the admin can delete accounts allow_deletions: boolean; @@ -1315,8 +1315,27 @@ export namespace TalerCorebankApi { taler_withdraw_uri: TalerActionString; } export interface WithdrawalPublicInfo { + // Current status of the operation + // pending: the operation is pending parameters selection (exchange and reserve public key) + // selected: the operations has been selected and is pending confirmation + // aborted: the operation has been aborted + // confirmed: the transfer has been confirmed and registered by the bank + status: WithdrawalOperationStatus; + + // Amount that will be withdrawn with this operation + // (raw amount without fee considerations). + amount: AmountString; + // Account username username: string; + + // Reserve public key selected by the exchange, + // only non-null if status is selected or confirmed. + selected_reserve_pub?: string; + + // Exchange account selected by the wallet + // only non-null if status is selected or confirmed. + selected_exchange_account?: PaytoString; } @@ -1398,6 +1417,10 @@ export namespace TalerCorebankApi { // Internal payto URI of this bank account. // Used mostly for testing. internal_payto_uri?: PaytoString; + + // If present, set the max debit allowed for this user + // Only admin can change this property. + debit_threshold?: AmountString; } export interface ChallengeContactData { diff --git a/packages/taler-util/src/http-client/utils.ts b/packages/taler-util/src/http-client/utils.ts index 32a9c4009..ab6f809ef 100644 --- a/packages/taler-util/src/http-client/utils.ts +++ b/packages/taler-util/src/http-client/utils.ts @@ -1,6 +1,4 @@ import { base64FromArrayBuffer } from "../base64.js"; -import { HttpResponse, readSuccessResponseJsonOrThrow, readTalerErrorResponse } from "../http-common.js"; -import { Codec, TalerError, TalerErrorCode, TalerErrorDetail } from "../index.js"; import { stringToBytes } from "../taler-crypto.js"; import { AccessToken, PaginationParams } from "./types.js"; -- cgit v1.2.3