if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->redirect($this->url->link('checkout/cart'));
}
if($this->customer->isLogged()) {
/**
* If the customer is already logged in
*/
$this->session->data['paypal']['guest'] = false;
unset($this->session->data['guest']);
} else {
if($this->config->get('config_guest_checkout') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload() && !$this->cart->hasRecurringProducts()) {
/**
* If the guest checkout is allowed (config ok, no login for price and doesn't have downloads)
*/
$this->session->data['paypal']['guest'] = true;
} else {
/**
* If guest checkout disabled or login is required before price or order has downloads
*
* Send them to the normal checkout flow.
*/
unset($this->session->data['guest']);
$this->redirect($this->url->link('checkout/checkout', '', 'SSL'));
}
}
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
$this->load->model('payment/pp_express');
$this->load->model('tool/image');
if($this->cart->hasShipping()) {
$shipping = 2;
} else {
$shipping = 1;
}
$max_amount = $this->currency->convert($this->cart->getTotal(), $this->config->get('config_currency'), 'USD');
$max_amount = min($max_amount * 1.5, 10000);
$max_amount = $this->currency->format($max_amount, $this->currency->getCode(), '', false);
$data = array(
'METHOD' => 'SetExpressCheckout',
'MAXAMT' => $max_amount,
'RETURNURL' => $this->url->link('payment/pp_express/expressReturn', '', 'SSL'),
'CANCELURL' => $this->url->link('checkout/cart'),
'REQCONFIRMSHIPPING' => 0,
'NOSHIPPING' => $shipping,
'ALLOWNOTE' => $this->config->get('pp_express_allow_note'),
'LOCALECODE' => 'EN',
'LANDINGPAGE' => 'Login',
'HDRIMG' => $this->model_tool_image->resize($this->config->get('pp_express_logo'), 790, 90),
'HDRBORDERCOLOR' => $this->config->get('pp_express_border_colour'),
'HDRBACKCOLOR' => $this->config->get('pp_express_header_colour'),
'PAYFLOWCOLOR' => $this->config->get('pp_express_page_colour'),
'CHANNELTYPE' => 'Merchant',
);
$data = array_merge($data, $this->model_payment_pp_express->paymentRequestInfo());
$result = $this->model_payment_pp_express->call($data);
/**
* If a failed PayPal setup happens, handle it.
*/
if(!isset($result['TOKEN'])) {
$this->session->data['error'] = $result['L_LONGMESSAGE0'];
/**
* Unable to add error message to user as the session errors/success are not
* used on the cart or checkout pages - need to be added?
* If PayPal debug log is off then still log error to normal error log.
*/
if($this->config->get('pp_express_debug')) {
$this->log->write(serialize($result));
}
$this->redirect($this->url->link('checkout/checkout', '', 'SSL'));
}
$this->session->data['paypal']['token'] = $result['TOKEN'];
if ($this->config->get('pp_express_test') == 1) {
header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $result['TOKEN']);
} else {
header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $result['TOKEN']);
}