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";
|
2020-08-12 09:11:00 +02:00
|
|
|
import { PurchaseDetails } from "taler-wallet-core";
|
2019-08-31 13:27:12 +02:00
|
|
|
|
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<
|
2020-08-12 09:11:00 +02:00
|
|
|
PurchaseDetails | undefined
|
2019-08-31 13:27:12 +02:00
|
|
|
>(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 {
|
2020-05-15 09:23:35 +02:00
|
|
|
const result = await wxApi.applyRefund(props.talerRefundUri);
|
2019-08-31 13:27:12 +02:00
|
|
|
setApplied(true);
|
2020-08-21 17:26:25 +02:00
|
|
|
// const r = await wxApi.getPurchaseDetails(result.proposalId);
|
|
|
|
// setPurchaseDetails(r);
|
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
|
|
|
}
|
|
|
|
|
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-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>
|
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 {
|
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) {
|
2020-04-06 20:02:01 +02:00
|
|
|
throw Error("taler refund URI requred");
|
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
|
|
|
}
|