Beispiel #1
0
    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);
            }
        }
    }
Beispiel #2
0
            Tools::redirect('/index.php?controller=order&step=3&err=1');
        } else {
            Tools::redirectLink($website . '/order.php?step=3&err=1');
        }
        return false;
    } catch (Syspay_Merchant_UnexpectedResponseException $s) {
        $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 false;
    }
} elseif (Tools::isSubmit('rebill')) {
    $client = new Syspay_Merchant_Client($mid, $pass, $mode);
    $id_rebill = Tools::getValue('rebill');
    if (version_compare(_PS_VERSION_, '1.5', '>=')) {
        $customer = Customer::getCustomersByEmail(Tools::getValue('email'));
        $id = SyspayTools::getIdsRebillByIdCustomer($customer[0]['id_customer']);
    } else {
        $customer = new Customer();
        $customer = $customer->getByEmail(Tools::getValue('email'));
        $id = SyspayTools::getIdsRebillByIdCustomer($customer->id);
    }
    if ($id_rebill != $id) {
        $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');
Beispiel #3
0
    public function hookUpdateOrderStatus($params)
    {
        require_once dirname(__FILE__) . '/tools/loader.php';
        $order_state = $params['newOrderStatus'];
        $id_order = $params['id_order'];
        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);
        if (!$client) {
            return false;
        }
        $original_payment_id = 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=' . $id_order);
        if (!$original_payment_id) {
            return false;
        }
        $info_request = new Syspay_Merchant_PaymentInfoRequest($original_payment_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;
        }
        $id_status = $order_state->id;
        $id_fos = Db::getInstance()->getValue('
			SELECT `id_order_state`
			FROM `' . _DB_PREFIX_ . 'order_history`
			WHERE `id_order` = ' . (int) $id_order . '
			ORDER BY `date_add` ASC, `id_order_history` ASC');
        if ($id_fos == Configuration::get('PS_OS_SYSPAY_AUTHORIZED') && $id_status == Configuration::get('SYSPAY_CAPTURE_OS') && $payment->getStatus() == 'AUTHORIZED') {
            $confirm_request = new Syspay_Merchant_ConfirmRequest();
            $confirm_request->setPaymentId($original_payment_id);
            // Returned to you on the initial payment request
            try {
                $client->request($confirm_request);
            } catch (Syspay_Merchant_RequestException $s) {
                return false;
            } catch (Syspay_Merchant_UnexpectedResponseException $s) {
                return false;
            }
        }
        return true;
    }