Fix postback handling.

This commit is contained in:
Patrick Fic
2023-08-16 15:28:05 -07:00
parent c10517a11b
commit a879e99e77
4 changed files with 15 additions and 11 deletions

View File

@@ -97,16 +97,12 @@ const CardPaymentModalComponent = ({
};
const handleFinish = async (values) => {
console.log(
"🚀 ~ file: card-payment-modal.component..jsx:100 ~ handleFinish ~ values:",
values
);
try {
const paymentResult = await insertPayment({
variables: {
paymentInput: {
amount: values.amount,
transactionid: values.paymentResponse.paymentid,
transactionid: (values.paymentResponse.paymentid || "").toString(),
payer: t("payments.labels.customer"),
type: values.paymentResponse.cardbrand,
jobid: values.jobid,

View File

@@ -177,6 +177,7 @@ export function JobPayments({
bodyshop,
amount: balance.getAmount(),
account: job.ro_number,
invoice: job.id,
}
);
setGeneratingtURL(false);
@@ -209,7 +210,7 @@ export function JobPayments({
>
{t("menus.header.enterpayment")}
</Button>
<Button
onClick={() =>
setCardPaymentContext({

View File

@@ -987,6 +987,7 @@ exports.GET_JOB_BY_PK = `query GET_JOB_BY_PK($id: uuid!) {
ins_ph1
est_co_nm
est_ct_fn
shopid
est_ct_ln
vehicle{
id

View File

@@ -4,6 +4,7 @@ const queries = require("../graphql-client/queries");
const Dinero = require("dinero.js");
const qs = require("query-string");
const axios = require("axios");
const moment = require("moment");
require("dotenv").config({
path: path.resolve(
process.cwd(),
@@ -111,6 +112,7 @@ exports.generate_payment_url = async (req, res) => {
data: qs.stringify({
...shopCredentials,
...req.body,
bodyshopid: "1234",
createshorturl: true,
//The postback URL is set at the CP teller global terminal settings page.
}),
@@ -131,9 +133,13 @@ exports.postback = async (req, res) => {
const { body: values } = req;
if (!values.invoice) {
res.sendStatus(200);
return;
}
// TODO query job by account name
const job = await gqlClient.request(queries.GET_JOB_BY_RO_NUMBER, {
ro_number: values.account,
const job = await gqlClient.request(queries.GET_JOB_BY_PK, {
id: values.invoice,
});
// TODO add mutation to database
@@ -143,7 +149,7 @@ exports.postback = async (req, res) => {
transactionid: `C00 ${values.authcode}`,
payer: "Customer",
type: values.cardtype,
jobid: job.jobs[0].id,
jobid: values.invoice,
date: moment(Date.now()),
},
});
@@ -151,9 +157,9 @@ exports.postback = async (req, res) => {
await gqlClient.request(queries.INSERT_PAYMENT_RESPONSE, {
paymentResponse: {
amount: values.total,
bodyshopid: job.jobs[0].bodyshop.id,
bodyshopid: job.jobs_by_pk.shopid,
paymentid: paymentResult.id,
jobid: job.jobs[0].id,
jobid: values.invoice,
declinereason: "Approved",
ext_paymentid: values.paymentid,
successful: true,