diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Refund/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Refund/state.ts | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts index 7d6576445..eb7d8834f 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts @@ -14,7 +14,12 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { Amounts, NotificationType } from "@gnu-taler/taler-util"; +import { + Amounts, + NotificationType, + TransactionPayment, + TransactionType, +} from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; @@ -35,10 +40,22 @@ export function useComponentState({ const info = useAsyncAsHook(async () => { if (!talerRefundUri) throw Error("ERROR_NO-URI-FOR-REFUND"); - const refund = await api.wallet.call(WalletApiOperation.StartRefundQueryForUri, { - talerRefundUri, - }); - return { refund, uri: talerRefundUri }; + const refund = await api.wallet.call( + WalletApiOperation.StartRefundQueryForUri, + { + talerRefundUri, + }, + ); + const purchase = await api.wallet.call( + WalletApiOperation.GetTransactionById, + { + transactionId: refund.transactionId, + }, + ); + if (purchase.type !== TransactionType.Payment) { + throw Error("Refund of non purchase transaction is not handled"); + } + return { refund, purchase, uri: talerRefundUri }; }); useEffect(() => @@ -67,12 +84,15 @@ export function useComponentState({ // }; // } - const { refund, uri } = info.response; + const { refund, purchase, uri } = info.response; const doAccept = async (): Promise<void> => { - const res = await api.wallet.call(WalletApiOperation.AcceptPurchaseRefund, { - transactionId: uri, - }); + const res = await api.wallet.call( + WalletApiOperation.StartRefundQueryForUri, + { + talerRefundUri: uri, + }, + ); onSuccess(res.transactionId); }; @@ -82,11 +102,11 @@ export function useComponentState({ }; const baseInfo = { - amount: Amounts.parseOrThrow(info.response.refund.effectivePaid), - granted: Amounts.parseOrThrow(info.response.refund.granted), - merchantName: info.response.refund.info.merchant.name, - products: info.response.refund.info.products, - awaitingAmount: Amounts.parseOrThrow(refund.awaiting), + amount: Amounts.parseOrThrow(purchase.amountEffective), + // granted: Amounts.parseOrThrow(info.response.refund.granted), + // awaitingAmount: Amounts.parseOrThrow(refund.awaiting), + merchantName: purchase.info.merchant.name, + products: purchase.info.products, error: undefined, }; @@ -97,17 +117,18 @@ export function useComponentState({ }; } - if (refund.pending) { - return { - status: "in-progress", - ...baseInfo, - }; - } + //FIXME: DD37 wallet-core is not returning this value + // if (refund.pending) { + // return { + // status: "in-progress", + // ...baseInfo, + // }; + // } return { status: "ready", ...baseInfo, - orderId: info.response.refund.info.orderId, + orderId: purchase.info.orderId, accept: { onClick: pushAlertOnError(doAccept), }, |