Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @author PrestaShop SA <contact@prestashop.com>
- * @copyright 2007-2012 PrestaShop SA
- * @version Release: $Revision: 1.4 $
- *
- * International Registered Trademark & Property of PrestaShop SA
- */
- require_once(dirname(__FILE__).'/../../config/config.inc.php');
- require_once(dirname(__FILE__).'/lib/paypal.class.php');
- require_once(dirname(__FILE__).'/paypalpro.php');
- require_once(dirname(__FILE__).'/backward_compatibility/backward.php');
- /* SSL Tricks to bypass the redirect for the FrontController in 1.5 + */
- if (Configuration::get('PS_SSL_ENABLED'))
- {
- $resetSsl = true;
- Configuration::updateValue('PS_SSL_ENABLED', 0);
- }
- include(dirname(__FILE__). '/../../init.php');
- if (isset($resetSsl) && $resetSsl)
- Configuration::updateValue('PS_SSL_ENABLED', 1);
- if (Tools::isSubmit('paypalInfo'))
- {
- try
- {
- $PayPal = new PayPal(json_decode(base64_decode($_POST['paypalInfo']), true));
- $response = $PayPal->DoDirectPayment(array(
- 'DPFields' => array(
- 'paymentaction' => 'Sale',
- 'ipaddress' => Tools::safeOutput($_SERVER['REMOTE_ADDR']),
- 'returnfmfdetails' => '1',
- ),
- 'CCDetails' => array(
- 'creditcardtype' => Tools::safeOutput($_POST['paypalpro_cardType']),
- 'acct' => Tools::safeOutput($_POST['x_card_num']),
- 'expdate' => forgeDate($_POST['x_exp_date_m'], $_POST['x_exp_date_y']),
- 'cvv2' => Tools::safeOutput($_POST['paypalpro_card_code']),
- ),
- 'PayerName' => json_decode(base64_decode($_POST['userInfo']), true),
- 'BillingAddress' => json_decode(base64_decode($_POST['billingAddressInfo']), true),
- 'PaymentDetails' => json_decode(base64_decode($_POST['paymentInfo']), true),
- ));
- if (!isset($response['ACK']) || !isset($response['REQUESTDATA']))
- throw new Exception('Paypal returned malformed response');
- if (isset($response['ERRORS']) && count($response['ERRORS']))
- throw new Exception('PayPalPro returned errors: <pre>'.
- print_r($response['ERRORS'], true).'</pre>');
- if (!(int)$response['REQUESTDATA']['INVNUM'])
- throw new Exception('Missing cart number');
- if (!(float)$response['AMT'])
- throw new Exception('Missing price paid');
- $cart = new Cart((int)$response['REQUESTDATA']['INVNUM']);
- if (!Validate::isLoadedObject($cart))
- throw new Exception('Cart loading failed for cart '.
- (int)$response['REQUESTDATA']['INVNUM']);
- $customer = new Customer((int)$cart->id_customer);
- if (!Validate::isLoadedObject($customer))
- throw new Exception('Customer laoding failed for customer '.
- (int)$cart->id_customer);
- switch (strtolower($response['ACK']))
- {
- case 'success':
- $paypalpro = new PayPalPro();
- $paypalpro->validateOrder((int)$cart->id,
- Configuration::get('PS_OS_PAYMENT'), (float)$response['AMT'],
- (!Configuration::get('PAYPALPRO_DISPLAY_LOGO') ? 'PayPal Pro Direct Payment' : 'Credit Card Payment'), NULL, NULL, false,
- $customer->secure_key);
- $url = 'index.php?controller=order-confirmation&';
- if (_PS_VERSION_ < '1.5')
- $url = 'order-confirmation.php?';
- Tools::redirect($url.'id_module='.(int)$paypalpro->id.'&id_cart='.
- (int)$cart->id.'&key='.$customer->secure_key);
- break ;
- default:
- throw new Exception('The transaction did not succeed: '.
- $response['ACK']);
- }
- }
- catch (Exception $e)
- {
- Logger::AddLog('[PayPalPro] '.Tools::safeOutput($e->getMessage()), 2);
- $checkout_type = Configuration::get('PS_ORDER_PROCESS_TYPE') ?
- 'order-opc' : 'order';
- $url = _PS_VERSION_ >= '1.5' ?
- 'index.php?controller='.$checkout_type.'&' : $checkout_type.'.php?';
- $url .= 'step=3&cgv=1&paypalproerror=1';
- if (!isset($_SERVER['HTTP_REFERER']) ||
- strstr($_SERVER['HTTP_REFERER'], 'order'))
- Tools::redirect($url);
- elseif (strstr($_SERVER['HTTP_REFERER'], '?'))
- Tools::redirect(Tools::safeOutput($_SERVER['HTTP_REFERER']).'&paypalproerror=1', '');
- else
- Tools::redirect(Tools::safeOutput($_SERVER['HTTP_REFERER']).'?paypalproerror=1', '');
- exit;
- }
- }
- function forgeDate($m, $y)
- {
- $m = substr(Tools::safeOutput($m), 0, 2);
- $y = substr(Tools::safeOutput($y), 0, 2);
- if (intval($m) <= 0 || intval($y) <= 0)
- throw new Exception('Wrong date');
- return $m.'20'.$y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement