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
|
|
|
|
*/
|
|
|
|
|
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 {
|
|
|
|
ApplyRefundResponse,
|
|
|
|
Amounts,
|
|
|
|
} from "@gnu-taler/taler-util";
|
2021-05-07 15:38:28 +02:00
|
|
|
// import { h } from 'preact';
|
|
|
|
import { useEffect, useState } from "preact/hooks";
|
|
|
|
import { JSX } from "preact/jsx-runtime";
|
2019-08-31 13:27:12 +02:00
|
|
|
|
2020-04-06 20:02:01 +02:00
|
|
|
function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
|
2021-05-07 15:38:28 +02:00
|
|
|
const [applyResult, setApplyResult] = useState<ApplyRefundResponse|undefined>(undefined);
|
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 {
|
2020-05-15 09:23:35 +02:00
|
|
|
const result = await wxApi.applyRefund(props.talerRefundUri);
|
2020-09-09 09:15:49 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-09-09 09:15:49 +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-10-15 18:30:02 +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{" "}
|
2020-09-09 09:15:49 +02:00
|
|
|
<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 {
|
2019-12-02 00:42:40 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-02 00:42:40 +01:00
|
|
|
const talerRefundUri = url.searchParams.get("talerRefundUri");
|
2019-08-31 11:49:36 +02:00
|
|
|
if (!talerRefundUri) {
|
2021-04-28 00:01:52 +02:00
|
|
|
throw Error("taler refund URI required");
|
2019-08-31 11:49:36 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 17:35:51 +02:00
|
|
|
return <RefundStatusView talerRefundUri={talerRefundUri} />;
|
2017-08-27 03:56:19 +02:00
|
|
|
}
|