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 fixes] Fixed minor bugs in the code #1

Merged
merged 6 commits into from
Sep 28, 2017
Merged

[bug fixes] Fixed minor bugs in the code #1

merged 6 commits into from
Sep 28, 2017

Conversation

mayankamencherla
Copy link
Contributor

Bug fixes in the code

@@ -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;
Copy link
Contributor

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';
Copy link
Contributor

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;
Copy link
Contributor

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()
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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
{
/**
Copy link
Contributor

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
Copy link
Contributor

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)
{
//
Copy link
Contributor

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 . '\'';
Copy link
Contributor

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)
Copy link
Contributor

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?

@@ -1,330 +1,216 @@
<?php
/*
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants