aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay-peer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer.ts103
1 files changed, 100 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts
index 73dd3bf2c..ff0e15c00 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer.ts
@@ -73,10 +73,15 @@ import {
codecForTimestamp,
CancellationToken,
NotificationType,
+ HttpStatusCode,
+ codecForWalletKycUuid,
+ WalletKycUuid,
} from "@gnu-taler/taler-util";
import { SpendCoinDetails } from "../crypto/cryptoImplementation.js";
import {
DenominationRecord,
+ KycPendingInfo,
+ KycUserType,
OperationStatus,
PeerPullPaymentIncomingStatus,
PeerPullPaymentInitiationRecord,
@@ -115,6 +120,7 @@ import { getPeerPaymentBalanceDetailsInTx } from "./balance.js";
import { updateExchangeFromUrl } from "./exchanges.js";
import { getTotalRefreshCost } from "./refresh.js";
import {
+ checkWithdrawalKycStatus,
getExchangeWithdrawalInfo,
internalCreateWithdrawalGroup,
processWithdrawalGroup,
@@ -866,6 +872,23 @@ export async function processPeerPushCredit(
const amount = Amounts.parseOrThrow(contractTerms.amount);
+ if (
+ peerInc.status === PeerPushPaymentIncomingStatus.KycRequired &&
+ peerInc.kycInfo
+ ) {
+ const txId = makeTransactionId(
+ TransactionType.PeerPushCredit,
+ peerInc.peerPushPaymentIncomingId,
+ );
+ await checkWithdrawalKycStatus(
+ ws,
+ peerInc.exchangeBaseUrl,
+ txId,
+ peerInc.kycInfo,
+ "individual",
+ );
+ }
+
const mergeReserveInfo = await getMergeReserveInfo(ws, {
exchangeBaseUrl: peerInc.exchangeBaseUrl,
});
@@ -902,10 +925,40 @@ export async function processPeerPushCredit(
reserve_sig: sigRes.accountSig,
};
- const mergeHttpReq = await ws.http.postJson(mergePurseUrl.href, mergeReq);
+ const mergeHttpResp = await ws.http.postJson(mergePurseUrl.href, mergeReq);
+
+ if (mergeHttpResp.status === HttpStatusCode.UnavailableForLegalReasons) {
+ const respJson = await mergeHttpResp.json();
+ const kycPending = codecForWalletKycUuid().decode(respJson);
+ logger.info(`kyc uuid response: ${j2s(kycPending)}`);
+
+ await ws.db
+ .mktx((x) => [x.peerPushPaymentIncoming])
+ .runReadWrite(async (tx) => {
+ const peerInc = await tx.peerPushPaymentIncoming.get(
+ peerPushPaymentIncomingId,
+ );
+ if (!peerInc) {
+ return;
+ }
+ peerInc.kycInfo = {
+ paytoHash: kycPending.h_payto,
+ requirementRow: kycPending.requirement_row,
+ };
+ peerInc.status = PeerPushPaymentIncomingStatus.KycRequired;
+ await tx.peerPushPaymentIncoming.put(peerInc);
+ });
+ return {
+ type: OperationAttemptResultType.Pending,
+ result: undefined,
+ };
+ }
logger.trace(`merge request: ${j2s(mergeReq)}`);
- const res = await readSuccessResponseJsonOrThrow(mergeHttpReq, codecForAny());
+ const res = await readSuccessResponseJsonOrThrow(
+ mergeHttpResp,
+ codecForAny(),
+ );
logger.trace(`merge response: ${j2s(res)}`);
await internalCreateWithdrawalGroup(ws, {
@@ -932,7 +985,10 @@ export async function processPeerPushCredit(
if (!peerInc) {
return;
}
- if (peerInc.status === PeerPushPaymentIncomingStatus.Accepted) {
+ if (
+ peerInc.status === PeerPushPaymentIncomingStatus.Accepted ||
+ peerInc.status === PeerPushPaymentIncomingStatus.KycRequired
+ ) {
peerInc.status = PeerPushPaymentIncomingStatus.WithdrawalCreated;
}
await tx.peerPushPaymentIncoming.put(peerInc);
@@ -1423,6 +1479,22 @@ export async function processPeerPullCredit(
return {
type: OperationAttemptResultType.Longpoll,
};
+ case PeerPullPaymentInitiationStatus.KycRequired: {
+ if (pullIni.kycInfo) {
+ const txId = makeTransactionId(
+ TransactionType.PeerPullCredit,
+ pullIni.pursePub,
+ );
+ await checkWithdrawalKycStatus(
+ ws,
+ pullIni.exchangeBaseUrl,
+ txId,
+ pullIni.kycInfo,
+ "individual",
+ );
+ }
+ break;
+ }
case PeerPullPaymentInitiationStatus.Initial:
break;
default:
@@ -1496,6 +1568,31 @@ export async function processPeerPullCredit(
reservePurseReqBody,
);
+ if (httpResp.status === HttpStatusCode.UnavailableForLegalReasons) {
+ const respJson = await httpResp.json();
+ const kycPending = codecForWalletKycUuid().decode(respJson);
+ logger.info(`kyc uuid response: ${j2s(kycPending)}`);
+
+ await ws.db
+ .mktx((x) => [x.peerPullPaymentInitiations])
+ .runReadWrite(async (tx) => {
+ const peerIni = await tx.peerPullPaymentInitiations.get(pursePub);
+ if (!peerIni) {
+ return;
+ }
+ peerIni.kycInfo = {
+ paytoHash: kycPending.h_payto,
+ requirementRow: kycPending.requirement_row,
+ };
+ peerIni.status = PeerPullPaymentInitiationStatus.KycRequired;
+ await tx.peerPullPaymentInitiations.put(peerIni);
+ });
+ return {
+ type: OperationAttemptResultType.Pending,
+ result: undefined,
+ };
+ }
+
const resp = await readSuccessResponseJsonOrThrow(httpResp, codecForAny());
logger.info(`reserve merge response: ${j2s(resp)}`);