diff options
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-merchant.ts | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts index 13fb2cb18..1614677ed 100644 --- a/packages/taler-wallet-core/src/operations/pay-merchant.ts +++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts @@ -552,7 +552,7 @@ async function processDownloadProposal( return { oldTxState, newTxState, - } + }; }); notifyTransition(ws, transactionId, transitionInfo); @@ -659,7 +659,7 @@ async function createPurchase( return { oldTxState, newTxState, - } + }; }); const transactionId = constructTransactionIdentifier({ @@ -730,7 +730,7 @@ async function storeFirstPaySuccess( return { oldTxState, newTxState, - } + }; }); notifyTransition(ws, transactionId, transitionInfo); } @@ -1325,6 +1325,11 @@ export async function confirmPay( throw Error(`proposal with id ${proposalId} not found`); } + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.Payment, + proposalId, + }); + const d = await expectProposalDownload(ws, proposal); if (!d) { throw Error("proposal is in invalid state"); @@ -1395,7 +1400,7 @@ export async function confirmPay( `recording payment on ${proposal.orderId} with session ID ${sessionId}`, ); - await ws.db + const transitionInfo = await ws.db .mktx((x) => [ x.purchases, x.coins, @@ -1408,6 +1413,7 @@ export async function confirmPay( if (!p) { return; } + const oldTxState = computePayMerchantTransactionState(p); switch (p.purchaseStatus) { case PurchaseStatus.Proposed: p.payInfo = { @@ -1437,8 +1443,12 @@ export async function confirmPay( default: break; } + const newTxState = computePayMerchantTransactionState(p); + return { oldTxState, newTxState }; }); + notifyTransition(ws, transactionId, transitionInfo); + ws.notify({ type: NotificationType.ProposalAccepted, proposalId: proposal.proposalId, @@ -1450,7 +1460,6 @@ export async function confirmPay( export async function processPurchase( ws: InternalWalletState, proposalId: string, - options: Record<any, never> = {}, ): Promise<OperationAttemptResult> { const purchase = await ws.db .mktx((x) => [x.purchases]) @@ -1682,37 +1691,44 @@ export async function refuseProposal( ws: InternalWalletState, proposalId: string, ): Promise<void> { - const success = await ws.db + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.Payment, + proposalId, + }); + const transitionInfo = await ws.db .mktx((x) => [x.purchases]) .runReadWrite(async (tx) => { const proposal = await tx.purchases.get(proposalId); if (!proposal) { logger.trace(`proposal ${proposalId} not found, won't refuse proposal`); - return false; + return undefined; } if (proposal.purchaseStatus !== PurchaseStatus.Proposed) { - return false; + return undefined; } + const oldTxState = computePayMerchantTransactionState(proposal); proposal.purchaseStatus = PurchaseStatus.AbortedProposalRefused; + const newTxState = computePayMerchantTransactionState(proposal); await tx.purchases.put(proposal); - return true; - }); - if (success) { - ws.notify({ - type: NotificationType.ProposalRefused, + return { oldTxState, newTxState }; }); - } + + notifyTransition(ws, transactionId, transitionInfo); } export async function abortPayMerchant( ws: InternalWalletState, proposalId: string, ): Promise<void> { + const transactionId = constructTransactionIdentifier({ + tag: TransactionType.Payment, + proposalId, + }); const opId = constructTaskIdentifier({ tag: PendingTaskType.Purchase, proposalId, }); - await ws.db + const transitionInfo = await ws.db .mktx((x) => [ x.purchases, x.refreshGroups, @@ -1726,6 +1742,7 @@ export async function abortPayMerchant( if (!purchase) { throw Error("purchase not found"); } + const oldTxState = computePayMerchantTransactionState(purchase); const oldStatus = purchase.purchaseStatus; if (purchase.timestampFirstSuccessfulPay) { // No point in aborting it. We don't even report an error. @@ -1757,8 +1774,10 @@ export async function abortPayMerchant( } } await tx.operationRetries.delete(opId); + const newTxState = computePayMerchantTransactionState(purchase); + return { oldTxState, newTxState }; }); - + notifyTransition(ws, transactionId, transitionInfo); ws.workAvailable.trigger(); } |