diff --git a/CRM/Core/Payment/Redsys.php b/CRM/Core/Payment/Redsys.php index 95dcd00030e9615141fb1156f6163be7ee41c076..4a4a3f0413d013b340b8f758fafdecfd822efe95 100644 --- a/CRM/Core/Payment/Redsys.php +++ b/CRM/Core/Payment/Redsys.php @@ -6,16 +6,18 @@ * payment processor for their payment processors. */ +use CRM_Redsys_ExtensionUtil as E; + require_once 'CRM/Core/Payment.php'; require_once 'includes/apiRedsys.php'; class CRM_Core_Payment_Redsys extends CRM_Core_Payment { - CONST REDSYS_CURRENCY_EURO = 978; - CONST REDSYS_LANGUAGE_SPANISH = 1; - CONST REDSYS_LANGUAGE_BASQUE = 13; - CONST REDSYS_LANGUAGE_CATALAN = 3; - CONST REDSYS_LANGUAGE_GALICIAN = 12; - CONST REDSYS_TRANSACTION_TYPE_OPERATION_STANDARD = 0; + const REDSYS_CURRENCY_EURO = 978; + const REDSYS_LANGUAGE_SPANISH = 1; + const REDSYS_LANGUAGE_BASQUE = 13; + const REDSYS_LANGUAGE_CATALAN = 3; + const REDSYS_LANGUAGE_GALICIAN = 12; + const REDSYS_TRANSACTION_TYPE_OPERATION_STANDARD = 0; /** * We only need one instance of this object. So we use the singleton @@ -24,14 +26,14 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { * @var object * @static */ - static private $_singleton = null; + static private $_singleton = NULL; /** * mode of operation: live or test * * @var object */ - protected $_mode = null; + protected $_mode = NULL; /** * Processor type label. @@ -42,7 +44,7 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { * * @var string */ - public $_processorName = null; + public $_processorName = NULL; /** * Constructor @@ -52,9 +54,9 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { * @return void */ function __construct($mode, &$paymentProcessor) { - $this->_mode = $mode; - $this->_paymentProcessor = $paymentProcessor; - $this->_processorName = 'Redsys'; + $this->_mode = $mode; + $this->_paymentProcessor = $paymentProcessor; + $this->_processorName = 'Redsys'; } /** @@ -68,7 +70,7 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { */ static function &singleton($mode, &$paymentProcessor) { $processorName = $paymentProcessor["name"]; - if (self::$_singleton[$processorName] === NULL ) { + if (self::$_singleton[$processorName] === NULL) { self::$_singleton[$processorName] = new self($mode, $paymentProcessor); } return self::$_singleton[$processorName]; @@ -85,15 +87,16 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $error = array(); if (empty($this->_paymentProcessor["user_name"])) { - $error[] = ts( "Merchant Code is not set in the Redsys Payment Processor settings." ); + $error[] = E::ts("Merchant Code is not set in the Redsys Payment Processor settings."); } if (empty($this->_paymentProcessor["password"])) { - $error[] = ts( "Merchant Password is not set in the Redsys Payment Processor settings." ); + $error[] = E::ts("Merchant Password is not set in the Redsys Payment Processor settings."); } if (!empty($error)) { return implode("

", $error); - } else { + } + else { return NULL; } } @@ -104,8 +107,8 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { * * @param type $params */ - function doDirectPayment( &$params ) { - CRM_Core_Error::fatal( ts( "This function is not implemented" ) ); + function doDirectPayment(&$params) { + CRM_Core_Error::fatal(E::ts("This function is not implemented")); } /** @@ -117,13 +120,14 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $config = CRM_Core_Config::singleton(); if ($component != 'contribute' && $component != 'event') { - CRM_Core_Error::fatal(ts('Component is invalid')); + CRM_Core_Error::fatal(E::ts('Component is invalid')); } - if( array_key_exists( 'webform_redirect_success', $params ) ) { + if (array_key_exists('webform_redirect_success', $params)) { $returnURL = $params['webform_redirect_success']; $cancelURL = $params['webform_redirect_cancel']; - } else { + } + else { $url = ($component == 'event') ? 'civicrm/event/register' : 'civicrm/contribute/transact'; $cancel = ($component == 'event') ? '_qf_Register_display' : '_qf_Main_display'; $returnURL = CRM_Utils_System::url($url, @@ -131,7 +135,6 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { TRUE, NULL, FALSE ); - $cancelUrlString = "$cancel=1&cancel=1&qfKey={$params['qfKey']}"; if (CRM_Utils_Array::value('is_recur', $params)) { $cancelUrlString .= "&isRecur=1&recurId={$params['contributionRecurID']}&contribId={$params['contributionID']}"; @@ -173,32 +176,33 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { TRUE, NULL, FALSE, TRUE ); - // Force http if set + // Force http if set. $redsys_settings = CRM_Core_BAO_Setting::getItem("Redsys Settings", 'redsys_settings'); - if($redsys_settings['ipn_http'] == '1') + if ($redsys_settings['ipn_http'] == '1') $merchantUrl = preg_replace('/^https:/i', 'http:', $merchantUrl); - // The payment processor id can be named payment_processor (contribution pages) - if( array_key_exists( 'payment_processor', $params ) ) { + // The payment processor id can be named payment_processor (contribution pages). + if (array_key_exists('payment_processor', $params)) { $paymentProcessorId = $params['payment_processor']; - } elseif( array_key_exists( 'payment_processor_id', $params ) ) { + } + elseif (array_key_exists('payment_processor_id', $params)) { $paymentProcessorId = $params['payment_processor_id']; } - // Get the terminal for this payment processor - if( array_key_exists('merchant_terminal_' . $paymentProcessorId, $redsys_settings) ) { - if( $redsys_settings['merchant_terminal_' . $paymentProcessorId] ) { + // Get the terminal for this payment processor. + if(array_key_exists('merchant_terminal_' . $paymentProcessorId, $redsys_settings)) { + if ($redsys_settings['merchant_terminal_' . $paymentProcessorId]) { $merchantTerminal = $redsys_settings['merchant_terminal_' . $paymentProcessorId]; } } // Use the default terminal if the processor doesn't have an assigned one - if( ! $merchantTerminal ) { + if(!$merchantTerminal) { $merchantTerminal = empty($redsys_settings['merchant_terminal']) ? 1 : $redsys_settings['merchant_terminal']; } - $miObj = new RedsysAPI; + $miObj = new RedsysAPI(); $miObj->setParameter("Ds_Merchant_Amount", $params["amount"] * 100); $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); $miObj->setParameter("Ds_Merchant_MerchantCode", $this->_paymentProcessor["user_name"]); @@ -209,14 +213,14 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $miObj->setParameter("Ds_Merchant_UrlOK", $returnURL); $miObj->setParameter("Ds_Merchant_UrlKO", $cancelURL); $miObj->setParameter("Ds_Merchant_ProductDescription", $params["contributionType_name"]); - $miObj->setParameter("Ds_Merchant_Titular", $params["first_name"] . " " . $params["last_name"] ); + $miObj->setParameter("Ds_Merchant_Titular", $params["first_name"] . " " . $params["last_name"]); $miObj->setParameter("Ds_Merchant_ConsumerLanguage", self::REDSYS_LANGUAGE_SPANISH); $version = "HMAC_SHA256_V1"; $signature = $miObj->createMerchantSignature($this->_paymentProcessor["password"]); - // Print the tpl to redirect and send POST variables to RedSys Getaway + // Print the tpl to redirect and send POST variables to RedSys Getaway. $template = CRM_Core_Smarty::singleton(); $tpl = 'CRM/Core/Payment/Redsys.tpl'; @@ -235,9 +239,9 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $input = $ids = $objects = array(); $ipn = new CRM_Core_Payment_RedsysIPN(); - // load vars in $input, &ids + // Load vars in $input, &ids. $ipn->getInput($input, $ids); - CRM_Core_Error::debug_log_message("Redsys IPN Response: Parameteres received \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE) ); + CRM_Core_Error::debug_log_message("Redsys IPN Response: Parameteres received \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE)); $paymentProcessorID = $this->_paymentProcessor['id']; if (!$ipn->validateData($this->_paymentProcessor, $input, $ids, $objects, TRUE, $paymentProcessorID)) { @@ -257,4 +261,5 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { static function trimAmount($amount, $pad = '0'){ return ltrim(trim($amount), $pad); } + } diff --git a/CRM/Core/Payment/RedsysIPN.php b/CRM/Core/Payment/RedsysIPN.php index 5c512f3af93e1b561aaf0bfc8167a33bd577307b..12be539beccd2db3ae7ae54264c5ae949426e03c 100644 --- a/CRM/Core/Payment/RedsysIPN.php +++ b/CRM/Core/Payment/RedsysIPN.php @@ -54,7 +54,7 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN { $contribution = &$objects['contribution']; if (!$recur) { - if (str_replace(",", "", $contribution->total_amount) != str_replace(",", "", $input['amount']) ) { + if (str_replace(",", "", $contribution->total_amount) != str_replace(",", "", $input['amount'])) { CRM_Core_Error::debug_log_message("Amount values dont match between database and IPN request"); echo "Failure: Amount values dont match between database and IPN request

"; return FALSE; @@ -64,14 +64,14 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN { $transaction = new CRM_Core_Transaction(); if ($input['Ds_Response'] != self::REDSYS_RESPONSE_CODE_ACCEPTED) { $error = self::trimAmount($input['Ds_Response']); - if(array_key_exists($error, $this->_errors)) { + if (array_key_exists($error, $this->_errors)) { $input['reasonCode'] = $this->_errors[$error]; } - CRM_Core_Error::debug_log_message("Redsys IPN Response: About to cancel contr \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE) . "\n objects: " . print_r($objects, TRUE) ); + CRM_Core_Error::debug_log_message("Redsys IPN Response: About to cancel contr \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE) . "\n objects: " . print_r($objects, TRUE)); return $this->cancelled($objects, $transaction, $input); } - // check if contribution is already completed, if so we ignore this ipn + // Check if contribution is already completed, if so we ignore this ipn. if ($contribution->contribution_status_id == 1) { $transaction->commit(); CRM_Core_Error::debug_log_message("returning since contribution has already been handled"); @@ -79,28 +79,28 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN { return TRUE; } - CRM_Core_Error::debug_log_message("Redsys IPN Response: About complete trans \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE) . "\n objects: " . print_r($objects, TRUE) ); + CRM_Core_Error::debug_log_message("Redsys IPN Response: About complete trans \n input: " . print_r($input, TRUE) . "\n ids: " . print_r($ids, TRUE) . "\n objects: " . print_r($objects, TRUE)); return $this->completeTransaction($input, $ids, $objects, $transaction, $recur); } function getInput(&$input, &$ids) { $input = array( - // GET Parameters - 'module' => self::retrieve('md', 'String', 'GET', true), - 'component' => self::retrieve('md', 'String', 'GET', true), - 'qfKey' => self::retrieve('qfKey', 'String', 'GET', false), - 'contributionID' => self::retrieve('contributionID', 'String', 'GET', true), - 'contactID' => self::retrieve('contactID', 'String', 'GET', true), - 'eventID' => self::retrieve('eventID', 'String', 'GET', false), - 'participantID' => self::retrieve('participantID', 'String', 'GET', false), - 'membershipID' => self::retrieve('membershipID', 'String', 'GET', false), - 'contributionPageID' => self::retrieve('contributionPageID', 'String', 'GET', false), - 'relatedContactID' => self::retrieve('relatedContactID', 'String', 'GET', false), - 'onBehalfDupeAlert' => self::retrieve('onBehalfDupeAlert', 'String', 'GET', false), - // POST Parameters - 'Ds_SignatureVersion' => self::retrieve('Ds_SignatureVersion', 'String', 'POST', true), - 'Ds_MerchantParameters' => self::retrieve('Ds_MerchantParameters', 'String', 'POST', true), - 'Ds_Signature' => self::retrieve('Ds_Signature', 'String', 'POST', true), + // GET Parameters. + 'module' => self::retrieve('md', 'String', 'GET', TRUE), + 'component' => self::retrieve('md', 'String', 'GET', TRUE), + 'qfKey' => self::retrieve('qfKey', 'String', 'GET', FALSE), + 'contributionID' => self::retrieve('contributionID', 'String', 'GET', TRUE), + 'contactID' => self::retrieve('contactID', 'String', 'GET', TRUE), + 'eventID' => self::retrieve('eventID', 'String', 'GET', FALSE), + 'participantID' => self::retrieve('participantID', 'String', 'GET', FALSE), + 'membershipID' => self::retrieve('membershipID', 'String', 'GET', FALSE), + 'contributionPageID' => self::retrieve('contributionPageID', 'String', 'GET', FALSE), + 'relatedContactID' => self::retrieve('relatedContactID', 'String', 'GET', FALSE), + 'onBehalfDupeAlert' => self::retrieve('onBehalfDupeAlert', 'String', 'GET', FALSE), + // POST Parameters. + 'Ds_SignatureVersion' => self::retrieve('Ds_SignatureVersion', 'String', 'POST', TRUE), + 'Ds_MerchantParameters' => self::retrieve('Ds_MerchantParameters', 'String', 'POST', TRUE), + 'Ds_Signature' => self::retrieve('Ds_Signature', 'String', 'POST', TRUE), ); $decodecResponseJson = $this->_redsysAPI->decodeMerchantParameters($input["Ds_MerchantParameters"]); $decodecResponse = json_decode($decodecResponseJson); @@ -129,23 +129,23 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN { function validateData($paymentProcessor, &$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL) { $signatureNotif = $this->_redsysAPI->createMerchantSignatureNotif($paymentProcessor["password"], $input["Ds_MerchantParameters"]); - if($input['Ds_MerchantCode'] != $paymentProcessor["user_name"]){ + if ($input['Ds_MerchantCode'] != $paymentProcessor["user_name"]) { CRM_Core_Error::debug_log_message("Redsys Response param Ds_MerchantCode incorrect"); - return false; + return FALSE; } - if ($signatureNotif !== $input['Ds_Signature']){ + if ($signatureNotif !== $input['Ds_Signature']) { CRM_Core_Error::debug_log_message("Redsys signature doesn't match"); - return false; + return FALSE; } return parent::validateData($input, $ids, $objects, $required, $paymentProcessorID); } - static function retrieve($name, $type, $location = 'POST', $abort = true) { - static $store = null; - $value = CRM_Utils_Request::retrieve($name, $type, $store, false, null, $location); - if ($abort && $value === null) { + static function retrieve($name, $type, $location = 'POST', $abort = TRUE) { + static $store = NULL; + $value = CRM_Utils_Request::retrieve($name, $type, $store, FALSE, NULL, $location); + if ($abort && $value === NULL) { CRM_Core_Error::debug_log_message("Could not find an entry for $name in $location"); echo "Failure: Missing Parameter

"; exit(); @@ -153,7 +153,7 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN { return $value; } - static function trimAmount($amount, $pad = '0'){ + static function trimAmount($amount, $pad = '0') { return ltrim(trim($amount), $pad); } diff --git a/CRM/Redsys/Form/Settings.php b/CRM/Redsys/Form/Settings.php index f553f69ceae3f6c5d1e9ed37107a0359a72491d7..a546b24934dc828422b8cfd619900d9560fa3d89 100644 --- a/CRM/Redsys/Form/Settings.php +++ b/CRM/Redsys/Form/Settings.php @@ -1,6 +1,7 @@ add('text', 'merchant_terminal', 'Merchant Terminal', array('size' => 5)); $paymentProcessors = $this->getPaymentProcessors(); - foreach( $paymentProcessors as $paymentProcessor ) { - $settingCode = 'merchant_terminal_' . $paymentProcessor[ "id" ]; - $settingTitle = $paymentProcessor[ "name" ] . " (" . - ( $paymentProcessor["is_test"] == 0 ? "Live" : "Test" ) . ")"; + foreach ($paymentProcessors as $paymentProcessor) { + $settingCode = 'merchant_terminal_' . $paymentProcessor["id"]; + $settingTitle = $paymentProcessor["name"] . " (" . + ($paymentProcessor["is_test"] == 0 ? "Live" : "Test") . ")"; $this->add('text', $settingCode, $settingTitle, array('size' => 5)); } $this->addButtons(array( array( 'type' => 'submit', - 'name' => ts('Submit'), + 'name' => E::ts('Submit'), 'isDefault' => TRUE, ), )); @@ -38,30 +39,32 @@ class CRM_Redsys_Form_Settings extends CRM_Core_Form { $values = $this->exportValues(); $redsys_settings['ipn_http'] = $values['ipn_http']; $redsys_settings['merchant_terminal'] = $values['merchant_terminal']; - + $paymentProcessors = $this->getPaymentProcessors(); - foreach( $paymentProcessors as $paymentProcessor ) { - $settingId = 'merchant_terminal_' . $paymentProcessor[ "id" ]; + foreach ($paymentProcessors as $paymentProcessor) { + $settingId = 'merchant_terminal_' . $paymentProcessor["id"]; $redsys_settings[$settingId] = $values[$settingId]; } - + CRM_Core_BAO_Setting::setItem($redsys_settings, "Redsys Settings", 'redsys_settings'); - CRM_Core_Session::setStatus(ts('Redsys Settings Saved', array( 'domain' => 'com.ixiam.payment.redsys')), 'Configuration Updated', 'success'); + CRM_Core_Session::setStatus(E::ts('Redsys Settings Saved', array('domain' => 'com.ixiam.payment.redsys')), 'Configuration Updated', 'success'); parent::postProcess(); } public function getPaymentProcessors() { - // Get the Redsys payment processor type - $redsysName = array( 'name' => 'Redsys' ); - $paymentProcessorType = civicrm_api3( 'PaymentProcessorType', 'getsingle', $redsysName ); + // Get the Redsys payment processor type. + $redsysName = array('name' => 'Redsys'); + $paymentProcessorType = civicrm_api3('PaymentProcessorType', 'getsingle', $redsysName); - // Get the payment processors of Redsys type + // Get the payment processors of Redsys type. $redsysType = array( - 'payment_processor_type_id' => $paymentProcessorType[ 'id' ], - 'is_active' => 1 ); - $paymentProcessors = civicrm_api3( 'PaymentProcessor', 'get', $redsysType ); + 'payment_processor_type_id' => $paymentProcessorType['id'], + 'is_active' => 1, + ); + $paymentProcessors = civicrm_api3('PaymentProcessor', 'get', $redsysType); return $paymentProcessors["values"]; } + } diff --git a/CRM/Redsys/Upgrader.php b/CRM/Redsys/Upgrader.php index 7ccd689da2ba034db448dbad772dfb12c49d930a..befeb10b5c071fd86754879cd09184873353c6e8 100644 --- a/CRM/Redsys/Upgrader.php +++ b/CRM/Redsys/Upgrader.php @@ -1,5 +1,7 @@ fetch()){ + if ($dao->fetch()) { $menu_params = array( - 'label' => ts('Redsys Settings', array( 'domain' => 'com.ixiam.payment.redsys')), + 'label' => E::ts('Redsys Settings', array('domain' => 'com.ixiam.payment.redsys')), 'url' => 'civicrm/redsys/settings', 'permission' => array('administer OfflinePay'), 'permission_operator' => 'AND', 'has_separator' => '1', 'is_active' => '1', - 'parent_id' => $dao->id + 'parent_id' => $dao->id, ); $parent = CRM_Core_BAO_Navigation::add($menu_params); - // also reset navigation - CRM_Core_Menu::store( ); - CRM_Core_BAO_Navigation::resetNavigation( ); + // Also reset navigation. + CRM_Core_Menu::store(); + CRM_Core_BAO_Navigation::resetNavigation(); } $dao->free(); } diff --git a/CRM/Redsys/Upgrader/Base.php b/CRM/Redsys/Upgrader/Base.php index efe41c2d029499568c3891def1e5b7ee5b1eb171..b5d806c45943ec86b1c693894c40f1eca2decd20 100644 --- a/CRM/Redsys/Upgrader/Base.php +++ b/CRM/Redsys/Upgrader/Base.php @@ -1,6 +1,7 @@ getCurrentRevision(); foreach ($this->getRevisions() as $revision) { if ($revision > $currentRevision) { - $title = ts('Upgrade %1 to revision %2', array( + $title = E::ts('Upgrade %1 to revision %2', array( 1 => $this->extensionName, 2 => $revision, )); diff --git a/LICENSE.txt b/LICENSE.txt index 94a9ed024d3859793618152ea559a168bbcbb5e2..a2e515099ce13c1e1f58edab62d144d6a2d608ca 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,11 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +Package: com.ixiam.payment.redsys +Copyright (C) 2018, Ruben +Licensed under the GNU Affero Public License 3.0 (below). + +------------------------------------------------------------------------------- + + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies @@ -7,17 +13,15 @@ Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to +our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. +software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -26,44 +30,34 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. The precise terms and conditions for copying, distribution and modification follow. @@ -72,7 +66,7 @@ modification follow. 0. Definitions. - "This License" refers to version 3 of the GNU General Public License. + "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. @@ -549,35 +543,45 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Use with the GNU Affero General Public License. + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single +under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General +Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published +GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's +versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. @@ -635,40 +639,29 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by + it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Affero General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see +For more information on this, and how to apply and follow the GNU AGPL, see . - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/redsys.civix.php b/redsys.civix.php index 87b1b054da34a8e7b80f48b27a1893950c3947e2..66760a64338e3e555ac878c09fe1caf82b194c3c 100644 --- a/redsys.civix.php +++ b/redsys.civix.php @@ -2,6 +2,83 @@ // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file +/** + * The ExtensionUtil class provides small stubs for accessing resources of this + * extension. + */ +class CRM_Redsys_ExtensionUtil { + const SHORT_NAME = "redsys"; + const LONG_NAME = "com.ixiam.payment.redsys"; + const CLASS_PREFIX = "CRM_Redsys"; + + /** + * Translate a string using the extension's domain. + * + * If the extension doesn't have a specific translation + * for the string, fallback to the default translations. + * + * @param string $text + * Canonical message text (generally en_US). + * @param array $params + * @return string + * Translated text. + * @see ts + */ + public static function ts($text, $params = array()) { + if (!array_key_exists('domain', $params)) { + $params['domain'] = array(self::LONG_NAME, NULL); + } + return ts($text, $params); + } + + /** + * Get the URL of a resource file (in this extension). + * + * @param string|NULL $file + * Ex: NULL. + * Ex: 'css/foo.css'. + * @return string + * Ex: 'http://example.org/sites/default/ext/org.example.foo'. + * Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'. + */ + public static function url($file = NULL) { + if ($file === NULL) { + return rtrim(CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME), '/'); + } + return CRM_Core_Resources::singleton()->getUrl(self::LONG_NAME, $file); + } + + /** + * Get the path of a resource file (in this extension). + * + * @param string|NULL $file + * Ex: NULL. + * Ex: 'css/foo.css'. + * @return string + * Ex: '/var/www/example.org/sites/default/ext/org.example.foo'. + * Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'. + */ + public static function path($file = NULL) { + // return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file); + return __DIR__ . ($file === NULL ? '' : (DIRECTORY_SEPARATOR . $file)); + } + + /** + * Get the name of a class within this extension. + * + * @param string $suffix + * Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'. + * @return string + * Ex: 'CRM_Foo_Page_HelloWorld'. + */ + public static function findClass($suffix) { + return self::CLASS_PREFIX . '_' . str_replace('\\', '_', $suffix); + } + +} + +use CRM_Redsys_ExtensionUtil as E; + /** * (Delegated) Implements hook_civicrm_config(). * @@ -19,14 +96,14 @@ function _redsys_civix_civicrm_config(&$config = NULL) { $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; $extDir = $extRoot . 'templates'; - if ( is_array( $template->template_dir ) ) { - array_unshift( $template->template_dir, $extDir ); + if (is_array($template->template_dir)) { + array_unshift($template->template_dir, $extDir); } else { - $template->template_dir = array( $extDir, $template->template_dir ); + $template->template_dir = array($extDir, $template->template_dir); } - $include_path = $extRoot . PATH_SEPARATOR . get_include_path( ); + $include_path = $extRoot . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); } @@ -55,6 +132,20 @@ function _redsys_civix_civicrm_install() { } } +/** + * Implements hook_civicrm_postInstall(). + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall + */ +function _redsys_civix_civicrm_postInstall() { + _redsys_civix_civicrm_config(); + if ($upgrader = _redsys_civix_upgrader()) { + if (is_callable(array($upgrader, 'onPostInstall'))) { + $upgrader->onPostInstall(); + } + } +} + /** * Implements hook_civicrm_uninstall(). * @@ -117,7 +208,7 @@ function _redsys_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { * @return CRM_Redsys_Upgrader */ function _redsys_civix_upgrader() { - if (!file_exists(__DIR__.'/CRM/Redsys/Upgrader.php')) { + if (!file_exists(__DIR__ . '/CRM/Redsys/Upgrader.php')) { return NULL; } else { @@ -153,7 +244,8 @@ function _redsys_civix_find_files($dir, $pattern) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry{0} == '.') { - } elseif (is_dir($path)) { + } + elseif (is_dir($path)) { $todos[] = $path; } } @@ -175,9 +267,12 @@ function _redsys_civix_civicrm_managed(&$entities) { $es = include $file; foreach ($es as $e) { if (empty($e['module'])) { - $e['module'] = 'com.ixiam.payment.redsys'; + $e['module'] = E::LONG_NAME; } $entities[] = $e; + if (empty($e['params']['version'])) { + $e['params']['version'] = '3'; + } } } } @@ -204,7 +299,7 @@ function _redsys_civix_civicrm_caseTypes(&$caseTypes) { // throw new CRM_Core_Exception($errorMessage); } $caseTypes[$name] = array( - 'module' => 'com.ixiam.payment.redsys', + 'module' => E::LONG_NAME, 'name' => $name, 'file' => $file, ); @@ -230,7 +325,7 @@ function _redsys_civix_civicrm_angularModules(&$angularModules) { $name = preg_replace(':\.ang\.php$:', '', basename($file)); $module = include $file; if (empty($module['ext'])) { - $module['ext'] = 'com.ixiam.payment.redsys'; + $module['ext'] = E::LONG_NAME; } $angularModules[$name] = $module; } @@ -273,12 +368,14 @@ function _redsys_civix_insert_navigation_menu(&$menu, $path, $item) { } else { // Find an recurse into the next level down - $found = false; + $found = FALSE; $path = explode('/', $path); $first = array_shift($path); foreach ($menu as $key => &$entry) { if ($entry['attributes']['name'] == $first) { - if (!$entry['child']) $entry['child'] = array(); + if (!isset($entry['child'])) { + $entry['child'] = array(); + } $found = _redsys_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key); } } @@ -305,7 +402,7 @@ function _redsys_civix_fixNavigationMenu(&$nodes) { if ($key === 'navID') { $maxNavID = max($maxNavID, $item); } - }); + }); _redsys_civix_fixNavigationMenuItems($nodes, $maxNavID, NULL); } @@ -342,7 +439,20 @@ function _redsys_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { $configured = TRUE; $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings'; - if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) { + if (is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) { $metaDataFolders[] = $settingsDir; } } + +/** + * (Delegated) Implements hook_civicrm_entityTypes(). + * + * Find any *.entityType.php files, merge their content, and return. + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes + */ + +function _redsys_civix_civicrm_entityTypes(&$entityTypes) { + $entityTypes = array_merge($entityTypes, array ( + )); +} diff --git a/redsys.php b/redsys.php index 75b933eed1c9bc5f4c5f1fc8e93f5e532621f6f6..6015f78e637779aa4662ab3dbc9322d1e843a538 100644 --- a/redsys.php +++ b/redsys.php @@ -1,9 +1,10 @@ 'notify', 'user_name_label' => 'Número de comercio', 'password_label' => 'Clave secreta de encriptación', - 'url_site_default'=> 'https://sis.redsys.es/sis/realizarPago', + 'url_site_default' => 'https://sis.redsys.es/sis/realizarPago', 'url_site_test_default' => 'https://sis-t.redsys.es:25443/sis/realizarPago', 'is_recur' => 0, 'payment_type' => 1, @@ -47,7 +55,7 @@ function redsys_civicrm_install() { } /** - * Implementation of hook_civicrm_uninstall + * Implements hook_civicrm_uninstall(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall */ @@ -58,7 +66,7 @@ function redsys_civicrm_uninstall() { 'name' => 'Redsys', ); $result = civicrm_api('PaymentProcessorType', 'get', $params); - if($result["count"] == 1) { + if ($result["count"] == 1) { $params = array( 'version' => 3, 'sequential' => 1, @@ -66,38 +74,29 @@ function redsys_civicrm_uninstall() { ); $result = civicrm_api('PaymentProcessorType', 'delete', $params); } - - - return _redsys_civix_civicrm_uninstall(); } /** - * Implementation of hook_civicrm_enable + * Implements hook_civicrm_enable(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable */ function redsys_civicrm_enable() { - return _redsys_civix_civicrm_enable(); + _redsys_civix_civicrm_enable(); } /** - * Implementation of hook_civicrm_disable + * Implements hook_civicrm_disable(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable */ function redsys_civicrm_disable() { - return _redsys_civix_civicrm_disable(); + _redsys_civix_civicrm_disable(); } /** - * Implementation of hook_civicrm_upgrade - * - * @param $op string, the type of operation being performed; 'check' or 'enqueue' - * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks - * - * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) - * for 'enqueue', returns void + * Implements hook_civicrm_upgrade(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade */ @@ -105,13 +104,22 @@ function redsys_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { return _redsys_civix_civicrm_upgrade($op, $queue); } - - +/** + * Implements hook_civicrm_managed(). + * + * Generate a list of entities to create/deactivate/delete when this module + * is installed, disabled, uninstalled. + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed + */ +function redsys_civicrm_managed(&$entities) { + _redsys_civix_civicrm_managed($entities); +} /** - * Implementation of hook_civicrm_caseTypes + * Implements hook_civicrm_caseTypes(). * - * Generate a list of case-types + * Generate a list of case-types. * * Note: This hook only runs in CiviCRM 4.4+. * @@ -122,10 +130,35 @@ function redsys_civicrm_caseTypes(&$caseTypes) { } /** - * Implementation of hook_civicrm_alterSettingsFolders + * Implements hook_civicrm_angularModules(). + * + * Generate a list of Angular modules. + * + * Note: This hook only runs in CiviCRM 4.5+. It may + * use features only available in v4.6+. + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules + */ +function redsys_civicrm_angularModules(&$angularModules) { + _redsys_civix_civicrm_angularModules($angularModules); +} + +/** + * Implements hook_civicrm_alterSettingsFolders(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders */ function redsys_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { _redsys_civix_civicrm_alterSettingsFolders($metaDataFolders); } + +/** + * Implements hook_civicrm_entityTypes(). + * + * Declare entity types provided by this module. + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes + */ +function redsys_civicrm_entityTypes(&$entityTypes) { + _redsys_civix_civicrm_entityTypes($entityTypes); +}