-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add support for currency switcher plugin #46
Conversation
albingeorge
commented
Jun 23, 2017
•
edited by harman28
Loading
edited by harman28
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.
Please test against both WC 2.4 and 3.x
const BAD_REQUEST_ERROR = 'BAD_REQUEST_ERROR'; | ||
const SERVER_ERROR = 'SERVER_ERROR'; | ||
const GATEWAY_ERROR = 'GATEWAY_ERROR'; | ||
const BAD_REQUEST_ERROR = 'BAD_REQUEST_ERROR'; |
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.
Create a new class for this. Try not to make any changes to sdk that we can't push back upstream.
|
||
namespace Razorpay\Api\Errors; | ||
|
||
class InvalidCurrencyError extends Error |
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.
Put this in a different directory and namespace?
razorpay-payments.php
Outdated
* | ||
* @return void | ||
*/ | ||
protected function validateOrderCreateData($data): Array |
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.
The flow here seems to be using exceptions pretty loosely. Instead of:
- Setup data
- Validate (if, check, throw)
- Catch-> Fix
- Proceed
Why not just check the conditions upfront:
if(INR) ->
else if ($installed and not INR)
else if(not INR)
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.
- Minor changes
- Please add screenshots on the PR for both the happy and sad flows.
includes/Errors/ErrorCode.php
Outdated
|
||
class ErrorCode extends ApiErrors\ErrorCode | ||
{ | ||
|
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.
nit: Extra newline
includes/Errors/ErrorCode.php
Outdated
@@ -0,0 +1,21 @@ | |||
<?php | |||
|
|||
namespace RazorpayWoo\Errors; |
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.
If we are creating a namespace, let us keep it as Razorpay\Woocommerce\
razorpay-payments.php
Outdated
|
||
if (array_key_exists('INR', $currencies) and array_key_exists($data['currency'], $currencies)) | ||
{ | ||
// Convert the currency to INR using the rates fetched from the Currency Switcher 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.
Are there any specific instructions someone would need to follow to add INR in this list?
Can you write a helper guide at https://github.com/razorpay/razorpay-woocommerce/wiki/Multi-Currency (screenshots will be very helpful)
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.
Added the instructions to get this working on the above wiki page.
razorpay-payments.php
Outdated
{ | ||
// Convert the currency to INR using the rates fetched from the Currency Switcher plugin | ||
$data['amount'] = round( | ||
(($data['amount'] * $currencies['INR']['rate']) / ($currencies[$data['currency']]['rate'] == 0 ? 1 : $currencies[$data['currency']]['rate'])), |
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.
too long, use if instead?
} | ||
else | ||
{ | ||
throw new Errors\BadRequestError( |
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.
How does this show up during a payment attempt?
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.
I've added screenshots below.
If the currency is not INR: If the currency swicth plugin is installed If both INR and current currency is configured in the currency switch plugin: Convert to INR and process further Else Throw an error asking to configure the CS plugin with both INR and the current currency Else Throw an error saying currency is not supported
It's not required. All we need is the error codes which we add via ErrorCode.php
The currency switcher plugin sets the currency rate to 0, if the selected currency is the same as default currency set from WooCommerce plugin
39f956c
to
0159f33
Compare
@captn3m0 Can we hide the message 'Thank you for your order, please click the button below to pay with Razorpay.' based on whether there is an error shown? Or should we change the verbiage of the error message to something simpler like 'RAZORPAY ERROR: Payment failed'. Previously, we used to show 'RAZORPAY ERROR: Api could not be reached' for every payment failures(even if the API was reachable). |
Yup, sounds like a good idea.
The idea was not to disclose anything sensitive by accident. If we are certain that nothing sensitive will be revealed by the exception message (ie, we are only catching known exceptions, and any other generic exception gets a generic message), I'm happy with switching this to detailed errors. |
Regarding the catching of exception, as of now, we're catching Instead, we can catch only the |
Yup, that is what I was suggesting as well 👍 |
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.
Minor changes.
razorpay-payments.php
Outdated
'description' => $productinfo, | ||
'notes' => array( | ||
'woocommerce_order_id' => $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.
closing bracket should align on left
razorpay-payments.php
Outdated
// If the currenct currency is the same as the default currency set in WooCommerce, | ||
// Currency Switcher plugin sets the rate of currenct currency as 0, because of which | ||
// we need to set this to 1 here if it's value is 0 | ||
$current_currency_rate = ($currencies[$data['currency']]['rate'] == 0 ? 1 : $currencies[$data['currency']]['rate']); |
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.
camelCase everywhere, unless wordpress hook-related things
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.
LGTM. Squash merge please.