IO-256 QBO SS Realm ID
This commit is contained in:
@@ -42,10 +42,13 @@ exports.default = async (req, res) => {
|
||||
const response = await apiGqlClient.request(queries.GET_QBO_AUTH, {
|
||||
email: req.user.email,
|
||||
});
|
||||
|
||||
const { qbo_realmId } = response.associations[0];
|
||||
oauthClient.setToken(response.associations[0].qbo_auth);
|
||||
|
||||
await refreshOauthToken(oauthClient, req);
|
||||
if (!qbo_realmId) {
|
||||
res.status(401).json({ error: "No company associated." });
|
||||
return;
|
||||
}
|
||||
await refreshOauthToken(oauthClient, qbo_realmId, req);
|
||||
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { payments: paymentsToQuery } = req.body;
|
||||
@@ -80,6 +83,7 @@ exports.default = async (req, res) => {
|
||||
//Query for top level customer, the insurance company name.
|
||||
insCoCustomerTier = await QueryInsuranceCo(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job
|
||||
);
|
||||
@@ -87,6 +91,7 @@ exports.default = async (req, res) => {
|
||||
//Creating the Insurance Customer.
|
||||
insCoCustomerTier = await InsertInsuranceCo(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job,
|
||||
bodyshop
|
||||
@@ -96,11 +101,17 @@ exports.default = async (req, res) => {
|
||||
|
||||
if (isThreeTier || (!isThreeTier && twoTierPref === "name")) {
|
||||
//Insert the name/owner and account for whether the source should be the ins co in 3 tier..
|
||||
ownerCustomerTier = await QueryOwner(oauthClient, req, payment.job);
|
||||
ownerCustomerTier = await QueryOwner(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job
|
||||
);
|
||||
//Query for the owner itself.
|
||||
if (!ownerCustomerTier) {
|
||||
ownerCustomerTier = await InsertOwner(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job,
|
||||
isThreeTier,
|
||||
@@ -110,20 +121,21 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
|
||||
//Query for the Job or Create it.
|
||||
jobTier = await QueryJob(oauthClient, req, payment.job);
|
||||
jobTier = await QueryJob(oauthClient, qbo_realmId, req, payment.job);
|
||||
|
||||
// Need to validate that the job tier is associated to the right individual?
|
||||
|
||||
if (!jobTier) {
|
||||
jobTier = await InsertJob(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job,
|
||||
ownerCustomerTier || insCoCustomerTier
|
||||
);
|
||||
}
|
||||
|
||||
await InsertPayment(oauthClient, req, payment, jobTier);
|
||||
await InsertPayment(oauthClient, qbo_realmId, req, payment, jobTier);
|
||||
ret.push({ paymentid: payment.id, success: true });
|
||||
} catch (error) {
|
||||
logger.log("qbo-payment-create-error", "ERROR", req.user.email, {
|
||||
@@ -150,9 +162,16 @@ exports.default = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
async function InsertPayment(oauthClient, req, payment, parentRef) {
|
||||
async function InsertPayment(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment,
|
||||
parentRef
|
||||
) {
|
||||
const { paymentMethods, invoices } = await QueryMetaData(
|
||||
oauthClient,
|
||||
qbo_realmId,
|
||||
req,
|
||||
payment.job.ro_number
|
||||
);
|
||||
@@ -199,7 +218,7 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
|
||||
});
|
||||
try {
|
||||
const result = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(req.cookies.qbo_realmId, "payment"),
|
||||
url: urlBuilder(qbo_realmId, "payment"),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -216,10 +235,10 @@ async function InsertPayment(oauthClient, req, payment, parentRef) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async function QueryMetaData(oauthClient, req, ro_number) {
|
||||
async function QueryMetaData(oauthClient, qbo_realmId, req, ro_number) {
|
||||
const invoice = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(
|
||||
req.cookies.qbo_realmId,
|
||||
qbo_realmId,
|
||||
"query",
|
||||
`select * From Invoice where DocNumber = '${ro_number}'`
|
||||
),
|
||||
@@ -230,11 +249,7 @@ async function QueryMetaData(oauthClient, req, ro_number) {
|
||||
});
|
||||
|
||||
const paymentMethods = await oauthClient.makeApiCall({
|
||||
url: urlBuilder(
|
||||
req.cookies.qbo_realmId,
|
||||
"query",
|
||||
`select * From PaymentMethod`
|
||||
),
|
||||
url: urlBuilder(qbo_realmId, "query", `select * From PaymentMethod`),
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -243,7 +258,7 @@ async function QueryMetaData(oauthClient, req, ro_number) {
|
||||
setNewRefreshToken(req.user.email, paymentMethods);
|
||||
|
||||
// const classes = await oauthClient.makeApiCall({
|
||||
// url: urlBuilder(req.cookies.qbo_realmId, "query", `select * From Class`),
|
||||
// url: urlBuilder(qbo_realmId, "query", `select * From Class`),
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user