Hello, I have the following code, each user must have a linked credit card, upon a Refund or a payout, there will be a pre-auth check, the problem here is that I need to add the condition but I believe I misplaced it, please take a look.
General information
VIP == 0 means check for card pre-auth
VIP == 1 Skip pre-auth and issue the refund or payout.
public function postProcess(){
$idRequest = (Tools::getValue('id_request'));
$id_Seller = Db::getInstance()->getValue('SELECT id_seller FROM '._DB_PREFIX_.'mangopay_wk_seller_refund_request WHERE id_request=' . $idRequest );
//var_dump($id_Seller) => it will return user id = 7 as expected so the query is valid;
$isVIP = Db::getInstance()->getValue('SELECT vip FROM '._DB_PREFIX_.'wk_mp_seller WHERE id_seller=' . $id_Seller);
//var_dump($isVIP) => will return 1 as the user is VIP enabled;
if (Tools::isSubmit('request_deny_button')) {
if ($idRequest = Tools::getValue('id_request')) {
if ($objRequest = new MangopaySellerRefundRequest($idRequest)) {
$objRequest->request_status = 2;
$objRequest->update();
Tools::redirectAdmin(
self::$currentIndex.'&id_request='.
(int) $idRequest.'&view'.
$this->table.'&conf=4&token='.$this->token
);
} else {
$this->errors[] = $this->l('Invalid id request');
}
} else {
$this->errors[] = $this->l('Invalid id request');
}
}
if (Tools::isSubmit('request_approve_button')) {
if ($idRequest = Tools::getValue('id_request')) {
if (!count($this->errors)) {
if ($objRequest = new MangopaySellerRefundRequest($idRequest,$isVIP == 1)) {
$objMgpMpService = new MangopayMpService();
$objMgpSeller = new MangopayMpSeller();
if ($details = $objRequest->getRefundRequestByTransferId($objRequest->mgp_transfer_id)) {
if ($details['valid'] == 0 && $details['refund_amount'] == $objRequest->refund_amount) {
$this->errors[] = $this->l('Mangopay duplicate refund. You can refund the same amount after 24 hours of your last request.');
}
}
}
if (!count($this->errors)) {
if ($this->checkSellerCardWithPreaouth($objRequest)) {
$this->processSellerRefund($objRequest);
} else {
$this->errors[] = $this->l('Invalid card details');
}
}
} else {
$this->errors[] = $this->l('Invalid request');
}
}
else {
$this->errors[] = $this->l('Invalid request');
}
}
if (Tools::isSubmit('request_note_button')) {
$message = Tools::getValue('refund_request_note');
$message = trim($message);
if ($idRequest = Tools::getValue('id_request')) {
if ($message == '') {
$this->errors[] = $this->l('Request Note is required.');
} else {
if ($objRequest = new MangopaySellerRefundRequest($idRequest)) {
$objRequest->note = $message;
$objRequest->update();
Tools::redirectAdmin(
self::$currentIndex.'&id_request='.
(int) $idRequest.'&view'.
$this->table.'&conf=5&token='.$this->token
);
} else {
$this->errors[] = $this->l('Invalid id request');
}
}
}
}
parent::postProcess();
}
Please look at this line:
if (Tools::isSubmit(‘request_approve_button’)) {
Orginal statement is
if ($objRequest = new MangopaySellerRefundRequest($idRequest)) {
I changed it to
if ($objRequest = new MangopaySellerRefundRequest($idRequest,$isVIP == 1)) {