Exemple #1
0
 public function initContent()
 {
     parent::initContent();
     $this->paypal = new PayPal();
     $this->context = Context::getContext();
     $this->id_module = (int) Tools::getValue('id_module');
     $this->id_order = (int) Tools::getValue('id_order');
     $order = new Order($this->id_order);
     $order_state = new OrderState($order->current_state);
     $paypal_order = PayPalOrder::getOrderById($this->id_order);
     if ($order_state->template[$this->context->language->id] == 'payment_error') {
         $this->context->smarty->assign(array('message' => $order_state->name[$this->context->language->id], 'logs' => array($this->paypal->l('An error occurred while processing payment.')), 'order' => $paypal_order, 'price' => Tools::displayPrice($paypal_order['total_paid'], $this->context->currency)));
         return $this->setTemplate('error.tpl');
     }
     $order_currency = new Currency((int) $order->id_currency);
     $display_currency = new Currency((int) $this->context->currency->id);
     $price = Tools::convertPriceFull($paypal_order['total_paid'], $order_currency, $display_currency);
     $this->context->smarty->assign(array('is_guest' => $this->context->customer->is_guest || $this->context->customer->id == false, 'order' => $paypal_order, 'price' => Tools::displayPrice($price, $this->context->currency->id), 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()));
     if ($this->context->customer->is_guest || $this->context->customer->id == false) {
         $this->context->smarty->assign(array('id_order' => (int) $this->id_order, 'id_order_formatted' => sprintf('#%06d', (int) $this->id_order), 'order_reference' => $order->reference));
         /* If guest we clear the cookie for security reason */
         $this->context->customer->mylogout();
     }
     if ($this->context->getMobileDevice() == true) {
         $this->setTemplate('order-confirmation-mobile.tpl');
     } else {
         $this->setTemplate('order-confirmation.tpl');
     }
 }
 public function displayContent()
 {
     $id_order = (int) Tools::getValue('id_order');
     $order = new Order($id_order);
     $paypal_order = PayPalOrder::getOrderById($id_order);
     if (defined("PAYPAL_FORCE_CURRENCY")) {
         $currency = new Currency((int) $this->context->currency->id);
         $paycurrency = new Currency(PAYPAL_FORCE_CURRENCY);
         $currency_decimals = $paycurrency->decimals;
         $paypal_order['total_paid'] = $paypal_order['total_paid'] / $currency->conversion_rate * $paycurrency->conversion_rate;
     }
     $price = Tools::displayPrice($paypal_order['total_paid'], $this->context->currency);
     $order_state = new OrderState($id_order);
     if ($order_state) {
         $order_state_message = $order_state->template[$this->context->language->id];
     }
     if (!$order || !$order_state || isset($order_state_message) && $order_state_message == 'payment_error') {
         $this->context->smarty->assign(array('logs' => array($this->paypal->l('An error occurred while processing payment.')), 'order' => $paypal_order, 'price' => $price));
         if (isset($order_state_message) && $order_state_message) {
             $this->context->smarty->assign('message', $order_state_message);
         }
         $template = 'error.tpl';
     } else {
         $this->context->smarty->assign(array('order' => $paypal_order, 'price' => $price));
         if (version_compare(_PS_VERSION_, '1.5', '>')) {
             $this->context->smarty->assign(array('reference_order' => Order::getUniqReferenceOf($paypal_order['id_order'])));
         }
         $template = 'order-confirmation.tpl';
     }
     $this->context->smarty->assign('use_mobile', (bool) $this->paypal->useMobile());
     echo $this->paypal->fetchTemplate($template);
 }
Exemple #3
0
 public function displayContent()
 {
     $id_order = (int) Tools::getValue('id_order');
     $order = PayPalOrder::getOrderById($id_order);
     $price = Tools::displayPrice($order['total_paid'], $this->context->currency);
     $this->context->smarty->assign(array('order' => $order, 'price' => $price));
     echo $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/paypal/views/templates/front/order-confirmation.tpl');
 }
 public function displayContent()
 {
     $order = PayPalOrder::getOrderById((int) Tools::getValue('id_order'));
     $this->context->smarty->assign(array('order' => $order, 'price' => Tools::displayPrice($order['total_paid'], $this->context->currency), 'use_mobile' => $this->context->getMobileDevice()));
     if (!$order) {
         $this->context->smarty->assign('errors', array($this->paypal->l('Payment error')));
     }
     echo $this->paypal->fetchTemplate('/views/templates/front/', 'order-confirmation');
 }
 public function displayContent()
 {
     $id_order = (int) Tools::getValue('id_order');
     $order = PayPalOrder::getOrderById($id_order);
     $price = Tools::displayPrice($order['total_paid'], $this->context->currency);
     $this->context->smarty->assign(array('order' => $order, 'price' => $price));
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         $this->context->smarty->assign(array('reference_order' => Order::getUniqReferenceOf($id_order)));
     }
     echo $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/paypal/views/templates/front/order-confirmation.tpl');
 }
 public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = null, $transaction = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false)
 {
     if ($this->active) {
         // Set transaction details if pcc is defined in PaymentModule class_exists
         if (isset($this->pcc)) {
             $this->pcc->transaction_id = isset($transaction['transaction_id']) ? $transaction['transaction_id'] : '';
         }
         parent::validateOrder((int) $id_cart, (int) $id_order_state, (double) $amountPaid, $paymentMethod, $message, $transaction, $currency_special, $dont_touch_amount, $secure_key);
         if (count($transaction) > 0) {
             PayPalOrder::saveOrder((int) $this->currentOrder, $transaction);
         }
     }
 }
 public function initContent()
 {
     parent::initContent();
     $this->paypal = new PayPal();
     $this->context = Context::getContext();
     $this->id_module = (int) Tools::getValue('id_module');
     $this->id_order = (int) Tools::getValue('id_order');
     $order = PayPalOrder::getOrderById($this->id_order);
     $this->context->smarty->assign(array('is_guest' => $this->context->customer->is_guest, 'order' => $order, 'price' => Tools::displayPrice($order['total_paid'], $this->context->currency), 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn()));
     if ($this->context->customer->is_guest) {
         $this->context->smarty->assign(array('id_order' => (int) $this->order->id_order, 'id_order_formatted' => sprintf('#%06d', (int) $this->order->id_order)));
         /* If guest we clear the cookie for security reason */
         $this->context->customer->mylogout();
     }
     $this->setTemplate('order-confirmation.tpl');
 }
 public function displayContent()
 {
     $id_order = (int) Tools::getValue('id_order');
     $order = PayPalOrder::getOrderById($id_order);
     if (defined("PAYPAL_FORCE_CURRENCY")) {
         $currency = new Currency((int) $this->context->currency->id);
         $paycurrency = new Currency(PAYPAL_FORCE_CURRENCY);
         $currency_decimals = $paycurrency->decimals;
         $order['total_paid'] = $order['total_paid'] / $currency->conversion_rate * $paycurrency->conversion_rate;
     }
     $price = Tools::displayPrice($order['total_paid'], $this->context->currency);
     $this->context->smarty->assign(array('order' => $order, 'price' => $price));
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         $this->context->smarty->assign(array('reference_order' => Order::getUniqReferenceOf($id_order)));
     }
     echo $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/paypal/views/templates/front/order-confirmation.tpl');
 }
Exemple #9
0
 public function confirmOrder($custom)
 {
     $cart = new Cart((int) $custom['id_cart']);
     $cart_details = $cart->getSummaryDetails(null, true);
     $cart_hash = sha1(serialize($cart->nbProducts()));
     $this->context->cart = $cart;
     $address = new Address((int) $cart->id_address_invoice);
     $this->context->country = new Country((int) $address->id_country);
     $this->context->customer = new Customer((int) $cart->id_customer);
     $this->context->language = new Language((int) $cart->id_lang);
     $this->context->currency = new Currency((int) $cart->id_currency);
     if (isset($cart->id_shop)) {
         $this->context->shop = new Shop($cart->id_shop);
     }
     $res = $this->getResult();
     if (strcmp($res, "VERIFIED") == 0) {
         $currency_decimals = is_array($this->context->currency) ? (int) $this->context->currency['decimals'] : (int) $this->context->currency->decimals;
         $this->decimals = $currency_decimals * _PS_PRICE_DISPLAY_PRECISION_;
         $message = null;
         $mc_gross = Tools::ps_round(Tools::getValue('mc_gross'), $this->decimals);
         $cart_details = $cart->getSummaryDetails(null, true);
         $shipping = $cart_details['total_shipping_tax_exc'];
         $subtotal = $cart_details['total_price_without_tax'] - $cart_details['total_shipping_tax_exc'];
         $tax = $cart_details['total_tax'];
         $total_price = Tools::ps_round($shipping + $subtotal + $tax, $this->decimals);
         if (bccomp($mc_gross, $total_price, 2) !== 0) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Price paid on paypal is not the same that on PrestaShop.') . '<br />';
         } elseif ($custom['hash'] != $cart_hash) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Cart changed, please retry.') . '<br />';
         } else {
             $payment = (int) Configuration::get('PS_OS_PAYMENT');
             $message = $this->l('Payment accepted.') . '<br />';
         }
         $customer = new Customer((int) $cart->id_customer);
         $transaction = PayPalOrder::getTransactionDetails(false);
         if (_PS_VERSION_ < '1.5') {
             $shop = null;
         } else {
             $shop_id = $this->context->shop->id;
             $shop = new Shop($shop_id);
         }
         $this->validateOrder($cart->id, $payment, $total_price, $this->displayName, $message, $transaction, $cart->id_currency, false, $customer->secure_key, $shop);
     }
 }
Exemple #10
0
 public function displayContent()
 {
     $id_order = (int) Tools::getValue('id_order');
     $order = new Order($id_order);
     $paypal_order = PayPalOrder::getOrderById($id_order);
     $price = Tools::displayPrice($paypal_order['total_paid'], $this->context->currency);
     $order_state = new OrderState($id_order);
     if ($order_state) {
         $order_state_message = $order_state->template[$this->context->language->id];
     }
     if (!$order || !$order_state || isset($order_state_message) && $order_state_message == 'payment_error') {
         $this->context->smarty->assign(array('logs' => array($this->paypal->l('An error occurred while processing payment.')), 'order' => $paypal_order, 'price' => $price));
         if (isset($order_state_message) && $order_state_message) {
             $this->context->smarty->assign('message', $order_state_message);
         }
         $template = 'error.tpl';
     } else {
         $this->context->smarty->assign(array('order' => $paypal_order, 'price' => $price));
         $template = 'order-confirmation.tpl';
     }
     $this->context->smarty->assign('use_mobile', (bool) $this->paypal->useMobile());
     echo $this->paypal->fetchTemplate($template);
 }
Exemple #11
0
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <*****@*****.**>
*  @copyright  2007-2012 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
include_once dirname(__FILE__) . '/../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../init.php';
include_once _PS_MODULE_DIR_ . 'paypal/paypal.php';
$paypal = new Paypal();
$paypal_order = new PayPalOrder();
if (!($transaction_id = Tools::getValue('txn_id'))) {
    die($paypal->l('No transaction id'));
}
if (!($id_order = $paypal_order->getIdOrderByTransactionId($transaction_id))) {
    die($paypal->l('No order'));
}
$order = new Order((int) $id_order);
if (!Validate::isLoadedObject($order) || !$order->id) {
    die($paypal->l('Invalid order'));
}
if (!($amount = (double) Tools::getValue('mc_gross') || $amount != $order->total_paid)) {
    die($paypal->l('Incorrect amount'));
}
if (!($status = (string) Tools::getValue('payment_status'))) {
    die($paypal->l('Incorrect order status'));
Exemple #12
0
/**
 * Check payment return
 */
function validateOrder($customer, $cart, $ppec)
{
    $amount_match = $ppec->rightPaymentProcess();
    $order_total = (double) $cart->getOrderTotal(true, Cart::BOTH);
    // Payment succeed
    if ($ppec->hasSucceedRequest() && !empty($ppec->token) && $amount_match) {
        if ((bool) Configuration::get('PAYPAL_CAPTURE')) {
            $payment_type = (int) Configuration::get('PS_OS_WS_PAYMENT');
            $payment_status = 'Pending_capture';
            $message = $ppec->l('Pending payment capture.') . '<br />';
        } else {
            if (isset($ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'])) {
                $payment_status = $ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'];
            } else {
                $payment_status = 'Error';
            }
            if (strcmp($payment_status, 'Completed') === 0) {
                $payment_type = (int) Configuration::get('PS_OS_PAYMENT');
                $message = $ppec->l('Payment accepted.') . '<br />';
            } elseif (strcmp($payment_status, 'Pending') === 0) {
                $payment_type = (int) Configuration::get('PS_OS_PAYPAL');
                $message = $ppec->l('Pending payment confirmation.') . '<br />';
            }
        }
    } else {
        //Check if error is 10486, if it is redirect user to paypal
        if ($ppec->result['L_ERRORCODE0'] == 10486) {
            $ppec->redirectToAPI();
        }
        $payment_status = $ppec->result['PAYMENTINFO_0_PAYMENTSTATUS'];
        $payment_type = (int) Configuration::get('PS_OS_ERROR');
        if ($amount_match) {
            $message = implode('<br />', $ppec->logs) . '<br />';
        } else {
            $message = $ppec->l('Price paid on paypal is not the same that on PrestaShop.') . '<br />';
        }
    }
    $transaction = PayPalOrder::getTransactionDetails($ppec, $payment_status);
    $ppec->context->cookie->id_cart = $cart->id;
    $ppec->validateOrder((int) $cart->id, $payment_type, $order_total, $ppec->displayName, $message, $transaction, (int) $cart->id_currency, false, $customer->secure_key, $ppec->context->shop);
}
Exemple #13
0
 public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $transaction = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null)
 {
     if ($this->active) {
         // Set transaction details if pcc is defined in PaymentModule class_exists
         if (isset($this->pcc)) {
             $this->pcc->transaction_id = isset($transaction['transaction_id']) ? $transaction['transaction_id'] : '';
         }
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             parent::validateOrder((int) $id_cart, (int) $id_order_state, (double) $amount_paid, $payment_method, $message, $transaction, $currency_special, $dont_touch_amount, $secure_key);
         } else {
             parent::validateOrder((int) $id_cart, (int) $id_order_state, (double) $amount_paid, $payment_method, $message, $transaction, $currency_special, $dont_touch_amount, $secure_key, $shop);
         }
         if (count($transaction) > 0) {
             PayPalOrder::saveOrder((int) $this->currentOrder, $transaction);
         }
         $this->setPayPalAsConfigured();
     }
 }
Exemple #14
0
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <*****@*****.**>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
include_once dirname(__FILE__) . '/../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../init.php';
include_once dirname(__FILE__) . '/paypal_orders.php';
function getIPNTransactionDetails()
{
    $transaction_id = pSQL(Tools::getValue('txn_id'));
    return array('id_invoice' => null, 'id_transaction' => $transaction_id, 'transaction_id' => $transaction_id, 'currency' => pSQL(Tools::getValue('mc_currency')), 'total_paid' => (double) Tools::getValue('mc_gross'), 'shipping' => (double) Tools::getValue('mc_shipping'), 'payment_date' => pSQL(Tools::getValue('payment_date')), 'payment_status' => pSQL(Tools::getValue('payment_status')));
}
if (Tools::getValue('payment_status') !== false) {
    $details = getIPNTransactionDetails();
    $id_order = PayPalOrder::getIdOrderByTransactionId($details['id_transaction']);
    PayPalOrder::updateOrder($id_order, $details);
    $history = new OrderHistory();
    $history->id_order = (int) $id_order;
    $history->changeIdOrderState((int) Configuration::get('PS_OS_PAYMENT'), $history->id_order);
    $history->addWithemail();
    $history->save();
}
Exemple #15
0
 public function confirmOrder($custom)
 {
     $result = $this->getResult();
     $payment_status = Tools::getValue('payment_status');
     $mc_gross = Tools::getValue('mc_gross');
     $txn_id = Tools::getValue('txn_id');
     $id_order = (int) PayPalOrder::getIdOrderByTransactionId($txn_id);
     if ($id_order != 0) {
         Context::getContext()->cart = new Cart((int) $id_order);
     } elseif (isset($custom['id_cart'])) {
         Context::getContext()->cart = new Cart((int) $custom['id_cart']);
     }
     $address = new Address((int) Context::getContext()->cart->id_address_invoice);
     Context::getContext()->country = new Country((int) $address->id_country);
     Context::getContext()->customer = new Customer((int) Context::getContext()->cart->id_customer);
     Context::getContext()->language = new Language((int) Context::getContext()->cart->id_lang);
     Context::getContext()->currency = new Currency((int) Context::getContext()->cart->id_currency);
     if (isset(Context::getContext()->cart->id_shop)) {
         Context::getContext()->shop = new Shop(Context::getContext()->cart->id_shop);
     }
     if (strcmp(trim($result), "VERIFIED") === false) {
         $details = $this->getIPNTransactionDetails($result);
         if ($id_order != 0) {
             $history = new OrderHistory();
             $history->id_order = (int) $id_order;
             PayPalOrder::updateOrder($id_order, $details);
             $history->changeIdOrderState((int) Configuration::get('PS_OS_ERROR'), $history->id_order);
             $history->addWithemail();
             $history->save();
         }
     } elseif (strcmp(trim($result), "VERIFIED") === 0) {
         $details = $this->getIPNTransactionDetails($result);
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             $shop = null;
         } else {
             $shop_id = Context::getContext()->shop->id;
             $shop = new Shop($shop_id);
         }
         if ($id_order != 0) {
             $order = new Order((int) $id_order);
             $values = $this->checkPayment($payment_status, $mc_gross, false);
             if ((int) $order->current_state == (int) $values['payment_type']) {
                 return;
             }
             $history = new OrderHistory();
             $history->id_order = (int) $id_order;
             PayPalOrder::updateOrder($id_order, $details);
             $history->changeIdOrderState($values['payment_type'], $history->id_order);
             $history->addWithemail();
             $history->save();
         } else {
             $values = $this->checkPayment($payment_status, $mc_gross, true);
             $customer = new Customer((int) Context::getContext()->cart->id_customer);
             $this->validateOrder(Context::getContext()->cart->id, $values['payment_type'], $values['total_price'], $this->displayName, $values['message'], $details, Context::getContext()->cart->id_currency, false, $customer->secure_key, $shop);
         }
     }
 }
    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;
    }