Db::getInstance()->Execute($sql); if (version_compare(_PS_VERSION_, '1.5', '>=')) { Tools::redirect($payment->getRedirect()); } else { Tools::redirectLink($payment->getRedirect()); } return; } elseif ($status == 'SUCCESS') { $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'syspay_payment VALUES(' . (int) $payment->getId() . ', ' . $payment->getDescription() . ', "' . Tools::getValue('order_ref') . '", "' . $payment->getRedirect() . '", "' . $type_of_payment . '")'; Db::getInstance()->Execute($sql); $params = array('result' => base64_encode(Tools::jsonEncode($client->getData())), 'merchant' => $client->getUsername()); $params['checksum'] = Syspay_Merchant_Utils::getChecksum($params['result'], $client->getSecret()); $website = SyspayTools::getWebsite(true, false); $redirect = sprintf($website . _MODULE_DIR_ . 'syspay/confirmation.php?%s', http_build_query($params)); if (version_compare(_PS_VERSION_, '1.5', '>=')) { Tools::redirect($redirect); } else { Tools::redirectLink($redirect); } return; } else { $website = SyspayTools::getWebsite(true, false); if (version_compare(_PS_VERSION_, '1.5', '>=')) { Tools::redirect('/index.php?controller=order&step=3&err=1'); } else { Tools::redirectLink($website . '/order.php?step=3&err=1'); } return; } }
public static function processAdminForms($order, $id) { if (Configuration::get('SYSPAY_MODE') == 0) { $mode = Syspay_Merchant_Client::BASE_URL_SANDBOX; $mid = Configuration::get('SYSPAY_TEST_MID'); $pass = Configuration::get('SYSPAY_TEST_SHA1_PRIVATE'); } else { $mode = Syspay_Merchant_Client::BASE_URL_PROD; $mid = Configuration::get('SYSPAY_LIVE_MID'); $pass = Configuration::get('SYSPAY_LIVE_SHA1_PRIVATE'); } $client = new Syspay_Merchant_Client($mid, $pass, $mode); $info_request = new Syspay_Merchant_PaymentInfoRequest($id); try { $payment = $client->request($info_request); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (!$payment) { return false; } if (Tools::getValue('sp_cancel_payment') == 2) { if (version_compare(_PS_VERSION_, '1.5', '<')) { $current_state = $order->getCurrentState(); } else { $current_state = $order->getCurrentOrderState()->id; } if ($current_state == Configuration::get('PS_OS_SYSPAY_AUTHORIZED') && $payment->getStatus() == 'AUTHORIZED') { $void_request = new Syspay_Merchant_VoidRequest(); $void_request->setPaymentId($id); // Returned to you on the initial payment request $client->request($void_request); if (version_compare(_PS_VERSION_, '1.5', '<')) { Tools::redirectAdmin(AdminController::$currentIndex . '&vieworder&id_order=' . $order->id . '&token=' . Tools::getAdminTokenLite('AdminOrders')); } else { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminOrders', true) . '&vieworder&id_order=' . $order->id); } } } if (Tools::getValue('refund_form') == 2) { $ids_syspay_refund = Db::getInstance()->executeS(' SELECT sr.id_syspay_refund FROM ' . _DB_PREFIX_ . 'syspay_refund sr WHERE sr.id_order=' . $order->id); $original_payment = Db::getInstance()->getValue(' SELECT sp.id_syspay_payment FROM ' . _DB_PREFIX_ . 'syspay_payment sp LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_cart=sp.id_cart WHERE o.id_order=' . $order->id); $payment_ir = new Syspay_Merchant_PaymentInfoRequest($original_payment); try { $payment_info = $client->request($payment_ir); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (!$payment_info) { return false; } $total_paid = $payment_info->getAmount(); $total_paid = $total_paid / 100; $total = 0; foreach ($ids_syspay_refund as $id) { $refund_ir = new Syspay_Merchant_RefundInfoRequest($id['id_syspay_refund']); $refund_info = $client->request($refund_ir); if (!$refund_info) { return false; } $amount = $refund_info->getAmount(); $amount = $amount / 100; $total += $amount; } $val = Tools::getValue('refund_value'); if ($val == '') { return false; } $val = str_replace(',', '.', $val); $val = number_format($val, 2, '.', ''); $refund_value = $val * 100; if ($val + $total > $total_paid) { return false; } $refund = new Syspay_Merchant_Entity_Refund(); $refund->setReference(count($ids_syspay_refund) . $payment->getReference()); // Your own reference for this refund $refund->setAmount($refund_value); // The amount to refund in *cents* $refund->setCurrency($payment->getCurrency()); // The currency of the refund. It must match the one of the original payment $refund->setDescription(Tools::getValue('refund_reason')); // An optional description for this refund $refund_request = new Syspay_Merchant_RefundRequest(); $refund_request->setPaymentId($original_payment); // The payment id to refund $website = SyspayTools::getWebsite(true, false); $refund_request->setEmsUrl($website . _MODULE_DIR_ . 'syspay/ems.php'); $refund_request->setRefund($refund); try { $refund = $client->request($refund_request); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (version_compare(_PS_VERSION_, '1.5', '<')) { Tools::redirectAdmin(AdminController::$currentIndex . '&vieworder&id_order=' . $order->id . '&token=' . Tools::getAdminTokenLite('AdminOrders')); } else { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminOrders', true) . '&vieworder&id_order=' . $order->id); } } }