wallet-core/packages/taler-wallet-webextension/src/pages/refund.tsx

97 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-08-27 03:56:19 +02:00
/*
This file is part of TALER
(C) 2015-2016 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* Page that shows refund status for purchases.
*
* @author Florian Dold
*/
2019-08-31 13:27:12 +02:00
import React, { useEffect, useState } from "react";
2017-10-15 19:28:35 +02:00
import * as wxApi from "../wxApi";
2019-08-31 13:27:12 +02:00
import { AmountView } from "../renderHtml";
2021-03-27 14:35:58 +01:00
import {
PurchaseDetails,
ApplyRefundResponse,
Amounts,
} from "@gnu-taler/taler-util";
2019-08-31 13:27:12 +02:00
2020-04-06 20:02:01 +02:00
function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
const [applyResult, setApplyResult] = useState<ApplyRefundResponse>();
2019-08-31 13:27:12 +02:00
const [errMsg, setErrMsg] = useState<string | undefined>(undefined);
useEffect(() => {
2020-04-06 20:02:01 +02:00
const doFetch = async (): Promise<void> => {
2019-08-31 13:27:12 +02:00
try {
const result = await wxApi.applyRefund(props.talerRefundUri);
setApplyResult(result);
2019-08-31 13:27:12 +02:00
} catch (e) {
console.error(e);
setErrMsg(e.message);
console.log("err message", e.message);
}
};
doFetch();
2020-04-07 10:07:32 +02:00
}, [props.talerRefundUri]);
2017-08-27 03:56:19 +02:00
2019-08-31 13:27:12 +02:00
console.log("rendering");
2017-08-27 03:56:19 +02:00
2019-08-31 13:27:12 +02:00
if (errMsg) {
return <span>Error: {errMsg}</span>;
2017-08-27 03:56:19 +02:00
}
if (!applyResult) {
2019-08-31 13:27:12 +02:00
return <span>Updating refund status</span>;
2017-08-27 03:56:19 +02:00
}
2017-08-27 03:56:19 +02:00
return (
2019-08-31 13:27:12 +02:00
<>
<h2>Refund Status</h2>
2017-10-15 19:28:35 +02:00
<p>
2021-03-27 14:35:58 +01:00
The product <em>{applyResult.info.summary}</em> has received a total
effective refund of{" "}
<AmountView amount={applyResult.amountRefundGranted} />.
2019-08-31 13:27:12 +02:00
</p>
2021-03-27 14:35:58 +01:00
{applyResult.pendingAtExchange ? (
<p>Refund processing is still in progress.</p>
) : null}
{!Amounts.isZero(applyResult.amountRefundGone) ? (
<p>
The refund amount of{" "}
<AmountView amount={applyResult.amountRefundGone} />
could not be applied.
</p>
) : null}
2019-08-31 13:27:12 +02:00
</>
2017-08-27 03:56:19 +02:00
);
}
2020-04-06 20:02:01 +02:00
export function createRefundPage(): JSX.Element {
const url = new URL(document.location.href);
2017-08-27 03:56:19 +02:00
const container = document.getElementById("container");
if (!container) {
2020-04-07 10:07:32 +02:00
throw Error("fatal: can't mount component, container missing");
2017-08-27 03:56:19 +02:00
}
const talerRefundUri = url.searchParams.get("talerRefundUri");
2019-08-31 11:49:36 +02:00
if (!talerRefundUri) {
2020-04-06 20:02:01 +02:00
throw Error("taler refund URI requred");
2019-08-31 11:49:36 +02:00
}
return <RefundStatusView talerRefundUri={talerRefundUri} />;
2017-08-27 03:56:19 +02:00
}