wallet-core/src/webex/pages/refund.tsx

90 lines
2.6 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-08-27 03:56:19 +02:00
2017-10-15 19:28:35 +02:00
import * as wxApi from "../wxApi";
import { PurchaseDetails } from "../../types/walletTypes";
2019-08-31 13:27:12 +02:00
import { AmountView } from "../renderHtml";
2020-04-06 20:02:01 +02:00
function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
2019-08-31 13:27:12 +02:00
const [applied, setApplied] = useState(false);
const [purchaseDetails, setPurchaseDetails] = useState<
PurchaseDetails | undefined
>(undefined);
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 hc = await wxApi.applyRefund(props.talerRefundUri);
setApplied(true);
const r = await wxApi.getPurchaseDetails(hc);
setPurchaseDetails(r);
} 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
}
2019-08-31 13:27:12 +02:00
if (!applied || !purchaseDetails) {
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>
2020-04-07 10:07:32 +02:00
The product <em>{purchaseDetails.contractTerms.summary}</em> has
2020-03-30 12:39:32 +02:00
received a total refund of{" "}
<AmountView amount={purchaseDetails.totalRefundAmount} />.
2019-08-31 13:27:12 +02:00
</p>
2020-03-30 12:39:32 +02:00
<p>Note that additional fees from the exchange may apply.</p>
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
}