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

Add support for currency switcher plugin #46

Merged
merged 9 commits into from
Jun 30, 2017

Conversation

albingeorge
Copy link
Contributor

@albingeorge albingeorge commented Jun 23, 2017

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

@albingeorge albingeorge requested a review from captn3m0 June 23, 2017 14:05
Copy link
Contributor

@captn3m0 captn3m0 left a 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';
Copy link
Contributor

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

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?

*
* @return void
*/
protected function validateOrderCreateData($data): Array
Copy link
Contributor

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:

  1. Setup data
  2. Validate (if, check, throw)
  3. Catch-> Fix
  4. Proceed

Why not just check the conditions upfront:

if(INR) ->
else if ($installed and not INR)
else if(not INR)

Copy link
Contributor

@captn3m0 captn3m0 left a comment

Choose a reason for hiding this comment

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

  1. Minor changes
  2. Please add screenshots on the PR for both the happy and sad flows.


class ErrorCode extends ApiErrors\ErrorCode
{

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Extra newline

@@ -0,0 +1,21 @@
<?php

namespace RazorpayWoo\Errors;
Copy link
Contributor

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\


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

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)

Copy link
Contributor Author

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.

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

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

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?

Copy link
Contributor Author

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
@albingeorge albingeorge force-pushed the support-currency-switcher branch from 39f956c to 0159f33 Compare June 28, 2017 07:13
@albingeorge
Copy link
Contributor Author

Screenshots

  1. Currency set from WooCommerce: GBP
    Currency Switcher plugin: Not installed

plugin_missing

  1. Currency set from WooCommerce: USD
    Currency Switcher plugin: Installed, INR not added

currency_not_configured

  1. Currency set from WooCommerce: USD
    Currency Switcher plugin: Installed and configured

order_success

@captn3m0
Copy link
Contributor

Can we improve this wording? Saying pay button where none exists doesn't look good.

image

Same for the first case as well.

@albingeorge
Copy link
Contributor Author

@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).

@captn3m0
Copy link
Contributor

Can we hide the message

Yup, sounds like a good idea.

Previously, we used to show 'RAZORPAY ERROR: Api could not be reached' for every payment failures(even if the API was reachable).

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.

@albingeorge
Copy link
Contributor Author

Regarding the catching of exception, as of now, we're catching Exception and the message from the same is pushed to the front-end.

Instead, we can catch only the BadRequestError exception and for the rest of the exceptions, we can show some generic message like 'RAZORPAY ERROR: Payment failed'. Let me know if that works.

@captn3m0
Copy link
Contributor

Yup, that is what I was suggesting as well 👍

Copy link
Contributor

@captn3m0 captn3m0 left a comment

Choose a reason for hiding this comment

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

Minor changes.

'description' => $productinfo,
'notes' => array(
'woocommerce_order_id' => $orderId
),
Copy link
Contributor

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

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

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

@captn3m0 captn3m0 mentioned this pull request Jun 29, 2017
4 tasks
Copy link
Contributor

@captn3m0 captn3m0 left a 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.

@albingeorge albingeorge merged commit 9a401c6 into master Jun 30, 2017
@albingeorge albingeorge deleted the support-currency-switcher branch June 30, 2017 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants