gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (e35c2f58 -> 39c4b42d)


From: gnunet
Subject: [taler-wallet-core] branch master updated (e35c2f58 -> 39c4b42d)
Date: Tue, 22 Jun 2021 15:30:57 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-core.

    from e35c2f58 simplify task loop, test coin suspension
     new c51b372a comment
     new 39c4b42d implement long-polling for auto-refunds

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 packages/taler-wallet-core/src/operations/pay.ts   |  9 ++++++
 .../taler-wallet-core/src/operations/refund.ts     | 35 ++++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/pay.ts 
b/packages/taler-wallet-core/src/operations/pay.ts
index e662ee72..71f11c96 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -368,6 +368,15 @@ export async function getCandidatePayCoins(
   };
 }
 
+/**
+ * Apply a coin selection to the database.  Marks coins as spent
+ * and creates a refresh session for the remaining amount.
+ *
+ * FIXME:  This does not deal well with conflicting spends!
+ * When two payments are made in parallel, the same coin can be selected
+ * for two payments.
+ * However, this is a situation that can also happen via sync.
+ */
 export async function applyCoinSpend(
   ws: InternalWalletState,
   tx: GetReadWriteAccess<{
diff --git a/packages/taler-wallet-core/src/operations/refund.ts 
b/packages/taler-wallet-core/src/operations/refund.ts
index 4ea80689..0bff2986 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -44,6 +44,8 @@ import {
   TalerErrorDetails,
   URL,
   timestampAddDuration,
+  codecForMerchantOrderStatusPaid,
+  isTimestampExpired,
 } from "@gnu-taler/taler-util";
 import {
   AbortStatus,
@@ -493,7 +495,7 @@ export async function applyRefund(
     ws.notify({
       type: NotificationType.RefundStarted,
     });
-    await processPurchaseQueryRefund(ws, proposalId);
+    await processPurchaseQueryRefundImpl(ws, proposalId, true, false);
   }
 
   purchase = await ws.db
@@ -571,7 +573,7 @@ export async function processPurchaseQueryRefund(
   const onOpErr = (e: TalerErrorDetails): Promise<void> =>
     incrementPurchaseQueryRefundRetry(ws, proposalId, e);
   await guardOperationException(
-    () => processPurchaseQueryRefundImpl(ws, proposalId, forceNow),
+    () => processPurchaseQueryRefundImpl(ws, proposalId, forceNow, true),
     onOpErr,
   );
 }
@@ -597,6 +599,7 @@ async function processPurchaseQueryRefundImpl(
   ws: InternalWalletState,
   proposalId: string,
   forceNow: boolean,
+  waitForAutoRefund: boolean,
 ): Promise<void> {
   if (forceNow) {
     await resetPurchaseQueryRefundRetry(ws, proposalId);
@@ -617,6 +620,34 @@ async function processPurchaseQueryRefundImpl(
   }
 
   if (purchase.timestampFirstSuccessfulPay) {
+    if (
+      waitForAutoRefund &&
+      purchase.autoRefundDeadline &&
+      !isTimestampExpired(purchase.autoRefundDeadline)
+    ) {
+      const requestUrl = new URL(
+        `orders/${purchase.download.contractData.orderId}`,
+        purchase.download.contractData.merchantBaseUrl,
+      );
+      requestUrl.searchParams.set(
+        "h_contract",
+        purchase.download.contractData.contractTermsHash,
+      );
+      // Long-poll for one second
+      requestUrl.searchParams.set("timeout_ms", "1000");
+      requestUrl.searchParams.set("await_refund_obtained", "yes");
+      logger.trace("making long-polling request for auto-refund");
+      const resp = await ws.http.get(requestUrl.href);
+      const orderStatus = await readSuccessResponseJsonOrThrow(
+        resp,
+        codecForMerchantOrderStatusPaid(),
+      );
+      if (!orderStatus.refunded) {
+        incrementPurchaseQueryRefundRetry(ws, proposalId, undefined);
+        return;
+      }
+    }
+
     const requestUrl = new URL(
       `orders/${purchase.download.contractData.orderId}/refund`,
       purchase.download.contractData.merchantBaseUrl,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]