/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.
GNU 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.
GNU 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
GNU Taler; see the file COPYING. If not, see
*/
/**
*
* @author Sebastian Javier Marchano (sebasjm)
*/
import { AmountJson, Amounts } from "@gnu-taler/taler-util";
import { format } from "date-fns";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { FormProvider } from "../../../../components/form/FormProvider";
import { Input } from "../../../../components/form/Input";
import { InputCurrency } from "../../../../components/form/InputCurrency";
import { InputDate } from "../../../../components/form/InputDate";
import { InputDuration } from "../../../../components/form/InputDuration";
import { InputGroup } from "../../../../components/form/InputGroup";
import { InputLocation } from "../../../../components/form/InputLocation";
import { TextField } from "../../../../components/form/TextField";
import { ProductList } from "../../../../components/product/ProductList";
import { useBackendContext } from "../../../../context/backend";
import { MerchantBackend } from "../../../../declaration";
import { Translate, useTranslator } from "../../../../i18n";
import { mergeRefunds } from "../../../../utils/amount";
import { RefundModal } from "../list/Table";
import { Event, Timeline } from "./Timeline";
type Entity = MerchantBackend.Orders.MerchantOrderStatusResponse;
type CT = MerchantBackend.ContractTerms;
interface Props {
onBack: () => void;
selected: Entity;
id: string;
onRefund: (id: string, value: MerchantBackend.Orders.RefundRequest) => void;
}
type Paid = MerchantBackend.Orders.CheckPaymentPaidResponse & {
refund_taken: string;
};
type Unpaid = MerchantBackend.Orders.CheckPaymentUnpaidResponse;
type Claimed = MerchantBackend.Orders.CheckPaymentClaimedResponse;
function ContractTerms({ value }: { value: CT }) {
const i18n = useTranslator();
return (
object={value} valueHandler={null}>
readonly
name="summary"
label={i18n`Summary`}
tooltip={i18n`human-readable description of the whole purchase`}
/>
readonly
name="amount"
label={i18n`Amount`}
tooltip={i18n`total price for the transaction`}
/>
{value.fulfillment_url && (
readonly
name="fulfillment_url"
label={i18n`Fulfillment URL`}
tooltip={i18n`URL for this purchase`}
/>
)}
readonly
name="max_fee"
label={i18n`Max fee`}
tooltip={i18n`maximum total deposit fee accepted by the merchant for this contract`}
/>
readonly
name="max_wire_fee"
label={i18n`Max wire fee`}
tooltip={i18n`maximum wire fee accepted by the merchant`}
/>
readonly
name="wire_fee_amortization"
label={i18n`Wire fee amortization`}
tooltip={i18n`over how many customer transactions does the merchant expect to amortize wire fees on average`}
/>
readonly
name="timestamp"
label={i18n`Created at`}
tooltip={i18n`time when this contract was generated`}
/>
readonly
name="refund_deadline"
label={i18n`Refund deadline`}
tooltip={i18n`after this deadline has passed no refunds will be accepted`}
/>
readonly
name="pay_deadline"
label={i18n`Payment deadline`}
tooltip={i18n`after this deadline, the merchant won't accept payments for the contract`}
/>
readonly
name="wire_transfer_deadline"
label={i18n`Wire transfer deadline`}
tooltip={i18n`transfer deadline for the exchange`}
/>
readonly
name="delivery_date"
label={i18n`Delivery date`}
tooltip={i18n`time indicating when the order should be delivered`}
/>
{value.delivery_date && (
)}
readonly
name="auto_refund"
label={i18n`Auto-refund delay`}
tooltip={i18n`how long the wallet should try to get an automatic refund for the purchase`}
/>
readonly
name="extra"
label={i18n`Extra info`}
tooltip={i18n`extra data that is only interpreted by the merchant frontend`}
/>
);
}
function ClaimedPage({
id,
order,
}: {
id: string;
order: MerchantBackend.Orders.CheckPaymentClaimedResponse;
}) {
const events: Event[] = [];
if (order.contract_terms.timestamp.t_s !== "never") {
events.push({
when: new Date(order.contract_terms.timestamp.t_s * 1000),
description: "order created",
type: "start",
});
}
if (order.contract_terms.pay_deadline.t_s !== "never") {
events.push({
when: new Date(order.contract_terms.pay_deadline.t_s * 1000),
description: "pay deadline",
type: "deadline",
});
}
if (order.contract_terms.refund_deadline.t_s !== "never") {
events.push({
when: new Date(order.contract_terms.refund_deadline.t_s * 1000),
description: "refund deadline",
type: "deadline",
});
}
if (order.contract_terms.wire_transfer_deadline.t_s !== "never") {
events.push({
when: new Date(order.contract_terms.wire_transfer_deadline.t_s * 1000),
description: "wire deadline",
type: "deadline",
});
}
if (
order.contract_terms.delivery_date &&
order.contract_terms.delivery_date.t_s !== "never"
) {
events.push({
when: new Date(order.contract_terms.delivery_date?.t_s * 1000),
description: "delivery",
type: "delivery",
});
}
const [value, valueHandler] = useState>(order);
const i18n = useTranslator();
return (