Skip to content

Commit

Permalink
Merge pull request #197 from razorpay/auto-webhook_config
Browse files Browse the repository at this point in the history
Updated the local server check condition for auto webhook setup
  • Loading branch information
ChetanGN authored Jul 15, 2021
2 parents 2f4e831 + f2b378d commit b83df3d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ public function autoEnableWebhook()
{
?>
<div class="notice error is-dismissible" >
<p><b><?php _e( 'Key Id and Key Secret can`t be empty'); ?><b></p>
<p><b><?php _e( 'Key Id and Key Secret are required.'); ?><b></p>
</div>
<?php

error_log('Key Id and Key Secret are required to enable the webhook.');
error_log('Key Id and Key Secret are required.');
return;
}

Expand All @@ -299,8 +299,20 @@ public function autoEnableWebhook()
}
}

if(in_array($_SERVER['SERVER_ADDR'], ["127.0.0.1","::1"]))
$domain = parse_url($webhookUrl, PHP_URL_HOST);

$domain_ip = gethostbyname($domain);

if (!filter_var($domain_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
{
$this->update_option( 'enable_webhook', 'no' );

?>
<div class="notice error is-dismissible" >
<p><b><?php _e( 'Could not enable webhook for localhost server.'); ?><b></p>
</div>
<?php

error_log('Could not enable webhook for localhost');
return;
}
Expand Down Expand Up @@ -351,12 +363,15 @@ public function autoEnableWebhook()

$webhook = $this->webhookAPI("GET", "webhooks");

foreach ($webhook['items'] as $key => $value)
if(count($webhook) > 0)
{
if($value['url'] === $webhookUrl)
foreach ($webhook['items'] as $key => $value)
{
$webhookExist = true;
$webhookId = $value['id'];
if($value['url'] === $webhookUrl)
{
$webhookExist = true;
$webhookId = $value['id'];
}
}
}

Expand Down

0 comments on commit b83df3d

Please sign in to comment.