Skip to content

Restrict Affirm and Klarna to domestic and cross EEA border transactions #3108

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

Merged
merged 8 commits into from
May 5, 2024
42 changes: 42 additions & 0 deletions includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,4 +1213,46 @@ public static function remove_payment_awaiting_action( $order, $save = true ) {
$order->save();
}
}

/**
* Returns the list of countries in the European Economic Area (EEA).
*
* Based on the list documented at https://www.gov.uk/eu-eea.
*
* @return string[]
*/
public static function get_european_economic_area_countries() {
return [
'AT', // Austria.
'BE', // Belgium.
'BG', // Bulgaria.
'HR', // Croatia.
'CY', // Cyprus.
'CZ', // Czech Republic.
'DK', // Denmark.
'EE', // Estonia.
'FI', // Finland.
'FR', // France.
'DE', // Germany.
'GR', // Greece.
'HU', // Hungary.
'IE', // Ireland.
'IS', // Iceland
'IT', // Italy.
'LV', // Latvia.
'LI', // Liechtenstein.
'LT', // Lithuania.
'LU', // Luxembourg.
'MT', // Malta.
'NO', // Norway.
'NL', // Netherlands.
'PL', // Poland.
'PT', // Portugal.
'RO', // Romania.
'SK', // Slovakia.
'SI', // Slovenia.
'ES', // Spain.
'SE', // Sweden.
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private function get_enabled_payment_method_config() {
'title' => $payment_method->get_title(),
'testingInstructions' => $payment_method->get_testing_instructions(),
'showSaveOption' => $this->should_upe_payment_method_show_save_option( $payment_method ),
'countries' => $payment_method->get_countries(),
'countries' => $payment_method->get_available_billing_countries(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,27 @@ public function __construct() {
'woocommerce-gateway-stripe'
);
}

/**
* Returns the supported customer locations for which charges for a payment method can be processed.
*
* Klarna has unique requirements for domestic transactions. The customer must be located in the same country as the merchant's Stripe account.
* Additionally, merchants located in the EEA can transact with customers located across all other EEA countries - including Switzerland and the UK.
*
* @return array Supported customer locations.
*/
public function get_available_billing_countries() {
$account = WC_Stripe::get_instance()->account->get_cached_account_data();
$account_country = strtoupper( $account['country'] );

// Countries in the EEA can transact across all other EEA countries. This includes Switzerland and the UK who aren't strictly in the EU.
$eea_countries = array_merge( WC_Stripe_Helper::get_european_economic_area_countries(), [ 'CH', 'GB' ] );

// If the merchant is in the EEA, all EEA countries are supported.
if ( in_array( $account_country, $eea_countries, true ) ) {
return $eea_countries;
}

return parent::get_available_billing_countries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,13 @@ public function is_enabled_at_checkout( $order_id = null, $account_domestic_curr
/**
* Returns the supported customer locations for which charges for a payment method can be processed.
*
* @return array
* @return array Supported customer locations.
*/
public function get_countries() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function was only used to populate the JS data with a list of eligible countries. Given I've changed it's purpose to return billing countries, I changed the name. Because this function is unreleased, there are no backwards compatibility concerns here.

return $this->supported_countries;
public function get_available_billing_countries() {
$account = WC_Stripe::get_instance()->account->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';

return $this->has_domestic_transactions_restrictions() ? [ $account_country ] : $this->supported_countries;
}

/**
Expand Down