diff --git a/admin/controller/extension/payment/razorpay.php b/admin/controller/extension/payment/razorpay.php index 2f710b2..abdbfd3 100755 --- a/admin/controller/extension/payment/razorpay.php +++ b/admin/controller/extension/payment/razorpay.php @@ -4,6 +4,19 @@ class ControllerExtensionPaymentRazorpay extends Controller { private $error = array(); + public function install() + { + $this->load->model('extension/payment/razorpay'); + $this->model_extension_payment_razorpay->addWebhookColumn(); + } + + public function uninstall() { + + $this->load->model('extension/payment/razorpay'); + $this->model_extension_payment_razorpay->removeWebhookColumn(); + + } + public function index() { $this->language->load('extension/payment/razorpay'); diff --git a/admin/model/extension/payment/razorpay.php b/admin/model/extension/payment/razorpay.php new file mode 100755 index 0000000..d4c4149 --- /dev/null +++ b/admin/model/extension/payment/razorpay.php @@ -0,0 +1,23 @@ +db->query("SHOW COLUMNS FROM " . DB_PREFIX . "order LIKE 'razorpay_webhook_count'"); + if($result->num_rows == 0){ + + $sql = "ALTER TABLE `".DB_PREFIX."order` ADD `razorpay_webhook_count` INT( 11 ) NOT NULL DEFAULT 0"; + $this->db->query($sql); + } + } + + public function removeWebhookColumn(){ + + $result = $this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "order LIKE 'razorpay_webhook_count'"); + if($result->num_rows > 0){ + $sql = "ALTER TABLE `".DB_PREFIX."order` DROP COLUMN `razorpay_webhook_count`"; + $this->db->query($sql); + } + } +} \ No newline at end of file diff --git a/catalog/controller/extension/payment/razorpay.php b/catalog/controller/extension/payment/razorpay.php index d443886..4e39fa1 100755 --- a/catalog/controller/extension/payment/razorpay.php +++ b/catalog/controller/extension/payment/razorpay.php @@ -120,8 +120,7 @@ public function callback() ); $api->utility->verifyPaymentSignature($attributes); - - $this->model_checkout_order->addOrderHistory($merchant_order_id, $this->config->get('payment_razorpay_order_status_id'), 'Payment Successful. Razorpay Payment Id:'.$razorpay_payment_id, true); + $this->model_checkout_order->addOrderHistory($merchant_order_id, $this->config->get('payment_razorpay_order_status_id'), 'Payment Successful. Razorpay Payment Id:'.$razorpay_payment_id, true); $this->response->redirect($this->url->link('checkout/success', '', true)); } catch(\Razorpay\Api\Errors\SignatureVerificationError $e) @@ -212,7 +211,15 @@ protected function orderPaid(array $data) $merchant_order_id = $data['payload']['payment']['entity']['notes']['opencart_order_id']; $razorpay_payment_id = $data['payload']['payment']['entity']['id']; if(isset($merchant_order_id) === true) - { + { + $this->load->model('extension/payment/razorpay'); + $order_flag = $this->model_extension_payment_razorpay->getWebhookFlag($merchant_order_id); + if($order_flag == 0){ + $flag = 1; + $this->model_extension_payment_razorpay->setWebhookFlag($merchant_order_id,$flag); + header('Status: 400 ', true, 400); + exit; + } $order_info = $this->model_checkout_order->getOrder($merchant_order_id); if($order_info['payment_code'] === 'razorpay' and diff --git a/catalog/model/extension/payment/razorpay.php b/catalog/model/extension/payment/razorpay.php index 6f117b8..2b19b62 100755 --- a/catalog/model/extension/payment/razorpay.php +++ b/catalog/model/extension/payment/razorpay.php @@ -15,4 +15,20 @@ public function getMethod($address, $total) return $method_data; } + + public function setWebhookFlag($order_id,$flag) { + + $this->db->query("UPDATE " . DB_PREFIX . "order SET razorpay_webhook_count = '" . (int)$flag . "' WHERE order_id = '" . (int)$order_id . "'"); + + } + + public function getWebhookFlag($order_id) { + + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order WHERE order_id = '" . (int)$order_id . "'"); + + if(isset($query->rows[0]['razorpay_webhook_count'])){ + return $query->rows[0]['razorpay_webhook_count']; + } + + } }