aboutsummaryrefslogtreecommitdiff
path: root/src/wallet-impl/pay.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-07 18:42:18 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-07 18:42:18 +0100
commit165486a11268ab3d8009506916cd22d233cd248b (patch)
treeb90db78eafd4eb12b84ea2e8f4dc0353a315ab7f /src/wallet-impl/pay.ts
parentd634626d7f3a179613a86eedb2f1c7a917ce65ba (diff)
downloadwallet-core-165486a11268ab3d8009506916cd22d233cd248b.tar.xz
auto-refund
Diffstat (limited to 'src/wallet-impl/pay.ts')
-rw-r--r--src/wallet-impl/pay.ts45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/wallet-impl/pay.ts b/src/wallet-impl/pay.ts
index 7076f905d..c39feeec3 100644
--- a/src/wallet-impl/pay.ts
+++ b/src/wallet-impl/pay.ts
@@ -62,6 +62,8 @@ import {
strcmp,
canonicalJson,
extractTalerStampOrThrow,
+ extractTalerDurationOrThrow,
+ extractTalerDuration,
} from "../util/helpers";
import { Logger } from "../util/logging";
import { InternalWalletState } from "./state";
@@ -359,6 +361,7 @@ async function recordConfirmPay(
lastRefundApplyError: undefined,
refundApplyRetryInfo: initRetryInfo(),
firstSuccessfulPayTimestamp: undefined,
+ autoRefundDeadline: undefined,
};
await runWithWriteTransaction(
@@ -704,9 +707,23 @@ export async function submitPay(
// FIXME: properly display error
throw Error("merchant payment signature invalid");
}
+ const isFirst = purchase.firstSuccessfulPayTimestamp === undefined;
purchase.firstSuccessfulPayTimestamp = getTimestampNow();
purchase.lastPayError = undefined;
purchase.payRetryInfo = initRetryInfo(false);
+ if (isFirst) {
+ const ar = purchase.contractTerms.auto_refund;
+ if (ar) {
+ const autoRefundDelay = extractTalerDuration(ar);
+ if (autoRefundDelay) {
+ purchase.refundStatusRequested = true;
+ purchase.autoRefundDeadline = {
+ t_ms: getTimestampNow().t_ms + autoRefundDelay.d_ms,
+ }
+ }
+ }
+ }
+
const modifiedCoins: CoinRecord[] = [];
for (const pc of purchase.payReq.coins) {
const c = await oneShotGet(ws.db, Stores.coins, pc.coin_pub);
@@ -1064,11 +1081,6 @@ async function acceptRefundResponse(
return;
}
- p.lastRefundStatusTimestamp = getTimestampNow();
- p.lastRefundStatusError = undefined;
- p.refundStatusRetryInfo = initRetryInfo();
- p.refundStatusRequested = false;
-
for (const perm of refundPermissions) {
if (
!p.refundsPending[perm.merchant_sig] &&
@@ -1079,6 +1091,29 @@ async function acceptRefundResponse(
}
}
+ // Are we done with querying yet, or do we need to do another round
+ // after a retry delay?
+ let queryDone = true;
+
+ if (numNewRefunds === 0) {
+ if (p.autoRefundDeadline && p.autoRefundDeadline.t_ms < getTimestampNow().t_ms) {
+ queryDone = false;
+ }
+ }
+
+ if (queryDone) {
+ p.lastRefundStatusTimestamp = getTimestampNow();
+ p.lastRefundStatusError = undefined;
+ p.refundStatusRetryInfo = initRetryInfo();
+ p.refundStatusRequested = false;
+ } else {
+ // No error, but we need to try again!
+ p.lastRefundStatusTimestamp = getTimestampNow();
+ p.refundStatusRetryInfo.retryCounter++;
+ updateRetryInfoTimeout(p.refundStatusRetryInfo);
+ p.lastRefundStatusError = undefined;
+ }
+
if (numNewRefunds) {
p.lastRefundApplyError = undefined;
p.refundApplyRetryInfo = initRetryInfo();