Added payments schema and connected to stripe BOD-146 BOD-147
This commit is contained in:
@@ -12338,6 +12338,27 @@
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>enterpayment</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>entertimeticket</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
@@ -14184,6 +14205,37 @@
|
||||
</folder_node>
|
||||
</children>
|
||||
</folder_node>
|
||||
<folder_node>
|
||||
<name>payments</name>
|
||||
<children>
|
||||
<folder_node>
|
||||
<name>labels</name>
|
||||
<children>
|
||||
<concept_node>
|
||||
<name>new</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
</children>
|
||||
</folder_node>
|
||||
</children>
|
||||
</folder_node>
|
||||
<folder_node>
|
||||
<name>printcenter</name>
|
||||
<children>
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
"proxy": "https://localhost:5000",
|
||||
"dependencies": {
|
||||
"@nivo/pie": "^0.61.1",
|
||||
"@stripe/react-stripe-js": "^1.1.2",
|
||||
"@stripe/stripe-js": "^1.7.0",
|
||||
"@tinymce/tinymce-react": "^3.6.0",
|
||||
"aamva": "^1.2.0",
|
||||
"antd": "^4.2.2",
|
||||
|
||||
@@ -26,6 +26,8 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
dispatch(setModalContext({ context: context, modal: "invoiceEnter" })),
|
||||
setTimeTicketContext: (context) =>
|
||||
dispatch(setModalContext({ context: context, modal: "timeTicket" })),
|
||||
setPaymentContext: (context) =>
|
||||
dispatch(setModalContext({ context: context, modal: "payment" })),
|
||||
});
|
||||
|
||||
function Header({
|
||||
@@ -37,6 +39,7 @@ function Header({
|
||||
signOutStart,
|
||||
setInvoiceEnterContext,
|
||||
setTimeTicketContext,
|
||||
setPaymentContext,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
//TODO Add
|
||||
@@ -199,6 +202,18 @@ function Header({
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Menu.Item
|
||||
key="enterpayments"
|
||||
onClick={() => {
|
||||
setPaymentContext({
|
||||
actions: {},
|
||||
context: {},
|
||||
});
|
||||
}}
|
||||
>
|
||||
{t("menus.header.enterpayment")}
|
||||
</Menu.Item>
|
||||
|
||||
<Menu.Item
|
||||
key="enterinvoices"
|
||||
onClick={() => {
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
import { handleUpload } from "../documents-upload/documents-upload.utility";
|
||||
import InvoiceFormContainer from "../invoice-form/invoice-form.container";
|
||||
import { UPDATE_JOB_LINE_STATUS } from "../../graphql/jobs-lines.queries";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
invoiceEnterModal: selectInvoiceEnterModal,
|
||||
bodyshop: selectBodyshop,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Form } from "antd";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
||||
import { CardElement } from "@stripe/react-stripe-js";
|
||||
|
||||
export default function PaymentFormComponent({
|
||||
form,
|
||||
roAutoCompleteOptions,
|
||||
stripeStateArr,
|
||||
}) {
|
||||
const [stripeState, setStripeState] = stripeStateArr;
|
||||
console.log("stripeState", stripeState);
|
||||
const { t } = useTranslation();
|
||||
const handleStripeChange = (e) => {
|
||||
setStripeState({ error: e.error, cardComplete: e.complete });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="invoice-form-wrapper">
|
||||
<Form.Item
|
||||
name="jobid"
|
||||
label={t("invoices.fields.ro_number")}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<JobSearchSelect options={roAutoCompleteOptions} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label={t("payment.fields.amount")} name="amount">
|
||||
<CurrencyInput />
|
||||
</Form.Item>
|
||||
<CardElement
|
||||
options={{
|
||||
style: {
|
||||
base: {
|
||||
color: "#32325d",
|
||||
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
|
||||
fontSmoothing: "antialiased",
|
||||
fontSize: "16px",
|
||||
"::placeholder": {
|
||||
color: "#aab7c4",
|
||||
},
|
||||
},
|
||||
invalid: {
|
||||
color: "#fa755a",
|
||||
iconColor: "#fa755a",
|
||||
},
|
||||
},
|
||||
}}
|
||||
onChange={handleStripeChange}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useQuery } from "@apollo/react-hooks";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { ACTIVE_JOBS_FOR_AUTOCOMPLETE } from "../../graphql/jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import PaymentFormComponent from "./payment-form.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function PaymentFormContainer({ bodyshop, form,stripeStateArr }) {
|
||||
const { data: RoAutoCompleteData } = useQuery(ACTIVE_JOBS_FOR_AUTOCOMPLETE, {
|
||||
variables: { statuses: bodyshop.md_ro_statuses.open_statuses || ["Open*"] },
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PaymentFormComponent
|
||||
form={form}
|
||||
roAutoCompleteOptions={RoAutoCompleteData && RoAutoCompleteData.jobs}
|
||||
stripeStateArr={stripeStateArr}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default connect(mapStateToProps, null)(PaymentFormContainer);
|
||||
125
client/src/components/payment-modal/payment-modal.container.jsx
Normal file
125
client/src/components/payment-modal/payment-modal.container.jsx
Normal file
@@ -0,0 +1,125 @@
|
||||
import { useElements, useStripe, CardElement } from "@stripe/react-stripe-js";
|
||||
import { Form, Modal } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
||||
import { selectPayment } from "../../redux/modals/modals.selectors";
|
||||
import {
|
||||
selectBodyshop,
|
||||
selectCurrentUser,
|
||||
} from "../../redux/user/user.selectors";
|
||||
import PaymentForm from "../payment-form/payment-form.container";
|
||||
import axios from "axios";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
paymentModal: selectPayment,
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleModalVisible: () => dispatch(toggleModalVisible("payment")),
|
||||
});
|
||||
|
||||
function InvoiceEnterModalContainer({
|
||||
paymentModal,
|
||||
toggleModalVisible,
|
||||
bodyshop,
|
||||
currentUser,
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const stripe = useStripe();
|
||||
const elements = useElements();
|
||||
const { t } = useTranslation();
|
||||
const { context, actions, visible } = paymentModal;
|
||||
const [loading, setLoading] = useState(false);
|
||||
const stripeStateArr = useState({
|
||||
error: null,
|
||||
cardComplete: false,
|
||||
});
|
||||
const [stripeState, setStripeState] = stripeStateArr;
|
||||
|
||||
const cardValid = !!!stripeState.error && stripeState.cardComplete;
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
if (!cardValid) return;
|
||||
|
||||
if (!stripe || !elements) {
|
||||
// Stripe.js has not yet loaded.
|
||||
// Make sure to disable form submission until Stripe.js has loaded.
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const pr = stripe.paymentRequest({
|
||||
country: "US",
|
||||
currency: "usd",
|
||||
total: {
|
||||
label: "Demo total",
|
||||
amount: 1099,
|
||||
},
|
||||
requestPayerName: true,
|
||||
requestPayerEmail: true,
|
||||
});
|
||||
console.log("handleFinish -> pr", pr);
|
||||
|
||||
// const secretKey = await axios.post("/stripe/payment", {
|
||||
// amount: Math.round(values.amount * 100),
|
||||
// stripe_acct_id: bodyshop.stripe_acct_id,
|
||||
// });
|
||||
// console.log("handleFinish -> secretKey", secretKey);
|
||||
// const result = await stripe.confirmCardPayment(
|
||||
// secretKey.data.clientSecret,
|
||||
// {
|
||||
// payment_method: {
|
||||
// card: elements.getElement(CardElement),
|
||||
// billing_details: {
|
||||
// name: "Jenny Rosen",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
// console.log("handleFinish -> result", result);
|
||||
|
||||
if (actions.refetch) actions.refetch();
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
// toggleModalVisible();
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
toggleModalVisible();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t("payments.labels.new")}
|
||||
width={"90%"}
|
||||
visible={visible}
|
||||
okText={t("general.actions.save")}
|
||||
onOk={() => form.submit()}
|
||||
onCancel={handleCancel}
|
||||
afterClose={() => form.resetFields()}
|
||||
okButtonProps={{ loading: loading, disabled: !cardValid }}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form
|
||||
onFinish={handleFinish}
|
||||
autoComplete={"off"}
|
||||
form={form}
|
||||
initialValues={{ jobid: context.jobId }}
|
||||
>
|
||||
<PaymentForm form={form} stripeStateArr={stripeStateArr} />
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(InvoiceEnterModalContainer);
|
||||
@@ -31,6 +31,7 @@ export const QUERY_BODYSHOP = gql`
|
||||
inhousevendorid
|
||||
accountingconfig
|
||||
appt_length
|
||||
stripe_acct_id
|
||||
employees {
|
||||
id
|
||||
first_name
|
||||
@@ -80,6 +81,7 @@ export const UPDATE_SHOP = gql`
|
||||
production_config
|
||||
invoice_tax_rates
|
||||
appt_length
|
||||
stripe_acct_id
|
||||
employees {
|
||||
id
|
||||
first_name
|
||||
@@ -99,3 +101,10 @@ export const QUERY_INTAKE_CHECKLIST = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const QUERY_STRIPE_ID = gql`
|
||||
query QUERY_STRIPE_ID {
|
||||
bodyshops {
|
||||
stripe_acct_id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
import { Elements } from "@stripe/react-stripe-js";
|
||||
import { BackTop, Layout } from "antd";
|
||||
import React, { lazy, Suspense, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { Route, Switch } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import BreadCrumbs from "../../components/breadcrumbs/breadcrumbs.component";
|
||||
import ChatAffixContainer from "../../components/chat-affix/chat-affix.container";
|
||||
import ConflictComponent from "../../components/conflict/conflict.component";
|
||||
import ErrorBoundary from "../../components/error-boundary/error-boundary.component";
|
||||
import FcmNotification from "../../components/fcm-notification/fcm-notification.component";
|
||||
import FooterComponent from "../../components/footer/footer.component";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectInstanceConflict } from "../../redux/user/user.selectors";
|
||||
//Component Imports
|
||||
import HeaderContainer from "../../components/header/header.container";
|
||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||
import PrintCenterModalContainer from "../../components/print-center-modal/print-center-modal.container";
|
||||
import ConflictComponent from "../../components/conflict/conflict.component";
|
||||
|
||||
import {
|
||||
selectInstanceConflict,
|
||||
selectBodyshop,
|
||||
} from "../../redux/user/user.selectors";
|
||||
import "./manage.page.styles.scss";
|
||||
import { loadStripe } from "@stripe/stripe-js";
|
||||
import { client } from "../../App/App.container";
|
||||
import { QUERY_STRIPE_ID } from "../../graphql/bodyshop.queries";
|
||||
|
||||
const ManageRootPage = lazy(() =>
|
||||
import("../manage-root/manage-root.page.container")
|
||||
);
|
||||
@@ -79,6 +86,9 @@ const EnterInvoiceModalContainer = lazy(() =>
|
||||
const TimeTicketModalContainer = lazy(() =>
|
||||
import("../../components/time-ticket-modal/time-ticket-modal.container")
|
||||
);
|
||||
const PaymentModalContainer = lazy(() =>
|
||||
import("../../components/payment-modal/payment-modal.container")
|
||||
);
|
||||
const ProductionListPage = lazy(() =>
|
||||
import("../production-list/production-list.container")
|
||||
);
|
||||
@@ -105,13 +115,20 @@ const ShopCsiPageContainer = lazy(() =>
|
||||
|
||||
const { Header, Content, Footer } = Layout;
|
||||
|
||||
const stripePromise = new Promise((resolve, reject) => {
|
||||
client.query({ query: QUERY_STRIPE_ID }).then((resp) => {
|
||||
resolve(
|
||||
loadStripe(process.env.REACT_APP_STRIPE_PUBLIC_KEY, {
|
||||
stripeAccount: resp.data.bodyshops[0].stripe_acct_id || "",
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
conflict: selectInstanceConflict,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
|
||||
export function Manage({ match, conflict }) {
|
||||
const { t } = useTranslation();
|
||||
@@ -145,6 +162,10 @@ export function Manage({ match, conflict }) {
|
||||
<EmailOverlayContainer />
|
||||
<TimeTicketModalContainer />
|
||||
<PrintCenterModalContainer />
|
||||
<Elements stripe={stripePromise}>
|
||||
<PaymentModalContainer />
|
||||
</Elements>
|
||||
|
||||
<Route
|
||||
exact
|
||||
path={`${match.path}`}
|
||||
|
||||
@@ -18,6 +18,7 @@ const INITIAL_STATE = {
|
||||
timeTicket: { ...baseModal },
|
||||
printCenter: { ...baseModal },
|
||||
reconciliation: { ...baseModal },
|
||||
payment: { ...baseModal },
|
||||
};
|
||||
|
||||
const modalsReducer = (state = INITIAL_STATE, action) => {
|
||||
|
||||
@@ -46,3 +46,7 @@ export const selectReconciliation = createSelector(
|
||||
[selectModals],
|
||||
(modals) => modals.reconciliation
|
||||
);
|
||||
export const selectPayment = createSelector(
|
||||
[selectModals],
|
||||
(modals) => modals.payment
|
||||
);
|
||||
|
||||
@@ -754,6 +754,7 @@
|
||||
"courtesycars-newcontract": "New Contract",
|
||||
"customers": "Customers",
|
||||
"enterinvoices": "Enter Invoices",
|
||||
"enterpayment": "Enter Payments",
|
||||
"entertimeticket": "Enter Time Tickets",
|
||||
"home": "Home",
|
||||
"invoices": "Invoices",
|
||||
@@ -886,6 +887,11 @@
|
||||
"created": "Parts order created successfully. "
|
||||
}
|
||||
},
|
||||
"payments": {
|
||||
"labels": {
|
||||
"new": "New Payment"
|
||||
}
|
||||
},
|
||||
"printcenter": {
|
||||
"errors": {
|
||||
"nocontexttype": "No context type set."
|
||||
|
||||
@@ -754,6 +754,7 @@
|
||||
"courtesycars-newcontract": "",
|
||||
"customers": "Clientes",
|
||||
"enterinvoices": "",
|
||||
"enterpayment": "",
|
||||
"entertimeticket": "",
|
||||
"home": "Casa",
|
||||
"invoices": "",
|
||||
@@ -886,6 +887,11 @@
|
||||
"created": "Pedido de piezas creado con éxito."
|
||||
}
|
||||
},
|
||||
"payments": {
|
||||
"labels": {
|
||||
"new": ""
|
||||
}
|
||||
},
|
||||
"printcenter": {
|
||||
"errors": {
|
||||
"nocontexttype": ""
|
||||
|
||||
@@ -754,6 +754,7 @@
|
||||
"courtesycars-newcontract": "",
|
||||
"customers": "Les clients",
|
||||
"enterinvoices": "",
|
||||
"enterpayment": "",
|
||||
"entertimeticket": "",
|
||||
"home": "Accueil",
|
||||
"invoices": "",
|
||||
@@ -886,6 +887,11 @@
|
||||
"created": "Commande de pièces créée avec succès."
|
||||
}
|
||||
},
|
||||
"payments": {
|
||||
"labels": {
|
||||
"new": ""
|
||||
}
|
||||
},
|
||||
"printcenter": {
|
||||
"errors": {
|
||||
"nocontexttype": ""
|
||||
|
||||
@@ -1999,6 +1999,18 @@
|
||||
resolved "https://registry.yarnpkg.com/@restart/hooks/-/hooks-0.3.21.tgz#5264d12019ffb844dc1fc44d55517ded7b580ee2"
|
||||
integrity sha512-Wcu3CFJV+iiqPEIoPVx3/CYnZBRgPeRABo6bLJByRH9ptJXyObn7WYPG7Rv0cg3+55bqcBbG0xEfovzwE2PNXg==
|
||||
|
||||
"@stripe/react-stripe-js@^1.1.2":
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@stripe/react-stripe-js/-/react-stripe-js-1.1.2.tgz#a7f5ef5b4d7dc7fa723501b706644414cfe6dcba"
|
||||
integrity sha512-07hu8RJXwWKGbvdvd1yt1cYvGtDB8jFX+q10f7FQuItUt9rlSo0am3WIx845iMHANiYgxyRb1PS201Yle9xxPQ==
|
||||
dependencies:
|
||||
prop-types "^15.7.2"
|
||||
|
||||
"@stripe/stripe-js@^1.7.0":
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@stripe/stripe-js/-/stripe-js-1.7.0.tgz#870885e69b7627e59cd4777da558e494ba5cb698"
|
||||
integrity sha512-/OreTnc8qWBsNrkpNTOxn67oRlqa+PZXukpiyZTcPo9/DRYyxtBZKvplFbH0C/qC/w0TpN8cueRl3h/dNYO4eg==
|
||||
|
||||
"@svgr/babel-plugin-add-jsx-attribute@^4.2.0":
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-4.2.0.tgz#dadcb6218503532d6884b210e7f3c502caaa44b1"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP TABLE "public"."payments";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,23 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
type: run_sql
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: "CREATE TABLE \"public\".\"payments\"(\"id\" uuid NOT NULL DEFAULT gen_random_uuid(),
|
||||
\"created_at\" timestamptz NOT NULL DEFAULT now(), \"updated_at\" timestamptz
|
||||
NOT NULL DEFAULT now(), \"jobid\" uuid NOT NULL, \"amount\" integer NOT NULL,
|
||||
PRIMARY KEY (\"id\") , FOREIGN KEY (\"jobid\") REFERENCES \"public\".\"jobs\"(\"id\")
|
||||
ON UPDATE restrict ON DELETE restrict);\nCREATE OR REPLACE FUNCTION \"public\".\"set_current_timestamp_updated_at\"()\nRETURNS
|
||||
TRIGGER AS $$\nDECLARE\n _new record;\nBEGIN\n _new := NEW;\n _new.\"updated_at\"
|
||||
= NOW();\n RETURN _new;\nEND;\n$$ LANGUAGE plpgsql;\nCREATE TRIGGER \"set_public_payments_updated_at\"\nBEFORE
|
||||
UPDATE ON \"public\".\"payments\"\nFOR EACH ROW\nEXECUTE PROCEDURE \"public\".\"set_current_timestamp_updated_at\"();\nCOMMENT
|
||||
ON TRIGGER \"set_public_payments_updated_at\" ON \"public\".\"payments\" \nIS
|
||||
'trigger to set value of column \"updated_at\" to current timestamp on row update';"
|
||||
type: run_sql
|
||||
- args:
|
||||
name: payments
|
||||
schema: public
|
||||
type: add_existing_table_or_view
|
||||
@@ -0,0 +1,12 @@
|
||||
- args:
|
||||
relationship: payments
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
type: drop_relationship
|
||||
- args:
|
||||
relationship: job
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: drop_relationship
|
||||
@@ -0,0 +1,20 @@
|
||||
- args:
|
||||
name: payments
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: jobid
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: create_array_relationship
|
||||
- args:
|
||||
name: job
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
using:
|
||||
foreign_key_constraint_on: jobid
|
||||
type: create_object_relationship
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
@@ -0,0 +1,28 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_upsert: true
|
||||
check:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
columns:
|
||||
- id
|
||||
- created_at
|
||||
- updated_at
|
||||
- jobid
|
||||
- amount
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
@@ -0,0 +1,26 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- amount
|
||||
- created_at
|
||||
- updated_at
|
||||
- id
|
||||
- jobid
|
||||
computed_fields: []
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
limit: null
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
@@ -0,0 +1,27 @@
|
||||
- args:
|
||||
permission:
|
||||
columns:
|
||||
- amount
|
||||
- created_at
|
||||
- updated_at
|
||||
- id
|
||||
- jobid
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: drop_delete_permission
|
||||
@@ -0,0 +1,17 @@
|
||||
- args:
|
||||
permission:
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
role: user
|
||||
table:
|
||||
name: payments
|
||||
schema: public
|
||||
type: create_delete_permission
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "stripe_acct_id";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "stripe_acct_id" text NULL;
|
||||
type: run_sql
|
||||
@@ -0,0 +1,52 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: bodyshops
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- accountingconfig
|
||||
- address1
|
||||
- address2
|
||||
- appt_length
|
||||
- city
|
||||
- country
|
||||
- created_at
|
||||
- email
|
||||
- federal_tax_id
|
||||
- id
|
||||
- inhousevendorid
|
||||
- insurance_vendor_id
|
||||
- intakechecklist
|
||||
- invoice_tax_rates
|
||||
- logo_img_path
|
||||
- md_order_statuses
|
||||
- md_responsibility_centers
|
||||
- md_ro_statuses
|
||||
- messagingservicesid
|
||||
- production_config
|
||||
- region_config
|
||||
- shopname
|
||||
- shoprates
|
||||
- state
|
||||
- state_tax_id
|
||||
- template_header
|
||||
- textid
|
||||
- updated_at
|
||||
- zip_post
|
||||
computed_fields: []
|
||||
filter:
|
||||
associations:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
role: user
|
||||
table:
|
||||
name: bodyshops
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,53 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: bodyshops
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- accountingconfig
|
||||
- address1
|
||||
- address2
|
||||
- appt_length
|
||||
- city
|
||||
- country
|
||||
- created_at
|
||||
- email
|
||||
- federal_tax_id
|
||||
- id
|
||||
- inhousevendorid
|
||||
- insurance_vendor_id
|
||||
- intakechecklist
|
||||
- invoice_tax_rates
|
||||
- logo_img_path
|
||||
- md_order_statuses
|
||||
- md_responsibility_centers
|
||||
- md_ro_statuses
|
||||
- messagingservicesid
|
||||
- production_config
|
||||
- region_config
|
||||
- shopname
|
||||
- shoprates
|
||||
- state
|
||||
- state_tax_id
|
||||
- stripe_acct_id
|
||||
- template_header
|
||||
- textid
|
||||
- updated_at
|
||||
- zip_post
|
||||
computed_fields: []
|
||||
filter:
|
||||
associations:
|
||||
bodyshop:
|
||||
associations:
|
||||
user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
role: user
|
||||
table:
|
||||
name: bodyshops
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -469,6 +469,7 @@ tables:
|
||||
- shoprates
|
||||
- state
|
||||
- state_tax_id
|
||||
- stripe_acct_id
|
||||
- template_header
|
||||
- textid
|
||||
- updated_at
|
||||
@@ -1867,6 +1868,13 @@ tables:
|
||||
table:
|
||||
schema: public
|
||||
name: parts_orders
|
||||
- name: payments
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: jobid
|
||||
table:
|
||||
schema: public
|
||||
name: payments
|
||||
- name: timetickets
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
@@ -3162,6 +3170,83 @@ tables:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
- table:
|
||||
schema: public
|
||||
name: payments
|
||||
object_relationships:
|
||||
- name: job
|
||||
using:
|
||||
foreign_key_constraint_on: jobid
|
||||
insert_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
check:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
columns:
|
||||
- id
|
||||
- created_at
|
||||
- updated_at
|
||||
- jobid
|
||||
- amount
|
||||
select_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
columns:
|
||||
- amount
|
||||
- created_at
|
||||
- updated_at
|
||||
- id
|
||||
- jobid
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
update_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
columns:
|
||||
- amount
|
||||
- created_at
|
||||
- updated_at
|
||||
- id
|
||||
- jobid
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
delete_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
- table:
|
||||
schema: public
|
||||
name: productionview
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"moment": "^2.26.0",
|
||||
"nodemailer": "^6.4.4",
|
||||
"phone": "^2.4.8",
|
||||
"stripe": "^8.60.0",
|
||||
"twilio": "^3.41.1",
|
||||
"xmlbuilder": "^15.1.1"
|
||||
},
|
||||
|
||||
@@ -80,6 +80,10 @@ app.post("/render", renderHandlebars.render);
|
||||
var fb = require("./server/firebase/firebase-handler");
|
||||
app.post("/notifications/send", fb.sendNotification);
|
||||
|
||||
//Stripe Processing
|
||||
var stripe = require("./server/stripe/payment");
|
||||
app.post("/stripe/payment", stripe.payment);
|
||||
|
||||
//Serve React App if in Production
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
app.use(express.static(path.join(__dirname, "client/build")));
|
||||
|
||||
60
server/stripe/payment.js
Normal file
60
server/stripe/payment.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
|
||||
|
||||
exports.payment = async (req, res) => {
|
||||
const { amount, stripe_acct_id } = req.body;
|
||||
console.log("exports.payment -> amount", amount);
|
||||
console.log("exports.payment -> stripe_acct_id", stripe_acct_id);
|
||||
try {
|
||||
|
||||
const pr = await stripe.paymentRequest.create({
|
||||
country: "CA",
|
||||
currency: "cad",
|
||||
total: {
|
||||
label: "Demo total",
|
||||
amount: 1099,
|
||||
},
|
||||
requestPayerName: true,
|
||||
requestPayerEmail: true,
|
||||
});
|
||||
|
||||
console.log(pr);
|
||||
|
||||
await stripe.paymentIntents
|
||||
.create(
|
||||
{
|
||||
payment_method_types: ["card"],
|
||||
amount: amount,
|
||||
currency: "cad",
|
||||
application_fee_amount: 100,
|
||||
},
|
||||
{
|
||||
stripeAccount: stripe_acct_id,
|
||||
}
|
||||
)
|
||||
.then(function (paymentIntent) {
|
||||
try {
|
||||
return res.send({
|
||||
clientSecret: paymentIntent.client_secret,
|
||||
});
|
||||
} catch (err) {
|
||||
return res.status(500).send({
|
||||
error: err.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
res.status(400).send(error);
|
||||
}
|
||||
};
|
||||
18
yarn.lock
18
yarn.lock
@@ -272,6 +272,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.17.tgz#191b71e7f4c325ee0fb23bc4a996477d92b8c39b"
|
||||
integrity sha512-Is+l3mcHvs47sKy+afn2O1rV4ldZFU7W8101cNlOd+MRbjM4Onida8jSZnJdTe/0Pcf25g9BNIUsuugmE6puHA==
|
||||
|
||||
"@types/node@>=8.1.0":
|
||||
version "14.0.11"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.11.tgz#61d4886e2424da73b7b25547f59fdcb534c165a3"
|
||||
integrity sha512-lCvvI24L21ZVeIiyIUHZ5Oflv1hhHQ5E1S25IRlKIXaRkVgmXpJMI3wUJkmym2bTbCe+WoIibQnMVAU3FguaOg==
|
||||
|
||||
"@types/node@^13.7.0":
|
||||
version "13.13.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.4.tgz#1581d6c16e3d4803eb079c87d4ac893ee7501c2c"
|
||||
@@ -2342,6 +2347,11 @@ qs@6.7.0:
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
|
||||
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==
|
||||
|
||||
qs@^6.6.0:
|
||||
version "6.9.4"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
|
||||
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==
|
||||
|
||||
qs@^6.9.1:
|
||||
version "6.9.2"
|
||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.2.tgz#a27b695006544a04bf0e6c6a7e8120778926d5bd"
|
||||
@@ -2759,6 +2769,14 @@ strip-json-comments@^3.0.1:
|
||||
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.0.1.tgz#85713975a91fb87bf1b305cca77395e40d2a64a7"
|
||||
integrity sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==
|
||||
|
||||
stripe@^8.60.0:
|
||||
version "8.60.0"
|
||||
resolved "https://registry.yarnpkg.com/stripe/-/stripe-8.60.0.tgz#764106ab639338447fddcedcd4c32ba6eb61b8bc"
|
||||
integrity sha512-FmM0Cy1YLW8Nk3dzWg83tDKROPAJwS2f+Xeezyq15JRUSOUqaSoj1FguBY460GWpzzQcqSXUXkQozYcLU1UtAg==
|
||||
dependencies:
|
||||
"@types/node" ">=8.1.0"
|
||||
qs "^6.6.0"
|
||||
|
||||
stubs@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/stubs/-/stubs-3.0.0.tgz#e8d2ba1fa9c90570303c030b6900f7d5f89abe5b"
|
||||
|
||||
Reference in New Issue
Block a user