From 676c4b6071c67f26b51b98ba9dce6111acf09eb4 Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 10 Dec 2020 10:20:00 +0000 Subject: [PATCH 01/12] Add payment Bizum, creating a new payment type --- CRM/Core/Payment/Bizum.php | 23 ++++++++++++ CRM/Core/Payment/Redsys.php | 9 ++++- CRM/Redsys/Upgrader.php | 72 ++++++++++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 CRM/Core/Payment/Bizum.php diff --git a/CRM/Core/Payment/Bizum.php b/CRM/Core/Payment/Bizum.php new file mode 100644 index 0000000..6e73b01 --- /dev/null +++ b/CRM/Core/Payment/Bizum.php @@ -0,0 +1,23 @@ +setParameter("Ds_Merchant_Amount", (int) (round($params["amount"] * 100))); - $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); $miObj->setParameter("Ds_Merchant_MerchantCode", $this->_paymentProcessor["user_name"]); $miObj->setParameter("Ds_Merchant_Currency", self::REDSYS_CURRENCY_EURO); $miObj->setParameter("Ds_Merchant_TransactionType", self::REDSYS_TRANSACTION_TYPE_OPERATION_STANDARD); @@ -239,6 +238,14 @@ 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 (isset($params["is_bizum"]) && $params["is_bizum"] == TRUE) { + $miObj->setParameter("Ds_Merchant_PayMethods", 'z'); + $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 7) . "BIZUM")); + } + else { + $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); + } + $version = "HMAC_SHA256_V1"; $signature = $miObj->createMerchantSignature($this->_paymentProcessor["password"]); diff --git a/CRM/Redsys/Upgrader.php b/CRM/Redsys/Upgrader.php index 679b5f7..ad6d52f 100644 --- a/CRM/Redsys/Upgrader.php +++ b/CRM/Redsys/Upgrader.php @@ -7,16 +7,43 @@ use CRM_Redsys_ExtensionUtil as E; */ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { + /** + * Implement insttall + * + * @return void + */ public function install() { + $this->addRedsysPayment(); + $this->addBizumPayment(); $this->buildMenu(); return TRUE; } + /** + * Implements Upgrade 4015 + * + * @return void + */ public function upgrade_4015() { $this->buildMenu(); return TRUE; } + /** + * Add Bizum. + * + * @return void + */ + public function upgrade_4016() { + $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); @@ -30,7 +57,7 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { '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 +66,47 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { $dao->free(); } + /** + * Add Redsys Payment + * + * @return void + */ + private static function addRedsysPayment() { + $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); + } + + /** + * Add Bizum Payment + * + * @return void + */ + private static function addBizumPayment() { + $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); + } } -- GitLab From a8a54eab616425e22b8b03f70e340560ebf4d5fb Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 10 Dec 2020 18:16:34 +0100 Subject: [PATCH 02/12] Change how is installed / uninstalled the 'payment processor type' --- CRM/Redsys/Upgrader.php | 49 ++++++++++++++++++++++++++++++++++++++--- redsys.php | 26 ---------------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/CRM/Redsys/Upgrader.php b/CRM/Redsys/Upgrader.php index ad6d52f..c3abacb 100644 --- a/CRM/Redsys/Upgrader.php +++ b/CRM/Redsys/Upgrader.php @@ -8,17 +8,60 @@ use CRM_Redsys_ExtensionUtil as E; class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { /** - * Implement insttall + * Implement Install * * @return void */ public function install() { - $this->addRedsysPayment(); - $this->addBizumPayment(); + + $paymentMethods = [ + ["name" => "Bizum", "method_create" => "addBizumPayment"], + ["name" => "Redsys", "method_create" => "addRedsysPayment"] + ]; + + foreach ($paymentMethods as $paymentMethod) { + $resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [ + 'sequential' => 1, + 'name' => $paymentMethod["name"], + ]); + if ($resultPaymentMethod["count"] == 0) { + $this->{$paymentMethod["method_create"]}(); + } + else { + foreach ($resultPaymentMethod["values"] as $resultPaymentMethodValue) { + civicrm_api3('PaymentProcessorType', 'create', ["id" => $resultPaymentMethodValue["id"], 'is_active' => 1]); + } + } + } + $this->buildMenu(); 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 * diff --git a/redsys.php b/redsys.php index aeb2c07..67a7a55 100644 --- a/redsys.php +++ b/redsys.php @@ -133,20 +133,6 @@ function redsys_civicrm_themes(&$themes) { * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function redsys_civicrm_install() { - $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, - ]; - $result = civicrm_api3('PaymentProcessorType', 'create', $params); return _redsys_civix_civicrm_install(); } @@ -156,17 +142,5 @@ function redsys_civicrm_install() { * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall */ function redsys_civicrm_uninstall() { - $params = [ - 'sequential' => 1, - 'name' => 'Redsys', - ]; - $result = civicrm_api('PaymentProcessorType', 'get', $params); - if ($result["count"] == 1) { - $params = [ - 'sequential' => 1, - 'id' => $result["id"], - ]; - $result = civicrm_api3('PaymentProcessorType', 'delete', $params); - } return _redsys_civix_civicrm_uninstall(); } -- GitLab From e68e19d05e71d20a9c7b8524dd03ac8f36ae202d Mon Sep 17 00:00:00 2001 From: rubofvil Date: Thu, 10 Dec 2020 20:37:16 +0000 Subject: [PATCH 03/12] Apply 1 suggestion(s) to 1 file(s) --- CRM/Core/Payment/Redsys.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Core/Payment/Redsys.php b/CRM/Core/Payment/Redsys.php index 6c1e98c..320c7f4 100644 --- a/CRM/Core/Payment/Redsys.php +++ b/CRM/Core/Payment/Redsys.php @@ -238,7 +238,7 @@ 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 (isset($params["is_bizum"]) && $params["is_bizum"] == TRUE) { + if (!empty($params["is_bizum"])) { $miObj->setParameter("Ds_Merchant_PayMethods", 'z'); $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 7) . "BIZUM")); } -- GitLab From 9d28ab7245e400bd529bfeeaf772e79112ef942a Mon Sep 17 00:00:00 2001 From: Ruben Date: Fri, 11 Dec 2020 11:53:15 +0000 Subject: [PATCH 04/12] Change criteria to generate the 'Ds_Merchant_Order', clean not required use 'ExtensionUtil' --- CRM/Core/Payment/Redsys.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Payment/Redsys.php b/CRM/Core/Payment/Redsys.php index 6c1e98c..c3c01c5 100644 --- a/CRM/Core/Payment/Redsys.php +++ b/CRM/Core/Payment/Redsys.php @@ -6,8 +6,6 @@ * payment processor for their payment processors. */ -use CRM_Redsys_ExtensionUtil as E; - require_once 'CRM/Core/Payment.php'; require_once 'includes/apiRedsys.php'; @@ -238,14 +236,12 @@ 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 (isset($params["is_bizum"]) && $params["is_bizum"] == TRUE) { + if (!empty($params["is_bizum"])) { $miObj->setParameter("Ds_Merchant_PayMethods", 'z'); - $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 7) . "BIZUM")); - } - else { - $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); } + $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); + $version = "HMAC_SHA256_V1"; $signature = $miObj->createMerchantSignature($this->_paymentProcessor["password"]); -- GitLab From a83177dfa5466d95386218743f9200dbe5bb99ee Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 15 Dec 2020 13:34:27 +0100 Subject: [PATCH 05/12] Replace how is created the menu, change the install(creating the payment processors type), restore CRM_Redsys_ExtensionUtil::LONG_NAME --- CRM/Redsys/Upgrader.php | 117 +++++++++++++++++++++++----------------- redsys.civix.php | 2 +- redsys.php | 19 +++++++ 3 files changed, 88 insertions(+), 50 deletions(-) diff --git a/CRM/Redsys/Upgrader.php b/CRM/Redsys/Upgrader.php index c3abacb..13ec8bb 100644 --- a/CRM/Redsys/Upgrader.php +++ b/CRM/Redsys/Upgrader.php @@ -14,27 +14,12 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { */ public function install() { - $paymentMethods = [ - ["name" => "Bizum", "method_create" => "addBizumPayment"], - ["name" => "Redsys", "method_create" => "addRedsysPayment"] - ]; - - foreach ($paymentMethods as $paymentMethod) { - $resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [ - 'sequential' => 1, - 'name' => $paymentMethod["name"], - ]); - if ($resultPaymentMethod["count"] == 0) { - $this->{$paymentMethod["method_create"]}(); - } - else { - foreach ($resultPaymentMethod["values"] as $resultPaymentMethodValue) { - civicrm_api3('PaymentProcessorType', 'create', ["id" => $resultPaymentMethodValue["id"], 'is_active' => 1]); - } - } - } + // Add Redsys. + $this->addRedsysPayment(); + + // Add Bizum. + $this->addBizumPayment(); - $this->buildMenu(); return TRUE; } @@ -78,6 +63,18 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { * @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; } @@ -94,7 +91,7 @@ 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', @@ -115,20 +112,31 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { * @return void */ private static function addRedsysPayment() { - $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); + $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]); + } + } } /** @@ -137,19 +145,30 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base { * @return void */ private static function addBizumPayment() { - $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); + $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]); + } + } } } diff --git a/redsys.civix.php b/redsys.civix.php index 244cea4..d97c2e0 100644 --- a/redsys.civix.php +++ b/redsys.civix.php @@ -8,7 +8,7 @@ */ class CRM_Redsys_ExtensionUtil { const SHORT_NAME = 'redsys'; - const LONG_NAME = 'redsys'; + const LONG_NAME = 'com.ixiam.payment.redsys'; const CLASS_PREFIX = 'CRM_Redsys'; /** diff --git a/redsys.php b/redsys.php index 67a7a55..1c72407 100644 --- a/redsys.php +++ b/redsys.php @@ -144,3 +144,22 @@ function redsys_civicrm_install() { function redsys_civicrm_uninstall() { return _redsys_civix_civicrm_uninstall(); } + +/** + * Implements hook_civicrm_navigationMenu() + * + * @param array $menu + * @return void + */ +function redsys_civicrm_navigationMenu(&$menu) { + _redsys_civix_insert_navigation_menu($menu, 'Administer/CiviContribute', [ + 'label' => E::ts('Redsys Settings'), + 'name' => 'redsys_settings', + 'url' => 'civicrm/redsys/settings', + 'permission' => 'administer CiviCRM', + 'operator' => 'OR', + 'has_separator' => 1, + 'is_active' => 1, + ]); + _redsys_civix_navigationMenu($menu); +} -- GitLab From 865f9dd6cd542e1471b9da2b185dd71408a89b53 Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 15 Dec 2020 14:13:55 +0100 Subject: [PATCH 06/12] Clean code --- CRM/Core/Payment/Redsys.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Payment/Redsys.php b/CRM/Core/Payment/Redsys.php index c3c01c5..0cce705 100644 --- a/CRM/Core/Payment/Redsys.php +++ b/CRM/Core/Payment/Redsys.php @@ -6,7 +6,8 @@ * payment processor for their payment processors. */ -require_once 'CRM/Core/Payment.php'; +use CRM_Redsys_ExtensionUtil as E; + require_once 'includes/apiRedsys.php'; class CRM_Core_Payment_Redsys extends CRM_Core_Payment { @@ -235,13 +236,12 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $miObj->setParameter("Ds_Merchant_ProductDescription", $description); $miObj->setParameter("Ds_Merchant_Titular", $params["first_name"] . " " . $params["last_name"]); $miObj->setParameter("Ds_Merchant_ConsumerLanguage", self::REDSYS_LANGUAGE_SPANISH); + $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); if (!empty($params["is_bizum"])) { $miObj->setParameter("Ds_Merchant_PayMethods", 'z'); } - $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); - $version = "HMAC_SHA256_V1"; $signature = $miObj->createMerchantSignature($this->_paymentProcessor["password"]); -- GitLab From b78aeb974c2eb76dc27c0e190df362bc81a6b27e Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 15 Dec 2020 14:33:42 +0100 Subject: [PATCH 07/12] Clean code --- CRM/Core/Payment/Redsys.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Core/Payment/Redsys.php b/CRM/Core/Payment/Redsys.php index 0cce705..8191a30 100644 --- a/CRM/Core/Payment/Redsys.php +++ b/CRM/Core/Payment/Redsys.php @@ -226,6 +226,7 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $miObj = new RedsysAPI(); $miObj->setParameter("Ds_Merchant_Amount", (int) (round($params["amount"] * 100))); + $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); $miObj->setParameter("Ds_Merchant_MerchantCode", $this->_paymentProcessor["user_name"]); $miObj->setParameter("Ds_Merchant_Currency", self::REDSYS_CURRENCY_EURO); $miObj->setParameter("Ds_Merchant_TransactionType", self::REDSYS_TRANSACTION_TYPE_OPERATION_STANDARD); @@ -236,7 +237,6 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment { $miObj->setParameter("Ds_Merchant_ProductDescription", $description); $miObj->setParameter("Ds_Merchant_Titular", $params["first_name"] . " " . $params["last_name"]); $miObj->setParameter("Ds_Merchant_ConsumerLanguage", self::REDSYS_LANGUAGE_SPANISH); - $miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12))); if (!empty($params["is_bizum"])) { $miObj->setParameter("Ds_Merchant_PayMethods", 'z'); -- GitLab From 5da9e14e5f91078e828d43e5fc5b01ae8678846d Mon Sep 17 00:00:00 2001 From: Ruben Date: Wed, 16 Dec 2020 14:58:11 +0100 Subject: [PATCH 08/12] Update documentation, Readme and Relesases --- README.md | 6 ++++-- RELEASES.md | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c67451..5af485d 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,10 @@ 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 +* Add two Payment Processor Types **Redsys** and **Bizum** (Administer / System Settings / Payment Processor) + * Could be used the same account from Redsys ([dashboard](https://canales.redsys.es/admincanales-web/index.jsp#/login)) to configure both payment processors. + * Is possible you will neet to talk with your bank(redsys provider) to enable **Bizum**. +* 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 diff --git a/RELEASES.md b/RELEASES.md index 39992fd..27b622c 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,9 @@ ## Release Notes ## +### v2.3.0 ### + +- Add **Bizum** as new payment processor type, keeping both avalible **Bizum** and **Redsys**. + ### v2.2.1 ### - Code Cleanup and migration to https://lab.civicrm.org/extensions/redsys -- GitLab From b9053507e860c9738c5a7b3f4a5a65c4fed0e9a5 Mon Sep 17 00:00:00 2001 From: sluc23 Date: Wed, 16 Dec 2020 14:20:08 +0000 Subject: [PATCH 09/12] Update README.md --- README.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5af485d..5405b6b 100644 --- a/README.md +++ b/README.md @@ -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,17 +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 two Payment Processor Types **Redsys** and **Bizum** (Administer / System Settings / Payment Processor) - * Could be used the same account from Redsys ([dashboard](https://canales.redsys.es/admincanales-web/index.jsp#/login)) to configure both payment processors. - * Is possible you will neet to talk with your bank(redsys provider) to enable **Bizum**. +* 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 +* 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 @@ -61,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/. -- GitLab From 53112ef6b6d68f1d97f716d9cdc52a8c13d2eb6d Mon Sep 17 00:00:00 2001 From: Luciano Spiegel Date: Wed, 16 Dec 2020 15:29:45 +0100 Subject: [PATCH 10/12] 2.3.0 --- info.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/info.xml b/info.xml index c69ca2c..9490a58 100644 --- a/info.xml +++ b/info.xml @@ -5,19 +5,25 @@ RedSys Payment Processor https://lab.civicrm.org/extensions/redsys + https://lab.civicrm.org/extensions/redsys/README.md + https://lab.civicrm.org/extensions/redsys/-/issues + http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0 iXiam Global Solutions info@ixiam.com - 2020-01-07 - 2.2.1 + 2020-12-16 + 2.3.0 stable - 5.16 + 5.21 RedSys Payment Processor. For more info about RedSys, check its web site: http://www.redsys.es/ + + + CRM/Redsys -- GitLab From c8f6a66cbbd876b348ee811593a6ee0913e06554 Mon Sep 17 00:00:00 2001 From: Luciano Spiegel Date: Wed, 16 Dec 2020 15:35:37 +0100 Subject: [PATCH 11/12] update Upgrade_Base class based on latest civix --- CRM/Redsys/Upgrader/Base.php | 150 ++++++++++++++++++++++++++++------- 1 file changed, 120 insertions(+), 30 deletions(-) diff --git a/CRM/Redsys/Upgrader/Base.php b/CRM/Redsys/Upgrader/Base.php index 29f7e1a..7037ba3 100644 --- a/CRM/Redsys/Upgrader/Base.php +++ b/CRM/Redsys/Upgrader/Base.php @@ -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'])) { -- GitLab From 502604c4eaebf1610ea7326fe6e2cfb461ff8954 Mon Sep 17 00:00:00 2001 From: Luciano Spiegel Date: Wed, 16 Dec 2020 15:40:02 +0100 Subject: [PATCH 12/12] typos and docs addition --- CRM/Core/Payment/Bizum.php | 9 +-------- CRM/Core/Payment/Redsys.php | 16 +++++++--------- CRM/Redsys/Form/Settings.php | 1 - RELEASES.md | 2 +- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/CRM/Core/Payment/Bizum.php b/CRM/Core/Payment/Bizum.php index 6e73b01..c7dd04d 100644 --- a/CRM/Core/Payment/Bizum.php +++ b/CRM/Core/Payment/Bizum.php @@ -1,14 +1,7 @@