aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-12-04 09:41:36 -0300
committerSebastian <sebasjm@gmail.com>2023-12-04 09:43:22 -0300
commit8616c67de8de79a39298299eac9dc368749bfc7a (patch)
tree415dc77c468e64142ce779b1c0e23b005648ac2b /packages
parentfb2cda63ae5532788eb452f668f15fb5b0d27a13 (diff)
downloadwallet-core-8616c67de8de79a39298299eac9dc368749bfc7a.tar.xz
bank api sync
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-util/src/http-client/bank-core.ts12
-rw-r--r--packages/taler-util/src/http-client/bank-integration.ts3
-rw-r--r--packages/taler-util/src/http-client/types.ts53
-rw-r--r--packages/taler-util/src/http-client/utils.ts2
4 files changed, 50 insertions, 20 deletions
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<TalerCorebankApi.Config> =>
.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<TalerCorebankApi.WithdrawalPublicInfo> =>
buildCodecForObject<TalerCorebankApi.WithdrawalPublicInfo>()
.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<TalerCorebankApi.BankAccountGetWithdrawalResponse> =>
-// buildCodecForObject<TalerCorebankApi.BankAccountGetWithdrawalResponse>()
-// .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<TalerCorebankApi.CashoutPending> =>
buildCodecForObject<TalerCorebankApi.CashoutPending>()
@@ -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";