gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: refund response


From: gnunet
Subject: [taler-wallet-core] branch master updated: refund response
Date: Tue, 11 Aug 2020 14:25:52 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 2e56a22f refund response
2e56a22f is described below

commit 2e56a22f6b192600e8ec662b01ad436cbd1a5e65
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Tue Aug 11 17:55:45 2020 +0530

    refund response
---
 .../taler-wallet-core/src/operations/refund.ts     | 72 +++++++++++++++++++++-
 1 file changed, 69 insertions(+), 3 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/refund.ts 
b/packages/taler-wallet-core/src/operations/refund.ts
index 2b6ee97a..d7aaf727 100644
--- a/packages/taler-wallet-core/src/operations/refund.ts
+++ b/packages/taler-wallet-core/src/operations/refund.ts
@@ -41,12 +41,13 @@ import {
 import { NotificationType } from "../types/notifications";
 import { parseRefundUri } from "../util/taleruri";
 import { createRefreshGroup, getTotalRefreshCost } from "./refresh";
-import { Amounts } from "../util/amounts";
+import { Amounts, AmountJson } from "../util/amounts";
 import {
   MerchantCoinRefundStatus,
   MerchantCoinRefundSuccessStatus,
   MerchantCoinRefundFailureStatus,
   codecForMerchantOrderStatusPaid,
+  AmountString,
 } from "../types/talerTypes";
 import { guardOperationException } from "./errors";
 import { getTimestampNow } from "../util/time";
@@ -302,6 +303,30 @@ async function acceptRefunds(
   });
 }
 
+/**
+ * Summary of the refund status of a purchase.
+ */
+export interface RefundSummary {
+  pendingAtExchange: boolean;
+  amountEffectivePaid: AmountJson;
+  amountRefundGranted: AmountJson;
+  amountRefundGone: AmountJson;
+}
+
+export interface ApplyRefundResponse {
+  contractTermsHash: string;
+
+  proposalId: string;
+
+  amountEffectivePaid: AmountString;
+
+  amountRefundGranted: AmountString;
+
+  amountRefundGone: AmountString;
+
+  pendingAtExchange: boolean;
+}
+
 /**
  * Accept a refund, return the contract hash for the contract
  * that was involved in the refund.
@@ -309,7 +334,7 @@ async function acceptRefunds(
 export async function applyRefund(
   ws: InternalWalletState,
   talerRefundUri: string,
-): Promise<{ contractTermsHash: string; proposalId: string }> {
+): Promise<ApplyRefundResponse> {
   const parseResult = parseRefundUri(talerRefundUri);
 
   logger.trace("applying refund", parseResult);
@@ -318,7 +343,7 @@ export async function applyRefund(
     throw Error("invalid refund URI");
   }
 
-  const purchase = await ws.db.getIndexed(Stores.purchases.orderIdIndex, [
+  let purchase = await ws.db.getIndexed(Stores.purchases.orderIdIndex, [
     parseResult.merchantBaseUrl,
     parseResult.orderId,
   ]);
@@ -355,9 +380,50 @@ export async function applyRefund(
     await processPurchaseQueryRefund(ws, proposalId);
   }
 
+  purchase = await ws.db.get(Stores.purchases, proposalId);
+
+  if (!purchase) {
+    throw Error("purchase no longer exists");
+  }
+
+  const p = purchase;
+
+  let amountRefundGranted = Amounts.getZero(
+    purchase.contractData.amount.currency,
+  );
+  let amountRefundGone = 
Amounts.getZero(purchase.contractData.amount.currency);
+
+  let pendingAtExchange = false;
+
+  Object.keys(purchase.refunds).forEach((rk) => {
+    const refund = p.refunds[rk];
+    if (refund.type === RefundState.Pending) {
+      pendingAtExchange = true;
+    }
+    if (
+      refund.type === RefundState.Applied ||
+      refund.type === RefundState.Pending
+    ) {
+      amountRefundGranted = Amounts.add(
+        amountRefundGranted,
+        Amounts.sub(
+          refund.refundAmount,
+          refund.refundFee,
+          refund.totalRefreshCostBound,
+        ).amount,
+      ).amount;
+    } else {
+      amountRefundGone = Amounts.add(amountRefundGone, 
refund.refundAmount).amount;
+    }
+  });
+
   return {
     contractTermsHash: purchase.contractData.contractTermsHash,
     proposalId: purchase.proposalId,
+    amountEffectivePaid: Amounts.stringify(purchase.payCostInfo.totalCost),
+    amountRefundGone: Amounts.stringify(amountRefundGone),
+    amountRefundGranted: Amounts.stringify(amountRefundGranted),
+    pendingAtExchange,
   };
 }
 

-- 
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]