Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions admin/controller/extension/payment/razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ class ControllerExtensionPaymentRazorpay extends Controller
{
private $error = array();

public function install()
{
$result = $this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "order LIKE 'webhook_flag'");
if($result->num_rows == 0){

$sql = "ALTER TABLE `".DB_PREFIX."order` ADD `webhook_flag` INT( 11 ) NOT NULL DEFAULT 0";
$this->db->query($sql);
}
}

public function uninstall() {

$result = $this->db->query("SHOW COLUMNS FROM " . DB_PREFIX . "order LIKE 'webhook_flag'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move DB changes it inside model

if($result->num_rows > 0){
$sql = "ALTER TABLE `".DB_PREFIX."order` DROP COLUMN `webhook_flag`";
$this->db->query($sql);
}
}

public function index()
{
$this->language->load('extension/payment/razorpay');
Expand Down
13 changes: 10 additions & 3 deletions catalog/controller/extension/payment/razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if this can be loaded one time only in class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramth05 have checked for this, tried using class instance but it not working out.

$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
Expand Down
16 changes: 16 additions & 0 deletions catalog/model/extension/payment/razorpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 webhook_flag = '" . (int)$flag . "' WHERE order_id = '" . (int)$order_id . "'");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this table if belongs to opencart, rename the column to razorpay_webhook_count


}

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]['webhook_flag'])){
return $query->rows[0]['webhook_flag'];
}

}
}