-
Notifications
You must be signed in to change notification settings - Fork 14
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
Examine currency before recognizing as an available payment method #120
Conversation
54a7e96
to
d506b55
Compare
d506b55
to
196369d
Compare
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.
Also, about supporting multi currency, I belive Komoju has currency conversion feature so I am not sure preventing user to pay when the currencies are different.
Below is an example that JPY payment method trying to pay KRW. So, in this case I think we should not filter the payment methods despite WC currency and payment currency is different.
class-wc-settings-page-komoju.php
Outdated
if (isset($methods_by_slug[$slug])) { | ||
$slug = $payment_method['type_slug']; | ||
$pm_currency = $payment_method['currency']; | ||
if (isset($methods_by_slug[$slug]) && $pm_currency !== $wc_currency) { |
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.
This seems wrong to me.
This was checking methods_by_slug
is already set, we are skipping the process.
Now it is checking When this slug is already set AND the cureencies are different, then skip
Which means, in the first check when this slug is not set yet, it will always skip this if statement and will set the slug.
Based on the above reason, this should be ||
or !(A && B)
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.
Good point. Actually I intentionally made this logic in this way.
Given that WC has USD
as the default "default currency", it's possible that this part of code is called with the default currency set in non-JPY
. Then, if we always reject payment methods with mismatched currency (like isset($methods_by_slug[$slug]) || $pm_currency !== $wc_currency
), it can end up with no payment method available, because PMs such as Konbini are available only in JPY.
Therefore I relaxed the condition. With the current logic, it will accept payment methods if 1) the currency matches, OR if 2) there is no alternative one available with the same type_slug
. IOW, as negation, it rejects PMs that 1) have alternatives, AND 2) the currency does not match.
Yep indeed I first thought it was a bad idea, and eventually I found out that it would be better, seeing how my first attempt here broke our tests.
That said I think that's not an intuitive logic, I'll add a comment into the code for future reference!
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.
Okay, I see. This is not about preventing registering the payment method but changing the priority.
In this case, I recommend to change the logic like below for the better redability.
// If $slug is not set, register
if (!isset($methods_by_slug[$slug])) {
$methods_by_slug[$slug] = $payment_method;
} else {
// If $slug is already registered and
// the payment currency matches the WooCommerce currency then override it
if ($pm_currency === $wc_currency) {
$methods_by_slug[$slug] = $payment_method;
}
}
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.
Good call, I've pushed another commit! 🙏
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.
Thanks! 👍
Right, this was the decisive fact to employ the logic of accepting PMs that 1) the currency matches, OR if 2) there is no alternative one available with the same |
Now I understand. It is about the overriding the priority. 😸 No problem. I thought this is about limiting user's payment methods. |
By default KOMOJU merchants have multicurrency enabled, with which there can by multiple payment methods with the same
type_slug
, but with differentcurrency
or sets ofsubtypes
(card brands).This PR makes sure that the plugin disposes only payment methods that don't support the currency configured for the WooCommerce instance.