Commit a1a31d47 authored by rubofvil's avatar rubofvil Committed by sluc23
Browse files

Dev token

parent c5ede917
......@@ -168,8 +168,15 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
}
}
if (!empty($params["is_token"])) {
$processorName = "Redsys_Tokenization";
}
else {
$processorName = "Redsys";
}
$merchantUrl = CRM_Utils_System::url('civicrm/payment/ipn',
'processor_name=Redsys&mode=' . $this->_mode . '&md=' . $component . '&qfKey=' . $params["qfKey"] . '&' . $merchantUrlParams,
"processor_name={$processorName}&mode={$this->_mode}&md={$component}&qfKey={$params['qfKey']}&{$merchantUrlParams}",
TRUE, NULL, FALSE, TRUE
);
......@@ -235,10 +242,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);
if (!empty($params["is_bizum"])) {
$miObj->setParameter("Ds_Merchant_PayMethods", 'z');
}
if (!empty($params["is_token"])) {
$miObj->setParameter("Ds_Merchant_Identifier", 'REQUIRED');
}
$version = "HMAC_SHA256_V1";
......
......@@ -91,6 +91,7 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN {
Civi::log()->debug("Redsys IPN Error Updating contribution: " . $e->getMessage());
}
}
return TRUE;
}
......@@ -115,6 +116,13 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN {
];
$decodecResponseJson = $this->_redsysAPI->decodeMerchantParameters($input["Ds_MerchantParameters"]);
$decodecResponse = json_decode($decodecResponseJson);
// 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'], $input['Ds_Merchant_Identifier'], number_format(($decodecResponse->Ds_Amount / 100), 2));
}
$input['Ds_MerchantCode'] = $decodecResponse->Ds_MerchantCode;
$input['Ds_Response'] = $decodecResponse->Ds_Response;
$input['Ds_AuthorisationCode'] = $decodecResponse->Ds_AuthorisationCode;
......
<?php
/**
* RedsysToken Payment Processor Class.
*/
class CRM_Core_Payment_RedsysToken extends CRM_Core_Payment_Redsys {
/**
* Method Transfer Checkout.
*/
public function doTransferCheckout(&$params, $component = 'contribute') {
$params["is_token"] = TRUE;
parent::doTransferCheckout($params, $component);
}
}
......@@ -55,7 +55,7 @@ class CRM_Redsys_Form_Settings extends CRM_Core_Form {
public function getPaymentProcessors() {
// Get the Redsys payment processor type.
$paymentProcessorTypes = civicrm_api3('PaymentProcessorType', 'get', ['name' => ['IN' => ["Redsys", "Bizum"]]]);
$paymentProcessorTypes = civicrm_api3('PaymentProcessorType', 'get', ['name' => ['IN' => ["Redsys", "Bizum", "Redsys_Tokenization"]]]);
$paymentProcessorTypesIds = [];
foreach ($paymentProcessorTypes["values"] as $paymentProcessorType) {
$paymentProcessorTypesIds[] = $paymentProcessorType["id"];
......
......@@ -20,6 +20,9 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
// Add Bizum.
$this->addBizumPayment();
// Add token
$this->addTokenPayment();
return TRUE;
}
......@@ -79,6 +82,16 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
return TRUE;
}
/**
* Add Tokenization/Recurring.
*
* @return void
*/
public function upgrade_4017() {
$this->addTokenPayment();
return TRUE;
}
/**
* Add build menu
*
......@@ -171,4 +184,37 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
}
}
}
/**
* Add Tokenization/Recurring Payment
*
* @return void
*/
private static function addTokenPayment() {
$resultPaymentMethod = civicrm_api3('PaymentProcessorType', 'get', [
'sequential' => 1,
'name' => "Redsys_Tokenization",
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
'name' => 'Redsys_Tokenization',
'title' => 'Recurring Redsys Payment Processor',
'description' => 'Works with Servired (Sermepa) and 4B (Pasat).',
'class_name' => 'Payment_RedsysToken',
'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]);
}
}
}
}
<?php
class CRM_Utils_Hooks_Redsys {
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');
}
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
......@@ -7,7 +7,7 @@
<td>
{$form.ipn_http.html}
<br>
<span class="description">Redsys doesn't support ipn callbacks using SSL shared certificate in multiples websites with a single IP. In that case you must force to use http protocol in ipn callback url</span>
<span class="description">Redsys doesn't support ipn callbacks using SSL shared certificate in multiples websites with a single IP. In that case you must force to use http protocol in ipn callback url</span>
</td>
</tr>
<tr class="crm-redsys-form-block-merchant_terminal">
......@@ -24,7 +24,7 @@
{foreach key=property item=terminal from=$form name=terminals}
{if $smarty.foreach.terminals.first}
<tr>
<th colspan="2">Merchant terminal numbers for specific payment prcessors</th>
<th colspan="2">Merchant terminal numbers for specific payment processors</th>
</tr>
{/if}
......
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