Skip to content

Commit

Permalink
Merge branch 'release/7.7.25'
Browse files Browse the repository at this point in the history
* release/7.7.25:
  Envío de cabecera con datos
  se eliminan hooks sin función y se añade el hook displayHeader para remplazar al hook deprecado header
  • Loading branch information
txerragh committed Nov 28, 2023
2 parents c91226d + 313adfe commit 7ddcacb
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 30 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -60,6 +60,10 @@ Todas las suscripciones mostrarán el estado actual:

## Release Notes

> 7.7.25:
- Mejoras de código

> 7.7.24:
- Mejoras de código
Expand Down
18 changes: 13 additions & 5 deletions classes/PaycometApiRest.php
Expand Up @@ -26,12 +26,14 @@
class PaycometApiRest
{
private $apiKey;
private $paycometHeader;

private $endpointUrl = "https://rest.paycomet.com";

public function __construct($apiKey)
public function __construct($apiKey, $paycometHeader = "")
{
$this->apiKey = $apiKey;
$this->paycometHeader = $paycometHeader;
}

public function form(
Expand Down Expand Up @@ -339,6 +341,15 @@ private function executeRequest($endpoint, $params)

$url = $this->endpointUrl . $endpoint;

$arrHeaders = array(
"PAYCOMET-API-TOKEN: $this->apiKey",
"Content-Type: application/json"
);

if ($this->paycometHeader != "") {
$arrHeaders[] = "X-PAYCOMET-DATA: " . $this->paycometHeader;
}

curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
Expand All @@ -347,10 +358,7 @@ private function executeRequest($endpoint, $params)
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $jsonParams,
CURLOPT_HTTPHEADER => array(
"PAYCOMET-API-TOKEN: $this->apiKey",
"Content-Type: application/json"
),
CURLOPT_HTTPHEADER => $arrHeaders
));

$response = curl_exec($curl);
Expand Down
8 changes: 4 additions & 4 deletions controllers/front/account.php
Expand Up @@ -75,7 +75,7 @@ public function initContent()

if ($paytpv->apikey != '') {
$notify = 2;
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$addUserResponse = $apiRest->addUser(
$idterminal,
$token,
Expand All @@ -99,7 +99,7 @@ public function initContent()
} else {
$result = array();
if ($paytpv->apikey != '') {
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$infoUserResponse = $apiRest->infoUser(
$idUser,
$tokenUser,
Expand Down Expand Up @@ -140,7 +140,7 @@ public function initContent()

if ($paytpv->apikey != '') {
try {
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$formResponse = $apiRest->form(
$operation,
$language,
Expand Down Expand Up @@ -177,7 +177,7 @@ public function initContent()
if ($saved_card[$key]['EXPIRY_DATE'] == '') {
if ($paytpv->apikey != '') {
try {
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);

$infoUserResponse = $apiRest->infoUser(
$saved_card[$key]["IDUSER"],
Expand Down
4 changes: 2 additions & 2 deletions controllers/front/actions.php
Expand Up @@ -171,7 +171,7 @@ public function processAddCard()
$scoring = $score["score"];

try {
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);

$payment = [
'terminal' => (int) $idterminal,
Expand Down Expand Up @@ -332,7 +332,7 @@ public function processSuscribe()
$userInteraction = '1';

try {
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);

$payment = [
'terminal' => (int) $idterminal,
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/apm.php
Expand Up @@ -61,7 +61,7 @@ public function initContent()
$URLOK = Context::getContext()->link->getModuleLink($paytpv->name, 'urlok', $values, $ssl);
$URLKO = Context::getContext()->link->getModuleLink($paytpv->name, 'urlko', $values, $ssl);

$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);

$ssl = Configuration::get('PS_SSL_ENABLED');

Expand Down
4 changes: 2 additions & 2 deletions controllers/front/capture.php
Expand Up @@ -65,7 +65,7 @@ public function initContent()
if ($paytpv->apikey != '') {
$notify = 2; // No notificar HTTP

$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$addUserResponse = $apiRest->addUser(
$idterminal,
$token,
Expand Down Expand Up @@ -184,7 +184,7 @@ public function initContent()
$methodId = '1';
$notifyDirectPayment = 1;

$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);

if ($jetPayment &&
(Tools::getIsset("paytpv_suscripcion") && Tools::getValue("paytpv_suscripcion")==1)) {
Expand Down
6 changes: 3 additions & 3 deletions controllers/front/url.php
Expand Up @@ -138,7 +138,7 @@ public function initContent()

if ($paytpv->apikey != '') {
include_once(_PS_MODULE_DIR_ . '/paytpv/classes/PaytpvApi.php');
$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$infoUserResponse = $apiRest->infoUser(
Tools::getValue('IdUser'),
Tools::getValue('TokenUser'),
Expand Down Expand Up @@ -267,7 +267,7 @@ public function initContent()

$notifyDirectPayment = 2;

$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$executeRefundReponse = $apiRest->executeRefund(
Tools::getValue('Order'),
$idterminal,
Expand Down Expand Up @@ -471,7 +471,7 @@ public function initContent()
if ($paytpv->apikey != '') {
include_once(_PS_MODULE_DIR_ . '/paytpv/classes/PaytpvApi.php');

$apiRest = new PaycometApiRest($paytpv->apikey);
$apiRest = new PaycometApiRest($paytpv->apikey, $paytpv->paycometHeader);
$infoUserResponse = $apiRest->infoUser(
$paytpv_iduser,
$paytpv_tokenuser,
Expand Down
26 changes: 13 additions & 13 deletions paytpv.php
Expand Up @@ -51,13 +51,15 @@ public function __construct()
$this->name = 'paytpv';
$this->tab = 'payments_gateways';
$this->author = 'Paycomet';
$this->version = '7.7.24';
$this->version = '7.7.25';
$this->module_key = 'deef285812f52026197223a4c07221c4';

$this->is_eu_compatible = 1;
$this->ps_versions_compliancy = array('min' => '1.7');
$this->controllers = array('payment', 'validation');

$this->paycometHeader = $this->version . ";" . _PS_VERSION_;

$this->bootstrap = true;
// Array config: configuration values
$config = $this->getConfigValues();
Expand Down Expand Up @@ -279,17 +281,15 @@ public function install()
// Valores por defecto al instalar el módulo
if (
!parent::install() ||
!$this->registerHook('displayPayment') ||
!$this->registerHook('displayPaymentTop') ||
!$this->registerHook('displayPaymentReturn') ||
!$this->registerHook('displayMyAccountBlock') ||
!$this->registerHook('displayAdminOrder') ||
!$this->registerHook('displayCustomerAccount') ||
!$this->registerHook('actionProductCancel') ||
!$this->registerHook('displayShoppingCart') ||
!$this->registerHook('paymentOptions') ||
!$this->registerHook('actionFrontControllerSetMedia') ||
!$this->registerHook('header') ||
!$this->registerHook('displayHeader') ||
!$this->registerHook('displayOrderConfirmation') ||
!$this->registerHook('displayOrderDetail') ||
!$this->registerHook('actionEmailAddAfterContent') ||
Expand Down Expand Up @@ -1813,7 +1813,7 @@ public function getPaymentMethods()
{

if (Configuration::get("PAYTPV_APIKEY") != "") {
$apiRest = new PaycometApiRest(Configuration::get("PAYTPV_APIKEY"));
$apiRest = new PaycometApiRest(Configuration::get("PAYTPV_APIKEY"), $this->paycometHeader);

$terminalId = 0;
if (isset(Tools::getValue("term")[0])) {
Expand Down Expand Up @@ -1865,7 +1865,7 @@ public function obtenerTerminalesConfigurados()
return $terminales;
}

public function hookHeader()
public function hookDisplayHeader()
{
// call your media file like this
$this->context->controller->addJqueryPlugin('fancybox');
Expand Down Expand Up @@ -1964,7 +1964,7 @@ public function getTemplateVarInfos()
if ($saved_card[$key]['EXPIRY_DATE'] == '') {
if ($this->apikey != '') {
try {
$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);

$infoUserResponse = $apiRest->infoUser(
$saved_card[$key]["IDUSER"],
Expand Down Expand Up @@ -2481,7 +2481,7 @@ public function paytpvIframeUrl()
$merchantData = $this->getMerchantData($cart);

try {
$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);

$payment = [
'terminal' => (int) $idterminal,
Expand Down Expand Up @@ -2867,7 +2867,7 @@ public function removeCard($paytpv_iduser)
$paytpv_tokenuser = $result["paytpv_tokenuser"];

if ($this->apikey != '') {
$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);
$result = $apiRest->removeUser(
$idterminal,
$paytpv_iduser,
Expand Down Expand Up @@ -2905,7 +2905,7 @@ public function removeSuscription($id_suscription)
$paytpv_tokenuser = $result["paytpv_tokenuser"];

if ($this->apikey != '') {
$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);
$removeSubscriptionResponse = $apiRest->removeSubscription(
$idterminal,
$paytpv_iduser,
Expand Down Expand Up @@ -2946,7 +2946,7 @@ public function cancelSuscription($id_suscription)
$order_ref = str_pad($order->id_cart, 8, "0", STR_PAD_LEFT);

if ($this->apikey != '') {
$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);
try {
$removeSubscriptionResponse = $apiRest->removeSubscription(
$idterminal,
Expand Down Expand Up @@ -3155,7 +3155,7 @@ private function makeRefund(
if ($this->apikey != '') {
$notifyDirectPayment = 2;

$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);
$executeRefundReponse = $apiRest->executeRefund(
$paytpv_order_ref,
$idterminal,
Expand Down Expand Up @@ -3192,7 +3192,7 @@ private function makeRefund(
if ($this->apikey != '') {
$notifyDirectPayment = 2;

$apiRest = new PaycometApiRest($this->apikey);
$apiRest = new PaycometApiRest($this->apikey, $this->paycometHeader);
$executeRefundReponse = $apiRest->executeRefund(
$paytpv_order_ref,
$idterminal,
Expand Down
16 changes: 16 additions & 0 deletions upgrade/upgrade-7.7.25.php
@@ -0,0 +1,16 @@
<?php
/**
*
* @author PAYCOMET <info@paycomet.com>
* @copyright 2021 PAYCOMET S.L.U
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_7_7_25($object)
{
return ($object->registerHook('displayHeader'));
}

0 comments on commit 7ddcacb

Please sign in to comment.