diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/transactions.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 3fb13d2a0..2570a4e5f 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -23,6 +23,7 @@ import { Amounts, constructPayPullUri, constructPayPushUri, + ExtendedStatus, Logger, OrderShortInfo, PaymentStatus, @@ -66,6 +67,7 @@ import { import { processDepositGroup } from "./deposits.js"; import { getExchangeDetails } from "./exchanges.js"; import { + abortPay, expectProposalDownload, extractContractData, processPurchasePay, @@ -352,6 +354,10 @@ function buildTransactionForPushPaymentDebit( summary: contractTerms.summary, }, frozen: false, + extendedStatus: + pi.status != PeerPushPaymentInitiationStatus.PurseCreated + ? ExtendedStatus.Pending + : ExtendedStatus.Done, pending: pi.status != PeerPushPaymentInitiationStatus.PurseCreated, timestamp: pi.timestampCreated, talerUri: constructPayPushUri({ @@ -377,6 +383,7 @@ function buildTransactionForPullPaymentDebit( exchangeBaseUrl: pi.exchangeBaseUrl, frozen: false, pending: false, + extendedStatus: ExtendedStatus.Done, info: { expiration: pi.contractTerms.purse_expiration, summary: pi.contractTerms.summary, @@ -401,6 +408,7 @@ function buildTransactionForPullPaymentCredit( amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), amountRaw: Amounts.stringify(wsr.instructedAmount), exchangeBaseUrl: wsr.exchangeBaseUrl, + extendedStatus: ExtendedStatus.Done, pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, info: { @@ -435,6 +443,9 @@ function buildTransactionForPushPaymentCredit( expiration: wsr.wgInfo.contractTerms.purse_expiration, summary: wsr.wgInfo.contractTerms.summary, }, + extendedStatus: wsr.timestampFinish + ? ExtendedStatus.Done + : ExtendedStatus.Pending, pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, transactionId: makeTransactionId( @@ -464,6 +475,9 @@ function buildTransactionForBankIntegratedWithdraw( bankConfirmationUrl: wsr.wgInfo.bankInfo.confirmUrl, }, exchangeBaseUrl: wsr.exchangeBaseUrl, + extendedStatus: wsr.timestampFinish + ? ExtendedStatus.Done + : ExtendedStatus.Pending, pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, transactionId: makeTransactionId( @@ -504,6 +518,9 @@ function buildTransactionForManualWithdraw( exchangePaytoUris, }, exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl, + extendedStatus: withdrawalGroup.timestampFinish + ? ExtendedStatus.Done + : ExtendedStatus.Pending, pending: !withdrawalGroup.timestampFinish, timestamp: withdrawalGroup.timestampStart, transactionId: makeTransactionId( @@ -523,6 +540,9 @@ function buildTransactionForDeposit( type: TransactionType.Deposit, amountRaw: Amounts.stringify(dg.effectiveDepositAmount), amountEffective: Amounts.stringify(dg.totalPayCost), + extendedStatus: dg.timestampFinished + ? ExtendedStatus.Done + : ExtendedStatus.Pending, pending: !dg.timestampFinished, frozen: false, timestamp: dg.timestampCreated, @@ -547,6 +567,9 @@ function buildTransactionForTip( type: TransactionType.Tip, amountEffective: Amounts.stringify(tipRecord.tipAmountEffective), amountRaw: Amounts.stringify(tipRecord.tipAmountRaw), + extendedStatus: tipRecord.pickedUpTimestamp + ? ExtendedStatus.Done + : ExtendedStatus.Pending, pending: !tipRecord.pickedUpTimestamp, frozen: false, timestamp: tipRecord.acceptedTimestamp, @@ -654,6 +677,7 @@ async function buildTransactionForRefund( purchaseRecord.refundAmountAwaiting === undefined ? undefined : Amounts.stringify(purchaseRecord.refundAmountAwaiting), + extendedStatus: ExtendedStatus.Done, pending: false, frozen: false, ...(ort?.lastError ? { error: ort.lastError } : {}), @@ -710,6 +734,33 @@ async function buildTransactionForPurchase( checkDbInvariant(!!timestamp); checkDbInvariant(!!purchaseRecord.payInfo); + + let status: ExtendedStatus; + switch (purchaseRecord.purchaseStatus) { + case PurchaseStatus.AbortingWithRefund: + status = ExtendedStatus.Aborting; + break; + case PurchaseStatus.Paid: + case PurchaseStatus.RepurchaseDetected: + status = ExtendedStatus.Done; + break; + case PurchaseStatus.DownloadingProposal: + case PurchaseStatus.QueryingRefund: + case PurchaseStatus.Proposed: + case PurchaseStatus.Paying: + status = ExtendedStatus.Pending; + break; + case PurchaseStatus.ProposalDownloadFailed: + status = ExtendedStatus.Failed; + break; + case PurchaseStatus.PaymentAbortFinished: + status = ExtendedStatus.Aborted; + break; + default: + // FIXME: Should we have some unknown status? + status = ExtendedStatus.Pending; + } + return { type: TransactionType.Payment, amountRaw: Amounts.stringify(contractData.amount), @@ -723,6 +774,7 @@ async function buildTransactionForPurchase( status: purchaseRecord.timestampFirstSuccessfulPay ? PaymentStatus.Paid : PaymentStatus.Accepted, + extendedStatus: status, pending: purchaseRecord.purchaseStatus === PurchaseStatus.Paying, refunds, timestamp, @@ -1163,3 +1215,19 @@ export async function deleteTransaction( throw Error(`can't delete a '${unknownTxType}' transaction`); } } + +export async function abortTransaction( + ws: InternalWalletState, + transactionId: string, + forceImmediateAbort?: boolean, +): Promise<void> { + const { type, args: rest } = parseId("txn", transactionId); + + if (type === TransactionType.Payment) { + const proposalId = rest[0]; + await abortPay(ws, proposalId, forceImmediateAbort); + } else { + const unknownTxType: any = type; + throw Error(`can't abort a '${unknownTxType}' transaction`); + } +} |