From 23fca6d8677a1e88dad426691fbe1033595f16a3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 2 May 2023 13:24:51 +0200 Subject: [PATCH] wallet-core: report pay-merchant DD37 state --- packages/taler-util/src/transactions-types.ts | 9 +++ .../src/operations/pay-merchant.ts | 63 ++++++++++++++++++- .../src/operations/transactions.ts | 3 +- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/packages/taler-util/src/transactions-types.ts b/packages/taler-util/src/transactions-types.ts index 5c5a6a913..998500f12 100644 --- a/packages/taler-util/src/transactions-types.ts +++ b/packages/taler-util/src/transactions-types.ts @@ -89,6 +89,8 @@ export enum TransactionMajorState { Aborting = "aborting", Aborted = "aborted", Suspended = "suspended", + SuspendedDeletable = "suspended-deletable", + Dialog = "dialog", SuspendedAborting = "suspended-aborting", Failed = "failed", // Only used for the notification, never in the transaction history @@ -104,15 +106,22 @@ export enum TransactionMinorState { KycRequired = "kyc", AmlRequired = "aml", Track = "track", + Pay = "pay", + RebindSession = "rebind-session", Refresh = "refresh", Pickup = "pickup", + AutoRefund = "auto-refund", User = "user", Bank = "bank", + ClaimProposal = "claim-proposal", + CheckRefunds = "check-refunds", + Repurchase = "repurchase", BankRegisterReserve = "bank-register-reserve", BankConfirmTransfer = "bank-confirm-transfer", WithdrawCoins = "withdraw-coins", ExchangeWaitReserve = "exchange-wait-reserve", AbortingBank = "aborting-bank", + Refused = "refused", } export interface TransactionsResponse { diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index e6ade08aa..d2713dc9d 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -71,6 +71,8 @@ import { TalerErrorDetail, TalerProtocolTimestamp, TalerProtocolViolationError, + TransactionMajorState, + TransactionMinorState, TransactionState, TransactionType, URL, @@ -2477,8 +2479,65 @@ export async function abortPay( }); } -export function computeWithdrawalTransactionStatus( +export function computePayMerchantTransactionState( purchaseRecord: PurchaseRecord, ): TransactionState { - throw Error("not implemented"); + switch (purchaseRecord.purchaseStatus) { + case PurchaseStatus.DownloadingProposal: + return { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.ClaimProposal, + }; + case PurchaseStatus.Paid: + return { + major: TransactionMajorState.Done, + }; + case PurchaseStatus.PaymentAbortFinished: + return { + major: TransactionMajorState.Aborted, + }; + case PurchaseStatus.Proposed: + return { + major: TransactionMajorState.Dialog, + }; + case PurchaseStatus.ProposalDownloadFailed: + return { + major: TransactionMajorState.Failed, + minor: TransactionMinorState.ClaimProposal, + }; + case PurchaseStatus.RepurchaseDetected: + return { + major: TransactionMajorState.Failed, + minor: TransactionMinorState.Repurchase, + }; + case PurchaseStatus.AbortingWithRefund: + return { + major: TransactionMajorState.Aborting, + }; + case PurchaseStatus.Paying: + return { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.Pay, + }; + case PurchaseStatus.PayingReplay: + return { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.RebindSession, + }; + case PurchaseStatus.ProposalRefused: + return { + major: TransactionMajorState.Failed, + minor: TransactionMinorState.Refused, + }; + case PurchaseStatus.QueryingAutoRefund: + return { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.AutoRefund, + }; + case PurchaseStatus.QueryingRefund: + return { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.CheckRefunds, + }; + } } diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 02b0b56ba..c122bb651 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -88,6 +88,7 @@ import { import { getExchangeDetails } from "./exchanges.js"; import { abortPay, + computePayMerchantTransactionState, expectProposalDownload, extractContractData, processPurchasePay, @@ -1030,7 +1031,7 @@ async function buildTransactionForPurchase( return { type: TransactionType.Payment, - txState: mkTxStateUnknown(), + txState: computePayMerchantTransactionState(purchaseRecord), amountRaw: Amounts.stringify(contractData.amount), amountEffective: Amounts.stringify(purchaseRecord.payInfo.totalPayCost), totalRefundRaw: Amounts.stringify(totalRefund.raw),