Fix postback handling.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user