/* ============================================================================ *\
|| ########################################################################## ||
|| # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
|| # ---------------------------------------------------------------------- # ||
|| # License # 35YAHCNR9344X6O666C123AB # ||
|| # ---------------------------------------------------------------------- # ||
|| # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
|| # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
const dateFormat = require('dateformat')
const md5 = require('md5')
const _ = require('underscore')
const mysqclass = require('./mysqli').default
/**
* @class class to handle refund functions
*/
class refundModule {
/**
* Mark Cart as Refund
* @param {object} req req object
* @param {number} cartID cartId which has to be marked as refund
* @param {number} paid Paid status
* @returns {object} sql response
*/
static async markCartRefund(req, cartID, paid) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
const escapeData = [
paid,
req.body.payment_method,
req.body.card_number,
req.body.card_expiry,
dateNow,
cartID,
]
const strQuery = await mysqclass.mysqli(mysql, 'refund_update_payment_success_cart')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Mark BuyNow Table Cart as Refund
* @param {number} InvoiceID Invoice ID which has to be marked
* @param {number} cartID cartId which has to be marked as refund
* @param {number} paid Paid status
* @returns {object} sql response
*/
static async markBuyNowRefund(cartID, InvoiceID, paid) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
const escapeData = [paid, InvoiceID, dateNow, cartID]
const strQuery = await mysqclass.mysqli(mysql, 'refund_update_payment_success_buynow')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Update Buynow table with the appointment
* @param {number} aptnID Appointment ID which has to be marked
* @param {number} cartID cartId which has to be updated
* @returns {object} sql response
*/
static async updateBuynowAppointment(cartID, aptnID) {
const mysql = {}
const escapeData = [aptnID, cartID]
const strQuery = await mysqclass.mysqli(mysql, 'refund_update_appointment_success_buynow')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Add Appointment
* @param {number} pickup pickup status
* @param {number} userID userID which has to be marked
* @param {number} locationID locationID which has to be added for appointment
* @returns {object} sql response
*/
static async addAppointment(pickup, userID, locationID) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
const aptnDateTime = dateFormat(new Date(pickup), 'yyyy-mm-dd HH:MM:ss')
const escapeData = [aptnDateTime, userID, locationID, dateNow, 1]
const strQuery = await mysqclass.mysqli(mysql, 'insert_appointments_table')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Insert Payment log
* @param {number} cartID cart ID for which log has to be added
* @param {number} userID userID which has to be marked
* @param {string} payType What type of payment Gateway
* @param {string} gateWay Which payment gateway is used
* @returns {object} sql response
*/
static async insertPayLogRequest(cartID, userID, payType, gateWay) {
const mysql = {}
const escapeData = [userID, cartID, gateWay, payType]
const strQuery = await mysqclass.mysqli(mysql, 'insert_payment_request_log')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Update Payment log
* @param {object} data req.body object
* @param {number} id id which has to be marked
* @param {string} type What type of payment Gateway
* @returns {object} sql response
*/
static async updatePayLogRequest(data, id, type) {
let postData = data
const mysqli = {}
const acceptedObjects = [
'requested_at',
'response_at',
'request',
'response',
'transactionID',
]
postData = _.omit(postData, (value, key) => {
if (
_.isNull(value) ||
_.isUndefined(value) ||
value === '' ||
!_.contains(acceptedObjects, key)
) {
return true
}
return false
})
let escapeData = []
postData = _.omit(postData, (value, key, object) => {
if (!_.contains(acceptedObjects, key)) {
return true
}
return false
})
let defaultKeys = []
if (type === 1) {
defaultKeys = ['requested_at']
} else {
defaultKeys = ['response_at']
}
const defaultValues = [dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')]
const keyswithescape = defaultKeys.concat(_.keys(postData))
escapeData = defaultValues.concat(_.values(postData))
mysqli.keys = _.map(keyswithescape, (val) => {
return `${val} = ?`
})
mysqli.log_id = id
const strQuery = await mysqclass.mysqli(mysqli, 'update_payment_log')
const dataPromise = await global.mysql.query(strQuery, escapeData)
return dataPromise
}
/**
* Authorize payment Insert Record
* @param {object} req req.body object
* @param {object} cardDetails cart Details
* @param {object} cartValue cart values
* @param {object} data req.body
* @returns {object} sql response
*/
static async authorizeInsertPayRecord(req, cardDetails, cartValue, data) {
const mysql = {}
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
const escapeData = [
cartValue.id,
cartValue.user_id,
data.transId,
dateNow,
'authorize',
req.body.no_of_cards,
data.accountNumber,
cardDetails.card_amount,
data.accountType,
]
const strQuery = await mysqclass.mysqli(mysql, 'insert_pay_record')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get Minimum Invoice ID
* @param {number} cardID cartID minimum invoice ID
* @returns {object} sql response
*/
static async getMinimumInvoiceID(cardID) {
const mysql = {}
const escapeData = [cardID]
const strQuery = await mysqclass.mysqli(mysql, 'refund_get_minimum_invoiceid')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get cart Details
* @param {number} cardID cartID details has to be fetched
* @returns {object} sql response
*/
static async getCartDetails(cardID) {
const mysql = {}
const escapeData = [cardID]
const strQuery = await mysqclass.mysqli(mysql, 'refund_get_cart_details')
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
* Get Return Common Invoice Number
* @returns {object} sql response
*/
static async getReturnCommonInvoiceNo() {
const mysql = {}
const escapeData = []
const strQuery = await mysqclass.mysqli(mysql, 'im_54_return')
const dataReturn = await global.mysqlsingle.query(strQuery, escapeData)
return dataReturn
}
}
module.exports.default = refundModule