diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 3c3878792..2c91d4184 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -116,9 +116,7 @@ import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION, } from "../versions.js"; -import { - makeTransactionId, -} from "./common.js"; +import { makeTransactionId } from "./common.js"; import { getExchangeDetails, getExchangePaytoUri, @@ -1226,9 +1224,14 @@ export async function processWithdrawalGroup( if (numKycRequired > 0) { if (kycInfo) { + const txId = makeTransactionId( + TransactionType.Withdrawal, + withdrawalGroup.withdrawalGroupId, + ); await checkWithdrawalKycStatus( ws, - withdrawalGroup, + withdrawalGroup.exchangeBaseUrl, + txId, kycInfo, "individual", ); @@ -1271,42 +1274,44 @@ export async function processWithdrawalGroup( export async function checkWithdrawalKycStatus( ws: InternalWalletState, - wg: WithdrawalGroupRecord, + exchangeUrl: string, + txId: string, kycInfo: KycPendingInfo, userType: KycUserType, ): Promise<void> { - const exchangeUrl = wg.exchangeBaseUrl; const url = new URL( `kyc-check/${kycInfo.requirementRow}/${kycInfo.paytoHash}/${userType}`, exchangeUrl, ); logger.info(`kyc url ${url.href}`); - const kycStatusReq = await ws.http.fetch(url.href, { + const kycStatusRes = await ws.http.fetch(url.href, { method: "GET", }); - if (kycStatusReq.status === HttpStatusCode.Ok) { + if ( + kycStatusRes.status === HttpStatusCode.Ok || + //FIXME: NoContent is not expected https://docs.taler.net/core/api-exchange.html#post--purses-$PURSE_PUB-merge + // remove after the exchange is fixed or clarified + kycStatusRes.status === HttpStatusCode.NoContent + ) { logger.warn("kyc requested, but already fulfilled"); return; - } else if (kycStatusReq.status === HttpStatusCode.Accepted) { - const kycStatus = await kycStatusReq.json(); + } else if (kycStatusRes.status === HttpStatusCode.Accepted) { + const kycStatus = await kycStatusRes.json(); logger.info(`kyc status: ${j2s(kycStatus)}`); ws.notify({ - type: NotificationType.WithdrawalGroupKycRequested, + type: NotificationType.KycRequested, kycUrl: kycStatus.kyc_url, - transactionId: makeTransactionId( - TransactionType.Withdrawal, - wg.withdrawalGroupId, - ), + transactionId: txId, }); throw TalerError.fromDetail( - TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, + TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED, //FIXME: another error code or rename for merge { kycUrl: kycStatus.kyc_url, }, - `KYC check required for withdrawal`, + `KYC check required for transfer`, ); } else { - throw Error(`unexpected response from kyc-check (${kycStatusReq.status})`); + throw Error(`unexpected response from kyc-check (${kycStatusRes.status})`); } } |