Skip to content

Commit

Permalink
Merge pull request #194 from razorpay/auto_webhook_config
Browse files Browse the repository at this point in the history
Handled the null event and secret field case for auto webhook
  • Loading branch information
ChetanGN authored May 31, 2021
2 parents 745bf5a + 1b42e90 commit ba76cde
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
== Changelog ==

= 2.7.1 =
* Update the Razorpay Order notes key.
* Updated the Razorpay Order notes key from woocommerce_order_id to woocommerce_order_number.

= 2.7.0 =
* Added auto-webhook setup feature.
Expand Down
37 changes: 30 additions & 7 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,23 @@ public function autoEnableWebhook()
$webhookExist = false;
$webhookUrl = esc_url(admin_url('admin-post.php')) . '?action=rzp_wc_webhook';

$enabled = $this->getSetting('enable_webhook');
$secret = $this->getSetting('webhook_secret');
$key_id = $this->getSetting('key_id');
$key_secret = $this->getSetting('key_secret');
$enabled = $this->getSetting('enable_webhook');
$secret = $this->getSetting('webhook_secret');

//validating the key id and key secret set properly or not.
if($key_id == null || $key_secret == null)
{
?>
<div class="notice error is-dismissible" >
<p><b><?php _e( 'Key Id and Key Secret can`t be empty'); ?><b></p>
</div>
<?php

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

$eventsSubscribe = $this->getSetting('webhook_events');

Expand All @@ -286,7 +301,7 @@ public function autoEnableWebhook()

if(in_array($_SERVER['SERVER_ADDR'], ["127.0.0.1","::1"]))
{
error_log(json_encode('Could not enable webhook for localhost'));
error_log('Could not enable webhook for localhost');
return;
}

Expand All @@ -299,22 +314,30 @@ public function autoEnableWebhook()
}
else
{
if (empty($eventsSubscribe) === true)
//validating event is not empty
if(empty($eventsSubscribe) === true)
{
?>
<div class="notice error is-dismissible" >
<p><b><?php _e( 'Please select the atlease one webhook event to enable webhook.' ); ?><b></p>
<p><b><?php _e( 'At least one webhook event needs to be subscribed to enable webhook.'); ?><b></p>
</div>
<?php

error_log('At least one webhook event needs to be subscribed to enable webhook.');
return;
}

if (empty($secret) === true)
//validating webhook secret is not empty
if(empty($secret) === true)
{
?>
<div class="notice error is-dismissible" >
<p><b><?php _e( 'Please enter the webhook secret.' ); ?><b></p>
<p><b><?php _e( 'Webhook secret field can`t be empty.' ); ?><b></p>
</div>
<?php

error_log('Webhook secret field can`t be empty.');
return;
}

$data = [
Expand Down

0 comments on commit ba76cde

Please sign in to comment.