Exemplo n.º 1
0
 public function __construct($id = null, $id_lang = null, $id_shop = null)
 {
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         self::$definition = array('table' => 'paypal_capture', 'primary' => 'id_paypal_capture', 'fields' => array('id_order' => array('type' => 1, 'validate' => 'isUnsignedId'), 'result' => array('type' => 3, 'validate' => 'isString'), 'capture_amount' => array('type' => 4, 'validate' => 'isFloat'), 'date_add' => array('type' => 5, 'validate' => 'isDate'), 'date_upd' => array('type' => 5, 'validate' => 'isDate')));
     } else {
         $tables = array('paypal_capture');
         $fieldsRequired = array('id_order', 'result', 'capture_amount', 'date_add', 'date_upd');
         $fieldsValidate = array();
     }
     $this->date_add = date('Y-m-d H:i:s');
     $this->date_upd = date('Y-m-d H:i:s');
     return parent::__construct($id, $id_lang, $id_shop);
 }
Exemplo n.º 2
0
    private function _doCapture($id_order, $capture_amount = false, $is_complete = false)
    {
        $paypal_order = PayPalOrder::getOrderById((int) $id_order);
        if (!$this->isPayPalAPIAvailable() || !$paypal_order) {
            return false;
        }
        $order = new Order((int) $id_order);
        $currency = new Currency((int) $order->id_currency);
        if (!$capture_amount) {
            $capture_amount = (double) $order->total_paid;
        }
        $complete = 'Complete';
        if (!$is_complete) {
            $complete = 'NotComplete';
        }
        $paypal_lib = new PaypalLib();
        $response = $paypal_lib->makeCall($this->getAPIURL(), $this->getAPIScript(), 'DoCapture', '&' . http_build_query(array('AMT' => $capture_amount, 'AUTHORIZATIONID' => $paypal_order['id_transaction'], 'CURRENCYCODE' => $currency->iso_code, 'COMPLETETYPE' => $complete), '', '&'));
        $message = $this->l('Capture operation result:') . '<br>';
        foreach ($response as $key => $value) {
            $message .= $key . ': ' . $value . '<br>';
        }
        $capture = new PaypalCapture();
        $capture->id_order = (int) $id_order;
        $capture->capture_amount = (double) $capture_amount;
        if (array_key_exists('ACK', $response) && $response['ACK'] == 'Success' && $response['PAYMENTSTATUS'] == 'Completed') {
            $capture->result = pSQL($response['PAYMENTSTATUS']);
            if ($capture->save()) {
                if (!$capture->getRestToCapture($capture->id_order)) {
                    //plus d'argent a capturer
                    if (!Db::getInstance()->Execute('
					UPDATE `' . _DB_PREFIX_ . 'paypal_order`
					SET `capture` = 0, `payment_status` = \'' . pSQL($response['PAYMENTSTATUS']) . '\', `id_transaction` = \'' . pSQL($response['TRANSACTIONID']) . '\'
					WHERE `id_order` = ' . (int) $id_order)) {
                        die(Tools::displayError('Error when updating PayPal database'));
                    }
                    $order_history = new OrderHistory();
                    $order_history->id_order = (int) $id_order;
                    if (version_compare(_PS_VERSION_, '1.5', '<')) {
                        $order_history->changeIdOrderState(Configuration::get('PS_OS_WS_PAYMENT'), (int) $id_order);
                    } else {
                        $order_history->changeIdOrderState(Configuration::get('PS_OS_WS_PAYMENT'), $order);
                    }
                    $order_history->addWithemail();
                    $message .= $this->l('Order finished with PayPal!');
                }
            }
        } elseif (isset($response['PAYMENTSTATUS'])) {
            $capture->result = pSQL($response['PAYMENTSTATUS']);
            $capture->save();
            $message .= $this->l('Transaction error!');
        }
        $this->_addNewPrivateMessage((int) $id_order, $message);
        Tools::redirect($_SERVER['HTTP_REFERER']);
    }