/includes/modules/payment/paypalwpp.php
PHP | 2970 lines | 2068 code | 275 blank | 627 comment | 718 complexity | 9f0912611febbb9394825e30cebc86de MD5 | raw file
Possible License(s): AGPL-1.0, BSD-3-Clause, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * paypalwpp.php payment module class for Paypal Express Checkout / Website Payments Pro / Payflow Pro payment methods
- *
- * @package paymentMethod
- * @copyright Copyright 2003-2007 Zen Cart Development Team
- * @copyright Portions Copyright 2003 osCommerce
- * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
- * @version $Id: paypalwpp.php 7620 2007-12-11 19:12:46Z drbyte $
- */
- /**
- * load the communications layer code
- */
- require_once(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_curl.php');
- /**
- * the PayPal payment module with Express Checkout
- *
- * currently supports US-NVP
- *
- */
- class paypalwpp extends base {
- /**
- * name of this module
- *
- * @var string
- */
- var $code;
- /**
- * displayed module title
- *
- * @var string
- */
- var $title;
- /**
- * displayed module description
- *
- * @var string
- */
- var $description;
- /**
- * module status - set based on various config and zone criteria
- *
- * @var string
- */
- var $enabled;
- /**
- * the zone to which this module is restricted for use
- *
- * @var string
- */
- var $zone;
- /**
- * array holding accepted DP/gateway card types
- *
- * @var array
- */
- var $cards = array();
- /**
- * JS code used for gateway/DP mode
- *
- * @var string
- */
- var $cc_type_javascript = '';
- /**
- * JS code used for gateway/DP mode
- *
- * @var string
- */
- var $cc_type_check = '';
- /**
- * debugging flag
- *
- * @var boolean
- */
- var $enableDebugging = false;
- /**
- * is DP enabled ?
- *
- * @var boolean
- */
- var $enableDirectPayment = false;
- /**
- * Determines whether payment page is displayed or not
- *
- * @var boolean
- */
- var $showPaymentPage = false;
- var $flagDisablePaymentAddressChange = false;
- /**
- * sort order of display
- *
- * @var int
- */
- var $sort_order = 0;
- /**
- * Button Source / BN code -- enables the module to work for Zen Cart
- *
- * @var string
- */
- var $buttonSourceEC = 'ZenCart-EC_us';
- /**
- * order status setting for pending orders
- *
- * @var int
- */
- var $order_pending_status = 1;
- /**
- * order status setting for completed orders
- *
- * @var int
- */
- var $order_status = DEFAULT_ORDERS_STATUS_ID;
- /**
- * Debug tools
- */
- var $_logDir = 'includes/modules/payment/paypal/logs/';
- var $_logLevel = 0;
- /**
- * class constructor
- */
- function paypalwpp() {
- include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
- global $order;
- $this->code = 'paypalwpp';
- $this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
- $this->codeVersion = '1.3.8a';
- $this->enableDirectPayment = (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True');
- $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
- // Set the title & description text based on the mode we're in ... EC vs DP vs admin
- if (IS_ADMIN_FLAG === true) {
- $this->description = sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_DESCRIPTION, ' (rev' . $this->codeVersion . ')');
- switch (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE) {
- case ('PayPal'):
- if (MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED == 'True') {
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_WPP;
- } else {
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
- }
- break;
- case ('Payflow-UK'):
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PRO20;
- break;
- case ('Payflow-US'):
- if (defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes') {
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_EC;
- } else {
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_GATEWAY;
- }
- break;
- default:
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
- }
- if ($this->enabled) {
- if ( (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'PayPal' && (MODULE_PAYMENT_PAYPALWPP_APISIGNATURE == '' || MODULE_PAYMENT_PAYPALWPP_APIUSERNAME == '' || MODULE_PAYMENT_PAYPALWPP_APIPASSWORD == ''))
- || (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' && (MODULE_PAYMENT_PAYPALWPP_PFPARTNER == '' || MODULE_PAYMENT_PAYPALWPP_PFVENDOR == '' || MODULE_PAYMENT_PAYPALWPP_PFUSER == '' || MODULE_PAYMENT_PAYPALWPP_PFPASSWORD == ''))
- ) $this->title .= '<span class="alert"><strong> NOT CONFIGURED YET</strong></span>';
- if (MODULE_PAYMENT_PAYPALWPP_SERVER =='sandbox') $this->title .= '<strong><span class="alert"> (sandbox active)</span></strong>';
- if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email') $this->title .= '<strong> (Debug)</strong>';
- if (!function_exists('curl_init')) $this->title .= '<strong><span class="alert"> CURL NOT FOUND. Cannot Use.</span></strong>';
- }
- } else {
- $this->description = MODULE_PAYMENT_PAYPALWPP_TEXT_DESCRIPTION;
- $this->title = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TITLE; //pp
- if (!$this->in_special_checkout() && $this->enableDirectPayment == true) {
- $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_TITLE; //cc
- }
- }
- if ((!defined('PAYPAL_OVERRIDE_CURL_WARNING') || (defined('PAYPAL_OVERRIDE_CURL_WARNING') && PAYPAL_OVERRIDE_CURL_WARNING != 'True')) && !function_exists('curl_init')) $this->enabled = false;
- $this->enableDebugging = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email');
- $this->emailAlerts = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Alerts Only');
- $this->doDPonly = (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE =='Payflow-US' && !(defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes'));
- $this->showPaymentPage = (MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE == 'No') ? true : false;
- $this->sort_order = MODULE_PAYMENT_PAYPALWPP_SORT_ORDER;
- $this->buttonSourceEC = 'ZenCart-EC_us';
- $this->buttonSourceDP = 'ZenCart-DP_us';
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') {
- $this->buttonSourceEC = 'ZenCart-EC_uk';
- $this->buttonSourceDP = 'ZenCart-DP_uk';
- }
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-US') {
- $this->buttonSourceEC = 'ZenCart-ECGW_us';
- $this->buttonSourceDP = 'ZenCart-GW_us';
- }
- $this->order_pending_status = MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID;
- if ((int)MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID > 0) {
- $this->order_status = MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID;
- }
- $this->new_acct_notify = MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY;
- $this->zone = (int)MODULE_PAYMENT_PAYPALWPP_ZONE;
- if (is_object($order)) $this->update_status();
- if (PROJECT_VERSION_MAJOR != '1' && substr(PROJECT_VERSION_MINOR, 0, 3) != '3.8') $this->enabled = false;
- // offer credit card choices for pull-down menu -- only needed for UK version
- $this->cards = array();
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') {
- if (CC_ENABLED_VISA=='1') $this->cards[] = array('id' => 'Visa', 'text' => 'Visa');
- if (CC_ENABLED_MC=='1') $this->cards[] = array('id' => 'MasterCard', 'text' => 'MasterCard');
- if (CC_ENABLED_MAESTRO=='1') $this->cards[] = array('id' => 'Maestro', 'text' => 'Maestro');
- if (CC_ENABLED_SWITCH=='1') $this->cards[] = array('id' => 'Switch', 'text' => 'Switch');
- if (CC_ENABLED_SOLO=='1') $this->cards[] = array('id' => 'Solo', 'text' => 'Solo');
- }
- // if operating in markflow mode, start EC process when submitting order
- if (!$this->in_special_checkout() && $this->enableDirectPayment == false) {
- $this->form_action_url = zen_href_link('ipn_main_handler.php', 'type=ec&markflow=1&clearSess=1&stage=final', 'SSL', true, true, true);
- }
- // debug setup
- if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_CATALOG . $this->_logDir;
- if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_SQL_CACHE;
- // Regular mode:
- if ($this->enableDebugging) $this->_logLevel = PEAR_LOG_INFO;
- // DEV MODE:
- if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $this->_logLevel = PEAR_LOG_DEBUG;
- if (IS_ADMIN_FLAG === true) $this->tableCheckup();
- }
- /**
- * Sets payment module status based on zone restrictions etc
- */
- function update_status() {
- global $order, $db;
- if ($this->enabled && (int)$this->zone > 0) {
- $check_flag = false;
- $sql = "SELECT zone_id
- FROM " . TABLE_ZONES_TO_GEO_ZONES . "
- WHERE geo_zone_id = :zoneId
- AND zone_country_id = :countryId
- ORDER BY zone_id";
- $sql = $db->bindVars($sql, ':zoneId', $this->zone, 'integer');
- $sql = $db->bindVars($sql, ':countryId', $order->billing['country']['id'], 'integer');
- $check = $db->Execute($sql);
- while (!$check->EOF) {
- if ($check->fields['zone_id'] < 1) {
- $check_flag = true;
- break;
- } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
- $check_flag = true;
- break;
- }
- $check->MoveNext();
- }
- if (!$check_flag) {
- $this->enabled = false;
- }
- // module cannot be used for purchase > $10,000 USD
- $order_amount = $this->calc_order_amount($order->info['total'], 'USD');
- if ($order_amount > 10000) $this->enabled = false;
- }
- }
- /**
- * Validate the credit card information via javascript (Number, Owner, and CVV Lengths)
- */
- function javascript_validation() {
- if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
- // if we are in express-checkout flow or if DirectPayment is disabled (ie: just mark flow) then no JS validation req'd
- return false;
- }
- return ' if (payment_value == "' . $this->code . '") {' . "\n" .
- ' var cc_firstname = document.checkout_payment.paypalec_cc_firstname.value;' . "\n" .
- ' var cc_lastname = document.checkout_payment.paypalec_cc_lastname.value;' . "\n" .
- ' var cc_number = document.checkout_payment.paypalec_cc_number.value;' . "\n" .
- ' var cc_checkcode = document.checkout_payment.paypalwpp_cc_checkcode.value;' . "\n" .
- ' if (cc_firstname == "" || cc_lastname == "" || eval(cc_firstname.length) + eval(cc_lastname.length) < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
- ' error_message = error_message + "' . MODULE_PAYMENT_PAYPALWPP_TEXT_JS_CC_OWNER . '";' . "\n" .
- ' error = 1;' . "\n" .
- ' }' . "\n" .
- ' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
- ' error_message = error_message + "' . MODULE_PAYMENT_PAYPALWPP_TEXT_JS_CC_NUMBER . '";' . "\n" .
- ' error = 1;' . "\n" .
- ' }' . "\n" .
- ' }' . "\n";
- }
- /**
- * Display Credit Card Information Submission Fields on the Checkout Payment Page
- */
- function selection() {
- global $order;
- $this->cc_type_check =
- 'var value = document.checkout_payment.paypalec_cc_type.value;' .
- 'if (value == "Switch" || value == "Solo") {' .
- ' document.checkout_payment.paypalec_cc_issue_month.disabled = false;' .
- ' document.checkout_payment.paypalec_cc_issue_year.disabled = false;' .
- ' document.checkout_payment.paypalec_cc_checkcode.disabled = true;' .
- ' if (document.checkout_payment.paypalec_cc_issuenumber) document.checkout_payment.paypalec_cc_issuenumber.disabled = true;' .
- '} else if (value == "Maestro") {' .
- ' document.checkout_payment.paypalec_cc_issuenumber.disabled = false;' .
- ' if (document.checkout_payment.paypalec_cc_issue_month) document.checkout_payment.paypalec_cc_issue_month.disabled = true;' .
- ' if (document.checkout_payment.paypalec_cc_issue_year) document.checkout_payment.paypalec_cc_issue_year.disabled = true;' .
- ' document.checkout_payment.paypalec_cc_checkcode.disabled = false;' .
- '} else {' .
- ' if (document.checkout_payment.paypalec_cc_issuenumber) document.checkout_payment.paypalec_cc_issuenumber.disabled = true;' .
- ' document.checkout_payment.paypalec_cc_checkcode.disabled = false;' .
- '}';
- if (sizeof($this->cards) == 0 || $this->enableDirectPayment == false) $this->cc_type_check = '';
- /**
- * if we are NOT processing via the gateway, we will only display MarkFlow payment option, and no CC fields
- */
- if ($this->enableDirectPayment == false) {
- return array('id' => $this->code,
- 'module' => '<img align="absmiddle" src="' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_IMG . '" alt="' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT . '" />' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT,
- 'info'=>'<li>If you <b>have paypal account</b>, you can pay your order by your paypal account.</li>
- <li>If you <b>don\'t have paypal account</b>, it doesn\'t matter. You canalso pay via paypal with you credit card or bank debit card.</li>
- <li>Payment can be submitted in any currency.</li>
- <li>Our paypal account is : <b>'.MODULE_PAYMENT_PAYPALWPP_APIUSERNAME.'</b></li>
- <a onclick="javascript:window.open(\'https://www.paypal.com/us/cgi-bin/webscr?cmd=xpt/cps/popup/OLCWhatIsPayPal-outside\',\'olcwhatispaypal\',\'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350\');" class="hand">
- <img border="0" alt="Solution Graphics" src="https://www.paypal.com/en_US/i/bnr/horizontal_solution_PP.gif"/></a>
- <a onclick="javascript:window.open(\'https://www.paypal.com/verified/pal='.MODULE_PAYMENT_PAYPALWPP_APIUSERNAME.'\',\'olcwhatispaypal\',\'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350\');" class="hand">
- <img border="0" src="includes/templates/chanelwatches/images/logo/PaypalVerify.gif"/>
- </a>'
- );
- }
- /**
- * if we ARE processing via the gateway, prepare and display both the CC fields and the PP option
- */
- $expires_month = array();
- $expires_year = array();
- $issue_year = array();
- for ($i = 1; $i < 13; $i++) {
- $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B - (%m)',mktime(0,0,0,$i,1,2000)));
- }
- $today = getdate();
- for ($i = $today['year']; $i < $today['year'] + 10; $i++) {
- $expires_year[] = array('id' => strftime('%y', mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
- }
- $onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
- $fieldsArray = array();
- $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_FIRSTNAME,
- 'field' => zen_draw_input_field('paypalec_cc_firstname', $order->billing['firstname'], 'id="'.$this->code.'-cc-ownerf"'. $onFocus) .
- '<script type="text/javascript">function paypalec_cc_type_check() { ' . $this->cc_type_check . ' } </script>',
- 'tag' => $this->code.'-cc-ownerf');
- $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_LASTNAME,
- 'field' => zen_draw_input_field('paypalec_cc_lastname', $order->billing['lastname'], 'id="'.$this->code.'-cc-ownerl"'. $onFocus),
- 'tag' => $this->code.'-cc-ownerl');
- if (sizeof($this->cards)>0) $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_TYPE,
- 'field' => zen_draw_pull_down_menu('paypalec_cc_type', $this->cards, '', 'onchange="paypalec_cc_type_check();" onblur="paypalec_cc_type_check();"' . 'id="'.$this->code.'-cc-type"'. $onFocus),
- 'tag' => $this->code.'-cc-type');
- $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_NUMBER,
- 'field' => zen_draw_input_field('paypalec_cc_number', $ccnum, 'id="'.$this->code.'-cc-number"' . $onFocus),
- 'tag' => $this->code.'-cc-number');
- $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_EXPIRES,
- 'field' => zen_draw_pull_down_menu('paypalec_cc_expires_month', $expires_month, '', 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . ' ' . zen_draw_pull_down_menu('paypalec_cc_expires_year', $expires_year, '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
- 'tag' => $this->code.'-cc-expires-month');
- $fieldsArray[] = array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_CHECKNUMBER,
- 'field' => zen_draw_input_field('paypalec_cc_checkcode', '', 'size="4" maxlength="4"' . ' id="'.$this->code.'-cc-cvv"' . $onFocus) . ' <small>' . MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_CHECKNUMBER_LOCATION . '</small><script type="text/javascript">paypalec_cc_type_check();</script>',
- 'tag' => $this->code.'-cc-cvv');
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'PayPal') $fieldsArray[] = array('title' => '<br /><img src="' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_IMG . '" alt="' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT . '" /><span style="font-size:11px; font-family: Arial, Verdana;"> ' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT . '</span>');
- $selection = array('id' => $this->code,
- 'module' => MODULE_PAYMENT_PAYPALWPP_TEXT_TITLE,
- 'fields' => $fieldsArray);
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK' && (CC_ENABLED_SOLO=='1' || CC_ENABLED_SWITCH=='1')) {
- // add extra fields for Switch/Solo cards
- for ($i = $today['year'] - 10; $i <= $today['year']; $i++) {
- $issue_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
- }
- array_splice($selection['fields'], 4, 0,
- array(array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_ISSUE,
- 'field' => zen_draw_pull_down_menu('paypalec_cc_issue_month', $expires_month, '', 'id="'.$this->code.'-cc-issue-month"' . $onFocus ) . ' ' . zen_draw_pull_down_menu('paypalec_cc_issue_year', $issue_year, '', 'id="'.$this->code.'-cc-issue-year"' . $onFocus),
- 'tag' => $this->code.'-cc-issue-month')));
- }
- /* @TODO -- convert this to handle Issue Number
- if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK' && CC_ENABLED_MAESTRO=='1') {
- // add extra field for Maestro cards
- array_splice($selection['fields'], 4, 0,
- array(array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_MAESTRO_ISSUENUMBER,
- 'field' => zen_draw_pull_down_menu('paypalec_cc_issuenumber', $expires_month, '', 'id="'.$this->code.'-cc-issue-month"' . $onFocus ),
- 'tag' => $this->code.'-cc-issue-month')));
- }
- */
- return $selection;
- }
- /**
- * This is the credit card check done between checkout_payment and
- * checkout_confirmation (called from checkout_confirmation).
- * Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date
- */
- function pre_confirmation_check() {
- // If this is an EC checkout, do nothing.
- if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
- return false;
- }
- include(DIR_WS_CLASSES . 'cc_validation.php');
- $cc_validation = new cc_validation();
- $result = $cc_validation->validate($_POST['paypalec_cc_number'],
- $_POST['paypalec_cc_expires_month'], $_POST['paypalec_cc_expires_year'],
- $_POST['paypalec_cc_issue_month'], $_POST['paypalec_cc_issue_year']);
- $error = '';
- switch ($result) {
- case -1:
- $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
- break;
- case -2:
- case -3:
- case -4:
- $error = TEXT_CCVAL_ERROR_INVALID_DATE;
- break;
- case false:
- $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
- break;
- }
- $_POST['paypalec_cc_checkcode'] = preg_replace('/[^0-9]/i', '', $_POST['paypalec_cc_checkcode']);
- $_POST['paypalec_cc_issuenumber'] = preg_replace('/[^0-9]/i', '', $_POST['paypalec_cc_issuenumber']);
- if (($result === false) || ($result < 1) ) {
- $this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_CARD_ERROR . '<br />' . $error, false, FILENAME_CHECKOUT_PAYMENT);
- }
- $this->cc_card_type = $cc_validation->cc_type;
- $this->cc_card_number = $cc_validation->cc_number;
- $this->cc_expiry_month = $cc_validation->cc_expiry_month;
- $this->cc_expiry_year = $cc_validation->cc_expiry_year;
- $this->cc_checkcode = $_POST['paypalec_cc_checkcode'];
- }
- /**
- * Display Credit Card Information for review on the Checkout Confirmation Page
- */
- function confirmation() {
- if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
- $confirmation = array('title' => '', 'fields' => array());
- } else {
- $confirmation = array('title' => '',
- 'fields' => array(array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_FIRSTNAME,
- 'field' => $_POST['paypalec_cc_firstname']),
- array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_LASTNAME,
- 'field' => $_POST['paypalec_cc_lastname']),
- array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_TYPE,
- 'field' => $this->cc_card_type),
- array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_NUMBER,
- 'field' => substr($_POST['paypalec_cc_number'], 0, 4) . str_repeat('X', (strlen($_POST['paypalec_cc_number']) - 8)) . substr($_POST['paypalec_cc_number'], -4)),
- array('title' => MODULE_PAYMENT_PAYPALWPP_TEXT_CREDIT_CARD_EXPIRES,
- 'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['paypalec_cc_expires_month'], 1, '20' . $_POST['paypalec_cc_expires_year'])))));
- }
- return $confirmation;
- }
- /**
- * Prepare the hidden fields comprising the parameters for the Submit button on the checkout confirmation page
- */
- function process_button() {
- if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
- $process_button_string = '';
- } else {
- $_SESSION['paypal_ec_markflow'] = 1;
- $process_button_string = zen_draw_hidden_field('ec_cc_type', $_POST['paypalec_cc_type']) .
- zen_draw_hidden_field('ec_cc_expdate_month', $_POST['paypalec_cc_expires_month']) .
- zen_draw_hidden_field('ec_cc_expdate_year', $_POST['paypalec_cc_expires_year']) .
- zen_draw_hidden_field('ec_cc_issuedate_month', $_POST['paypalec_cc_issue_month']) .
- zen_draw_hidden_field('ec_cc_issuedate_year', $_POST['paypalec_cc_issue_year']) .
- zen_draw_hidden_field('ec_cc_number', $_POST['paypalec_cc_number']) .
- zen_draw_hidden_field('ec_cc_checkcode', $_POST['paypalec_cc_checkcode']) .
- zen_draw_hidden_field('ec_payer_firstname', $_POST['paypalec_cc_firstname']) .
- zen_draw_hidden_field('ec_payer_lastname', $_POST['paypalec_cc_lastname']);
- }
- return $process_button_string;
- }
- /**
- * Prepare and submit the final authorization to PayPal via the appropriate means as configured
- */
- function before_process() {
- global $order, $doPayPal;
- $options = array();
- $optionsShip = array();
- $optionsNVP = array();
- $options = $this->getLineItemDetails();
- //$this->zcLog('before_process - 1', 'Have line-item details:' . "\n" . print_r($options, true));
- $doPayPal = $this->paypal_init();
- if ($this->in_special_checkout() || $this->enableDirectPayment == false) {
- $this->zcLog('before_process - EC-1', 'Beginning EC mode');
- /****************************************
- * Do EC checkout
- ****************************************/
- // do not allow blank address to be sent to PayPal
- if ($_SESSION['paypal_ec_payer_info']['ship_street_1'] != '' && $_SESSION['paypal_ec_payer_info']['ship_address_status'] != 'None') {
- $options = array_merge($options,
- array('SHIPTONAME' => $_SESSION['paypal_ec_payer_info']['ship_name'],
- 'SHIPTOSTREET' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
- 'SHIPTOSTREET2'=> $_SESSION['paypal_ec_payer_info']['ship_street_2'],
- 'SHIPTOCITY' => $_SESSION['paypal_ec_payer_info']['ship_city'],
- 'SHIPTOSTATE' => $_SESSION['paypal_ec_payer_info']['ship_state'],
- 'SHIPTOZIP' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
- 'SHIPTOCOUNTRYCODE'=> $_SESSION['paypal_ec_payer_info']['ship_country_code'],
- ));
- $this->zcLog('before_process - EC-2', 'address overrides added:' . "\n" . print_r($options, true));
- }
- $this->zcLog('before_process - EC-3', 'address info added:' . "\n" . print_r($options, true));
- // If the customer has changed their shipping address,
- // override the shipping address in PayPal with the shipping
- // address that is selected in Zen Cart.
- if ($order->delivery['street_address'] != $_SESSION['paypal_ec_payer_info']['ship_street_1'] && $_SESSION['paypal_ec_payer_info']['ship_street_1'] != '') {
- $_GET['markflow'] = 2;
- if (($address_arr = $this->getOverrideAddress()) !== false) {
- // set the override var
- $options['ADDROVERRIDE'] = 1;
- // set the address info
- $options['SHIPTONAME'] = $address_arr['entry_firstname'] . ' ' . $address_arr['entry_lastname'];
- $options['SHIPTOSTREET'] = $address_arr['entry_street_address'];
- if ($address_arr['entry_suburb'] != '') $options['SHIPTOSTREET2'] = $address_arr['entry_suburb'];
- $options['SHIPTOCITY'] = $address_arr['entry_city'];
- $options['SHIPTOZIP'] = $address_arr['entry_postcode'];
- $options['SHIPTOSTATE'] = $address_arr['zone_code'];
- $options['SHIPTOCOUNTRYCODE'] = $address_arr['countries_iso_code_2'];
- }
- }
- // if these optional parameters are blank, remove them from transaction
- if (isset($options['SHIPTOSTREET2']) && trim($options['SHIPTOSTREET2']) == '') unset($options['SHIPTOSTREET2']);
- if (isset($options['SHIPTOPHONE']) && trim($options['SHIPTOPHONE']) == '') unset($options['SHIPTOPHONE']);
- // if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
- if ((!isset($options['SHIPTOSTATE']) || trim($options['SHIPTOSTATE']) == '') && $options['SHIPTOCITY'] != '') $options['SHIPTOSTATE'] = $options['SHIPTOCITY'];
- $options['BUTTONSOURCE'] = $this->buttonSourceEC;
- $options['CURRENCY'] = $this->selectCurrency($order->info['currency']);
- $order_amount = $this->calc_order_amount($order->info['total'], $options['CURRENCY']);
- // unused at present:
- // $options['CUSTOM'] = '';
- // $options['INVNUM'] = '';
- // $options['DESC'] = '';
- // debug output
- $this->zcLog('before_process - EC-4', 'info being submitted:' . "\n" . $_SESSION['paypal_ec_token'] . ' ' . $_SESSION['paypal_ec_payer_id'] . ' ' . number_format($order_amount, 2) . "\n" . print_r($options, true));
- $response = $doPayPal->DoExpressCheckoutPayment($_SESSION['paypal_ec_token'],
- $_SESSION['paypal_ec_payer_id'],
- number_format((isset($options['AMT']) ? $options['AMT'] : $order_amount), 2),
- $options);
- $this->zcLog('before_process - EC-5', 'resultset:' . "\n" . urldecode(print_r($response, true)));
- // CHECK RESPONSE -- if error, actions are taken in the errorHandler
- $error = $this->_errorHandler($response, 'DoExpressCheckoutPayment');
- // SUCCESS
- $this->payment_type = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TYPE;
- $this->responsedata = $response;
- if ($response['PAYMENTTYPE'] != '') $this->payment_type .= ' (' . urldecode($response['PAYMENTTYPE']) . ')';
- $this->transaction_id = trim($response['PNREF'] . ' ' . $response['TRANSACTIONID']);
- if (empty($response['PENDINGREASON']) ||
- $response['PENDINGREASON'] == 'none' ||
- $response['PENDINGREASON'] == 'completed' ||
- $response['PAYMENTSTATUS'] == 'Completed') {
- $this->payment_status = 'Completed';
- if ($this->order_status > 0) $order->info['order_status'] = $this->order_status;
- } else {
- $this->payment_status = 'Pending (' . $response['PENDINGREASON'] . ')';
- $order->info['order_status'] = $this->order_pending_status;
- }
- $this->avs = 'N/A';
- $this->cvv2 = 'N/A';
- $this->correlationid = $response['CORRELATIONID'];
- $this->transactiontype = $response['TRANSACTIONTYPE'];
- $this->payment_time = urldecode($response['ORDERTIME']);
- $this->feeamt = urldecode($response['FEEAMT']);
- $this->taxamt = urldecode($response['TAXAMT']);
- $this->pendingreason = $response['PENDINGREASON'];
- $this->reasoncode = $response['REASONCODE'];
- // $this->numitems = $_SESSION['cart']->count_contents();
- $this->numitems = sizeof($order->products);
- $this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
- $this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
- } else {
- /****************************************
- * Do DP checkout
- ****************************************/
- $this->zcLog('before_process - DP-1', 'Beginning DP mode');
- // Set state fields depending on what PayPal wants to see for that country
- $this->setStateAndCountry($order->billing);
- if (zen_not_null($order->delivery['street_address'])) {
- $this->setStateAndCountry($order->delivery);
- }
- // Validate credit card data
- include(DIR_WS_CLASSES . 'cc_validation.php');
- $cc_validation = new cc_validation();
- $response = $cc_validation->validate($_POST['ec_cc_number'], $_POST['ec_cc_expdate_month'], $_POST['ec_cc_expdate_year'],
- $_POST['ec_cc_issuedate_month'], $_POST['ec_cc_issuedate_year']);
- $error = '';
- switch ($response) {
- case -1:
- $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
- break;
- case -2:
- case -3:
- case -4:
- $error = TEXT_CCVAL_ERROR_INVALID_DATE;
- break;
- case false:
- $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
- break;
- }
- $this->zcLog('before_process - DP-2', 'CC validation results: ' . $error . '(' . $response . ')');
- if ($response == false || $response < 1) {
- $this->terminateEC($error, false, FILENAME_CHECKOUT_PAYMENT);
- }
- if (!in_array($cc_validation->cc_type, array('Visa', 'MasterCard', 'Switch', 'Solo', 'Discover', 'American Express', 'Maestro'))) {
- $this->terminateEC(MODULE_PAYMENT_PAYPALWPP_TEXT_BAD_CARD, false, FILENAME_CHECKOUT_PAYMENT);
- }
- $this->zcLog('before_process - DP-3', 'CC info: ' . $cc_validation->cc_type . ' ' . substr($cc_validation->cc_number, 0, 4) . str_repeat('X', (strlen($cc_validation->cc_number) - 8)) . substr($cc_validation->cc_number, -4));
- // if CC validation passed, continue using the validated data
- $cc_type = $cc_validation->cc_type;
- $cc_number = $cc_validation->cc_number;
- $cc_first_name = $_POST['ec_payer_firstname'];
- $cc_last_name = $_POST['ec_payer_lastname'];
- $cc_checkcode = $_POST['ec_cc_checkcode'];
- $cc_expdate_month = $cc_validation->cc_expiry_month;
- $cc_expdate_year = $cc_validation->cc_expiry_year;
- $cc_issuedate_month = $_POST['ec_cc_issuedate_month'];
- $cc_issuedate_year = $_POST['ec_cc_issuedate_year'];
- $cc_owner_ip = zen_get_ip_address();
- // If they're still here, set some of the order object's variables.
- $order->info['cc_type'] = $cc_type;
- $order->info['cc_number'] = substr($cc_number, 0, 4) . str_repeat('X', (strlen($cc_number) - 8)) . substr($cc_number, -4);
- $order->info['cc_owner'] = $cc_first_name . ' ' . $cc_last_name;
- $order->info['cc_expires'] = $cc_expdate_month . substr($cc_expdate_year, -2);
- $order->info['ip_address'] = $cc_owner_ip;
- // Set currency
- $my_currency = $this->selectCurrency($order->info['currency'], 'DP');
- /*
- // if CC is switch or solo, must be GBP
- if (in_array($cc_type, array('Switch', 'Solo', 'Maestro'))) {
- $my_currency = 'GBP';
- }
- */
- $order_amount = $this->calc_order_amount($order->info['total'], $my_currency);
- // Initialize the paypal caller object.
- $doPayPal = $this->paypal_init();
- $optionsAll = array_merge($options,
- array('STREET' => $order->billing['street_address'],
- 'ZIP' => $order->billing['postcode']));
- $optionsNVP = array('CITY' => $order->billing['city'],
- 'STATE' => $order->billing['state'],
- 'COUNTRYCODE' => $order->billing['country']['iso_code_2'],
- 'EXPDATE' => $cc_expdate_month . $cc_expdate_year );
- $optionsShip = array();
- if (isset($order->delivery) && $order->delivery['street_address'] != '') {
- $optionsShip= array('SHIPTONAME' => ($order->delivery['name'] == '' ? $order->delivery['firstname'] . ' ' . $order->delivery['lastname'] : $order->delivery['name']),
- 'SHIPTOSTREET' => $order->delivery['street_address'],
- 'SHIPTOSTREET2'=> $order->delivery['suburb'],
- 'SHIPTOCITY' => $order->delivery['city'],
- 'SHIPTOZIP' => $order->delivery['postcode'],
- 'SHIPTOSTATE' => $order->delivery['state'],
- 'SHIPTOCOUNTRYCODE'=> $order->delivery['country']['iso_code_2']);
- }
- // if these optional parameters are blank, remove them from transaction
- if (isset($optionsShip['SHIPTOSTREET2']) && trim($optionsShip['SHIPTOSTREET2']) == '') unset($optionsShip['SHIPTOSTREET2']);
- if (isset($optionsShip['SHIPTOPHONE']) && trim($optionsShip['SHIPTOPHONE']) == '') unset($optionsShip['SHIPTOPHONE']);
- // if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
- if (!isset($optionsShip['SHIPTOSTATE']) || trim($optionsShip['SHIPTOSTATE']) == '') $optionsShip['SHIPTOSTATE'] = $optionsShip['SHIPTOCITY'];
- // Payment Transaction/Authorization Mode
- $optionsNVP['PAYMENTACTION'] = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Sale';
- // if (in_array($cc_type, array('Switch', 'Solo'))) {
- // $optionsNVP['PAYMENTACTION'] = 'Authorization';
- // }
- $optionsAll['BUTTONSOURCE'] = $this->buttonSourceDP;
- $optionsAll['CURRENCY'] = $my_currency;
- $optionsAll['IPADDRESS'] = $cc_owner_ip;
- if ($cc_issuedate_month && $cc_issuedate_year) {
- $optionsAll['CARDSTART'] = $cc_issuedate_month . substr($cc_issuedate_year, -2);
- }
- // unused at present:
- // $options['CUSTOM'] = '';
- // $options['INVNUM'] = '';
- // $options['DESC'] = '';
- $this->zcLog('before_process - DP-4', 'optionsAll: ' . print_r($optionsAll, true) . "\n" . 'optionsNVP: ' . print_r($optionsNVP, true) . "\n" . 'optionsShip' . print_r($optionsShip, true) . "\n" . 'Rest of data: ' . "\n" . number_format($order_amount, 2) . ' ' . $cc_expdate_month . ' ' . substr($cc_expdate_year, -2) . ' ' . $cc_first_name . ' ' . $cc_last_name . ' ' . $cc_type);
- $response = $doPayPal->DoDirectPayment(number_format($order_amount, 2),
- $cc_number,
- $cc_checkcode,
- $cc_expdate_month . substr($cc_expdate_year, -2),
- $cc_first_name, $cc_last_name,
- $cc_type,
- $optionsAll, array_merge($optionsNVP, $optionsShip));
- $this->zcLog('before_process - DP-5', 'resultset:' . "\n" . print_r($response, true));
- // CHECK RESPONSE
- $error = $this->_errorHandler($response, 'DoDirectPayment');
- $this->feeamt = '';
- $this->taxamt = '';
- $this->pendingreason = '';
- $this->reasoncode = '';
- $this->numitems = sizeof($order->products);
- $this->responsedata = $response;
- if ($response['PNREF']) {
- // PNREF only comes from payflow mode
- $this->payment_type = MODULE_PAYMENT_PAYPALWPP_PF_TEXT_TYPE;
- $this->transaction_id = $response['PNREF'];
- $this->payment_status = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Completed';
- $this->avs = 'AVSADDR: ' . $response['AVSADDR'] . ', AVSZIP: ' . $response['AVSZIP'] . ', IAVS: ' . $response['IAVS'];
- $this->cvv2 = $response['CVV2MATCH'];
- $this->amt = $order_amount . ' ' . $my_currency;
- $this->payment_time = date('Y-m-d h:i:s');
- $this->responsedata['CURRENCYCODE'] = $my_currency;
- $this->responsedata['EXCHANGERATE'] = $order->info['currency_value'];
- $this->auth_code = $this->response['AUTHCODE'];
- } else {
- // here we're in NVP mode
- $this->transaction_id = $response['TRANSACTIONID'];
- $this->payment_type = MODULE_PAYMENT_PAYPALWPP_DP_TEXT_TYPE;
- $this->payment_status = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'Authorization' : 'Completed';
- $this->pendingreason = (MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE == 'Auth Only') ? 'authorization' : '';
- $this->avs = $response['AVSCODE'];
- $this->cvv2 = $response['CVV2MATCH'];
- $this->correlationid = $response['CORRELATIONID'];
- $this->payment_time = urldecode($response['TIMESTAMP']);
- $this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
- $this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
- $this->transactiontype = 'cart';
- }
- }
- }
- /**
- * When the order returns from the processor, this stores the results in order-status-history and logs data for subsequent use
- */
- function after_process() {
- global $insert_id, $db, $order;
- // add a new OSH record for this order's PP details
- $commentString = "Transaction ID: :transID: " .
- (isset($this->responsedata['PPREF']) ? "\nPPRef: " . $this->responsedata['PPREF'] : "") .
- (isset($this->responsedata['AUTHCODE'])? "\nAuthCode: " . $this->responsedata['AUTHCODE'] : "") .
- "\nPayment Type: :pmtType: " .
- "\nTimestamp: :pmtTime: " .
- "\nPayment Status: :pmtStatus: " .
- ($this->avs != 'N/A' ? "\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2 : '') .
- "\nAmount: :orderAmt: ";
- $commentString = $db->bindVars($commentString, ':transID:', $this->transaction_id, 'noquotestring');
- $commentString = $db->bindVars($commentString, ':pmtType:', $this->payment_type, 'noquotestring');
- $commentString = $db->bindVars($commentString, ':pmtTime:', $this->payment_time, 'noquotestring');
- $commentString = $db->bindVars($commentString, ':pmtStatus:', $this->payment_status, 'noquotestring');
- $commentString = $db->bindVars($commentString, ':orderAmt:', $this->amt, 'noquotestring');
- $sql_data_array= array(array('fieldName'=>'orders_id', 'value'=>$insert_id, 'type'=>'integer'),
- array('fieldName'=>'orders_status_id', 'value'=>$order->info['order_status'], 'type'=>'integer'),
- array('fieldName'=>'date_added', 'value'=>'now()', 'type'=>'noquotestring'),
- array('fieldName'=>'customer_notified', 'value'=>0, 'type'=>'integer'),
- array('fieldName'=>'comments', 'value'=>$commentString, 'type'=>'string'));
- $db->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
- // store the PayPal order meta data -- used for later matching and back-end processing activities
- $paypal_order = array('order_id' => $insert_id,
- 'txn_type' => $this->transactiontype,
- 'module_name' => $this->code,
- 'module_mode' => MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,
- 'reason_code' => $this->reasoncode,
- 'payment_type' => $this->payment_type,
- 'payment_status' => $this->payment_status,
- 'pending_reason' => $this->pendingreason,
- 'invoice' => urldecode($_SESSION['paypal_ec_token'] . $this->responsedata['PPREF']),
- 'first_name' => $_SESSION['paypal_ec_payer_info']['payer_firstname'],
- 'last_name' => $_SESSION['paypal_ec_payer_info']['payer_lastname'],
- 'payer_business_name' => $_SESSION['paypal_ec_payer_info']['payer_business'],
- 'address_name' => $_SESSION['paypal_ec_payer_info']['ship_name'],
- 'address_street' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
- 'address_city' => $_SESSION['paypal_ec_payer_info']['ship_city'],
- 'address_state' => $_SESSION['paypal_ec_payer_info']['ship_state'],
- 'address_zip' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
- 'address_country' => $_SESSION['paypal_ec_payer_info']['ship_country'],
- 'address_status' => $_SESSION['paypal_ec_payer_info']['ship_address_status'],
- 'payer_email' => $_SESSION['paypal_ec_payer_info']['payer_email'],
- 'payer_id' => $_SESSION['paypal_ec_payer_id'],
- 'payer_status' => $_SESSION['paypal_ec_payer_info']['payer_status'],
- 'payment_date' => trim(preg_replace('/[^0-9-:]/', ' ', $this->payment_time)),
- 'business' => '',
- 'receiver_email' => (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' ? MODULE_PAYMENT_PAYPALWPP_PFVENDOR : str_replace('_api1', '', MODULE_PAYMENT_PAYPALWPP_APIUSERNAME)),
- 'receiver_id' => '',
- 'txn_id' => $this->transaction_id,
- 'parent_txn_id' => '',
- 'num_cart_items' => (float)$this->numitems,
- 'mc_gross' => (float)$this->amt,
- 'mc_fee' => (float)urldecode($this->feeamt),
- 'mc_currency' => $this->responsedata['CURRENCYCODE'],
- 'settle_amount' => (float)urldecode($this->responsedata['SETTLEAMT']),
- 'settle_currency' => $this->responsedata['CURRENCYCODE'],
- 'exchange_rate' => (urldecode($this->responsedata['EXCHANGERATE']) > 0 ? urldecode($this->responsedata['EXCHANGERATE']) : 1.0),
- 'notify_version' => '0',
- 'verify_sign' =>'',
- 'date_added' => 'now()',
- 'memo' => '{Record generated by payment module}'
- );
- zen_db_perform(TABLE_PAYPAL, $paypal_order);
- // Unregister the paypal session variables, making it necessary to start again for another purchase
- unset($_SESSION['paypal_ec_temp']);
- unset($_SESSION['paypal_ec_token']);
- unset($_SESSION['paypal_ec_payer_id']);
- unset($_SESSION['paypal_ec_payer_info']);
- unset($_SESSION['paypal_ec_final']);
- unset($_SESSION['paypal_ec_markflow']);
- }
- /**
- * Build admin-page components
- *
- * @param int $zf_order_id
- * @return string
- */
- function admin_notification($zf_order_id) {
- global $db;
- $module = $this->code;
- $output = '';
- $response = $this->_GetTransactionDetails($zf_order_id);
- //$response = $this->_TransactionSearch('2006-12-01T00:00:00Z', $zf_order_id);
- $sql = "SELECT * from " . TABLE_PAYPAL . " WHERE order_id = :orderID
- AND parent_txn_id = '' AND order_id > 0
- ORDER BY paypal_ipn_id DESC LIMIT 1";
- $sql = $db->bindVars($sql, ':orderID', $zf_order_id, 'integer');
- $ipn = $db->Execute($sql);
- if ($ipn->RecordCount() == 0) $ipn->fields = array();
- if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php')) require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypalwpp_admin_notification.php');
- return $output;
- }
- /**
- * Used to read details of an existing transaction. FOR FUTURE USE.
- */
- function _GetTransactionDetails($oID) {
- global $db, $messageStack, $doPayPal;
- $doPayPal = $this->paypal_init();
- // look up history on this order from PayPal table
- $sql = "select * from " . TABLE_PAYPAL . " where order_id = :orderID AND parent_txn_id = '' ";
- $sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
- $zc_ppHist = $db->Execute($sql);
- if ($zc_ppHist->RecordCount() == 0) return false;
- $txnID = $zc_ppHist->fields['txn_id'];
- /**
- * Read data from PayPal
- */
- $response = $doPayPal->GetTransactionDetails($txnID);
- $error = $this->_errorHandler($response, 'GetTransactionDetails', 10007);
- if ($error === false) {
- return false;
- } else {
- return $response;
- }
- }
- /**
- * Used to read details of existing transactions. FOR FUTURE USE.
- */
- function _TransactionSearch($startDate = '', $oID = '', $criteria = '') {
- global $db, $messageStack, $doPayPal;
- $doPayPal = $this->paypal_init();
- // look up history on this order from PayPal table
- $sql = "select * from " . TABLE_PAYPAL . " where order_id = :orderID AND parent_txn_id = '' ";
- $sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
- $zc_ppHist = $db->Execute($sql);
- if ($zc_ppHist->RecordCount() == 0) return false;
- $txnID = $zc_ppHist->fields['txn_id'];
- $startDate = $zc_ppHist->fields['payment_date'];
- $timeval = time();
- if ($startDate == '') $startDate = date('Y-m-d', $timeval) . 'T' . date('h:i:s', $timeval) . 'Z';
- /**
- * Read data from PayPal
- */
- $response = $doPayPal->TransactionSearch($startDate, $txnID, $email, $criteria);
- $error = $this->_errorHandler($response, 'TransactionSearch');
- if ($error === false) {
- return false;
- } else {
- return $response;
- }
- }
- /**
- * Display appropriate error message when needed
- */
- function get_error() {
- include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
- $error = array('title' => MODULE_PAYMENT_PAYPALWPP_ERROR_HEADING,
- 'error' => ((isset($_GET['error'])) ? stripslashes(urldecode($_GET['error'])) : MODULE_PAYMENT_PAYPALWPP_TEXT_CARD_ERROR));
- return $error;
- }
- /**
- * Evaluate installation status of this module. Returns true if the status key is found.
- */
- function check() {
- global $db;
- if (!isset($this->_check)) {
- $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPALWPP_STATUS'");
- $this->_check = !$check_query->EOF;
- }
- return $this->_check;
- }
- /**
- * Installs all the configuration keys for this module
- */
- function install() {
- global $db;
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable this Payment Module', 'MODULE_PAYMENT_PAYPALWPP_STATUS', 'True', 'Do you want to enable this payment module?', '6', '25', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Direct Payment', 'MODULE_PAYMENT_PAYPALWPP_DIRECT_ENABLED', 'False', 'Would you like to enable credit card payments through PayPal DIRECTLY on your website? <br />(<strong…
Large files files are truncated, but you can click here to view the full file