Commit f2509d20 authored by rubofvil's avatar rubofvil
Browse files

Replace hook procedure to call, clean

parent 28e38779
......@@ -92,11 +92,6 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN {
}
}
if(!empty($input["Ds_Merchant_Identifier"])) {
// Call the hook civicrm_redsysToken
CRM_Utils_Hooks_Offlinepay::redsystoken($input['contactID'], $input['contributionID'], $input["Ds_Merchant_Identifier"]);
}
return TRUE;
}
......@@ -125,7 +120,7 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN {
// Capture if is incoming a Ds_Merchant_Identifier, a token
if (!empty($decodecResponse->Ds_Merchant_Identifier)) {
$input['Ds_Merchant_Identifier'] = $decodecResponse->Ds_Merchant_Identifier;
CRM_Utils_Hooks_Redsys::redsystoken($input['contactID'], $input['contributionID'], number_format(($decodecResponse->Ds_Amount / 100), 2));
CRM_Utils_Hooks_Redsys::redsystoken($input['contactID'], $input['contributionID'], $input['Ds_Merchant_Identifier'], number_format(($decodecResponse->Ds_Amount / 100), 2));
}
$input['Ds_MerchantCode'] = $decodecResponse->Ds_MerchantCode;
......
......@@ -197,7 +197,7 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
private static function addTokenPayment() {
$resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [
'sequential' => 1,
'name' => "Recurring Redsys",
'name' => "Redsys_Tokenization",
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
......
......@@ -2,16 +2,31 @@
class CRM_Utils_Hooks_Redsys {
public static function redsystoken($contact_id, $contribution_id, $amount) {
return self::callHookByVersion(3, $contact_id, $contribution_id, $token, $amount, CRM_Utils_Hook::$_nullObject, 'civicrm_redsystoken');
public static function redsystoken($contact_id, $contribution_id, $token, $amount) {
$names = ['contact_id', 'contribution_id', 'token', 'amount'];
$args = [$contact_id, $contribution_id, $token, $amount];
return self::invokeHook($names, $args, 'civicrm_redsystoken');
}
public static function callHookByVersion($numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, $fnSuffix) {
if (version_compare(CRM_Utils_System::version(), '4.5', '<')) {
return CRM_Utils_Hook::singleton()->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $fnSuffix);
}
else {
return CRM_Utils_Hook::singleton()->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, CRM_Utils_Hook::$_nullObject, $fnSuffix);
private static function invokeHook($names, &$args, $fnSuffix) {
// Invoke classic hooks (legacy)
for ($i = 0; $i < 6; $i++) {
if (!isset($args[$i])) {
$args[$i] = CRM_Utils_Hook::$_nullObject;
}
}
CRM_Utils_Hook::singleton()
->invoke($names, $args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $fnSuffix);
// Invoke Symfony Dispatch (new convention)
$event = \Civi\Core\Event\GenericHookEvent::createOrdered(
$names,
[&$args[0], &$args[1], &$args[2], &$args[3], &$args[4], &$args[5]]
);
$fnSuffix = str_replace("civicrm_", "", $fnSuffix);
\Civi::dispatcher()->dispatch('redsys.' . $fnSuffix, $event);
return $event->getReturnValues();
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment