aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay-merchant.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-06-30 16:14:58 +0200
committerFlorian Dold <florian@dold.me>2023-06-30 16:14:58 +0200
commitd4ee96138774e8bc469f172bbb6276af89d6f240 (patch)
treeeda5bc6833306727f711cc5aedd5f307fa8b1f67 /packages/taler-wallet-core/src/operations/pay-merchant.ts
parent7523ffa9105f71a6a4c201d3ee46dbfccc929cea (diff)
downloadwallet-core-d4ee96138774e8bc469f172bbb6276af89d6f240.tar.xz
wallet-core: rename OperationAttempt->TaskRun, do not allow task result values anymore
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-merchant.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-merchant.ts79
1 files changed, 32 insertions, 47 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts
index f2df08247..c74fcedcf 100644
--- a/packages/taler-wallet-core/src/operations/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts
@@ -112,8 +112,8 @@ import { checkDbInvariant } from "../util/invariants.js";
import { GetReadOnlyAccess } from "../util/query.js";
import {
constructTaskIdentifier,
- OperationAttemptResult,
- OperationAttemptResultType,
+ TaskRunResult,
+ TaskRunResultType,
RetryInfo,
TaskIdentifiers,
} from "./common.js";
@@ -325,7 +325,7 @@ export function extractContractData(
async function processDownloadProposal(
ws: InternalWalletState,
proposalId: string,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const proposal = await ws.db
.mktx((x) => [x.purchases])
.runReadOnly(async (tx) => {
@@ -333,17 +333,11 @@ async function processDownloadProposal(
});
if (!proposal) {
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
}
if (proposal.purchaseStatus != PurchaseStatus.PendingDownloadingProposal) {
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
}
const transactionId = constructTransactionIdentifier({
@@ -560,10 +554,7 @@ async function processDownloadProposal(
notifyTransition(ws, transactionId, transitionInfo);
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
}
/**
@@ -1065,7 +1056,7 @@ export async function checkPaymentByProposalId(
notifyTransition(ws, transactionId, transitionInfo);
// FIXME: What about error handling?! This doesn't properly store errors in the DB.
const r = await processPurchasePay(ws, proposalId, { forceNow: true });
- if (r.type !== OperationAttemptResultType.Finished) {
+ if (r.type !== TaskRunResultType.Finished) {
// FIXME: This does not surface the original error
throw Error("submitting pay failed");
}
@@ -1253,7 +1244,7 @@ export async function runPayForConfirmPay(
});
logger.trace(`processPurchasePay response type ${res.type}`);
switch (res.type) {
- case OperationAttemptResultType.Finished: {
+ case TaskRunResultType.Finished: {
const purchase = await ws.db
.mktx((x) => [x.purchases])
.runReadOnly(async (tx) => {
@@ -1272,7 +1263,7 @@ export async function runPayForConfirmPay(
}),
};
}
- case OperationAttemptResultType.Error: {
+ case TaskRunResultType.Error: {
// We hide transient errors from the caller.
const opRetry = await ws.db
.mktx((x) => [x.operationRetries])
@@ -1286,7 +1277,7 @@ export async function runPayForConfirmPay(
}),
};
}
- case OperationAttemptResultType.Pending:
+ case TaskRunResultType.Pending:
logger.trace("reporting pending as confirmPay response");
return {
type: ConfirmPayResultType.Pending,
@@ -1296,7 +1287,7 @@ export async function runPayForConfirmPay(
}),
lastError: undefined,
};
- case OperationAttemptResultType.Longpoll:
+ case TaskRunResultType.Longpoll:
throw Error("unexpected processPurchasePay result (longpoll)");
default:
assertUnreachable(res);
@@ -1456,7 +1447,7 @@ export async function confirmPay(
export async function processPurchase(
ws: InternalWalletState,
proposalId: string,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const purchase = await ws.db
.mktx((x) => [x.purchases])
.runReadOnly(async (tx) => {
@@ -1464,7 +1455,7 @@ export async function processPurchase(
});
if (!purchase) {
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
@@ -1504,10 +1495,7 @@ export async function processPurchase(
case PurchaseStatus.SuspendedQueryingAutoRefund:
case PurchaseStatus.SuspendedQueryingRefund:
case PurchaseStatus.FailedAbort:
- return {
- type: OperationAttemptResultType.Finished,
- result: undefined,
- };
+ return TaskRunResult.finished();
default:
assertUnreachable(purchase.purchaseStatus);
// throw Error(`unexpected purchase status (${purchase.purchaseStatus})`);
@@ -1518,7 +1506,7 @@ export async function processPurchasePay(
ws: InternalWalletState,
proposalId: string,
options: unknown = {},
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const purchase = await ws.db
.mktx((x) => [x.purchases])
.runReadOnly(async (tx) => {
@@ -1526,7 +1514,7 @@ export async function processPurchasePay(
});
if (!purchase) {
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: {
// FIXME: allocate more specific error code
code: TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
@@ -1541,7 +1529,7 @@ export async function processPurchasePay(
case PurchaseStatus.PendingPayingReplay:
break;
default:
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
logger.trace(`processing purchase pay ${proposalId}`);
@@ -1589,7 +1577,7 @@ export async function processPurchasePay(
if (resp.status >= 500 && resp.status <= 599) {
const errDetails = await readUnexpectedResponseDetails(resp);
return {
- type: OperationAttemptResultType.Error,
+ type: TaskRunResultType.Error,
errorDetail: makeErrorDetail(
TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR,
{
@@ -1613,10 +1601,7 @@ export async function processPurchasePay(
// FIXME: Should we really consider this to be pending?
- return {
- type: OperationAttemptResultType.Pending,
- result: undefined,
- };
+ return TaskRunResult.pending();
}
}
@@ -1677,7 +1662,7 @@ export async function processPurchasePay(
await unblockBackup(ws, proposalId);
}
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
export async function refuseProposal(
@@ -2114,7 +2099,7 @@ export function computePayMerchantTransactionActions(
async function processPurchaseAutoRefund(
ws: InternalWalletState,
purchase: PurchaseRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const proposalId = purchase.proposalId;
logger.trace(`processing auto-refund for proposal ${proposalId}`);
@@ -2130,7 +2115,7 @@ async function processPurchaseAutoRefund(
// FIXME: Put this logic into runLongpollAsync?
if (ws.activeLongpoll[taskId]) {
- return OperationAttemptResult.longpoll();
+ return TaskRunResult.longpoll();
}
const download = await expectProposalDownload(ws, purchase);
@@ -2215,13 +2200,13 @@ async function processPurchaseAutoRefund(
}
});
- return OperationAttemptResult.longpoll();
+ return TaskRunResult.longpoll();
}
async function processPurchaseAbortingRefund(
ws: InternalWalletState,
purchase: PurchaseRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const proposalId = purchase.proposalId;
const download = await expectProposalDownload(ws, purchase);
logger.trace(`processing aborting-refund for proposal ${proposalId}`);
@@ -2296,7 +2281,7 @@ async function processPurchaseAbortingRefund(
async function processPurchaseQueryRefund(
ws: InternalWalletState,
purchase: PurchaseRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const proposalId = purchase.proposalId;
logger.trace(`processing query-refund for proposal ${proposalId}`);
@@ -2341,7 +2326,7 @@ async function processPurchaseQueryRefund(
return { oldTxState, newTxState };
});
notifyTransition(ws, transactionId, transitionInfo);
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
} else {
const refundAwaiting = Amounts.sub(
Amounts.parseOrThrow(orderStatus.refund_amount),
@@ -2367,14 +2352,14 @@ async function processPurchaseQueryRefund(
return { oldTxState, newTxState };
});
notifyTransition(ws, transactionId, transitionInfo);
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
}
async function processPurchaseAcceptRefund(
ws: InternalWalletState,
purchase: PurchaseRecord,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
const proposalId = purchase.proposalId;
const download = await expectProposalDownload(ws, purchase);
@@ -2472,7 +2457,7 @@ async function storeRefunds(
purchase: PurchaseRecord,
refunds: MerchantCoinRefundStatus[],
reason: RefundReason,
-): Promise<OperationAttemptResult> {
+): Promise<TaskRunResult> {
logger.info(`storing refunds: ${j2s(refunds)}`);
const transactionId = constructTransactionIdentifier({
@@ -2699,16 +2684,16 @@ async function storeRefunds(
});
if (!result) {
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
notifyTransition(ws, transactionId, result.transitionInfo);
if (result.numPendingItemsTotal > 0) {
- return OperationAttemptResult.pendingEmpty();
+ return TaskRunResult.pending();
}
- return OperationAttemptResult.finishedEmpty();
+ return TaskRunResult.finished();
}
export function computeRefundTransactionState(