/includes/modules/payment/paypalwpp.php
PHP | 2848 lines | 2011 code | 254 blank | 583 comment | 774 complexity | ac449f49cbcd135a624063dd2c7e4221 MD5 | raw file
Possible License(s): 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 payment method
- *
- * @package paymentMethod
- * @copyright Copyright 2003-2010 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 16878 2010-07-08 17:03:31Z 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
- */
- 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;
- /**
- * debugging flag
- *
- * @var boolean
- */
- var $enableDebugging = 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 = 'zhongtuo_cart_ec_c2';
- /**
- * 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;
- /**
- * FMF
- */
- var $fmfResponse = '';
- var $fmfErrors = array();
- /**
- * 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.9e';
- $this->enableDirectPayment = FALSE;
- $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
- // Set the title & description text based on the mode we're in ... EC vs US/UK 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'):
- $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 ((!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.9') $this->enabled = false;
- $this->cards = array();
- // if operating in markflow mode, start EC process when submitting order
- if (!$this->in_special_checkout()) {
- $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;
- if ($order->info['total'] == 0) $this->enabled = false;
- }
- }
- /**
- * Validate the credit card information via javascript (Number, Owner, and CVV Lengths)
- */
- function javascript_validation() {
- return false;
- }
- /**
- * Display Credit Card Information Submission Fields on the Checkout Payment Page
- */
- function selection() {
- $this->cc_type_check = '';
- /**
- * since we are NOT processing via the gateway, we will only display MarkFlow payment option, and no CC fields
- */
- return array('id' => $this->code,
- 'module' => '<img src="' . MODULE_PAYMENT_PAYPALEC_MARK_BUTTON_IMG . '" alt="' . MODULE_PAYMENT_PAYPALWPP_TEXT_BUTTON_ALTTEXT . '" /><span style="font-size:11px; font-family: Arial, Verdana;"> ' . MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT . '</span>');
- }
- function pre_confirmation_check() {
- // Since this is an EC checkout, do nothing.
- return false;
- }
- /**
- * Display Payment Information for review on the Checkout Confirmation Page
- */
- function confirmation() {
- $confirmation = array('title' => '', 'fields' => array());
- return $confirmation;
- }
- /**
- * Prepare the hidden fields comprising the parameters for the Submit button on the checkout confirmation page
- */
- function process_button() {
- $_SESSION['paypal_ec_markflow'] = 1;
- return '';
- }
- /**
- * Prepare and submit the final authorization to PayPal via the appropriate means as configured
- */
- function before_process() {
- global $order, $doPayPal, $messageStack;
- $options = array();
- $optionsShip = array();
- $optionsNVP = array();
- $options = $this->getLineItemDetails($this->selectCurrency($order->info['currency']));
- //$this->zcLog('before_process - 1', 'Have line-item details:' . "\n" . print_r($options, true));
- // Initializing DESC field: using for comments related to tax-included pricing, populated by getLineItemDetails()
- $options['DESC'] = '';
- $doPayPal = $this->paypal_init();
- $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'] != '' && strtoupper($_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));
- $options['BUTTONSOURCE'] = $this->buttonSourceEC;
- // 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'];
- // FMF support
- $options['RETURNFMFDETAILS'] = (MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS == 'Yes') ? 1 : 0;
- // Add note to track that this was an EC transaction (used in properly handling update IPNs related to EC transactions):
- $options['CUSTOM'] = 'EC-' . (int)$_SESSION['customer_id'] . '-' . time();
- // send the store name as transaction identifier, to help distinguish payments between multiple stores:
- $options['INVNUM'] = (int)$_SESSION['customer_id'] . '-' . time() . '-[' . substr(preg_replace('/[^a-zA-Z0-9_]/', '', STORE_NAME), 0, 30) . ']'; // (cannot send actual invoice number because it's not assigned until after payment is completed)
- $options['CURRENCY'] = $this->selectCurrency($order->info['currency']);
- $order_amount = $this->calc_order_amount($order->info['total'], $options['CURRENCY'], FALSE);
- // 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));
- if (isset($options['DESC']) && $options['DESC'] == '') unset($options['DESC']);
- if (!isset($options['AMT'])) $options['AMT'] = number_format($order_amount, 2, '.', '');
- $response = $doPayPal->DoExpressCheckoutPayment($_SESSION['paypal_ec_token'],
- $_SESSION['paypal_ec_payer_id'],
- $options);
- $this->zcLog('before_process - EC-5', 'resultset:' . "\n" . urldecode(print_r($response, true)));
- // CHECK RESPONSE -- if error, actions are taken in the errorHandler
- $errorHandlerMessage = $this->_errorHandler($response, 'DoExpressCheckoutPayment');
- if ($this->fmfResponse != '') {
- $this->order_status = $this->order_pending_status;
- }
- // 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 {
- if ($response['PAYMENTSTATUS'] == 'Pending')
- {
- if ($response['L_ERRORCODE0'] == 11610 && $response['PENDINGREASON'] == '') $response['PENDINGREASON'] = 'Pending FMF Review by Storeowner';
- }
- $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 = sizeof($order->products);
- $this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
- $this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
- }
- /**
- * 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;
- // FMF
- if ($this->fmfResponse != '') {
- $detailedMessage = $insert_id . "\n" . $this->fmfResponse . "\n" . MODULE_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_INTRO . "\n" . print_r($this->fmfErrors, TRUE);
- zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, MODULE_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_SUBJECT . ' (' . $insert_id . ')', $detailedMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($detailedMessage)), 'paymentalert');
- }
- // 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: " .
- ($this->payment_time != '' ? "\nTimestamp: :pmtTime: " : "") .
- "\nPayment Status: :pmtStatus: " .
- (isset($this->responsedata['auth_exp']) ? "\nAuth-Exp: " . $this->responsedata['auth_exp'] : "") .
- ($this->avs != 'N/A' ? "\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2 : '') .
- (trim($this->amt) != '' ? "\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' => (sizeof($this->fmfErrors) > 0 ? 'FMF Details ' . print_r($this->fmfErrors, TRUE) : '{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) {
- if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) return '';
- 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 order by last_modified DESC, date_added DESC, parent_txn_id DESC, paypal_ipn_id DESC ";
- $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;
- }
- }
- /**
- * 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, $messageStack;
- if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
- $messageStack->add_session('Express Checkout module already installed.', 'error');
- zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
- return 'failed';
- }
- if (defined('MODULE_PAYMENT_PAYPAL_STATUS')) {
- $messageStack->add_session('NOTE: You already have the PayPal Website Payments Standard module installed. You should REMOVE it if you want to install Express Checkout.', 'error');
- zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypal', 'NONSSL'));
- return 'failed';
- }
- $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 ('Live or Sandbox', 'MODULE_PAYMENT_PAYPALWPP_SERVER', 'live', '<strong>Live: </strong> Used to process Live transactions<br><strong>Sandbox: </strong>For developers and testing', '6', '25', 'zen_cfg_select_option(array(\'live\', \'sandbox\'), ', 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 ('Express Checkout: Require Confirmed Address', 'MODULE_PAYMENT_PAYPALWPP_CONFIRMED_ADDRESS', 'No', 'Do you want to require that your (not-logged-in) customers use a *confirmed* address when choosing their shipping address in PayPal?<br />(this is ignored for logged-in customers)', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', 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 ('Express Checkout: Select Cheapest Shipping Automatically', 'MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING', 'Yes', 'When customer returns from PayPal, do we want to automatically select the Cheapest shipping method and skip the shipping page? (making it more *express*)<br />Note: enabling this means the customer does *not* have easy access to select an alternate shipping method (without going back to the Checkout-Step-1 page)', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', 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 ('Express Checkout: Skip Payment Page', 'MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE', 'Yes', 'If the customer is checking out with Express Checkout, do you want to skip the checkout payment page, making things more *express*? <br /><strong>(NOTE: The Payment Page will auto-display regardless of this setting if you have Coupons or Gift Certificates enabled in your store.)</strong>', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', 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 ('Express Checkout: Automatic Account Creation', 'MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY', 'Yes', 'If a visitor is not an existing customer, a Zen Cart account is created for them. Would you like make it a permanent account and send them an email containing their login information?<br />NOTE: Permanent accounts are auto-created if the customer purchases downloads or gift certificates, regardless of this setting.', '6', '25', 'zen_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_PAYPALWPP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '25', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_PAYPALWPP_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '25', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID', '2', 'Set the status of orders paid with this payment module to this value. <br /><strong>Recommended: Processing[2]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Unpaid Order Status', 'MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID', '1', 'Set the status of unpaid orders made with this payment module to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Refund Order Status', 'MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID', '1', 'Set the status of refunded orders to this value. <br /><strong>Recommended: Pending[1]</strong>', '6', '25', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PayPal Page Style', 'MODULE_PAYMENT_PAYPALWPP_PAGE_STYLE', 'Primary', 'The page-layout style you want customers to see when they visit the PayPal site. You can configure your <strong>Custom Page Styles</strong> in your PayPal Profile settings. This value is case-sensitive.', '6', '25', 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 ('Payment Action', 'MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE', 'Final Sale', 'How do you want to obtain payment?<br /><strong>Default: Final Sale</strong>', '6', '25', 'zen_cfg_select_option(array(\'Auth Only\', \'Final Sale\'), ', 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 ('Transaction Currency', 'MODULE_PAYMENT_PAYPALWPP_CURRENCY', 'Selected Currency', 'Which currency should the order be sent to PayPal as? <br />NOTE: if an unsupported currency is sent to PayPal, it will be auto-converted to USD (or GBP if using UK account)<br /><strong>Default: Selected Currency</strong>', '6', '25', 'zen_cfg_select_option(array(\'Selected Currency\', \'Only USD\', \'Only AUD\', \'Only CAD\', \'Only EUR\', \'Only GBP\', \'Only CHF\', \'Only CZK\', \'Only DKK\', \'Only HKD\', \'Only HUF\', \'Only JPY\', \'Only NOK\', \'Only NZD\', \'Only PLN\', \'Only SEK\', \'Only SGD\', \'Only THB\', \'Only MXN\', \'Only ILS\', \'Only PHP\', \'Only TWD\', \'Only BRL\', \'Only MYR\'), ', 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 ('Fraud Mgmt Filters - FMF', 'MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS', 'No', 'If you have enabled FMF support in your PayPal account and wish to utilize it in your transactions, set this to yes. Otherwise, leave it at No.', '6', '25','zen_cfg_select_option(array(\'No\', \'Yes\'), ', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Signature -- Username', 'MODULE_PAYMENT_PAYPALWPP_APIUSERNAME', '', 'The API Username from your PayPal API Signature settings under *API Access*. This value typically looks like an email address and is case-sensitive.', '6', '25', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) values ('API Signature -- Password', 'MODULE_PAYMENT_PAYPALWPP_APIPASSWORD', '', 'The API Password from your PayPal API Signature settings under *API Access*. This value is a 16-character code and is case-sensitive.', '6', '25', now(), 'zen_cfg_password_input(', 'zen_cfg_password_display')");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) values ('API Signature -- Signature Code', 'MODULE_PAYMENT_PAYPALWPP_APISIGNATURE', '', 'The API Signature from your PayPal API Signature settings under *API Access*. This value is a 56-character code, and is case-sensitive.', '6', '25', now(), '', 'zen_cfg_password_display')");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: User', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', '', 'If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. Otherwise it should be the same value as VENDOR. This value is case-sensitive.', '6', '25', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: Partner', 'MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'ZenCart', 'Your Payflow Partner name linked to your Payflow account. This value is case-sensitive.<br />Typical values: <strong>PayPal</strong> or <strong>ZenCart</strong>', '6', '25', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('PAYFLOW: Vendor', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', '', 'Your merchant login ID that you created when you registered for the Payflow Pro account. This value is case-sensitive.', '6', '25', now())");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, set_function, use_function) values ('PAYFLOW: Password', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD', '', 'The 6- to 32-character password that you defined while registering for the account. This value is case-sensitive.', '6', '25', now(), 'zen_cfg_password_input(', 'zen_cfg_password_display')");
- $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('PayPal Mode', 'MODULE_PAYMENT_PAYPALWPP_MODULE_MODE', 'PayPal', 'Which PayPal API system should be used for processing? <br /><u>Choices:</u><br /><font color=green>For choice #1, you need to supply <strong>API Settings</strong> above.</font><br /><strong>1. PayPal</strong> = Express Checkout with a regular PayPal account<br />or<br /><font color=green>for choices 2 & 3 you need to supply <strong>PAYFLOW settings</strong>, below (and have a Payflow account)</font><br /><strong>2. Payflow-UK</strong> = Website Payments Pro UK Payflow Edition<br /><strong>3. Payflow-US</strong> = Payflow Pro Gateway only<!--<br /><strong>4. PayflowUS+EC</strong> = Payflow Pro with Express Checkout-->', '6', '25', 'zen_cfg_select_option(array(\'PayPal\', \'Payflow-UK\', \'Payflow-US\'), ', 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 ('Debug Mode', 'MODULE_PAYMENT_PAYPALWPP_DEBUGGING', 'Off', 'Would you like to enable debug mode? A complete detailed log of failed transactions will be emailed to the store owner.', '6', '25', 'zen_cfg_select_option(array(\'Off\', \'Alerts Only\', \'Log File\', \'Log and Email\'), ', now())");
- $this->notify('NOTIFY_PAYMENT_PAYPALWPP_INSTALLED');
- }
- function keys() {
- $keys_list = array('MODULE_PAYMENT_PAYPALWPP_STATUS', 'MODULE_PAYMENT_PAYPALWPP_SORT_ORDER', 'MODULE_PAYMENT_PAYPALWPP_ZONE', 'MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID', 'MODULE_PAYMENT_PAYPALWPP_CONFIRMED_ADDRESS', 'MODULE_PAYMENT_PAYPALWPP_AUTOSELECT_CHEAPEST_SHIPPING', 'MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE', 'MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY', 'MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE', 'MODULE_PAYMENT_PAYPALWPP_CURRENCY', 'MODULE_PAYMENT_PAYPALWPP_PAGE_STYLE', 'MODULE_PAYMENT_PAYPALWPP_APIUSERNAME', 'MODULE_PAYMENT_PAYPALWPP_APIPASSWORD', 'MODULE_PAYMENT_PAYPALWPP_APISIGNATURE', 'MODULE_PAYMENT_PAYPALWPP_MODULE_MODE', /*'MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD', */'MODULE_PAYMENT_PAYPALWPP_SERVER', 'MODULE_PAYMENT_PAYPALWPP_DEBUGGING');
- if (IS_ADMIN_FLAG === true && (PAYPAL_DEV_MODE == 'true' || strstr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE, 'Payflow'))) {
- $keys_list = array_merge($keys_list, array('MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD'));
- }
- return $keys_list;
- }
- /**
- * De-install this module
- */
- function remove() {
- global $messageStack;
- // cannot remove EC if DP installed:
- if (defined('MODULE_PAYMENT_PAYPALDP_STATUS')) {
- // this language text is hard-coded in english since Website Payments Pro is not yet available in any countries that speak any other language at this time.
- $messageStack->add_session('<strong>Sorry, you must remove Website Payments Pro (paypaldp) first.</strong> Website Payments Pro requires that you offer Express Checkout to your customers.<br /><a href="' . zen_href_link('modules.php?set=payment&module=paypaldp', '', 'NONSSL') . '">Click here to edit or remove your Website Payments Pro module.</a>' , 'error');
- zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
- return 'failed';
- }
- global $db;
- $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE\_PAYMENT\_PAYPALWPP\_%'");
- $this->notify('NOTIFY_PAYMENT_PAYPALWPP_UNINSTALLED');
- }
- /**
- * Check settings and conditions to determine whether we are in an Express Checkout phase or not
- */
- function in_special_checkout() {
- if ((defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') &&
- !empty($_SESSION['paypal_ec_token']) &&
- !empty($_SESSION['paypal_ec_payer_id']) &&
- !empty($_SESSION['paypal_ec_payer_info'])) {
- $this->flagDisablePaymentAddressChange = true;
- return true;
- }
- }
- /**
- * Determine whether the shipping-edit button should be displayed or not
- */
- function alterShippingEditButton() {
- return false;
- if ($this->in_special_checkout() && empty($_SESSION['paypal_ec_markflow'])) {
- return zen_href_link('ipn_main_handler.php', 'type=ec&clearSess=1', 'SSL', true,true, true);
- }
- }
- /**
- * Debug Logging support
- */
- function zcLog($stage, $message) {
- static $tokenHash;
- if ($tokenHash == '') $tokenHash = '_' . zen_create_random_value(4);
- if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File') {
- $token = (isset($_SESSION['paypal_ec_token'])) ? $_SESSION['paypal_ec_token'] : preg_replace('/[^0-9.A-Z\-]/', '', $_GET['token']);
- $token = ($token == '') ? date('m-d-Y-H-i') : $token; // or time()
- $token .= $tokenHash;
- $file = $this->_logDir . '/' . $this->code . '_Paypal_Action_' . $token . '.log';
- if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $file = $this->_logDir . '/' . $this->code . '_Paypal_Debug_' . $token . '.log';
- $fp = @fopen($file, 'a');
- @fwrite($fp, date('M-d-Y H:i:s') . ' (' . time() . ')' . "\n" . $stage . "\n" . $message . "\n=================================\n\n");
- @fclose($fp);
- }
- $this->_doDebug($stage, $message, false);
- }
- /**
- * Debug Emailing support
- */
- function _doDebug($subject = 'PayPal debug data', $data, $useSession = true) {
- if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email') {
- $data = urldecode($data) . "\n\n";
- if ($useSession) $data .= "\nSession data: " . print_r($_SESSION, true);
- zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, $subject, $this->code . "\n" . $data, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($this->code . "\n" . $data)), 'debug');
- }
- }
- /**
- * Initialize the PayPal/PayflowPro object for communication to the processing gateways
- */
- function paypal_init() {
- if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS') || !defined('MODULE_PAYMENT_PAYPALWPP_SERVER')) {
- $doPayPal = new paypal_curl(array('mode' => 'NOTCONFIGURED'));
- return $doPayPal;
- }
- $ec_uses_gateway = (defined('MODULE_PAYMENT_PAYPALWPP_PRO20_EC_METHOD') && MODULE_PAYMENT_PAYPALWPP_PRO20_EC_METHOD == 'Payflow') ? true : false;
- if (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow') {
- $doPayPal = new paypal_curl(array('mode' => 'payflow',
- 'user' => trim(MODULE_PAYMENT_PAYPALWPP_PFUSER),
- 'vendor' => trim(MODULE_PAYMENT_PAYPALWPP_PFVENDOR),
- 'partner'=> trim(MODULE_PAYMENT_PAYPALWPP_PFPARTNER),
- 'pwd' => trim(MODULE_PAYMENT_PAYPALWPP_PFPASSWORD),
- 'server' => MODULE_PAYMENT_PAYPALWPP_SERVER));
- $doPayPal->_endpoints = array('live' => 'https://payflowpro.paypal.com/transaction',
- 'sandbox' => 'https://pilot-payflowpro.paypal.com/transaction');
- } else {
- $doPayPal = new paypal_curl(array('mode' => 'nvp',
- 'user' => trim(MODULE_PAYMENT_PAYPALWPP_APIUSERNAME),
- 'pwd' => trim(MODULE_PAYMENT_PAYPALWPP_APIPASSWORD),
- 'signature' => trim(MODULE_PAYMENT_PAYPALWPP_APISIGNATURE),
- 'version' => '60.0',
- 'server' => MODULE_PAYMENT_PAYPALWPP_SERVER));
- $doPayPal->_endpoints = array('live' => 'https://api-3t.paypal.com/nvp',
- 'sandbox' => 'https://api.sandbox.paypal.com/nvp');
- }
- // set logging options
- $doPayPal->_logDir = $this->_logDir;
- // $doPayPal->_logLevel = $this->_logLevel;
- // set proxy options if configured
- if (CURL_PROXY_REQUIRED == 'True' && CURL_PROXY_SERVER_DETAILS != '') {
- $proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
- $doPayPal->setCurlOption(CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
- $doPayPal->setCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
- $doPayPal->setCurlOption(CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
- }
- // transaction processing mode
- $doPayPal->_trxtype = (in_array(MODULE_PAYMENT_PAYPALWPP_TRANSACTION_MODE, array('Auth Only', 'Order'))) ? 'A' : 'S';
- return $doPayPal;
- }
- /**
- * Determine which PayPal URL to direct the customer's browser to when needed
- */
- function getPayPalLoginServer() {
- if (MODULE_PAYMENT_PAYPALWPP_SERVER == 'live') {
- // live url
- $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
- } else {
- // sandbox url
- $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
- }
- return $paypal_url;
- }
- /**
- * Used to submit a refund for a given transaction. FOR FUTURE USE.
- */
- function _doRefund($oID, $amount = 'Full', $note = '') {
- global $db, $doPayPal, $messageStack;
- $new_order_status = (int)MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID;
- $orig_order_amount = 0;
- $doPayPal = $this->paypal_init();
- $proceedToRefund = false;
- $refundNote = strip_tags(zen_db_input($_POST['refnote']));
- if (isset($_POST['fullrefund']) && $_POST['fullrefund'] == MODULE_PAYMENT_PAYPAL_ENTRY_REFUND_BUTTON_TEXT_FULL) {
- $refundAmt = 'Full';
- if (isset($_POST['reffullconfirm']) && $_POST['reffullconfirm'] == 'on') {
- $proceedToRefund = true;
- } else {
- $messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_REFUND_FULL_CONFIRM_ERROR, 'error');
- }
- }
- if (isset($_POST['partialrefund']) && $_POST['partialrefund'] == MODULE_PAYMENT_PAYPAL_ENTRY_REFUND_BUTTON_TEXT_PARTIAL) {
- $refundAmt = (float)$_POST['refamt'];
- $proceedToRefund = true;
- if ($refundAmt == 0) {
- $messageStack->add_session(MODULE_PAYMENT_PAYPALWPP_TEXT_INVALID_REFUND_AMOUNT, 'error');
- $proceedToRefund = false;
- }
- }
- // look up history on this order from PayPal table
- $sql = "select * from " . TABLE_PAYPAL . " wh…
Large files files are truncated, but you can click here to view the full file