Commit 28e38779 authored by rubofvil's avatar rubofvil
Browse files

Redsys Tokenization - Add hook to save the token with another dev, refactor params to send

parent 5b505fc5
......@@ -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
);
......@@ -223,31 +230,24 @@ class CRM_Core_Payment_Redsys extends CRM_Core_Payment {
}
$miObj = new RedsysAPI();
if (empty($params["is_token"])) {
$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);
$miObj->setParameter("Ds_Merchant_Terminal", $merchantTerminal);
$miObj->setParameter("Ds_Merchant_MerchantURL", $merchantUrl);
$miObj->setParameter("Ds_Merchant_UrlOK", $returnURL);
$miObj->setParameter("Ds_Merchant_UrlKO", $cancelURL);
$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');
}
$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);
$miObj->setParameter("Ds_Merchant_Terminal", $merchantTerminal);
$miObj->setParameter("Ds_Merchant_MerchantURL", $merchantUrl);
$miObj->setParameter("Ds_Merchant_UrlOK", $returnURL);
$miObj->setParameter("Ds_Merchant_UrlKO", $cancelURL);
$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');
}
else {
if (!empty($params["is_token"])) {
$miObj->setParameter("DS_MERCHANT_IDENTIFIER", 'REQUIRED');
$miObj->setParameter("Ds_Merchant_Amount", 0);
$miObj->setParameter("Ds_Merchant_MerchantCode", $this->_paymentProcessor["user_name"]);
$miObj->setParameter("Ds_Merchant_Order", strval(self::formatAmount($params["contributionID"], 12)));
$miObj->setParameter("Ds_Merchant_Currency", self::REDSYS_CURRENCY_EURO);
$miObj->setParameter("Ds_Merchant_Terminal", $merchantTerminal);
$miObj->setParameter("Ds_Merchant_TransactionType", self::REDSYS_TRANSACTION_TYPE_OPERATION_STANDARD);
}
$version = "HMAC_SHA256_V1";
......
......@@ -91,6 +91,12 @@ class CRM_Core_Payment_RedsysIPN extends CRM_Core_Payment_BaseIPN {
Civi::log()->debug("Redsys IPN Error Updating contribution: " . $e->getMessage());
}
}
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;
}
......@@ -115,6 +121,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'], 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;
......
......@@ -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;
}
......@@ -88,6 +91,10 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
$this->addTokenPayment();
return TRUE;
}
public function upgrade_4018() {
$this->addTokenPayment();
return TRUE;
}
/**
* Add build menu
......@@ -194,7 +201,7 @@ class CRM_Redsys_Upgrader extends CRM_Redsys_Upgrader_Base {
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
'name' => 'Recurring Redsys',
'name' => 'Redsys_Tokenization',
'title' => 'Recurring Redsys Payment Processor',
'description' => 'Works with Servired (Sermepa) and 4B (Pasat).',
'class_name' => 'Payment_RedsysToken',
......
<?php
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 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);
}
}
}
\ 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