Added receipt print out at end of payment processing BOD-93
This commit is contained in:
@@ -14,6 +14,11 @@ import PaymentForm from "../payment-form/payment-form.container";
|
||||
import axios from "axios";
|
||||
import { useMutation } from "@apollo/react-hooks";
|
||||
import { INSERT_NEW_PAYMENT } from "../../graphql/payments.queries";
|
||||
import { TemplateList } from "../../utils/TemplateConstants";
|
||||
import RenderTemplate, {
|
||||
displayTemplateInWindow,
|
||||
} from "../../utils/RenderTemplate";
|
||||
import { setEmailOptions } from "../../redux/email/email.actions";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
paymentModal: selectPayment,
|
||||
@@ -22,6 +27,7 @@ const mapStateToProps = createStructuredSelector({
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setEmailOptions: (e) => dispatch(setEmailOptions(e)),
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("payment")),
|
||||
});
|
||||
|
||||
@@ -30,6 +36,7 @@ function InvoiceEnterModalContainer({
|
||||
toggleModalVisible,
|
||||
bodyshop,
|
||||
currentUser,
|
||||
setEmailOptions,
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const [insertPayment] = useMutation(INSERT_NEW_PAYMENT);
|
||||
@@ -48,7 +55,7 @@ function InvoiceEnterModalContainer({
|
||||
const cardValid = !!!stripeState.error && stripeState.cardComplete;
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
const { useStripe, ...paymentObj } = values;
|
||||
const { useStripe, sendby, ...paymentObj } = values;
|
||||
if (useStripe && !cardValid) return;
|
||||
|
||||
if ((useStripe && !stripe) || !elements) {
|
||||
@@ -106,6 +113,33 @@ function InvoiceEnterModalContainer({
|
||||
notification["error"]({ message: t("payments.errors.payment") });
|
||||
}
|
||||
|
||||
if (sendby === "email") {
|
||||
setEmailOptions({
|
||||
messageOptions: {
|
||||
// to: appData.email,
|
||||
replyTo: bodyshop.email,
|
||||
},
|
||||
template: {
|
||||
name: TemplateList.payment_receipt.key,
|
||||
variables: {
|
||||
id: newPayment.data.insert_payments.returning[0].id,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
displayTemplateInWindow(
|
||||
await RenderTemplate(
|
||||
{
|
||||
name: TemplateList.payment_receipt.key,
|
||||
variables: {
|
||||
id: newPayment.data.insert_payments.returning[0].id,
|
||||
},
|
||||
},
|
||||
bodyshop
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (actions.refetch) actions.refetch();
|
||||
toggleModalVisible();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user