Add support for currency switcher plugin#46
Conversation
captn3m0
left a comment
There was a problem hiding this comment.
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.
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.
Put this in a different directory and namespace?
| * | ||
| * @return void | ||
| */ | ||
| protected function validateOrderCreateData($data): Array |
There was a problem hiding this comment.
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)
captn3m0
left a comment
There was a problem hiding this comment.
- Minor changes
- Please add screenshots on the PR for both the happy and sad flows.
|
|
||
| class ErrorCode extends ApiErrors\ErrorCode | ||
| { | ||
|
|
| @@ -0,0 +1,21 @@ | |||
| <?php | |||
|
|
|||
| namespace RazorpayWoo\Errors; | |||
There was a problem hiding this comment.
If we are creating a namespace, let us keep it as Razorpay\Woocommerce\
|
|
||
| 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.
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.
Added the instructions to get this working on the above wiki page.
| { | ||
| // 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.
too long, use if instead?
| } | ||
| else | ||
| { | ||
| throw new Errors\BadRequestError( |
There was a problem hiding this comment.
How does this show up during a payment attempt?
There was a problem hiding this comment.
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 👍 |
| 'description' => $productinfo, | ||
| 'notes' => array( | ||
| 'woocommerce_order_id' => $orderId | ||
| ), |
There was a problem hiding this comment.
closing bracket should align on left
| // 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.
camelCase everywhere, unless wordpress hook-related things
captn3m0
left a comment
There was a problem hiding this comment.
LGTM. Squash merge please.




Uh oh!
There was an error while loading. Please reload this page.