Skip to content

Commit 849b8b5

Browse files
authored
Add 'get_supported_currencies' function for klarna (#3378)
* add 'get_supported_currencies' function for klarna * add comment * add safety check
1 parent bf88cd5 commit 849b8b5

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* Fix - Address QIT PHPStan test errors.
2525
* Update - Specify the JS Stripe API version as 2024-06-20.
2626
* Fix - Ensure payment tokens are detached from Stripe when a user is deleted, regardless of if the admin user has a Stripe account.
27+
* Fix - Address Klarna availability based on correct presentment currency rules.
2728

2829
= 8.6.1 - 2024-08-09 =
2930
* Tweak - Improves the wording of the invalid Stripe keys errors, instructing merchants to click the "Configure connection" button instead of manually setting the keys.

includes/payment-methods/class-wc-stripe-upe-payment-method-klarna.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,39 @@ public function get_available_billing_countries() {
8282
return parent::get_available_billing_countries();
8383
}
8484

85+
/**
86+
* Returns the currencies this UPE method supports for the Stripe account.
87+
*
88+
* Klarna has unique requirements for domestic transactions. The customer must be located in the same country as the merchant's Stripe account and the currency must match.
89+
* - Stores connected to US account and presenting USD can only transact with customers located in the US.
90+
* - Stores connected to US account and presenting non-USD currency can not transact with customers irrespective of their location.
91+
*
92+
* Additionally, if the merchant is in the EEA, the country they can transact with depends on the presentment currency.
93+
* EUR stores can transact with other EUR countries. Stores with currencies like GBP, CHF, etc. can only transact with customers located in those countries.
94+
* This creates the following unique situations:
95+
* - Stores presenting EUR, with a Stripe account in any EEA country including Switzerland or the UK can transact with countries where Euros are the standard currency: AT, BE, FI, FR, GR, DE, IE, IT, NL, PT, ES.
96+
* - Stores presenting GBP with a Stripe account in any EEA country including Switzerland or the UK can transact with: GB.
97+
* - Stores presenting NOK with a Stripe account in France, for example, cannot sell into France. They can only sell into Norway.
98+
*
99+
* @return array Supported currencies.
100+
*/
101+
public function get_supported_currencies() {
102+
$account = WC_Stripe::get_instance()->account->get_cached_account_data();
103+
$account_country = strtoupper( $account['country'] ?? '' );
104+
105+
// Countries in the EEA + UK and Switzerland can transact across all other EEA countries as long as the currency matches.
106+
$eea_countries = array_merge( WC_Stripe_Helper::get_european_economic_area_countries(), [ 'CH', 'GB' ] );
107+
108+
// Countries outside the EEA can only transact with customers in their own currency.
109+
if ( ! in_array( $account_country, $eea_countries, true ) ) {
110+
return [ strtoupper( $account['default_currency'] ?? '' ) ];
111+
}
112+
113+
// Stripe account in EEA + UK and Switzerland can present the following as store currencies.
114+
// EEA currencies can only transact with countries where that currency is the standard currency.
115+
return [ 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'NOK', 'PLN', 'SEK' ];
116+
}
117+
85118
/**
86119
* Returns whether the payment method is available for the Stripe account's country.
87120
*

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
152152
* Fix - Address QIT PHPStan test errors.
153153
* Update - Specify the JS Stripe API version as 2024-06-20.
154154
* Fix - Ensure payment tokens are detached from Stripe when a user is deleted, regardless of if the admin user has a Stripe account.
155+
* Fix - Address Klarna availability based on correct presentment currency rules.
155156

156157
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/phpunit/test-class-wc-stripe-upe-payment-method.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ public function test_payment_methods_with_domestic_restrictions_are_disabled_on_
525525
*/
526526
public function test_payment_methods_with_domestic_restrictions_are_enabled_on_currency_match() {
527527
WC_Stripe_Helper::update_main_stripe_settings( [ 'testmode' => 'yes' ] );
528+
WC_Stripe::get_instance()->account = $this->getMockBuilder( 'WC_Stripe_Account' )
529+
->disableOriginalConstructor()
530+
->setMethods(
531+
[
532+
'get_cached_account_data',
533+
]
534+
)
535+
->getMock();
536+
WC_Stripe::get_instance()->account->method( 'get_cached_account_data' )->willReturn(
537+
[
538+
'country' => 'US',
539+
'default_currency' => 'USD',
540+
]
541+
);
528542

529543
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', 'USD', true );
530544

0 commit comments

Comments
 (0)