PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/includes/modules/payment/paypalwpp.php

https://bitbucket.org/gcooksey3/zencart
PHP | 2949 lines | 2060 code | 262 blank | 627 comment | 808 complexity | 2dd11783943721b5963187ec25c48d8a MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * paypalwpp.php payment module class for PayPal Express Checkout payment method
  4. *
  5. * @package paymentMethod
  6. * @copyright Copyright 2003-2012 Zen Cart Development Team
  7. * @copyright Portions Copyright 2003 osCommerce
  8. * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9. * @version GIT: $Id: Author: DrByte Tue Aug 28 14:21:34 2012 -0400 Modified in v1.5.1 $
  10. */
  11. /**
  12. * load the communications layer code
  13. */
  14. require_once(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/paypal/paypal_curl.php');
  15. /**
  16. * the PayPal payment module with Express Checkout
  17. */
  18. class paypalwpp extends base {
  19. /**
  20. * name of this module
  21. *
  22. * @var string
  23. */
  24. var $code;
  25. /**
  26. * displayed module title
  27. *
  28. * @var string
  29. */
  30. var $title;
  31. /**
  32. * displayed module description
  33. *
  34. * @var string
  35. */
  36. var $description;
  37. /**
  38. * module status - set based on various config and zone criteria
  39. *
  40. * @var string
  41. */
  42. var $enabled;
  43. /**
  44. * the zone to which this module is restricted for use
  45. *
  46. * @var string
  47. */
  48. var $zone;
  49. /**
  50. * debugging flag
  51. *
  52. * @var boolean
  53. */
  54. var $enableDebugging = false;
  55. /**
  56. * Determines whether payment page is displayed or not
  57. *
  58. * @var boolean
  59. */
  60. var $showPaymentPage = false;
  61. var $flagDisablePaymentAddressChange = false;
  62. /**
  63. * sort order of display
  64. *
  65. * @var int
  66. */
  67. var $sort_order = 0;
  68. /**
  69. * Button Source / BN code -- enables the module to work for Zen Cart
  70. *
  71. * @var string
  72. */
  73. var $buttonSourceEC = 'ZenCart-EC_us';
  74. /**
  75. * order status setting for pending orders
  76. *
  77. * @var int
  78. */
  79. var $order_pending_status = 1;
  80. /**
  81. * order status setting for completed orders
  82. *
  83. * @var int
  84. */
  85. var $order_status = DEFAULT_ORDERS_STATUS_ID;
  86. /**
  87. * Debug tools
  88. */
  89. var $_logDir = 'includes/modules/payment/paypal/logs/';
  90. var $_logLevel = 0;
  91. /**
  92. * FMF
  93. */
  94. var $fmfResponse = '';
  95. var $fmfErrors = array();
  96. /**
  97. * class constructor
  98. */
  99. function paypalwpp() {
  100. include_once(zen_get_file_directory(DIR_FS_CATALOG . DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', 'paypalwpp.php', 'false'));
  101. global $order;
  102. $this->code = 'paypalwpp';
  103. $this->codeTitle = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
  104. $this->codeVersion = '1.5.1';
  105. $this->enableDirectPayment = FALSE;
  106. $this->enabled = (MODULE_PAYMENT_PAYPALWPP_STATUS == 'True');
  107. // Set the title & description text based on the mode we're in ... EC vs US/UK vs admin
  108. if (IS_ADMIN_FLAG === true) {
  109. $this->description = sprintf(MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_DESCRIPTION, ' (rev' . $this->codeVersion . ')');
  110. switch (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE) {
  111. case ('PayPal'):
  112. $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
  113. break;
  114. case ('Payflow-UK'):
  115. $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PRO20;
  116. break;
  117. case ('Payflow-US'):
  118. if (defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes') {
  119. $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_EC;
  120. } else {
  121. $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_PF_GATEWAY;
  122. }
  123. break;
  124. default:
  125. $this->title = MODULE_PAYMENT_PAYPALWPP_TEXT_ADMIN_TITLE_EC;
  126. }
  127. if ($this->enabled) {
  128. if ( (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'PayPal' && (MODULE_PAYMENT_PAYPALWPP_APISIGNATURE == '' || MODULE_PAYMENT_PAYPALWPP_APIUSERNAME == '' || MODULE_PAYMENT_PAYPALWPP_APIPASSWORD == ''))
  129. || (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 == ''))
  130. ) $this->title .= '<span class="alert"><strong> NOT CONFIGURED YET</strong></span>';
  131. if (MODULE_PAYMENT_PAYPALWPP_SERVER =='sandbox') $this->title .= '<strong><span class="alert"> (sandbox active)</span></strong>';
  132. if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email') $this->title .= '<strong> (Debug)</strong>';
  133. if (!function_exists('curl_init')) $this->title .= '<strong><span class="alert"> CURL NOT FOUND. Cannot Use.</span></strong>';
  134. }
  135. } else {
  136. $this->description = MODULE_PAYMENT_PAYPALWPP_TEXT_DESCRIPTION;
  137. $this->title = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TITLE; //pp
  138. }
  139. if ((!defined('PAYPAL_OVERRIDE_CURL_WARNING') || (defined('PAYPAL_OVERRIDE_CURL_WARNING') && PAYPAL_OVERRIDE_CURL_WARNING != 'True')) && !function_exists('curl_init')) $this->enabled = false;
  140. $this->enableDebugging = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email');
  141. $this->emailAlerts = (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING =='Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Alerts Only');
  142. $this->doDPonly = (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE =='Payflow-US' && !(defined('MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC') && MODULE_PAYMENT_PAYPALWPP_PAYFLOW_EC == 'Yes'));
  143. $this->showPaymentPage = (MODULE_PAYMENT_PAYPALWPP_SKIP_PAYMENT_PAGE == 'No') ? true : false;
  144. $this->sort_order = MODULE_PAYMENT_PAYPALWPP_SORT_ORDER;
  145. $this->buttonSourceEC = 'ZenCart-EC_us';
  146. $this->buttonSourceDP = 'ZenCart-DP_us';
  147. if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') {
  148. $this->buttonSourceEC = 'ZenCart-EC_uk';
  149. $this->buttonSourceDP = 'ZenCart-DP_uk';
  150. }
  151. if (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-US') {
  152. $this->buttonSourceEC = 'ZenCart-ECGW_us';
  153. $this->buttonSourceDP = 'ZenCart-GW_us';
  154. }
  155. $this->order_pending_status = MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID;
  156. if ((int)MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID > 0) {
  157. $this->order_status = MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID;
  158. }
  159. $this->new_acct_notify = MODULE_PAYMENT_PAYPALWPP_NEW_ACCT_NOTIFY;
  160. $this->zone = (int)MODULE_PAYMENT_PAYPALWPP_ZONE;
  161. if (is_object($order)) $this->update_status();
  162. if (PROJECT_VERSION_MAJOR != '1' && substr(PROJECT_VERSION_MINOR, 0, 3) != '5.0') $this->enabled = false;
  163. $this->cards = array();
  164. // if operating in markflow mode, start EC process when submitting order
  165. if (!$this->in_special_checkout()) {
  166. $this->form_action_url = zen_href_link('ipn_main_handler.php', 'type=ec&markflow=1&clearSess=1&stage=final', 'SSL', true, true, true);
  167. }
  168. // debug setup
  169. if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_CATALOG . $this->_logDir;
  170. if (!@is_writable($this->_logDir)) $this->_logDir = DIR_FS_SQL_CACHE;
  171. // Regular mode:
  172. if ($this->enableDebugging) $this->_logLevel = 2;
  173. // DEV MODE:
  174. if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $this->_logLevel = 3;
  175. if (IS_ADMIN_FLAG === true) $this->tableCheckup();
  176. }
  177. /**
  178. * Sets payment module status based on zone restrictions etc
  179. */
  180. function update_status() {
  181. global $order, $db;
  182. // $this->zcLog('update_status', 'Checking whether module should be enabled or not.');
  183. if ($this->enabled && (int)$this->zone > 0) {
  184. $check_flag = false;
  185. $sql = "SELECT zone_id
  186. FROM " . TABLE_ZONES_TO_GEO_ZONES . "
  187. WHERE geo_zone_id = :zoneId
  188. AND zone_country_id = :countryId
  189. ORDER BY zone_id";
  190. $sql = $db->bindVars($sql, ':zoneId', $this->zone, 'integer');
  191. $sql = $db->bindVars($sql, ':countryId', $order->billing['country']['id'], 'integer');
  192. $check = $db->Execute($sql);
  193. while (!$check->EOF) {
  194. if ($check->fields['zone_id'] < 1) {
  195. $check_flag = true;
  196. break;
  197. } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
  198. $check_flag = true;
  199. break;
  200. }
  201. $check->MoveNext();
  202. }
  203. if (!$check_flag) {
  204. $this->enabled = false;
  205. $this->zcLog('update_status', 'Module disabled due to zone restriction. Billing address is not within the Payment Zone selected in the module settings.');
  206. }
  207. // module cannot be used for purchase > $10,000 USD
  208. $order_amount = $this->calc_order_amount($order->info['total'], 'USD');
  209. if ($order_amount > 10000) {
  210. $this->enabled = false;
  211. $this->zcLog('update_status', 'Module disabled because purchase price (' . $order_amount . ') exceeds PayPal-imposed maximum limit of 10,000 USD.');
  212. }
  213. if ($order->info['total'] == 0) {
  214. $this->enabled = false;
  215. $this->zcLog('update_status', 'Module disabled because purchase amount is set to 0.00.' . "\n" . print_r($order, true));
  216. }
  217. }
  218. }
  219. /**
  220. * Validate the credit card information via javascript (Number, Owner, and CVV Lengths)
  221. */
  222. function javascript_validation() {
  223. return false;
  224. }
  225. /**
  226. * Display Credit Card Information Submission Fields on the Checkout Payment Page
  227. */
  228. function selection() {
  229. $this->cc_type_check = '';
  230. /**
  231. * since we are NOT processing via the gateway, we will only display MarkFlow payment option, and no CC fields
  232. */
  233. return array('id' => $this->code,
  234. '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>');
  235. }
  236. function pre_confirmation_check() {
  237. // Since this is an EC checkout, do nothing.
  238. return false;
  239. }
  240. /**
  241. * Display Payment Information for review on the Checkout Confirmation Page
  242. */
  243. function confirmation() {
  244. $confirmation = array('title' => '', 'fields' => array());
  245. return $confirmation;
  246. }
  247. /**
  248. * Prepare the hidden fields comprising the parameters for the Submit button on the checkout confirmation page
  249. */
  250. function process_button() {
  251. $_SESSION['paypal_ec_markflow'] = 1;
  252. return '';
  253. }
  254. /**
  255. * Prepare and submit the final authorization to PayPal via the appropriate means as configured
  256. */
  257. function before_process() {
  258. global $order, $doPayPal, $messageStack;
  259. $options = array();
  260. $optionsShip = array();
  261. $optionsNVP = array();
  262. $options = $this->getLineItemDetails($this->selectCurrency($order->info['currency']));
  263. if (defined('MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT') && MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT == 'Instant Only') $options['ALLOWEDPAYMENTMETHOD'] = 'InstantPaymentOnly';
  264. //$this->zcLog('before_process - 1', 'Have line-item details:' . "\n" . print_r($options, true));
  265. // Initializing DESC field: using for comments related to tax-included pricing, populated by getLineItemDetails()
  266. $options['DESC'] = '';
  267. $doPayPal = $this->paypal_init();
  268. $this->zcLog('before_process - EC-1', 'Beginning EC mode');
  269. /****************************************
  270. * Do EC checkout
  271. ****************************************/
  272. // do not allow blank address to be sent to PayPal
  273. if ($_SESSION['paypal_ec_payer_info']['ship_street_1'] != '' && strtoupper($_SESSION['paypal_ec_payer_info']['ship_address_status']) != 'NONE') {
  274. $options = array_merge($options,
  275. array('SHIPTONAME' => $_SESSION['paypal_ec_payer_info']['ship_name'],
  276. 'SHIPTOSTREET' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
  277. 'SHIPTOSTREET2'=> $_SESSION['paypal_ec_payer_info']['ship_street_2'],
  278. 'SHIPTOCITY' => $_SESSION['paypal_ec_payer_info']['ship_city'],
  279. 'SHIPTOSTATE' => $_SESSION['paypal_ec_payer_info']['ship_state'],
  280. 'SHIPTOZIP' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
  281. 'SHIPTOCOUNTRYCODE'=> $_SESSION['paypal_ec_payer_info']['ship_country_code'],
  282. ));
  283. $this->zcLog('before_process - EC-2', 'address overrides added:' . "\n" . print_r($options, true));
  284. }
  285. $this->zcLog('before_process - EC-3', 'address info added:' . "\n" . print_r($options, true));
  286. $options['BUTTONSOURCE'] = $this->buttonSourceEC;
  287. // If the customer has changed their shipping address,
  288. // override the shipping address in PayPal with the shipping
  289. // address that is selected in Zen Cart.
  290. if ($order->delivery['street_address'] != '' && $order->delivery['street_address'] != $_SESSION['paypal_ec_payer_info']['ship_street_1'] && $_SESSION['paypal_ec_payer_info']['ship_street_1'] != '') {
  291. $_GET['markflow'] = 2;
  292. if (($address_arr = $this->getOverrideAddress()) !== false) {
  293. // set the override var
  294. $options['ADDROVERRIDE'] = 1;
  295. // set the address info
  296. $options['SHIPTONAME'] = $address_arr['entry_firstname'] . ' ' . $address_arr['entry_lastname'];
  297. $options['SHIPTOSTREET'] = $address_arr['entry_street_address'];
  298. if ($address_arr['entry_suburb'] != '') $options['SHIPTOSTREET2'] = $address_arr['entry_suburb'];
  299. $options['SHIPTOCITY'] = $address_arr['entry_city'];
  300. $options['SHIPTOZIP'] = $address_arr['entry_postcode'];
  301. $options['SHIPTOSTATE'] = $address_arr['zone_code'];
  302. $options['SHIPTOCOUNTRYCODE'] = $address_arr['countries_iso_code_2'];
  303. }
  304. }
  305. // if these optional parameters are blank, remove them from transaction
  306. if (isset($options['SHIPTOSTREET2']) && trim($options['SHIPTOSTREET2']) == '') unset($options['SHIPTOSTREET2']);
  307. if (isset($options['SHIPTOPHONENUM']) && trim($options['SHIPTOPHONENUM']) == '') unset($options['SHIPTOPHONENUM']);
  308. // if State is not supplied, repeat the city so that it's not blank, otherwise PayPal croaks
  309. if ((!isset($options['SHIPTOSTATE']) || trim($options['SHIPTOSTATE']) == '') && $options['SHIPTOCITY'] != '') $options['SHIPTOSTATE'] = $options['SHIPTOCITY'];
  310. // FMF support
  311. $options['RETURNFMFDETAILS'] = (MODULE_PAYMENT_PAYPALWPP_EC_RETURN_FMF_DETAILS == 'Yes') ? 1 : 0;
  312. // Add note to track that this was an EC transaction (used in properly handling update IPNs related to EC transactions):
  313. $options['CUSTOM'] = 'EC-' . (int)$_SESSION['customer_id'] . '-' . time();
  314. // send the store name as transaction identifier, to help distinguish payments between multiple stores:
  315. $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)
  316. $options['CURRENCY'] = $this->selectCurrency($order->info['currency']);
  317. // $order->info['total'] = zen_round($order->info['total'], 2);
  318. $order_amount = $this->calc_order_amount($order->info['total'], $options['CURRENCY'], FALSE);
  319. // debug output
  320. $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));
  321. if (isset($options['DESC']) && $options['DESC'] == '') unset($options['DESC']);
  322. if (!isset($options['AMT'])) $options['AMT'] = number_format($order_amount, 2, '.', '');
  323. $response = $doPayPal->DoExpressCheckoutPayment($_SESSION['paypal_ec_token'],
  324. $_SESSION['paypal_ec_payer_id'],
  325. $options);
  326. $this->zcLog('before_process - EC-5', 'resultset:' . "\n" . urldecode(print_r($response, true)));
  327. // CHECK RESPONSE -- if error, actions are taken in the errorHandler
  328. $errorHandlerMessage = $this->_errorHandler($response, 'DoExpressCheckoutPayment');
  329. if ($this->fmfResponse != '') {
  330. $this->order_status = $this->order_pending_status;
  331. }
  332. // SUCCESS
  333. $this->payment_type = MODULE_PAYMENT_PAYPALWPP_EC_TEXT_TYPE;
  334. $this->responsedata = $response;
  335. if ($response['PAYMENTTYPE'] != '') $this->payment_type .= ' (' . urldecode($response['PAYMENTTYPE']) . ')';
  336. $this->transaction_id = trim($response['PNREF'] . ' ' . $response['TRANSACTIONID']);
  337. if (empty($response['PENDINGREASON']) ||
  338. $response['PENDINGREASON'] == 'none' ||
  339. $response['PENDINGREASON'] == 'completed' ||
  340. $response['PAYMENTSTATUS'] == 'Completed') {
  341. $this->payment_status = 'Completed';
  342. if ($this->order_status > 0) $order->info['order_status'] = $this->order_status;
  343. } else {
  344. if ($response['PAYMENTSTATUS'] == 'Pending')
  345. {
  346. if ($response['L_ERRORCODE0'] == 11610 && $response['PENDINGREASON'] == '') $response['PENDINGREASON'] = 'Pending FMF Review by Storeowner';
  347. }
  348. $this->payment_status = 'Pending (' . $response['PENDINGREASON'] . ')';
  349. $order->info['order_status'] = $this->order_pending_status;
  350. }
  351. $this->avs = 'N/A';
  352. $this->cvv2 = 'N/A';
  353. $this->correlationid = $response['CORRELATIONID'];
  354. $this->transactiontype = $response['TRANSACTIONTYPE'];
  355. $this->payment_time = urldecode($response['ORDERTIME']);
  356. $this->feeamt = urldecode($response['FEEAMT']);
  357. $this->taxamt = urldecode($response['TAXAMT']);
  358. $this->pendingreason = $response['PENDINGREASON'];
  359. $this->reasoncode = $response['REASONCODE'];
  360. $this->numitems = sizeof($order->products);
  361. $this->amt = urldecode($response['AMT'] . ' ' . $response['CURRENCYCODE']);
  362. $this->auth_code = (isset($this->response['AUTHCODE'])) ? $this->response['AUTHCODE'] : $this->response['TOKEN'];
  363. }
  364. /**
  365. * When the order returns from the processor, this stores the results in order-status-history and logs data for subsequent use
  366. */
  367. function after_process() {
  368. global $insert_id, $db, $order;
  369. // FMF
  370. if ($this->fmfResponse != '') {
  371. $detailedMessage = $insert_id . "\n" . $this->fmfResponse . "\n" . MODULES_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_INTRO . "\n" . print_r($this->fmfErrors, TRUE);
  372. zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, MODULES_PAYMENT_PAYPALDP_TEXT_EMAIL_FMF_SUBJECT . ' (' . $insert_id . ')', $detailedMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($detailedMessage)), 'paymentalert');
  373. }
  374. // add a new OSH record for this order's PP details
  375. $commentString = "Transaction ID: :transID: " .
  376. (isset($this->responsedata['PPREF']) ? "\nPPRef: " . $this->responsedata['PPREF'] : "") .
  377. (isset($this->responsedata['AUTHCODE'])? "\nAuthCode: " . $this->responsedata['AUTHCODE'] : "") .
  378. "\nPayment Type: :pmtType: " .
  379. ($this->payment_time != '' ? "\nTimestamp: :pmtTime: " : "") .
  380. "\nPayment Status: :pmtStatus: " .
  381. (isset($this->responsedata['auth_exp']) ? "\nAuth-Exp: " . $this->responsedata['auth_exp'] : "") .
  382. ($this->avs != 'N/A' ? "\nAVS Code: ".$this->avs."\nCVV2 Code: ".$this->cvv2 : '') .
  383. (trim($this->amt) != '' ? "\nAmount: :orderAmt: " : "");
  384. $commentString = $db->bindVars($commentString, ':transID:', $this->transaction_id, 'noquotestring');
  385. $commentString = $db->bindVars($commentString, ':pmtType:', $this->payment_type, 'noquotestring');
  386. $commentString = $db->bindVars($commentString, ':pmtTime:', $this->payment_time, 'noquotestring');
  387. $commentString = $db->bindVars($commentString, ':pmtStatus:', $this->payment_status, 'noquotestring');
  388. $commentString = $db->bindVars($commentString, ':orderAmt:', $this->amt, 'noquotestring');
  389. $sql_data_array= array(array('fieldName'=>'orders_id', 'value'=>$insert_id, 'type'=>'integer'),
  390. array('fieldName'=>'orders_status_id', 'value'=>$order->info['order_status'], 'type'=>'integer'),
  391. array('fieldName'=>'date_added', 'value'=>'now()', 'type'=>'noquotestring'),
  392. array('fieldName'=>'customer_notified', 'value'=>0, 'type'=>'integer'),
  393. array('fieldName'=>'comments', 'value'=>$commentString, 'type'=>'string'));
  394. $db->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  395. // store the PayPal order meta data -- used for later matching and back-end processing activities
  396. $paypal_order = array('order_id' => $insert_id,
  397. 'txn_type' => $this->transactiontype,
  398. 'module_name' => $this->code,
  399. 'module_mode' => MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,
  400. 'reason_code' => $this->reasoncode,
  401. 'payment_type' => $this->payment_type,
  402. 'payment_status' => $this->payment_status,
  403. 'pending_reason' => $this->pendingreason,
  404. 'invoice' => urldecode($_SESSION['paypal_ec_token'] . $this->responsedata['PPREF']),
  405. 'first_name' => $_SESSION['paypal_ec_payer_info']['payer_firstname'],
  406. 'last_name' => $_SESSION['paypal_ec_payer_info']['payer_lastname'],
  407. 'payer_business_name' => $_SESSION['paypal_ec_payer_info']['payer_business'],
  408. 'address_name' => $_SESSION['paypal_ec_payer_info']['ship_name'],
  409. 'address_street' => $_SESSION['paypal_ec_payer_info']['ship_street_1'],
  410. 'address_city' => $_SESSION['paypal_ec_payer_info']['ship_city'],
  411. 'address_state' => $_SESSION['paypal_ec_payer_info']['ship_state'],
  412. 'address_zip' => $_SESSION['paypal_ec_payer_info']['ship_postal_code'],
  413. 'address_country' => $_SESSION['paypal_ec_payer_info']['ship_country'],
  414. 'address_status' => $_SESSION['paypal_ec_payer_info']['ship_address_status'],
  415. 'payer_email' => $_SESSION['paypal_ec_payer_info']['payer_email'],
  416. 'payer_id' => $_SESSION['paypal_ec_payer_id'],
  417. 'payer_status' => $_SESSION['paypal_ec_payer_info']['payer_status'],
  418. 'payment_date' => trim(preg_replace('/[^0-9-:]/', ' ', $this->payment_time)),
  419. 'business' => '',
  420. 'receiver_email' => (substr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE,0,7) == 'Payflow' ? MODULE_PAYMENT_PAYPALWPP_PFVENDOR : str_replace('_api1', '', MODULE_PAYMENT_PAYPALWPP_APIUSERNAME)),
  421. 'receiver_id' => '',
  422. 'txn_id' => $this->transaction_id,
  423. 'parent_txn_id' => '',
  424. 'num_cart_items' => (float)$this->numitems,
  425. 'mc_gross' => (float)$this->amt,
  426. 'mc_fee' => (float)urldecode($this->feeamt),
  427. 'mc_currency' => $this->responsedata['CURRENCYCODE'],
  428. 'settle_amount' => (float)urldecode($this->responsedata['SETTLEAMT']),
  429. 'settle_currency' => $this->responsedata['CURRENCYCODE'],
  430. 'exchange_rate' => (urldecode($this->responsedata['EXCHANGERATE']) > 0 ? urldecode($this->responsedata['EXCHANGERATE']) : 1.0),
  431. 'notify_version' => '0',
  432. 'verify_sign' =>'',
  433. 'date_added' => 'now()',
  434. 'memo' => (sizeof($this->fmfErrors) > 0 ? 'FMF Details ' . print_r($this->fmfErrors, TRUE) : '{Record generated by payment module}'),
  435. );
  436. zen_db_perform(TABLE_PAYPAL, $paypal_order);
  437. // Unregister the paypal session variables, making it necessary to start again for another purchase
  438. unset($_SESSION['paypal_ec_temp']);
  439. unset($_SESSION['paypal_ec_token']);
  440. unset($_SESSION['paypal_ec_payer_id']);
  441. unset($_SESSION['paypal_ec_payer_info']);
  442. unset($_SESSION['paypal_ec_final']);
  443. unset($_SESSION['paypal_ec_markflow']);
  444. }
  445. /**
  446. * Build admin-page components
  447. *
  448. * @param int $zf_order_id
  449. * @return string
  450. */
  451. function admin_notification($zf_order_id) {
  452. if (!defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) return '';
  453. global $db;
  454. $module = $this->code;
  455. $output = '';
  456. $response = $this->_GetTransactionDetails($zf_order_id);
  457. //$response = $this->_TransactionSearch('2006-12-01T00:00:00Z', $zf_order_id);
  458. $sql = "SELECT * from " . TABLE_PAYPAL . " WHERE order_id = :orderID
  459. AND parent_txn_id = '' AND order_id > 0
  460. ORDER BY paypal_ipn_id DESC LIMIT 1";
  461. $sql = $db->bindVars($sql, ':orderID', $zf_order_id, 'integer');
  462. $ipn = $db->Execute($sql);
  463. if ($ipn->RecordCount() == 0) $ipn->fields = array();
  464. 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');
  465. return $output;
  466. }
  467. /**
  468. * Used to read details of an existing transaction. FOR FUTURE USE.
  469. */
  470. function _GetTransactionDetails($oID) {
  471. if ($oID == '' || $oID < 1) return FALSE;
  472. global $db, $messageStack, $doPayPal;
  473. $doPayPal = $this->paypal_init();
  474. // look up history on this order from PayPal table
  475. $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 ";
  476. $sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
  477. $zc_ppHist = $db->Execute($sql);
  478. if ($zc_ppHist->RecordCount() == 0) return false;
  479. $txnID = $zc_ppHist->fields['txn_id'];
  480. if ($txnID == '' || $txnID === 0) return FALSE;
  481. /**
  482. * Read data from PayPal
  483. */
  484. $response = $doPayPal->GetTransactionDetails($txnID);
  485. $error = $this->_errorHandler($response, 'GetTransactionDetails', 10007);
  486. if ($error === false) {
  487. return false;
  488. } else {
  489. return $response;
  490. }
  491. }
  492. /**
  493. * Used to read details of existing transactions. FOR FUTURE USE.
  494. */
  495. function _TransactionSearch($startDate = '', $oID = '', $criteria = '') {
  496. global $db, $messageStack, $doPayPal;
  497. $doPayPal = $this->paypal_init();
  498. // look up history on this order from PayPal table
  499. $sql = "select * from " . TABLE_PAYPAL . " where order_id = :orderID AND parent_txn_id = '' ";
  500. $sql = $db->bindVars($sql, ':orderID', $oID, 'integer');
  501. $zc_ppHist = $db->Execute($sql);
  502. if ($zc_ppHist->RecordCount() == 0) return false;
  503. $txnID = $zc_ppHist->fields['txn_id'];
  504. $startDate = $zc_ppHist->fields['payment_date'];
  505. $timeval = time();
  506. if ($startDate == '') $startDate = date('Y-m-d', $timeval) . 'T' . date('h:i:s', $timeval) . 'Z';
  507. /**
  508. * Read data from PayPal
  509. */
  510. $response = $doPayPal->TransactionSearch($startDate, $txnID, $email, $criteria);
  511. $error = $this->_errorHandler($response, 'TransactionSearch');
  512. if ($error === false) {
  513. return false;
  514. } else {
  515. return $response;
  516. }
  517. }
  518. /**
  519. * Evaluate installation status of this module. Returns true if the status key is found.
  520. */
  521. function check() {
  522. global $db;
  523. if (!isset($this->_check)) {
  524. $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPALWPP_STATUS'");
  525. $this->_check = !$check_query->EOF;
  526. }
  527. return $this->_check;
  528. }
  529. /**
  530. * Installs all the configuration keys for this module
  531. */
  532. function install() {
  533. global $db, $messageStack;
  534. if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
  535. $messageStack->add_session('Express Checkout module already installed.', 'error');
  536. zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
  537. return 'failed';
  538. }
  539. if (defined('MODULE_PAYMENT_PAYPAL_STATUS')) {
  540. $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');
  541. zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypal', 'NONSSL'));
  542. return 'failed';
  543. }
  544. $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())");
  545. $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())");
  546. $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 Shortcut Button', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', 'On', 'The Express Checkout Shortcut button shows up on your shopping cart page to invite your customers to pay using PayPal without having to give all their address details on your site first before selecting shipping options.<br />It has been shown to increase sales and conversions when enabled.<br />Default: On ', '6', '25', 'zen_cfg_select_option(array(\'On\', \'Off\'), ', now())");
  547. $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())");
  548. $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())");
  549. $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())");
  550. $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())");
  551. $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())");
  552. $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())");
  553. $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())");
  554. $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())");
  555. $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())");
  556. $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())");
  557. $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Store (Brand) Name at PayPal', 'MODULE_PAYMENT_PAYPALWPP_BRANDNAME', '', 'The name of your store as it should appear on the PayPal login page. If blank, your store name will be used.', '6', '25', now())");
  558. $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())");
  559. $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\', \'Only TKD\'), ', now())");
  560. $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Allow eCheck?', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', 'Any', 'Do you want to allow non-instant payments like eCheck/EFT/ELV?', '6', '25', 'zen_cfg_select_option(array(\'Any\', \'Instant Only\'), ', now())");
  561. $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())");
  562. $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())");
  563. $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')");
  564. $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')");
  565. $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())");
  566. $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())");
  567. $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())");
  568. $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')");
  569. $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 &amp; 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())");
  570. $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())");
  571. $this->notify('NOTIFY_PAYMENT_PAYPALWPP_INSTALLED');
  572. }
  573. function keys() {
  574. if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS')) {
  575. global $db;
  576. if (!defined('MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON')) {
  577. $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 Shortcut Button', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', 'On', 'The Express Checkout Shortcut button shows up on your shopping cart page to invite your customers to pay using PayPal without having to give all their address details on your site first before selecting shipping options.<br />It has been shown to increase sales and conversions when enabled.<br />Default: On ', '6', '25', 'zen_cfg_select_option(array(\'On\', \'Off\'), ', now())");
  578. }
  579. if (!defined('MODULE_PAYMENT_PAYPALWPP_BRANDNAME')) {
  580. $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Store Brand Name at PayPal', 'MODULE_PAYMENT_PAYPALWPP_BRANDNAME', '', 'The name of your store as it should appear on the PayPal login page. If blank, your store name will be used.', '6', '25', now())");
  581. }
  582. if (!defined('MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT')) {
  583. $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Allow eCheck?', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', 'Any', 'Do you want to allow non-instant payments like eCheck/EFT/ELV?', '6', '25', 'zen_cfg_select_option(array(\'Any\', \'Instant Only\'), ', now())");
  584. }
  585. }
  586. $keys_list = array('MODULE_PAYMENT_PAYPALWPP_STATUS', 'MODULE_PAYMENT_PAYPALWPP_SORT_ORDER', 'MODULE_PAYMENT_PAYPALWPP_ZONE', 'MODULE_PAYMENT_PAYPALWPP_ECS_BUTTON', '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_BRANDNAME', 'MODULE_PAYMENT_PAYPALEC_ALLOWEDPAYMENT', '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_SERVER', 'MODULE_PAYMENT_PAYPALWPP_DEBUGGING');
  587. if (IS_ADMIN_FLAG === true && (PAYPAL_DEV_MODE == 'true' || strstr(MODULE_PAYMENT_PAYPALWPP_MODULE_MODE, 'Payflow'))) {
  588. $keys_list = array_merge($keys_list, array('MODULE_PAYMENT_PAYPALWPP_PFPARTNER', 'MODULE_PAYMENT_PAYPALWPP_PFVENDOR', 'MODULE_PAYMENT_PAYPALWPP_PFUSER', 'MODULE_PAYMENT_PAYPALWPP_PFPASSWORD'));
  589. }
  590. return $keys_list;
  591. }
  592. /**
  593. * De-install this module
  594. */
  595. function remove() {
  596. global $messageStack;
  597. // cannot remove EC if DP installed:
  598. if (defined('MODULE_PAYMENT_PAYPALDP_STATUS')) {
  599. // 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.
  600. $messageStack->add_session('<strong>Sorry, you must remove PayPal Payments Pro (paypaldp) first.</strong> PayPal Payments Pro (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 PayPal Payments Pro module.</a>' , 'error');
  601. zen_redirect(zen_href_link(FILENAME_MODULES, 'set=payment&module=paypalwpp', 'NONSSL'));
  602. return 'failed';
  603. }
  604. global $db;
  605. $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE\_PAYMENT\_PAYPALWPP\_%' or configuration_key like 'MODULE\_PAYMENT\_PAYPALEC\_%'");
  606. $this->notify('NOTIFY_PAYMENT_PAYPALWPP_UNINSTALLED');
  607. }
  608. /**
  609. * Check settings and conditions to determine whether we are in an Express Checkout phase or not
  610. */
  611. function in_special_checkout() {
  612. if ((defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') &&
  613. !empty($_SESSION['paypal_ec_token']) &&
  614. !empty($_SESSION['paypal_ec_payer_id']) &&
  615. !empty($_SESSION['paypal_ec_payer_info'])) {
  616. $this->flagDisablePaymentAddressChange = true;
  617. return true;
  618. }
  619. }
  620. /**
  621. * Determine whether the shipping-edit button should be displayed or not
  622. */
  623. function alterShippingEditButton() {
  624. return false;
  625. if ($this->in_special_checkout() && empty($_SESSION['paypal_ec_markflow'])) {
  626. return zen_href_link('ipn_main_handler.php', 'type=ec&clearSess=1', 'SSL', true,true, true);
  627. }
  628. }
  629. /**
  630. * Debug Logging support
  631. */
  632. function zcLog($stage, $message) {
  633. static $tokenHash;
  634. if ($tokenHash == '') $tokenHash = '_' . zen_create_random_value(4);
  635. if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email' || MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log File') {
  636. $token = (isset($_SESSION['paypal_ec_token'])) ? $_SESSION['paypal_ec_token'] : preg_replace('/[^0-9.A-Z\-]/', '', $_GET['token']);
  637. $token = ($token == '') ? date('m-d-Y-H-i') : $token; // or time()
  638. $token .= $tokenHash;
  639. $file = $this->_logDir . '/' . $this->code . '_Paypal_Action_' . $token . '.log';
  640. if (defined('PAYPAL_DEV_MODE') && PAYPAL_DEV_MODE == 'true') $file = $this->_logDir . '/' . $this->code . '_Paypal_Debug_' . $token . '.log';
  641. $fp = @fopen($file, 'a');
  642. @fwrite($fp, date('M-d-Y H:i:s') . ' (' . time() . ')' . "\n" . $stage . "\n" . $message . "\n=================================\n\n");
  643. @fclose($fp);
  644. }
  645. $this->_doDebug($stage, $message, false);
  646. }
  647. /**
  648. * Debug Emailing support
  649. */
  650. function _doDebug($subject = 'PayPal debug data', $data, $useSession = true) {
  651. if (MODULE_PAYMENT_PAYPALWPP_DEBUGGING == 'Log and Email') {
  652. $data = urldecode($data) . "\n\n";
  653. if ($useSession) $data .= "\nSession data: " . print_r($_SESSION, true);
  654. 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');
  655. }
  656. }
  657. /**
  658. * Initialize the PayPal/PayflowPro o…

Large files files are truncated, but you can click here to view the full file