Exemplo n.º 1
0
    private function _updatePaymentStatusOfOrder($id_order)
    {
        include_once _PS_MODULE_DIR_ . 'paypal/api/paypal_lib.php';
        if (!$id_order || !$this->isPayPalAPIAvailable()) {
            return false;
        }
        $paypal_order = PayPalOrder::getOrderById((int) $id_order);
        if (!$paypal_order) {
            return false;
        }
        $paypal_lib = new PaypalLib();
        $response = $paypal_lib->makeCall($this->getAPIURL(), $this->getAPIScript(), 'GetTransactionDetails', '&' . http_build_query(array('TRANSACTIONID' => $paypal_order->id_transaction), '', '&'));
        if (array_key_exists('ACK', $response)) {
            if ($response['ACK'] == 'Success' && isset($response['PAYMENTSTATUS'])) {
                $history = new OrderHistory();
                $history->id_order = (int) $id_order;
                if ($response['PAYMENTSTATUS'] == 'Completed') {
                    $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), (int) $id_order);
                } elseif ($response['PAYMENTSTATUS'] == 'Pending' && $response['PENDINGREASON'] == 'authorization') {
                    $history->changeIdOrderState((int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), (int) $id_order);
                } elseif ($response['PAYMENTSTATUS'] == 'Reversed') {
                    $history->changeIdOrderState(Configuration::get('PS_OS_ERROR'), (int) $id_order);
                }
                $history->addWithemail();
                if (!Db::getInstance()->Execute('
				UPDATE `' . _DB_PREFIX_ . 'paypal_order`
				SET `payment_status` = \'' . pSQL($response['PAYMENTSTATUS']) . ($response['PENDINGREASON'] == 'authorization' ? '_authorization' : '') . '\'
				WHERE `id_order` = ' . (int) $id_order)) {
                    die(Tools::displayError('Error when updating PayPal database'));
                }
            }
            $message = $this->l('Verification status :') . '<br>';
            PayPalTools::formatMessage($response, $message);
            $this->_addNewPrivateMessage((int) $id_order, $message);
            return $response;
        }
        return false;
    }