summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/deposits.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-02-12 19:30:59 +0100
committerFlorian Dold <florian@dold.me>2023-02-12 19:31:37 +0100
commit13f0442736479fb6ea8d1ecc7311cdac354a4de5 (patch)
treea39badc56b57a5039ec04267adb4df42b84cee7a /packages/taler-wallet-core/src/operations/deposits.ts
parent04ab9f37801f6a42b85581cc79667239d3fc79e5 (diff)
downloadwallet-core-13f0442736479fb6ea8d1ecc7311cdac354a4de5.tar.gz
wallet-core-13f0442736479fb6ea8d1ecc7311cdac354a4de5.tar.bz2
wallet-core-13f0442736479fb6ea8d1ecc7311cdac354a4de5.zip
harness: finish kyc test
We mock the KYC gateway now, use the new notification-based wallet API and the test is not experimental anymore.
Diffstat (limited to 'packages/taler-wallet-core/src/operations/deposits.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/deposits.ts40
1 files changed, 38 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts
index e97738b55..4ff6a65cd 100644
--- a/packages/taler-wallet-core/src/operations/deposits.ts
+++ b/packages/taler-wallet-core/src/operations/deposits.ts
@@ -38,8 +38,10 @@ import {
hashTruncate32,
hashWire,
HttpStatusCode,
+ j2s,
Logger,
MerchantContractTerms,
+ NotificationType,
parsePaytoUri,
PayCoinSelection,
PrepareDepositRequest,
@@ -61,7 +63,7 @@ import {
TransactionStatus,
} from "../db.js";
import { TalerError } from "../errors.js";
-import { checkKycStatus } from "../index.js";
+import { checkWithdrawalKycStatus, KycPendingInfo, KycUserType } from "../index.js";
import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "../util/http.js";
import { OperationAttemptResult } from "../util/retries.js";
@@ -80,6 +82,40 @@ import { getTotalRefreshCost } from "./refresh.js";
*/
const logger = new Logger("deposits.ts");
+
+export async function checkDepositKycStatus(
+ ws: InternalWalletState,
+ exchangeUrl: string,
+ kycInfo: KycPendingInfo,
+ userType: KycUserType,
+): Promise<void> {
+ 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, {
+ method: "GET",
+ });
+ if (kycStatusReq.status === HttpStatusCode.Ok) {
+ logger.warn("kyc requested, but already fulfilled");
+ return;
+ } else if (kycStatusReq.status === HttpStatusCode.Accepted) {
+ const kycStatus = await kycStatusReq.json();
+ logger.info(`kyc status: ${j2s(kycStatus)}`);
+ // FIXME: This error code is totally wrong
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_WITHDRAWAL_KYC_REQUIRED,
+ {
+ kycUrl: kycStatus.kyc_url,
+ },
+ `KYC check required for deposit`,
+ );
+ } else {
+ throw Error(`unexpected response from kyc-check (${kycStatusReq.status})`);
+ }
+}
+
/**
* @see {processDepositGroup}
*/
@@ -162,7 +198,7 @@ export async function processDepositGroup(
const paytoHash = encodeCrock(
hashTruncate32(stringToBytes(depositGroup.wire.payto_uri + "\0")),
);
- await checkKycStatus(
+ await checkDepositKycStatus(
ws,
perm.exchange_url,
{ paytoHash, requirementRow },