name = 'paypal'; $this->tab = 'Payment'; $this->version = '1.6'; $this->currencies = true; $this->currencies_mode = 'radio'; parent::__construct(); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('PayPal'); $this->description = $this->l('Accepts payments by PayPal'); $this->confirmUninstall = $this->l('Are you sure you want to delete your details ?'); if (Configuration::get('PAYPAL_BUSINESS') == 'paypal@prestashop.com') $this->warning = $this->l('You are currently using the default PayPal email address, you need to use your own email address'); if ($_SERVER['SERVER_NAME'] == 'localhost') $this->warning = $this->l('Your are in localhost, PayPal we can\'t validate order'); } public function getPaypalUrl() { return Configuration::get('PAYPAL_SANDBOX') ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; } public function install() { if (!parent::install() OR !Configuration::updateValue('PAYPAL_BUSINESS', 'paypal@prestashop.com') OR !Configuration::updateValue('PAYPAL_SANDBOX', 1) OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn')) return false; return true; } public function uninstall() { if (!Configuration::deleteByName('PAYPAL_BUSINESS') OR !Configuration::deleteByName('PAYPAL_SANDBOX') OR !parent::uninstall()) return false; return true; } public function getContent() { $this->_html = '

Paypal

'; if (isset($_POST['submitPaypal'])) { if (empty($_POST['business'])) $this->_postErrors[] = $this->l('Paypal business e-mail address is required.'); elseif (!Validate::isEmail($_POST['business'])) $this->_postErrors[] = $this->l('Paypal business must be an e-mail address.'); if (!isset($_POST['sandbox'])) $_POST['sandbox'] = 1; if (!sizeof($this->_postErrors)) { Configuration::updateValue('PAYPAL_BUSINESS', strval($_POST['business'])); Configuration::updateValue('PAYPAL_SANDBOX', intval($_POST['sandbox'])); Configuration::updateValue('PAYPAL_HEADER', strval($_POST['header'])); $this->displayConf(); } else $this->displayErrors(); } $this->displayPayPal(); $this->displayFormSettings(); return $this->_html; } public function displayConf() { $this->_html .= '
'.$this->l('Confirmation').' '.$this->l('Settings updated').'
'; } public function displayErrors() { $nbErrors = sizeof($this->_postErrors); $this->_html .= '

'.($nbErrors > 1 ? $this->l('There are') : $this->l('There is')).' '.$nbErrors.' '.($nbErrors > 1 ? $this->l('errors') : $this->l('error')).'

    '; foreach ($this->_postErrors AS $error) $this->_html .= '
  1. '.$error.'
  2. '; $this->_html .= '
'; } public function displayPayPal() { $this->_html .= '

'.$this->l('Opening your PayPal account').'

'.$this->l('By opening your PayPal account by clicking on the following image you are helping us significantly to improve the PrestaShop software:').'

PrestaShop & PayPal

'.$this->l('This module allows you to accept payments by PayPal.').'

'.$this->l('If the client chooses this payment mode, your PayPal account will be automatically credited.').'
'.$this->l('You need to configure your PayPal account first before using this module.').'
 
'; } public function displayFormSettings() { $conf = Configuration::getMultiple(array('PAYPAL_BUSINESS', 'PAYPAL_SANDBOX', 'PAYPAL_HEADER')); $business = array_key_exists('business', $_POST) ? $_POST['business'] : (array_key_exists('PAYPAL_BUSINESS', $conf) ? $conf['PAYPAL_BUSINESS'] : ''); $sandbox = array_key_exists('sandbox', $_POST) ? $_POST['sandbox'] : (array_key_exists('PAYPAL_SANDBOX', $conf) ? $conf['PAYPAL_SANDBOX'] : ''); $header = array_key_exists('header', $_POST) ? $_POST['header'] : (array_key_exists('PAYPAL_HEADER', $conf) ? $conf['PAYPAL_HEADER'] : ''); $this->_html .= '
'.$this->l('Settings').'

'.$this->l('The image should be host on a securised server in order to avoid security warnings. Size should be limited at 750x90px.').'







'.$this->l('Information').' '.$this->l('In order to use your PayPal payment module, you have to configure your PayPal account (sandbox account as well as live account). Log in to PayPal and follow these instructions.').'

'.$this->l('In').' '.$this->l('My account > Profile > Website Payment Preferences').', '. $this->l('set:').'
- '.$this->l('Auto Return').' : '.$this->l('Off').',
- '.$this->l('Payment Data Transfer').' '.$this->l('to').' Off.

'.$this->l('In').' '.$this->l('My account > Profile > Shipping Calculations').'
- check '.$this->l('Click here to allow transaction-based shipping values to override the profile shipping settings listed above').'

'.$this->l('All PrestaShop currencies must be also configured inside Profile > Financial Information > Currency balances').'
'; } public function hookPayment($params) { if (!$this->active) return ; return $this->display(__FILE__, 'paypal.tpl'); } public function hookPaymentReturn($params) { if (!$this->active) return ; return $this->display(__FILE__, 'confirmation.tpl'); } public function getL($key) { $translations = array( 'mc_gross' => $this->l('Paypal key \'mc_gross\' not specified, can\'t control amount paid.'), 'payment_status' => $this->l('Paypal key \'payment_status\' not specified, can\'t control payment validity'), 'payment' => $this->l('Payment: '), 'custom' => $this->l('Paypal key \'custom\' not specified, can\'t rely to cart'), 'txn_id' => $this->l('Paypal key \'txn_id\' not specified, transaction unknown'), 'mc_currency' => $this->l('Paypal key \'mc_currency\' not specified, currency unknown'), 'cart' => $this->l('Cart not found'), 'order' => $this->l('Order has already been placed'), 'transaction' => $this->l('Paypal Transaction ID: '), 'verified' => $this->l('The PayPal transaction could not be VERIFIED.'), 'connect' => $this->l('Problem connecting to the PayPal server.'), 'nomethod' => $this->l('No communications transport available.'), 'socketmethod' => $this->l('Verification failure (using fsockopen). Returned: '), 'curlmethod' => $this->l('Verification failure (using cURL). Returned: '), 'curlmethodfailed' => $this->l('Connection using cURL failed'), 'Please wait, redirecting to Paypal... Thanks.' => $this->l('Please wait, redirecting to Paypal... Thanks.'), 'Cancel' => $this->l('Cancel'), 'My cart' => $this->l('My cart'), 'Return to shop' => $this->l('Return to shop'), 'Paypal error: (invalid or undefined business account email)' => $this->l('Paypal error: (invalid or undefined business account email)'), 'Paypal error: (invalid address or customer)' => $this->l('Paypal error: (invalid address or customer)') ); return $translations[$key]; } function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false) { if (!$this->active) return ; parent::validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod, $message, $extraVars); } }