Пример #1
0
 public function getAuthorisation()
 {
     global $cookie, $cart;
     // Getting cart informations
     $currency = new Currency(intval($cookie->id_currency));
     if (!Validate::isLoadedObject($currency)) {
         $this->_logs[] = $this->l('Not a valid currency');
     }
     if (sizeof($this->_logs)) {
         return false;
     }
     // Making request
     $vars = '?fromPayPal=1';
     $returnURL = Tools::getHttpHost(true, true) . __PS_BASE_URI__ . 'modules/paypalapi/payment/submit.php' . $vars;
     $cancelURL = Tools::getHttpHost(true, true) . __PS_BASE_URI__ . 'order.php';
     $paymentAmount = floatval($cart->getOrderTotal());
     $currencyCodeType = strval($currency->iso_code);
     $paymentType = 'Sale';
     $request = '&Amt=' . urlencode($paymentAmount) . '&PAYMENTACTION=' . urlencode($paymentType) . '&ReturnUrl=' . urlencode($returnURL) . '&CANCELURL=' . urlencode($cancelURL) . '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&NOSHIPPING=1';
     if ($this->_pp_integral) {
         $request .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
     } else {
         $request .= '&SOLUTIONTYPE=Mark&LANDINGPAGE=Login';
     }
     $request .= '&LOCALECODE=' . strval($this->getCountryCode());
     if ($this->_header) {
         $request .= '&HDRIMG=' . urlencode($this->_header);
     }
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypalapi/api/paypallib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'SetExpressCheckout', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     return $result;
 }
Пример #2
0
 public function getAuthorisation()
 {
     global $cookie, $cart;
     // Getting cart informations
     $currency = new Currency(intval($cookie->id_currency));
     if (!Validate::isLoadedObject($currency)) {
         $this->_logs[] = $this->l('Not a valid currency');
     }
     if (sizeof($this->_logs)) {
         return false;
     }
     // Making request
     $vars = '?fromPayPal=1';
     $returnURL = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/paypalapi/payment/submit.php' . $vars;
     $cancelURL = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order.php';
     $paymentAmount = number_format(floatval($cart->getOrderTotalLC()), 2, '.', '');
     $currencyCodeType = strval($currency->iso_code);
     $paymentType = 'Sale';
     $request = '&Amt=' . urlencode($paymentAmount) . '&PAYMENTACTION=' . urlencode($paymentType) . '&ReturnUrl=' . urlencode($returnURL) . '&CANCELURL=' . urlencode($cancelURL) . '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&NOSHIPPING=1';
     if ($this->_header) {
         $request .= '&HDRIMG=' . urlencode($this->_header);
     }
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypalapi/api/PaypalLib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'SetExpressCheckout', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     return $result;
 }
Пример #3
0
 public function getAuthorisation()
 {
     global $cookie, $cart;
     // Getting cart informations
     $currency = new Currency((int) $cart->id_currency);
     if (!Validate::isLoadedObject($currency)) {
         $this->_logs[] = $this->l('Not a valid currency');
     }
     if (sizeof($this->_logs)) {
         return false;
     }
     // Making request
     $vars = '?fromPayPal=1';
     $returnURL = Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/paypal/payment/submit.php' . $vars;
     $cancelURL = Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order.php';
     $paymentAmount = (double) $cart->getOrderTotal();
     $currencyCodeType = strval($currency->iso_code);
     $paymentType = Configuration::get('PAYPAL_CAPTURE') == 1 ? 'Authorization' : 'Sale';
     $request = '&Amt=' . urlencode($paymentAmount) . '&PAYMENTACTION=' . urlencode($paymentType) . '&ReturnUrl=' . urlencode($returnURL) . '&CANCELURL=' . urlencode($cancelURL) . '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&NOSHIPPING=1';
     if (Configuration::get('PAYPAL_PAYMENT_METHOD') == 0) {
         $request .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
     } else {
         $request .= '&SOLUTIONTYPE=Mark&LANDINGPAGE=Login';
     }
     $request .= '&LOCALECODE=' . strtoupper(Language::getIsoById($cart->id_lang));
     if (Configuration::get('PAYPAL_HEADER')) {
         $request .= '&HDRIMG=' . urlencode(Configuration::get('PAYPAL_HEADER'));
     }
     // Customer informations
     $customer = new Customer((int) $cart->id_customer);
     $request .= '&EMAIL=' . urlencode($customer->email);
     //customer
     // address of delivery
     $address = new Address((int) $cart->id_address_delivery);
     $country = new Country((int) $address->id_country);
     if ($address->id_state) {
         $state = new State((int) $address->id_state);
     }
     $request .= '&SHIPTONAME=' . urlencode($address->firstname . ' ' . $address->lastname);
     $request .= '&SHIPTOSTREET=' . urlencode($address->address1);
     $request .= '&SHIPTOSTREET2=' . urlencode($address->address2);
     $request .= '&SHIPTOCITY=' . urlencode($address->city);
     $request .= '&SHIPTOSTATE=' . ($address->id_state ? $state->iso_code : $country->iso_code);
     $request .= '&SHIPTOZIP=' . urlencode($address->postcode);
     $request .= '&SHIPTOCOUNTRY=' . urlencode($country->iso_code);
     $request .= '&SHIPTOPHONENUM=' . urlencode($address->phone);
     $request .= '&ADDROVERRIDE=1';
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypal/api/paypallib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'SetExpressCheckout', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     return $result;
 }
Пример #4
0
 public function getCustomerInfos()
 {
     global $cookie;
     // Making request
     $request = '&TOKEN=' . urlencode(strval($cookie->paypal_token));
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypalapi/api/PaypalLib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'GetExpressCheckoutDetails', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     return $result;
 }
Пример #5
0
    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'));
}
// Getting params
$params = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $params .= '&' . $key . '=' . urlencode(stripslashes($value));
}
// Checking params by asking PayPal
include _PS_MODULE_DIR_ . 'paypal/api/paypal_lib.php';
$paypalAPI = new PaypalLib();
$result = $paypalAPI->makeSimpleCall($paypal->getAPIURL(), $paypal->getAPIScript(), $params);
if (!$result || Tools::strlen($result) < 8 || !($status = substr($result, -8)) || $status != 'VERIFIED') {
    die($paypal->l('Cannot verify PayPal order'));
}
// Getting order status
switch ($status) {
    case 'Completed':
        $id_order_state = Configuration::get('PS_OS_PAYMENT');
        break;
    case 'Pending':
        $id_order_state = Configuration::get('PS_OS_PAYPAL');
        break;
    default:
        $id_order_state = Configuration::get('PS_OS_ERROR');
}
Пример #6
0
 private function callAPI($fields)
 {
     $this->logs = array();
     $paypal_lib = new PaypalLib();
     $this->result = $paypal_lib->makeCall($this->getAPIURL(), $this->getAPIScript(), $this->method, $fields, $this->method_version);
     $this->logs = array_merge($this->logs, $paypal_lib->getLogs());
     $this->_storeToken();
 }
Пример #7
0
 private function _updatePaymentStatusOfOrder($id_order)
 {
     global $cookie;
     include_once _PS_MODULE_DIR_ . 'paypal/api/paypallib.php';
     if (!$this->_isPayPalAPIAvailable()) {
         return false;
     }
     if (!$id_order) {
         return false;
     }
     $id_transaction = $this->_getTransactionId((int) $id_order);
     if (!$id_transaction) {
         return false;
     }
     $request = '&TRANSACTIONID=' . urlencode($id_transaction);
     $paypalLib = new PaypalLib();
     $response = $paypalLib->makeCall($this->getAPIURL(), $this->getAPIScript(), 'GetTransactionDetails', $request);
     if (array_key_exists('ACK', $response)) {
         if ($response['ACK'] == 'Success') {
             if (isset($response['PAYMENTSTATUS'])) {
                 if ($response['PAYMENTSTATUS'] == 'Completed') {
                     $history = new OrderHistory();
                     $history->id_order = (int) $id_order;
                     $history->changeIdOrderState(Configuration::get('PS_OS_PAYMENT'), (int) $id_order);
                     $history->addWithemail();
                 } elseif ($response['PAYMENTSTATUS'] == 'Pending' and $response['PENDINGREASON'] == 'authorization') {
                     $history = new OrderHistory();
                     $history->id_order = (int) $id_order;
                     $history->changeIdOrderState((int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), (int) $id_order);
                     $history->addWithemail();
                 } elseif ($response['PAYMENTSTATUS'] == 'Reversed') {
                     $history = new OrderHistory();
                     $history->id_order = (int) $id_order;
                     $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>';
         foreach ($response as $k => $value) {
             $message .= $k . ': ' . $value . '<br>';
         }
         $this->_addNewPrivateMessage((int) $id_order, $message);
         return $response;
     }
     return false;
 }
Пример #8
0
    private function _updatePaymentStatusOfOrder($id_order)
    {
        if (!(bool) $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>';
            $this->formatMessage($response, $message);
            $this->_addNewPrivateMessage((int) $id_order, $message);
            return $response;
        }
        return false;
    }
Пример #9
0
    die('Invalid order');
}
if (!($amount = floatval(Tools::getValue('mc_gross'))) or $amount != $order->total_paid) {
    die('Incorrect amount');
}
if (!($status = strval(Tools::getValue('payment_status')))) {
    die('Incorrect order status');
}
// Getting params
$params = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $params .= '&' . $key . '=' . urlencode(stripslashes($value));
}
// Checking params by asking PayPal
include _PS_MODULE_DIR_ . 'paypalapi/api/PaypalLib.php';
$ppAPI = new PaypalLib();
$result = $ppAPI->makeSimpleCall($ppAPI->getPayPalURL(), $ppAPI->getPayPalScript(), $params);
if (!$result or Tools::strlen($result) < 8 or !($statut = substr($result, -8)) or $statut != 'VERIFIED') {
    die('Incorrect PayPal verified');
}
// Getting order status
switch ($status) {
    case 'Completed':
        $id_order_state = _PS_OS_PAYMENT_;
        break;
    case 'Pending':
        $id_order_state = _PS_OS_PAYPAL_;
        break;
    default:
        $id_order_state = _PS_OS_ERROR_;
}
Пример #10
0
 public function getAuthorisation()
 {
     global $cookie, $cart;
     // Getting cart informations
     $currency = new Currency((int) $cart->id_currency);
     if (!Validate::isLoadedObject($currency)) {
         $this->_logs[] = $this->l('Not a valid currency');
     }
     if (sizeof($this->_logs)) {
         return false;
     }
     // Making request
     $vars = '?fromPayPal=1';
     $returnURL = Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/paypal/payment/submit.php' . $vars;
     $cancelURL = Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'order.php';
     $paymentAmount = (double) $cart->getOrderTotal();
     $currencyCodeType = strval($currency->iso_code);
     $paymentType = Configuration::get('PAYPAL_CAPTURE') == 1 ? 'Authorization' : 'Sale';
     $request = '&Amt=' . urlencode($paymentAmount) . '&PAYMENTACTION=' . urlencode($paymentType) . '&ReturnUrl=' . urlencode($returnURL) . '&CANCELURL=' . urlencode($cancelURL) . '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&NOSHIPPING=1';
     if (Configuration::get('PAYPAL_PAYMENT_METHOD') == 0) {
         $request .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
     } else {
         $request .= '&SOLUTIONTYPE=Mark&LANDINGPAGE=Login';
     }
     $request .= '&LOCALECODE=' . strtoupper(Language::getIsoById($cart->id_lang));
     if (Configuration::get('PAYPAL_HEADER')) {
         $request .= '&HDRIMG=' . urlencode(Configuration::get('PAYPAL_HEADER'));
     }
     // Customer informations
     $customer = new Customer((int) $cart->id_customer);
     $request .= '&EMAIL=' . urlencode($customer->email);
     //customer
     // address of delivery
     $id_address = $cart->id_address_delivery;
     $address = new Address((int) $id_address);
     $country = new Country((int) $address->id_country);
     if ($address->id_state) {
         $state = new State((int) $address->id_state);
     }
     $discounts = (double) $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
     if ($discounts == 0) {
         if ($params['cart']->id_customer) {
             $customer = new Customer((int) $params['cart']->id_customer);
             $taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
         } else {
             $taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
         }
         $priceField = $taxCalculationMethod == PS_TAX_EXC ? 'price' : 'price_wt';
         $products = $cart->getProducts();
         $amt = 0;
         for ($i = 0; $i < sizeof($products); $i++) {
             $request .= '&L_NAME' . $i . '=' . substr(urlencode($products[$i]['name'] . (isset($products[$i]['attributes']) ? ' - ' . $products[$i]['attributes'] : '') . (isset($products[$i]['instructions']) ? ' - ' . $products[$i]['instructions'] : '')), 0, 127);
             $request .= '&L_AMT' . $i . '=' . urlencode($this->PayPalRound($products[$i][$priceField]));
             $request .= '&L_QTY' . $i . '=' . urlencode($products[$i]['cart_quantity']);
             $amt += $this->PayPalRound($products[$i][$priceField] * $products[$i]['cart_quantity']);
         }
         $shipping = $this->PayPalRound($cart->getOrderShippingCost($cart->id_carrier, false));
         $request .= '&ITEMAMT=' . urlencode($amt);
         $request .= '&SHIPPINGAMT=' . urlencode($shipping);
         $request .= '&TAXAMT=' . urlencode((double) max($this->PayPalRound($paymentAmount - $amt - $shipping), 0));
     } else {
         $products = $cart->getProducts();
         $description = 0;
         for ($i = 0; $i < sizeof($products); $i++) {
             $description .= ($description == '' ? '' : ', ') . $products[$i]['cart_quantity'] . " x " . $products[$i]['name'] . (isset($products[$i]['attributes']) ? ' - ' . $products[$i]['attributes'] : '') . (isset($products[$i]['instructions']) ? ' - ' . $products[$i]['instructions'] : '');
         }
         $request .= '&ORDERDESCRIPTION=' . urlencode(substr($description, 0, 120));
     }
     $request .= '&SHIPTONAME=' . urlencode($address->firstname . ' ' . $address->lastname);
     $request .= '&SHIPTOSTREET=' . urlencode($address->address1);
     $request .= '&SHIPTOSTREET2=' . urlencode($address->address2);
     $request .= '&SHIPTOCITY=' . urlencode($address->city);
     $request .= '&SHIPTOSTATE=' . ($address->id_state ? $state->iso_code : $country->iso_code);
     $request .= '&SHIPTOZIP=' . urlencode($address->postcode);
     $request .= '&SHIPTOCOUNTRY=' . urlencode($country->iso_code);
     $request .= '&SHIPTOPHONENUM=' . urlencode($address->phone);
     $request .= '&ADDROVERRIDE=1';
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypal/api/paypallib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'SetExpressCheckout', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     return $result;
 }
Пример #11
0
 public function validOrder($cookie, $cart, $id_currency, $payerID, $type)
 {
     global $cookie;
     if (!$this->active) {
         return;
     }
     // Filling-in vars
     $id_cart = intval($cart->id);
     $currency = new Currency(intval($id_currency));
     $iso_currency = $currency->iso_code;
     $token = strval($cookie->paypal_token);
     $total = floatval($cart->getOrderTotal(true, 3));
     $payerID = strval($payerID);
     $paymentType = 'Sale';
     $serverName = urlencode($_SERVER['SERVER_NAME']);
     $bn = $type == 'express' ? 'ECS' : 'ECM';
     $notifyURL = urlencode('http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__ . 'modules/paypalapi/ipn.php');
     // Getting address
     if (isset($cookie->id_cart) and $cookie->id_cart) {
         $cart = new Cart(intval($cookie->id_cart));
     }
     if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
         $address = new Address(intval($cart->id_address_delivery));
     }
     $requestAddress = '';
     if (Validate::isLoadedObject($address)) {
         $country = new Country(intval($address->id_country));
         $state = new State(intval($address->id_state));
         $requestAddress = '&SHIPTONAME=' . urlencode($address->company . ' ' . $address->lastname . ' ' . $address->firstname) . '&SHIPTOSTREET=' . urlencode($address->address1 . ' ' . $address->address2) . '&SHIPTOCITY=' . urlencode($address->city) . '&SHIPTOSTATE=' . urlencode($state->iso_code) . '&SHIPTOCOUNTRYCODE=' . urlencode($country->iso_code) . '&SHIPTOZIP=' . urlencode($address->postcode);
     }
     // Making request
     $request = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payerID) . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $total . '&CURRENCYCODE=' . $iso_currency . '&IPADDRESS=' . $serverName . '&NOTIFYURL=' . $notifyURL . '&BUTTONSOURCE=PRESTASHOP_' . $bn . $requestAddress;
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypalapi/api/paypallib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'DoExpressCheckoutPayment', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     // Checking PayPal result
     if (!is_array($result) or !sizeof($result)) {
         $this->displayError($this->l('Authorisation to PayPal failed'), $this->_logs);
     } elseif (!isset($result['ACK']) or strtoupper($result['ACK']) != 'SUCCESS') {
         $this->displayError($this->l('PayPal returned error'), $this->_logs);
     } elseif (!isset($result['TOKEN']) or $result['TOKEN'] != $cookie->paypal_token) {
         $logs[] = '<b>' . $ppExpress->l('Token given by PayPal is not the same that cookie one', 'submit') . '</b>';
         $ppExpress->displayError($ppExpress->l('PayPal returned error', 'submit'), $logs);
     }
     // Making log
     $id_transaction = strval($result['TRANSACTIONID']);
     $this->_logs[] = $this->l('Order finished with PayPal!');
     $message = Tools::htmlentitiesUTF8(strip_tags(implode("\n", $this->_logs)));
     // Order status
     switch ($result['PAYMENTSTATUS']) {
         case 'Completed':
             $id_order_state = _PS_OS_PAYMENT_;
             break;
         case 'Pending':
             $id_order_state = _PS_OS_PAYPAL_;
             break;
         default:
             $id_order_state = _PS_OS_ERROR_;
     }
     // Execute Module::validateOrder()
     $this->validateOrder($id_cart, $id_order_state, floatval($cart->getOrderTotal(true, 3)), $this->displayName, $message, array(), $id_currency);
     // Filling PayPal table
     $this->addOrder($id_transaction);
     // Displaying output
     $this->displayFinal($id_cart);
 }
Пример #12
0
 public function validOrder($cookie, $cart, $id_currency, $payerID, $type)
 {
     if (!$this->active) {
         return;
     }
     // Filling-in vars
     $id_cart = intval($cart->id);
     $currency = new Currency(intval($id_currency));
     $iso_currency = $currency->iso_code;
     $token = strval($cookie->paypal_token);
     $total = number_format(floatval($cart->getOrderTotal(true, 3)), 2, '.', '');
     $payerID = strval($payerID);
     $paymentType = 'Sale';
     $serverName = urlencode($_SERVER['SERVER_NAME']);
     $bn = $type == 'express' ? 'ECS' : 'ECM';
     $notifyURL = urlencode('http://' . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/paypalapi/ipn.php');
     // Making request
     $request = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payerID) . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $total . '&CURRENCYCODE=' . $iso_currency . '&IPADDRESS=' . $serverName . '&NOTIFYURL=' . $notifyURL . '&BUTTONSOURCE=PRESTASHOP_' . $bn;
     // Calling PayPal API
     include _PS_MODULE_DIR_ . 'paypalapi/api/PaypalLib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'DoExpressCheckoutPayment', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     // Checking PayPal result
     if (!is_array($result) or !sizeof($result)) {
         $this->displayError($this->l('Authorisation to PayPal failed'), $this->_logs);
     } elseif (!isset($result['ACK']) or strtoupper($result['ACK']) != 'SUCCESS') {
         $this->displayError($this->l('PayPal returned error'), $this->_logs);
     } elseif (!isset($result['TOKEN']) or $result['TOKEN'] != $cookie->paypal_token) {
         $logs[] = '<b>' . $ppExpress->l('Token given by PayPal is not the same that cookie one', 'submit') . '</b>';
         $ppExpress->displayError($ppExpress->l('PayPal returned error', 'submit'), $logs);
     }
     // Making log
     $id_transaction = strval($result['TRANSACTIONID']);
     $this->_logs[] = $this->l('Order finished with PayPal!');
     $message = Tools::htmlentitiesUTF8(strip_tags(implode("\n", $this->_logs)));
     // Order status
     switch ($result['PAYMENTSTATUS']) {
         case 'Completed':
             $id_order_state = _PS_OS_PAYMENT_;
             break;
         case 'Pending':
             $id_order_state = _PS_OS_PAYPAL_;
             break;
         default:
             $id_order_state = _PS_OS_ERROR_;
     }
     // Execute Module::validateOrder()
     $this->validateOrder($id_cart, $id_order_state, floatval($cart->getOrderTotal(true, 3)), $this->displayName, $message, array(), $id_currency);
     // Filling PayPal table
     $this->addOrder($id_transaction);
     // Displaying output
     $this->displayFinal($id_cart);
 }