-
Notifications
You must be signed in to change notification settings - Fork 7
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 fixes] Fixed minor bugs in the code #1
Conversation
8bace96
to
af650ad
Compare
af650ad
to
c27f415
Compare
@@ -1,14 +1,27 @@ | |||
<?php | |||
|
|||
require_once __DIR__.'/../razorpay-payments.php'; | |||
require_once __DIR__.'/../razorpay-sdk/Razorpay.php'; | |||
$pluginRoot = WP_PLUGIN_DIR . '/' . RAZORPAY_WOOCOMMERCE_PLUGIN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verify if require is necessary here. The script is getting called from razorpay-subscriptions.php, which already includes everything.
protected $razorpay; | ||
protected $api; | ||
|
||
const PAYMENT_AUTHORIZED = 'payment.authorized'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed. already defined in parent class
{ | ||
const RAZORPAY_SUBSCRIPTION_ID = 'razorpay_subscription_id'; | ||
protected $razorpay; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already defined as protected in parent class. Not needed
const PAYMENT_AUTHORIZED = 'payment.authorized'; | ||
const PAYMENT_FAILED = 'payment.failed'; | ||
|
||
function __construct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove, already same defined in parent class
@@ -21,11 +34,11 @@ public function process() | |||
return; | |||
} | |||
|
|||
if ($this->razorpay->enable_webhook === 'yes' && empty($data['event']) === false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove process method, exactly same as in parent class
return $this->processSubscription($orderId, $paymentId); | ||
$invoiceId = $data['payload']['payment']['entity']['invoice_id']; | ||
|
||
$invoice = $this->api->invoice->fetch($invoiceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try/catch needed
@@ -148,7 +168,7 @@ protected function paymentAuthorized($data) | |||
* | |||
* @param $data | |||
*/ | |||
protected function paymentFailed($data) | |||
protected function paymentFailed(array $data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs fixing
return $this->processSubscription($orderId, $paymentId); | ||
$invoiceId = $data['payload']['payment']['entity']['invoice_id']; | ||
|
||
$invoice = $this->getInvoice($invoiceId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to getSubscription, and throw an exception if no subscription is found
} | ||
} | ||
|
||
exit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't exit for cases you aren't handling
|
||
class RZP_Subscription_Webhook extends RZP_Webhook | ||
{ | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a similar comment like the one at https://github.com/razorpay/razorpay-woocommerce/pull/60/files#diff-5ceb8b9921fd0248b3e9e9669726b4d1R24 for this plugin as well
/** | ||
* Helper method used to handle all subscription processing | ||
* | ||
* @param $orderId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderId is not a param
*/ | ||
protected function processSubscription($paymentId, $subscriptionId, $success = true) | ||
{ | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment in wrong place
catch (Exception $e) | ||
{ | ||
$message = $e->getMessage(); | ||
return 'RAZORPAY ERROR: Subscription fetch failed with the message \'' . $message . '\''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string interpolation instead for simple strings.
|
||
$orderId = $subscription->notes->woocommerce_order_id; | ||
|
||
if ($success === false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to the top?
includes/razorpay-subscriptions.php
Outdated
@@ -1,330 +1,216 @@ | |||
<?php | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include files don't need this
Please fix this file?
Bug fixes in the code