Commit f8a76a20 authored by rubofvil's avatar rubofvil
Browse files

Add the new 'Payment Processor Type' to generate a token

parent c5ede917
......@@ -223,21 +223,31 @@ 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);
$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');
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');
}
}
else {
$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";
......
......@@ -79,6 +79,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 +181,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' => "Recurring Redsys",
]);
if ($resultPaymentMethod["count"] == 0) {
$params = [
'name' => 'Recurring Redsys',
'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]);
}
}
}
}
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