Commit 75afd19e authored by rubofvil's avatar rubofvil Committed by sluc23
Browse files

Add Bizum Payment Processor

parent 08b4ef20
<?php
/**
* Bizum Payment Processor Class.
*/
class CRM_Core_Payment_Bizum extends CRM_Core_Payment_Redsys {
/**
* Method Transfer Checkout.
*/
public function doTransferCheckout(&$params, $component = 'contribute') {
$params["is_bizum"] = TRUE;
parent::doTransferCheckout($params, $component);
}
}
<?php
/**
* CiviCRM Payment Processor for Redsys (before called Sermepa).
*
* Redsys is a company based in Spain. Many banks are using its
* payment processor for their payment processors.
*/
use CRM_Redsys_ExtensionUtil as E;
require_once 'CRM/Core/Payment.php';
require_once 'includes/apiRedsys.php';
/**
* Redsys Payment Processor Class.
*/
class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
const REDSYS_CURRENCY_EURO = 978;
const REDSYS_LANGUAGE_SPANISH = 1;
......@@ -40,9 +35,9 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
*
* (Deprecated parameter but used in some messages).
*
* @deprecated
*
* @var string
*
* @deprecated
*/
public $_processorName = NULL;
......@@ -50,6 +45,7 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
* Constructor
*
* @param string $mode the mode of operation: live or test
* @param int $paymentProcessor paymentProcessor id
*
* @return void
*/
......@@ -63,6 +59,7 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
* Singleton function used to manage this object
*
* @param string $mode the mode of operation: live or test
* @param int $paymentProcessor paymentProcessor id
*
* @return object
* @static
......@@ -239,6 +236,10 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
$miObj->setParameter("Ds_Merchant_Titular", $params["first_name"] . " " . $params["last_name"]);
$miObj->setParameter("Ds_Merchant_ConsumerLanguage", self::REDSYS_LANGUAGE_SPANISH);
if (!empty($params["is_bizum"])) {
$miObj->setParameter("Ds_Merchant_PayMethods", 'z');
}
$version = "HMAC_SHA256_V1";
$signature = $miObj->createMerchantSignature($this->_paymentProcessor["password"]);
......
<?php
require_once 'CRM/Core/Form.php';
use CRM_Redsys_ExtensionUtil as E;
class CRM_Redsys_Form_Settings extends CRM_Core_Form {
......
......@@ -7,16 +7,83 @@ use CRM_Redsys_ExtensionUtil as E;
*/
class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
/**
* Implement Install
*
* @return void
*/
public function install() {
$this->buildMenu();
// Add Redsys.
$this->addRedsysPayment();
// Add Bizum.
$this->addBizumPayment();
return TRUE;
}
/**
* Implement Unistall
*
* @return void
*/
public function uninstall() {
$result = civicrm_api3('PaymentProcessorType', 'get', [
'sequential' => 1,
'name' => ['IN' => ["Redsys", "Bizum"]],
]);
if ($result["count"] > 0) {
foreach ($result["values"] as $paymentProcessorType) {
try {
Civi::log()->debug("Redsys-Unistall: Delete payment processor type with id {$paymentProcessorType['id']}");
civicrm_api3('PaymentProcessorType', 'delete', ["id" => $paymentProcessorType["id"]]);
} catch (\Throwable $th) {
Civi::log()->debug("Redsys-Unistall: The payment processor type is disabled, because can by deleted {$paymentProcessorType['id']}");
civicrm_api3('PaymentProcessorType', 'create', ["id" => $paymentProcessorType["id"], 'is_active' => 0]);
}
}
}
}
/**
* Implements Upgrade 4015
*
* @return void
*/
public function upgrade_4015() {
$this->buildMenu();
return TRUE;
}
/**
* Add Bizum.
*
* @return void
*/
public function upgrade_4016() {
// Delete menu, replaced with hook_civicrm_navigationMenu
$resultNavigation = civicrm_api3('Navigation', 'get', [
'sequential' => 1,
'name' => "Redsys Settings",
]);
if ($resultNavigation["count"] > 0) {
foreach ($resultNavigation["values"] as $resultNavigationValue) {
civicrm_api3('Navigation', 'delete', ['id' => $resultNavigationValue["id"]]);
}
}
$this->addBizumPayment();
return TRUE;
}
/**
* Add build menu
*
* @return void
*/
private static function buildMenu() {
$query = "SELECT id FROM `civicrm_navigation` WHERE name = 'CiviContribute'";
$dao = CRM_Core_DAO::executeQuery($query);
......@@ -24,13 +91,13 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
$menu_params = [
'label' => E::ts('Redsys Settings', ['domain' => 'com.ixiam.payment.redsys']),
'url' => 'civicrm/redsys/settings',
'permission' => ['administer OfflinePay'],
'permission' => ['administer CiviCRM'],
'permission_operator' => 'AND',
'has_separator' => '1',
'is_active' => '1',
'parent_id' => $dao->id,
];
$parent = CRM_Core_BAO_Navigation::add($menu_params);
CRM_Core_BAO_Navigation::add($menu_params);
// Also reset navigation.
CRM_Core_Menu::store();
......@@ -39,4 +106,69 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
$dao->free();
}
/**
* Add Redsys Payment
*
* @return void
*/
private static function addRedsysPayment() {
$resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [
'sequential' => 1,
'name' => "Redsys",
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
'name' => 'Redsys',
'title' => 'Redsys Payment Processor',
'description' => 'Works with Servired (Sermepa) and 4B (Pasat).',
'class_name' => 'Payment_Redsys',
'billing_mode' => '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_test_default' => 'https://sis-t.redsys.es:25443/sis/realizarPago',
'is_recur' => 0,
'payment_type' => 1,
];
civicrm_api3('PaymentProcessorType', 'create', $params);
}
else {
foreach ($resultPaymentMethod["values"] as $resultPaymentMethodValue) {
civicrm_api3('PaymentProcessorType', 'create', ["id" => $resultPaymentMethodValue["id"], 'is_active' => 1]);
}
}
}
/**
* Add Bizum Payment
*
* @return void
*/
private static function addBizumPayment() {
$resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [
'sequential' => 1,
'name' => "Bizum",
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
'name' => 'Bizum',
'title' => 'Bizum Payment Processor',
'description' => 'Works with Servired (Sermepa) and 4B (Pasat).',
'class_name' => 'Payment_Bizum',
'billing_mode' => '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_test_default' => 'https://sis-t.redsys.es:25443/sis/realizarPago',
'is_recur' => 0,
'payment_type' => 1,
];
civicrm_api3('PaymentProcessorType', 'create', $params);
}
else {
foreach ($resultPaymentMethod["values"] as $resultPaymentMethodValue) {
civicrm_api3('PaymentProcessorType', 'create', ["id" => $resultPaymentMethodValue["id"], 'is_active' => 1]);
}
}
}
}
......@@ -9,9 +9,9 @@ use CRM_Redsys_ExtensionUtil as E;
class CRM_Redsys_Upgrader_Base {
/**
* @var varies, subclass of ttis
* @var CRM_Redsys_Upgrader_Base
*/
static $instance;
public static $instance;
/**
* @var CRM_Queue_TaskContext
......@@ -19,29 +19,37 @@ class CRM_Redsys_Upgrader_Base {
protected $ctx;
/**
* @var string, eg 'com.example.myextension'
* @var string
* eg 'com.example.myextension'
*/
protected $extensionName;
/**
* @var string, full path to the extension's source tree
* @var string
* full path to the extension's source tree
*/
protected $extensionDir;
/**
* @var array(revisionNumber) sorted numerically
* @var array
* sorted numerically
*/
private $revisions;
/**
* @var bool
* Flag to clean up extension revision data in civicrm_setting
*/
private $revisionStorageIsDeprecated = FALSE;
/**
* Obtain a reference to the active upgrade handler.
*/
public static function instance() {
if (!self::$instance) {
// FIXME auto-generate
self::$instance = new CRM_Redsys_Upgrader(
'com.ixiam.payment.redsys',
realpath(__DIR__ . '/../../../')
'redsys',
E::path()
);
}
return self::$instance;
......@@ -53,9 +61,9 @@ class CRM_Redsys_Upgrader_Base {
* Note: Each upgrader instance should only be associated with one
* task-context; otherwise, this will be non-reentrant.
*
* @code
* ```
* CRM_Redsys_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2');
* @endcode
* ```
*/
public static function _queueAdapter() {
$instance = self::instance();
......@@ -66,6 +74,12 @@ class CRM_Redsys_Upgrader_Base {
return call_user_func_array([$instance, $method], $args);
}
/**
* CRM_Redsys_Upgrader_Base constructor.
*
* @param $extensionName
* @param $extensionDir
*/
public function __construct($extensionName, $extensionDir) {
$this->extensionName = $extensionName;
$this->extensionDir = $extensionDir;
......@@ -76,7 +90,8 @@ class CRM_Redsys_Upgrader_Base {
/**
* Run a CustomData file.
*
* @param string $relativePath the CustomData XML file path (relative to this extension's dir)
* @param string $relativePath
* the CustomData XML file path (relative to this extension's dir)
* @return bool
*/
public function executeCustomDataFile($relativePath) {
......@@ -87,12 +102,12 @@ class CRM_Redsys_Upgrader_Base {
/**
* Run a CustomData file
*
* @param string $xml_file the CustomData XML file path (absolute path)
* @param string $xml_file
* the CustomData XML file path (absolute path)
*
* @return bool
*/
protected static function executeCustomDataFileByAbsPath($xml_file) {
require_once 'CRM/Utils/Migrate/Import.php';
protected function executeCustomDataFileByAbsPath($xml_file) {
$import = new CRM_Utils_Migrate_Import();
$import->run($xml_file);
return TRUE;
......@@ -101,14 +116,38 @@ class CRM_Redsys_Upgrader_Base {
/**
* Run a SQL file.
*
* @param string $relativePath the SQL file path (relative to this extension's dir)
* @param string $relativePath
* the SQL file path (relative to this extension's dir)
*
* @return bool
*/
public function executeSqlFile($relativePath) {
CRM_Utils_File::sourceSQLFile(
CIVICRM_DSN,
$this->extensionDir . '/' . $relativePath
$this->extensionDir . DIRECTORY_SEPARATOR . $relativePath
);
return TRUE;
}
/**
* Run the sql commands in the specified file.
*
* @param string $tplFile
* The SQL file path (relative to this extension's dir).
* Ex: "sql/mydata.mysql.tpl".
*
* @return bool
* @throws \CRM_Core_Exception
*/
public function executeSqlTemplate($tplFile) {
// Assign multilingual variable to Smarty.
$upgrade = new CRM_Upgrade_Form();
$tplFile = CRM_Utils_File::isAbsolute($tplFile) ? $tplFile : $this->extensionDir . DIRECTORY_SEPARATOR . $tplFile;
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('domainID', CRM_Core_Config::domainID());
CRM_Utils_File::sourceSQLFile(
CIVICRM_DSN, $smarty->fetch($tplFile), NULL, TRUE
);
return TRUE;
}
......@@ -117,8 +156,10 @@ class CRM_Redsys_Upgrader_Base {
* Run one SQL query.
*
* This is just a wrapper for CRM_Core_DAO::executeSql, but it
* provides syntatic sugar for queueing several tasks that
* provides syntactic sugar for queueing several tasks that
* run different queries
*
* @return bool
*/
public function executeSql($query, $params = []) {
// FIXME verify that we raise an exception on error
......@@ -127,7 +168,7 @@ class CRM_Redsys_Upgrader_Base {
}
/**
* Syntatic sugar for enqueuing a task which calls a function in this class.
* Syntactic sugar for enqueuing a task which calls a function in this class.
*
* The task is weighted so that it is processed
* as part of the currently-pending revision.
......@@ -169,6 +210,8 @@ class CRM_Redsys_Upgrader_Base {
/**
* Add any pending revisions to the queue.
*
* @param CRM_Queue_Queue $queue
*/
public function enqueuePendingRevisions(CRM_Queue_Queue $queue) {
$this->queue = $queue;
......@@ -203,7 +246,8 @@ class CRM_Redsys_Upgrader_Base {
/**
* Get a list of revisions.
*
* @return array(revisionNumbers) sorted numerically
* @return array
* revisionNumbers sorted numerically
*/
public function getRevisions() {
if (!is_array($this->revisions)) {
......@@ -223,24 +267,41 @@ class CRM_Redsys_Upgrader_Base {
}
public function getCurrentRevision() {
// return CRM_Core_BAO_Extension::getSchemaVersion($this->extensionName);
$revision = CRM_Core_BAO_Extension::getSchemaVersion($this->extensionName);
if (!$revision) {
$revision = $this->getCurrentRevisionDeprecated();
}
return $revision;
}
private function getCurrentRevisionDeprecated() {
$key = $this->extensionName . ':version';
return CRM_Core_BAO_Setting::getItem('Extension', $key);
if ($revision = \Civi::settings()->get($key)) {
$this->revisionStorageIsDeprecated = TRUE;
}
return $revision;
}
public function setCurrentRevision($revision) {
// We call this during hook_civicrm_install, but the underlying SQL
// UPDATE fails because the extension record hasn't been INSERTed yet.
// Instead, track revisions in our own namespace.
// CRM_Core_BAO_Extension::setSchemaVersion($this->extensionName, $revision);
$key = $this->extensionName . ':version';
CRM_Core_BAO_Setting::setItem($revision, 'Extension', $key);
CRM_Core_BAO_Extension::setSchemaVersion($this->extensionName, $revision);
// clean up legacy schema version store (CRM-19252)
$this->deleteDeprecatedRevision();
return TRUE;
}
private function deleteDeprecatedRevision() {
if ($this->revisionStorageIsDeprecated) {
$setting = new CRM_Core_BAO_Setting();
$setting->name = $this->extensionName . ':version';
$setting->delete();
CRM_Core_Error::debug_log_message("Migrated extension schema revision ID for {$this->extensionName} from civicrm_setting (deprecated) to civicrm_extension.\n");
}
}
// ******** Hook delegates ********
/**
* Hook delegates
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
public function onInstall() {
$files = glob($this->extensionDir . '/sql/*_install.sql');
......@@ -249,6 +310,12 @@ class CRM_Redsys_Upgrader_Base {
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $file);
}
}
$files = glob($this->extensionDir . '/sql/*_install.mysql.tpl');
if (is_array($files)) {
foreach ($files as $file) {
$this->executeSqlTemplate($file);
}
}
$files = glob($this->extensionDir . '/xml/*_install.xml');
if (is_array($files)) {
foreach ($files as $file) {
......@@ -258,13 +325,31 @@ class CRM_Redsys_Upgrader_Base {
if (is_callable([$this, 'install'])) {
$this->install();
}
}
/**
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
*/
public function onPostInstall() {
$revisions = $this->getRevisions();
if (!empty($revisions)) {
$this->setCurrentRevision(max($revisions));
}
if (is_callable([$this, 'postInstall'])) {
$this->postInstall();
}
}
/**
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
*/
public function onUninstall() {
$files = glob($this->extensionDir . '/sql/*_uninstall.mysql.tpl');
if (is_array($files)) {
foreach ($files as $file) {
$this->executeSqlTemplate($file);
}
}
if (is_callable([$this, 'uninstall'])) {
$this->uninstall();
}
......@@ -274,9 +359,11 @@ class CRM_Redsys_Upgrader_Base {
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $file);
}
}
$this->setCurrentRevision(NULL);
}
/**
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
public function onEnable() {
// stub for possible future use
if (is_callable([$this, 'enable'])) {
......@@ -284,6 +371,9 @@ class CRM_Redsys_Upgrader_Base {
}
}
/**
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
*/
public function onDisable() {
// stub for possible future use
if (is_callable([$this, 'disable'])) {
......
......@@ -6,6 +6,8 @@ This is a Redsys Payment Processor for CiviCRM.
- For more information about CiviCRM payment processors, see:
http://book.civicrm.org/user/current/contributions/payment-processors/
- Since version *2.3.0* this extension adds support for [Bizum](https://bizum.es/) payments
## Release Notes ##
For Releases Notes, please check file [RELEASES.md](RELEASES.md)
......@@ -43,15 +45,16 @@ This is a standard CiviCRM extension and can be directly installed from your Civ
After installing and activating the extension, you'll need to configure your payment processor:
* Add a new Payment Processor (Administer / System Settings / Payment Processor)
* Select Redsys Payment Processor as Payment Processor Type
* Configure it with your Mechant Account Id (número de comercio) and Encription Password (clave secreta de encriptación),
* By default the test key is sq7HjrUOBfKmC576ILgskD5srU870gJ7
* This extensions adds two Payment Processor Types **Redsys** and **Bizum** (Administer / System Settings / Payment Processor)
* Unique **Redsys** [account](https://canales.redsys.es/admincanales-web/index.jsp#/login) is used for both payment processors.
Contact Redsys Customer service to enable **Bizum** support on your account.
* Select Redsys/Bizum Payment Processor as Payment Processor Type
* Configure it with your Mechant Account Id *(número de comercio)* and Encription Password *(clave secreta de encriptación)*
* By default the test key is `sq7HjrUOBfKmC576ILgskD5srU870gJ7`
### Requirements ###
Version 1.9 works with CiviCRM 4.6 / 4.7 / 5.x (until 5.3.0).
Version 2.0 works with CiviCRM 5.3.0 or newer versions.
Version *2.3.x* works with **CiviCRM 5.21.x** or newer versions.
### Error Log
......@@ -59,10 +62,12 @@ To search if it's failing in some cases, search in ConfigLog from civicrm the wo
## License ##
Redsys Payment Processor for CiviCRM. Copyright (C) 2013 - 2020 Ixiam http://www.ixiam.com (originally supported by Amnesty International)
Redsys Payment Processor for CiviCRM. Copyright (c) 2013 - 2020 by [iXiam Global Solutions](https://www.ixiam.com).
[iXiam Global Solutions](https://www.ixiam.com) has no affiliation with Redsys Company.
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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
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 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.
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.
You should have received a copy of the GNU General Public License along with this program (see LICENSE.txt). If not, see http://www.gnu.org/licenses/.
You should have received a copy of the GNU General Public License along with this program (see [LICENSE.txt](LICENSE.txt)). More info in http://www.gnu.org/licenses/.
## Release Notes ##
### v2.3.0 ###
- Add support for **Bizum** as new payment processor type.
### v2.2.1 ###
- Code Cleanup and migration to https://lab.civicrm.org/extensions/redsys
......
......@@ -5,19 +5,25 @@
<description>RedSys Payment Processor</description>
<urls>
<url desc="Main Extension Page">https://lab.civicrm.org/extensions/redsys</url>
<url desc="Documentation">https://lab.civicrm.org/extensions/redsys/README.md</url>
<url desc="Support">https://lab.civicrm.org/extensions/redsys/-/issues</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<license>AGPL-3.0</license>
<maintainer>
<author>iXiam Global Solutions</author>
<email>info@ixiam.com</email>
</maintainer>
<releaseDate>2020-01-07</releaseDate>
<version>2.2.1</version>
<releaseDate>2020-12-16</releaseDate>
<version>2.3.0</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.16</ver>
<ver>5.21</ver>
</compatibility>
<comments>RedSys Payment Processor. For more info about RedSys, check its web site: http://www.redsys.es/</comments>
<classloader>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>