Skip to content

Commit

Permalink
Merge pull request #274 from razorpay/auto-webhook-bug-fix
Browse files Browse the repository at this point in the history
buf fix
  • Loading branch information
jampulanaveen authored May 20, 2022
2 parents cc5a02c + 1c6603f commit f527d01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 4 additions & 7 deletions includes/razorpay-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ public function process()
return;
}

$enabled = $this->razorpay->getSetting('enable_webhook');

if (($enabled === 'yes') and
(empty($data['event']) === false)) {


if (empty($data['event']) === false) {
// Skip the webhook if not the valid data and event
if ($this->shouldConsumeWebhook($data) === false) {
return;
}

if (isset($_SERVER['HTTP_X_RAZORPAY_SIGNATURE']) === true) {
$razorpayWebhookSecret = $this->razorpay->getSetting('webhook_secret');

$razorpayWebhookSecret = get_option('rzp_webhook_secret');
//
// If the webhook secret isn't set on wordpress, return
//
Expand Down
10 changes: 7 additions & 3 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function autoEnableWebhook()
$enabled = true;
$alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
$secret = substr(str_shuffle($alphanumericString), 0, 20);

update_option('rzp_webhook_secret', $secret);
$getWebhookFlag = get_option('webhook_enable_flag');
$time = time();

Expand Down Expand Up @@ -338,7 +338,6 @@ public function autoEnableWebhook()

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" >
Expand Down Expand Up @@ -588,13 +587,18 @@ private function getRedirectUrl($orderId)
protected function getRazorpayPaymentParams($orderId)
{
$getWebhookFlag = get_option('webhook_enable_flag');

$time = time();
if (!empty($getWebhookFlag))
{
if ($getWebhookFlag + 86400 < time())
{
$this->autoEnableWebhook();
}
}
else
{
update_option('webhook_enable_flag', $time);
$this->autoEnableWebhook();
}
rzpLogInfo("getRazorpayPaymentParams $orderId");
$razorpayOrderId = $this->createOrGetRazorpayOrderId($orderId);
Expand Down

0 comments on commit f527d01

Please sign in to comment.