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

99 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";
import ReactDOM from "react-dom";
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";
function RefundStatusView(props: { talerRefundUri: string }) {
const [applied, setApplied] = useState(false);
const [purchaseDetails, setPurchaseDetails] = useState<
PurchaseDetails | undefined
>(undefined);
const [errMsg, setErrMsg] = useState<string | undefined>(undefined);
useEffect(() => {
const doFetch = async () => {
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();
2019-08-31 17:41:31 +02:00
}, []);
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>
2019-08-31 13:27:12 +02:00
The product <em>{purchaseDetails.contractTerms.summary!}</em> has
received a total refund of <AmountView amount={purchaseDetails.totalRefundAmount} />.
2017-10-15 19:28:35 +02:00
</p>
2019-08-31 13:27:12 +02:00
<p>
Note that additional fees from the exchange may apply.
</p>
</>
2017-08-27 03:56:19 +02:00
);
}
async function main() {
const url = new URL(document.location.href);
2017-08-27 03:56:19 +02:00
const container = document.getElementById("container");
if (!container) {
2019-08-31 13:27:12 +02:00
console.error("fatal: can't mount component, container missing");
2017-08-27 03:56:19 +02:00
return;
}
const talerRefundUri = url.searchParams.get("talerRefundUri");
2019-08-31 11:49:36 +02:00
if (!talerRefundUri) {
console.error("taler refund URI requred");
return;
}
2019-08-31 13:27:12 +02:00
ReactDOM.render(
<RefundStatusView talerRefundUri={talerRefundUri} />,
container,
);
2017-08-27 03:56:19 +02:00
}
document.addEventListener("DOMContentLoaded", () => main());