From 058b8a5ea8026762caf6d535441937a0f3baec08 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 20 Aug 2015 20:51:35 -0400 Subject: [PATCH] CRM-17004 - Remove Moneris from core --- CRM/Core/Payment/Moneris.php | 339 ------------------ CRM/Upgrade/Incremental/Base.php | 19 + CRM/Upgrade/Incremental/php/FourSeven.php | 6 + templates/CRM/Admin/Form/Setting/Url.hlp | 2 +- templates/CRM/Admin/Page/PaymentProcessor.hlp | 32 -- xml/templates/civicrm_data.tpl | 1 - 6 files changed, 26 insertions(+), 373 deletions(-) delete mode 100644 CRM/Core/Payment/Moneris.php diff --git a/CRM/Core/Payment/Moneris.php b/CRM/Core/Payment/Moneris.php deleted file mode 100644 index 62c000cd1e..0000000000 --- a/CRM/Core/Payment/Moneris.php +++ /dev/null @@ -1,339 +0,0 @@ -_mode = $mode; - $this->_paymentProcessor = $paymentProcessor; - $this->_processorName = ts('Moneris'); - - // require moneris supplied api library - if ((include_once 'Services/mpgClasses.php') === FALSE) { - CRM_Core_Error::fatal(ts('Please download and put the Moneris mpgClasses.php file in packages/Services directory to enable Moneris Support.')); - } - - // get merchant data from config - $config = CRM_Core_Config::singleton(); - // live or test - $this->_profile['mode'] = $mode; - $this->_profile['storeid'] = $this->_paymentProcessor['signature']; - $this->_profile['apitoken'] = $this->_paymentProcessor['password']; - $currencyID = $config->defaultCurrency; - if ('CAD' != $currencyID) { - return self::error('Invalid configuration:' . $currencyID . ', you must use currency $CAD with Moneris'); - // Configuration error: default currency must be CAD - } - } - - /** - * This function collects all the information from a web/api form and invokes - * the relevant payment processor specific functions to perform the transaction - * - * @param array $params - * Assoc array of input parameters for this transaction. - * - * @return array - * the result in an nice formatted array (or an error object) - * @abstract - */ - public function doDirectPayment(&$params) { - //make sure i've been called correctly ... - if (!$this->_profile) { - return self::error('Unexpected error, missing profile'); - } - if ($params['currencyID'] != 'CAD') { - return self::error('Invalid currency selection, must be $CAD'); - } - /* unused params: cvv not yet implemented, payment action ingored (should test for 'Sale' value?) - [cvv2] => 000 - [ip_address] => 192.168.0.103 - [contact_type] => Individual - [geo_coord_id] => 1 */ - - //this code based on Moneris example code # - //create an mpgCustInfo object - $mpgCustInfo = new mpgCustInfo(); - //call set methods of the mpgCustinfo object - $mpgCustInfo->setEmail($params['email']); - //get text representations of province/country to send to moneris for billing info - - $billing = array( - 'first_name' => $params['first_name'], - 'last_name' => $params['last_name'], - 'address' => $params['street_address'], - 'city' => $params['city'], - 'province' => $params['state_province'], - 'postal_code' => $params['postal_code'], - 'country' => $params['country'], - ); - $mpgCustInfo->setBilling($billing); - // set orderid as invoiceID to help match things up with Moneris later - $my_orderid = $params['invoiceID']; - $expiry_string = sprintf('%04d%02d', $params['year'], $params['month']); - - $txnArray = array( - 'type' => 'purchase', - 'order_id' => $my_orderid, - 'amount' => sprintf('%01.2f', $params['amount']), - 'pan' => $params['credit_card_number'], - 'expdate' => substr($expiry_string, 2, 4), - 'crypt_type' => '7', - 'cust_id' => $params['contactID'], - ); - - // Allow further manipulation of params via custom hooks - CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $txnArray); - - //create a transaction object passing the hash created above - $mpgTxn = new mpgTransaction($txnArray); - - //use the setCustInfo method of mpgTransaction object to - //set the customer info (level 3 data) for this transaction - $mpgTxn->setCustInfo($mpgCustInfo); - // add a recurring payment if requested - if ($params['is_recur'] && $params['installments'] > 1) { - //Recur Variables - $recurUnit = $params['frequency_unit']; - $recurInterval = $params['frequency_interval']; - $next = time(); - $day = 60 * 60 * 24; - switch ($recurUnit) { - case 'day': - $next += $recurInterval * $day; - break; - - case 'week': - $next += $recurInterval * $day * 7; - break; - - case 'month': - $date = getdate(); - $date['mon'] += $recurInterval; - while ($date['mon'] > 12) { - $date['mon'] -= 12; - $date['year'] += 1; - } - $next = mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']); - break; - - case 'year': - $date = getdate(); - $date['year'] += 1; - $next = mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']); - break; - - default: - die('Unexpected error!'); - } - // next payment in moneris required format - $startDate = date("Y/m/d", $next); - $numRecurs = $params['installments'] - 1; - //$startNow = 'true'; -- setting start now to false will mean the main transaction doesn't happen! - $recurAmount = sprintf('%01.2f', $params['amount']); - //Create an array with the recur variables - // (day | week | month) - $recurArray = array( - 'recur_unit' => $recurUnit, - // yyyy/mm/dd - 'start_date' => $startDate, - 'num_recurs' => $numRecurs, - 'start_now' => 'true', - 'period' => $recurInterval, - 'recur_amount' => $recurAmount, - ); - $mpgRecur = new mpgRecur($recurArray); - // set the Recur Object to mpgRecur - $mpgTxn->setRecur($mpgRecur); - } - //create a mpgRequest object passing the transaction object - $mpgRequest = new mpgRequest($mpgTxn); - - // create mpgHttpsPost object which does an https post ## - // [extra parameter added to library by AD] - $isProduction = ($this->_profile['mode'] == 'live'); - $mpgHttpPost = new mpgHttpsPost($this->_profile['storeid'], $this->_profile['apitoken'], $mpgRequest, $isProduction); - // get an mpgResponse object - $mpgResponse = $mpgHttpPost->getMpgResponse(); - $params['trxn_result_code'] = $mpgResponse->getResponseCode(); - if (self::isError($mpgResponse)) { - if ($params['trxn_result_code']) { - return self::error($mpgResponse); - } - else { - return self::error('No reply from server - check your settings &/or try again'); - } - } - /* Check for application errors */ - - $result = self::checkResult($mpgResponse); - if (is_a($result, 'CRM_Core_Error')) { - return $result; - } - - /* Success */ - - $params['trxn_result_code'] = (integer) $mpgResponse->getResponseCode(); - // todo: above assignment seems to be ignored, not getting stored in the civicrm_financial_trxn table - $params['trxn_id'] = $mpgResponse->getTxnNumber(); - $params['gross_amount'] = $mpgResponse->getTransAmount(); - return $params; - } - - /** - * @param $response - * - * @return bool - */ - public function isError(&$response) { - $responseCode = $response->getResponseCode(); - if (is_null($responseCode)) { - return TRUE; - } - if ('null' == $responseCode) { - return TRUE; - } - if (($responseCode >= 0) && ($responseCode < 50)) { - return FALSE; - } - return TRUE; - } - - /** - * ignore for now, more elaborate error handling later. - * @param $response - * - * @return object - */ - public function &checkResult(&$response) { - return $response; - - $errors = $response->getErrors(); - if (empty($errors)) { - return $result; - } - - $e = CRM_Core_Error::singleton(); - if (is_a($errors, 'ErrorType')) { - $e->push($errors->getErrorCode(), - 0, NULL, - $errors->getShortMessage() . ' ' . $errors->getLongMessage() - ); - } - else { - foreach ($errors as $error) { - $e->push($error->getErrorCode(), - 0, NULL, - $error->getShortMessage() . ' ' . $error->getLongMessage() - ); - } - } - return $e; - } - - /** - * @param null $error - * - * @return object - */ - public function &error($error = NULL) { - $e = CRM_Core_Error::singleton(); - if (is_object($error)) { - $e->push($error->getResponseCode(), - 0, NULL, - $error->getMessage() - ); - } - elseif (is_string($error)) { - $e->push(9002, - 0, NULL, - $error - ); - } - else { - $e->push(9001, 0, NULL, "Unknown System Error."); - } - return $e; - } - - /** - * This function checks to see if we have the right config values. - * - * @return string - * the error message if any - */ - public function checkConfig() { - $error = array(); - - if (empty($this->_paymentProcessor['signature'])) { - $error[] = ts('Store ID is not set in the Administer CiviCRM » System Settings » Payment Processors.'); - } - - if (empty($this->_paymentProcessor['password'])) { - $error[] = ts('Password is not set in the Administer CiviCRM » System Settings » Payment Processors.'); - } - - if (!empty($error)) { - return implode('

', $error); - } - else { - return NULL; - } - } - -} diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 29e8725dac..7b8abadaa5 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -103,4 +103,23 @@ class CRM_Upgrade_Incremental_Base { $queue->createItem($task, array('weight' => -1)); } + /** + * Remove a payment processor if not in use + * + * @param $name + * @throws \CiviCRM_API3_Exception + */ + public static function removePaymentProcessorType($name) { + $processors = civicrm_api3('PaymentProcessor', 'getcount', array('payment_processor_type_id' => $name)); + if (empty($processors['result'])) { + $result = civicrm_api3('PaymentProcessorType', 'get', array( + 'name' => $name, + 'return' => 'id', + )); + if (!empty($result['id'])) { + civicrm_api3('PaymentProcessorType', 'delete', array('id' => $result['id'])); + } + } + } + } diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index d4006bc1c6..5d9798c177 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -44,6 +44,11 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base */ public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { if ($rev == '4.7.alpha1') { + // CRM-17004 Warn of Moneris removal + $monerisProcessors = civicrm_api3('PaymentProcessor', 'getcount', array('payment_processor_type_id' => "Moneris")); + if (!empty($monerisProcessors['result']) && !function_exists('moneris_civicrm_managed')) { + $preUpgradeMessage .= '

' . ts('The %1 payment processor is no longer bundled with CiviCRM. After upgrading you will need to install the extension to continue using it.', array(1 => 'Moneris')) . '

'; + } // CRM-16478 Remove custom fatal error template path option $config = CRM_Core_Config::singleton(); @@ -104,6 +109,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); $this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev); $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), 'addGettingStartedDashlet', $rev); + $this->addTask(ts('Remove %1', array(1 => 'Moneris')), 'removePaymentProcessorType', 'Moneris'); } /** diff --git a/templates/CRM/Admin/Form/Setting/Url.hlp b/templates/CRM/Admin/Form/Setting/Url.hlp index d31e45f129..c26e3d7659 100644 --- a/templates/CRM/Admin/Form/Setting/Url.hlp +++ b/templates/CRM/Admin/Form/Setting/Url.hlp @@ -28,7 +28,7 @@ {/htxt} {htxt id='id-enable_ssl'}

{ts}This setting forces a redirect of all online contribution / member / event and CiviCRM administrator page requests to SSL secured URLs (https).{/ts}

-

{ts}If you use a payment processor service where credit card and billing information is collected ON YOUR SITE (PayPal Website Payments Pro or Moneris as of now) it is strongly recommended that you create or obtain an SSL certificate and configure your webserver to support SSL connections. Consult your hosting provider or web-server documentation for more information on obtaining and installing SSL certificates.{/ts}

+

{ts}If you use a payment processor service where credit card and billing information is collected on your site it is strongly recommended that you create or obtain an SSL certificate and configure your webserver to support SSL connections. Consult your hosting provider or web-server documentation for more information on obtaining and installing SSL certificates.{/ts}

{ts}Once you have your certificate installed, test that is working by navigating to one of your online contribution pages and changing the URL prefix from 'http://' to 'https://'. If your browser loads the page and indicates a valid security certificate - then you can change this setting to Yes and CiviCRM will automatically redirect requests for all online contribution / member / event / admin pages to the corresponding SSL secured URLs.{/ts}

{/htxt} diff --git a/templates/CRM/Admin/Page/PaymentProcessor.hlp b/templates/CRM/Admin/Page/PaymentProcessor.hlp index f2adcb588d..570c65d40d 100644 --- a/templates/CRM/Admin/Page/PaymentProcessor.hlp +++ b/templates/CRM/Admin/Page/PaymentProcessor.hlp @@ -293,38 +293,6 @@

http://checkout.google.com/buttons/checkout.gif?merchant_id=1234567890&w=180&h=46&style=white&variant=text&loc=en_US

{/htxt} -{htxt id='Moneris-live-user-name'} -

{ts}Moneris doesn't currently use the Username field. Enter 'ignoreme' as a placeholder since the field can't be left blank.{/ts}

-{/htxt} -{htxt id='Moneris-live-password'} -

{ts}Enter the API Token from your live merchant account.{/ts}

-{/htxt} -{htxt id='Moneris-live-signature'} -

{ts}Enter your live merchant account Store ID.{/ts}

-{/htxt} -{htxt id='Moneris-live-url-site'} -{ts}The URL for the Moneris LIVE Payment server. Use the default value unless otherwise advised by the processor.{/ts} -{/htxt} -{htxt id='Moneris-live-url-recur'} -

{ts}The Recurring Payments URL is not currently used for Moneris.{/ts}

-{/htxt} -{htxt id='Moneris-test-user-name'} -

{ts}Moneris doesn't currently use the Username field. Enter 'ignoreme' as a placeholder since the field can't be left blank.{/ts}

-{/htxt} -{htxt id='Moneris-test-password'} -

{ts 1='yesguy'}All Moneris test transactions are submitted to a shared test merchant account. Enter %1 here, which is the API Token for this test account.{/ts}

-{/htxt} -{htxt id='Moneris-test-signature'} -

{ts 1='store3' 2='store1' 3='store2'}All Moneris test transactions are submitted to a shared merchant account. You can use %1 as your test store ID. '%2' and '%3' also work, but only '%1' accepts recurring payments.{/ts}

-{/htxt} -{htxt id='Moneris-test-url-site'} -{ts}The URL for the Moneris TEST Payment server. Use the default value unless otherwise advised by the processor.{/ts} -{/htxt} -{htxt id='Moneris-test-url-recur'} -

{ts}The Recurring Payments URL is not currently used for Moneris.{/ts}

-{/htxt} - - {htxt id='Dummy-live-user-name'} {ts}Set up a 'Dummy' Processor if you want to test Online Contribution pages or Event Registration pages prior to selecting and configuring a real payment processor. You can enter any values for User Name and Site URL.{/ts}

{/htxt} diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 48ce51faf1..a5fd28f57e 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -1121,7 +1121,6 @@ VALUES ('PayPal', '{ts escape="sql"}PayPal - Website Payments Pro{/ts}', NULL,1,0,'{ts escape="sql"}User Name{/ts}','{ts escape="sql"}Password{/ts}','{ts escape="sql"}Signature{/ts}',NULL,'Payment_PayPalImpl','https://www.paypal.com/','https://api-3t.paypal.com/','https://www.paypal.com/','https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif','https://www.sandbox.paypal.com/','https://api-3t.sandbox.paypal.com/','https://www.sandbox.paypal.com/','https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',3, 1 ), ('PayPal_Express', '{ts escape="sql"}PayPal - Express{/ts}', NULL,1,0,'{ts escape="sql"}User Name{/ts}','{ts escape="sql"}Password{/ts}','{ts escape="sql"}Signature{/ts}',NULL,'Payment_PayPalImpl','https://www.paypal.com/','https://api-3t.paypal.com/',NULL,'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif','https://www.sandbox.paypal.com/','https://api-3t.sandbox.paypal.com/',NULL,'https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif',2,NULL), ('Google_Checkout', '{ts escape="sql"}Google Checkout{/ts}', NULL,1,0,'{ts escape="sql"}Merchant ID{/ts}','{ts escape="sql"}Key{/ts}',NULL,NULL,'Payment_Google','https://checkout.google.com/',NULL,'https://checkout.google.com/','https://checkout.google.com/buttons/checkout.gif?merchant_id=YOURMERCHANTIDHERE&w=160&h=43&style=white&variant=text&loc=en_US','https://sandbox.google.com/checkout/',NULL,'https://sandbox.google.com/checkout/','https://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=YOURMERCHANTIDHERE&w=160&h=43&style=white&variant=text&loc=en_US',4,1), - ('Moneris', '{ts escape="sql"}Moneris{/ts}', NULL,1,0,'{ts escape="sql"}User Name{/ts}','{ts escape="sql"}Password{/ts}','{ts escape="sql"}Store ID{/ts}',NULL,'Payment_Moneris','https://www3.moneris.com/',NULL,NULL,NULL,'https://esqa.moneris.com/',NULL,NULL,NULL,1,1), ('AuthNet', '{ts escape="sql"}Authorize.Net{/ts}', NULL,1,0,'{ts escape="sql"}API Login{/ts}','{ts escape="sql"}Payment Key{/ts}','{ts escape="sql"}MD5 Hash{/ts}',NULL,'Payment_AuthorizeNet','https://secure2.authorize.net/gateway/transact.dll',NULL,'https://api2.authorize.net/xml/v1/request.api',NULL,'https://test.authorize.net/gateway/transact.dll',NULL,'https://apitest.authorize.net/xml/v1/request.api',NULL,1,1), ('PayJunction', '{ts escape="sql"}PayJunction{/ts}', NULL,1,0,'User Name','Password',NULL,NULL,'Payment_PayJunction','https://payjunction.com/quick_link',NULL,NULL,NULL,'https://www.payjunctionlabs.com/quick_link',NULL,NULL,NULL,1,1), ('eWAY', '{ts escape="sql"}eWAY (Single Currency){/ts}', NULL,1,0,'Customer ID',NULL,NULL,NULL,'Payment_eWAY','https://www.eway.com.au/gateway_cvn/xmlpayment.asp',NULL,NULL,NULL,'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp',NULL,NULL,NULL,1,0), -- 2.25.1