Skip to content

Commit

Permalink
Merge pull request #282 from razorpay/bugfix-webhook
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
jampulanaveen authored May 23, 2022
2 parents 55a752b + 8976825 commit 8de4f0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
29 changes: 21 additions & 8 deletions includes/razorpay-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,35 @@ public function process()
return;
}



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

$orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_number'];

// Skip the webhook if not the valid data and event
if ($this->shouldConsumeWebhook($data) === false) {
rzpLogInfo("Woocommerce orderId: $orderId webhook process exited in shouldConsumeWebhook function");

return;
}
if (isset($_SERVER['HTTP_X_RAZORPAY_SIGNATURE']) === true) {
$razorpayWebhookSecret = get_option('rzp_webhook_secret');
$razorpayWebhookSecret = $this->razorpay->getSetting('webhook_secret');
//
// If the webhook secret isn't set on wordpress, return
//
if (empty($razorpayWebhookSecret) === true) {
return;
}
if (empty($razorpayWebhookSecret) === true ) {
$razorpayWebhookSecret = get_option('rzp_webhook_secret');
if (empty($razorpayWebhookSecret) === false){
$this->razorpay->update_option('webhook_secret', $razorpayWebhookSecret);
}
else
{
rzpLogInfo("Woocommerce orderId: $orderId webhook process exited due to secret not available");

return;
}
}


try
{
$this->api->utility->verifyWebhookSignature($post,
Expand All @@ -104,12 +117,12 @@ public function process()
'event' => 'razorpay.wc.signature.verify_failed',
);

rzpLogError(json_encode($log));

error_log(json_encode($log));
return;
}

$orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_number'];

rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated");

switch ($data['event']) {
Expand Down
5 changes: 3 additions & 2 deletions woo-razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public function autoEnableWebhook()
$enabled = true;
$alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
$secret = substr(str_shuffle($alphanumericString), 0, 20);
update_option('rzp_webhook_secret', $secret);

$this->update_option('webhook_secret', $secret);
$getWebhookFlag = get_option('webhook_enable_flag');
$time = time();

Expand Down Expand Up @@ -591,7 +592,7 @@ protected function getRazorpayPaymentParams($orderId)
{
$getWebhookFlag = get_option('webhook_enable_flag');
$time = time();
if (!empty($getWebhookFlag))
if (empty($getWebhookFlag) == false)
{
if ($getWebhookFlag + 86400 < time())
{
Expand Down

0 comments on commit 8de4f0b

Please sign in to comment.