Skip to content

Commit

Permalink
Merge pull request #18 from conekta/feature/card-1.7
Browse files Browse the repository at this point in the history
webhook + pruebas
  • Loading branch information
eduardoconekta authored Jul 28, 2017
2 parents d1013c1 + c63ac2d commit 0a9db4b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions conekta_prestashop.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ public function getContent()
Configuration::updateValue($configuration_key, $configuration_value);
}

$this->_createWebhook($url);
$this->_createWebhook();

$webhook_message = Configuration::get('CONEKTA_WEBHOOK_ERROR_MESSAGE');

Expand Down Expand Up @@ -779,7 +779,7 @@ public function getContent()
return $this->_html;
}

private function _createWebhook($url)
private function _createWebhook()
{
$key = Configuration::get('CONEKTA_MODE') ?
Configuration::get('CONEKTA_PRIVATE_KEY_LIVE') :
Expand All @@ -797,24 +797,19 @@ private function _createWebhook($url)
)
);

// Reset error message

$url = Tools::safeOutput(Tools::getValue('WEB_HOOK'));

Configuration::deleteByName('CONEKTA_WEBHOOK_ERROR_MESSAGE');

// Obtain stored value

$config_url = Tools::safeOutput(Configuration::get('CONEKTA_WEBHOOK'));
$is_valid_url = !empty($url) && !filter_var($url, FILTER_VALIDATE_URL) === false;
$failed_attempts = (integer) Configuration::get('CONEKTA_WEBHOOK_FAILED_ATTEMPTS');



// If input is valid, has not been stored and has not failed more than 5 times
echo $is_valid_url."<-valid <br>";
echo ($config_url != $url)."<-config<br>" ;
echo ($failed_attempts < 5 )."<-failed<br>";
echo $url."<--URL<br>";
echo Configuration::get('CONEKTA_WEBHOOK_FAILED_URL')."<----FAILED_RUL<br>";
die();

if ($is_valid_url && ($config_url != $url) && ($failed_attempts < 5 && $url != Configuration::get('CONEKTA_WEBHOOK_FAILED_URL'))) {
try {
$different = true;
Expand All @@ -839,6 +834,7 @@ private function _createWebhook($url)
$webhook = \Conekta\Webhook::create(array_merge(array(
"url" => $url
), $mode, $events));

Configuration::updateValue('CONEKTA_WEBHOOK', $url);

// delete error variables
Expand All @@ -863,7 +859,6 @@ private function _createWebhook($url)
Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', "Webhook was already registered in your shop!");
}
}

if (!empty(Configuration::get('CONEKTA_WEBHOOK_ERROR_MESSAGE'))) {
$failed_attempts = $failed_attempts + 1;
Configuration::updateValue('CONEKTA_WEBHOOK_FAILED_ATTEMPTS', $failed_attempts);
Expand Down

0 comments on commit 0a9db4b

Please sign in to comment.