aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/refund.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-08-10 16:48:38 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-08-10 16:48:38 +0530
commit66d76a35912d7687d76b349f1cac462306306d3f (patch)
tree3cdfce8178c3928dbcfc13263f8752b3f9ca9c7b /packages/taler-wallet-core/src/operations/refund.ts
parent5f8714091aac80144be118fa6427d65222e7509c (diff)
downloadwallet-core-66d76a35912d7687d76b349f1cac462306306d3f.tar.xz
simplify refunds a bit, show in transaction history, add integration tests
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refund.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/refund.ts60
1 files changed, 26 insertions, 34 deletions
diff --git a/packages/taler-wallet-core/src/operations/refund.ts b/packages/taler-wallet-core/src/operations/refund.ts
index 9792d2268..2b6ee97ae 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -203,7 +203,7 @@ async function acceptRefunds(
refunds: MerchantCoinRefundStatus[],
reason: RefundReason,
): Promise<void> {
- console.log("handling refunds", refunds);
+ logger.trace("handling refunds", refunds);
const now = getTimestampNow();
await ws.db.runWithWriteTransaction(
@@ -302,37 +302,6 @@ async function acceptRefunds(
});
}
-async function startRefundQuery(
- ws: InternalWalletState,
- proposalId: string,
-): Promise<void> {
- const success = await ws.db.runWithWriteTransaction(
- [Stores.purchases],
- async (tx) => {
- const p = await tx.get(Stores.purchases, proposalId);
- if (!p) {
- logger.error("no purchase found for refund URL");
- return false;
- }
- p.refundStatusRequested = true;
- p.lastRefundStatusError = undefined;
- p.refundStatusRetryInfo = initRetryInfo();
- await tx.put(Stores.purchases, p);
- return true;
- },
- );
-
- if (!success) {
- return;
- }
-
- ws.notify({
- type: NotificationType.RefundStarted,
- });
-
- await processPurchaseQueryRefund(ws, proposalId);
-}
-
/**
* Accept a refund, return the contract hash for the contract
* that was involved in the refund.
@@ -360,8 +329,31 @@ export async function applyRefund(
);
}
+ const proposalId = purchase.proposalId;
+
logger.info("processing purchase for refund");
- await startRefundQuery(ws, purchase.proposalId);
+ const success = await ws.db.runWithWriteTransaction(
+ [Stores.purchases],
+ async (tx) => {
+ const p = await tx.get(Stores.purchases, proposalId);
+ if (!p) {
+ logger.error("no purchase found for refund URL");
+ return false;
+ }
+ p.refundStatusRequested = true;
+ p.lastRefundStatusError = undefined;
+ p.refundStatusRetryInfo = initRetryInfo();
+ await tx.put(Stores.purchases, p);
+ return true;
+ },
+ );
+
+ if (success) {
+ ws.notify({
+ type: NotificationType.RefundStarted,
+ });
+ await processPurchaseQueryRefund(ws, proposalId);
+ }
return {
contractTermsHash: purchase.contractData.contractTermsHash,
@@ -422,7 +414,7 @@ async function processPurchaseQueryRefundImpl(
const request = await ws.http.get(requestUrl.href);
- console.log("got json", JSON.stringify(await request.json(), undefined, 2));
+ logger.trace("got json", JSON.stringify(await request.json(), undefined, 2));
const refundResponse = await readSuccessResponseJsonOrThrow(
request,