This commit is contained in:
emmymayo
2025-02-05 23:15:46 +01:00
commit 7269c99357
16995 changed files with 3389680 additions and 0 deletions
@@ -0,0 +1,61 @@
<?php
/**
* Class Affirm_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Affirm Payment Method class extending UPE base class
*/
class Affirm_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'affirm';
/**
* Constructor for Affirm payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo.svg', WCPAY_PLUGIN_FILE );
$this->dark_icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo-dark.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR ];
$this->accept_only_domestic_payment = true;
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA ];
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Affirm', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,79 @@
<?php
/**
* Class Afterpay_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Afterpay Payment Method class extending UPE base class
*/
class Afterpay_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'afterpay_clearpay';
/**
* Constructor for Afterpay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/afterpay-logo.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR, Currency_Code::AUSTRALIAN_DOLLAR, Currency_Code::NEW_ZEALAND_DOLLAR, Currency_Code::POUND_STERLING ];
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA, Country_Code::AUSTRALIA, Country_Code::NEW_ZEALAND, Country_Code::UNITED_KINGDOM ];
$this->accept_only_domestic_payment = true;
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
}
/**
* Returns payment method title.
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Payment details from charge object. Not used by this class.
* @return string|null
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( 'GB' === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}
return __( 'Afterpay', 'woocommerce-payments' );
}
/**
* Returns payment method icon.
*
* @param string|null $account_country Country of merchants account.
* @return string|null
*/
public function get_icon( ?string $account_country = null ) {
if ( 'GB' === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}
return plugins_url( 'assets/images/payment-methods/afterpay-badge.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class Bancontact_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Bancontact Payment Method class extending UPE base class
*/
class Bancontact_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'bancontact';
/**
* Constructor for Bancontact payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Bancontact';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/bancontact.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::BELGIUM ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class Becs_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Becs Payment Method class extending UPE base class
*/
class Becs_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'au_becs_debit';
/**
* Constructor for Becs payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'BECS Direct Debit';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::AUSTRALIAN_DOLLAR ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/bank-debit.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRALIA ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return __( '<strong>Test mode:</strong> use the test account number <number>000123456</number>. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a>here</a>.', 'woocommerce-payments' );
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Class CC_Payment_Gateway
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payment_Gateway_WCPay;
use WC_Payments_Account;
use WC_Payments_Action_Scheduler_Service;
use WC_Payments_API_Client;
use WC_Payments_Customer_Service;
use WC_Payments_Token_Service;
use WC_Payments_Order_Service;
/**
* Credit card Payment method.
* Right now behaves exactly like WC_Payment_Gateway_WCPay for max compatibility.
*/
class CC_Payment_Gateway extends WC_Payment_Gateway_WCPay {
}
@@ -0,0 +1,82 @@
<?php
/**
* Class CC_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Test_Cards;
/**
* Credit card Payment Method class extending UPE base class
*/
class CC_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'card';
/**
* Constructor for card payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = true;
$this->currencies = [];// All currencies are supported.
$this->icon_url = plugins_url( 'assets/images/payment-methods/generic-card.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns payment method title
*
* @param string|null $account_country Account country.
* @param array|false $payment_details Payment details.
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( ! $payment_details ) {
return __( 'Credit card / debit card', 'woocommerce-payments' );
}
$details = $payment_details[ $this->stripe_id ];
$funding_types = [
'credit' => __( 'credit', 'woocommerce-payments' ),
'debit' => __( 'debit', 'woocommerce-payments' ),
'prepaid' => __( 'prepaid', 'woocommerce-payments' ),
'unknown' => __( 'unknown', 'woocommerce-payments' ),
];
$card_network = $details['display_brand'] ?? $details['network'] ?? $details['networks']['preferred'] ?? $details['networks']['available'][0];
// Networks like `cartes_bancaires` may use underscores, so we replace them with spaces.
$card_network = str_replace( '_', ' ', $card_network );
$payment_method_title = sprintf(
// Translators: %1$s card brand, %2$s card funding (prepaid, credit, etc.).
__( '%1$s %2$s card', 'woocommerce-payments' ),
ucwords( $card_network ),
$funding_types[ $details['funding'] ]
);
return $payment_method_title;
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
$test_card_number = Country_Test_Cards::get_test_card_for_country( $account_country );
return sprintf(
// Translators: %s is a test card number.
__( 'Use test card <number>%s</number> or refer to our <a>testing guide</a>.', 'woocommerce-payments' ),
$test_card_number
);
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class Eps_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* EPS Payment Method class extending UPE base class
*/
class Eps_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'eps';
/**
* Constructor for EPS payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'EPS';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/eps.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRIA ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class Giropay_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Giropay Payment Method class extending UPE base class
*/
class Giropay_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'giropay';
/**
* Constructor for Giropay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'giropay';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/giropay.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::GERMANY ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class Ideal_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* IDEAL Payment Method class extending UPE base class
*/
class Ideal_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'ideal';
/**
* Constructor for iDEAL payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'iDEAL';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/ideal.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::NETHERLANDS ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,90 @@
<?php
/**
* Class Affirm_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Affirm Payment Method class extending UPE base class
*/
class Klarna_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'klarna';
/**
* Constructor for Klarna payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/klarna-pill.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::POUND_STERLING, Currency_Code::EURO, Currency_Code::DANISH_KRONE, Currency_Code::NORWEGIAN_KRONE, Currency_Code::SWEDISH_KRONA ];
$this->accept_only_domestic_payment = true;
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::UNITED_KINGDOM, Country_Code::AUSTRIA, Country_Code::GERMANY, Country_Code::NETHERLANDS, Country_Code::BELGIUM, Country_Code::SPAIN, Country_Code::ITALY, Country_Code::IRELAND, Country_Code::DENMARK, Country_Code::FINLAND, Country_Code::NORWAY, Country_Code::SWEDEN, Country_Code::FRANCE ];
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Klarna', 'woocommerce-payments' );
}
/**
* Returns payment method supported countries.
*
* For Klarna we need to include additional logic to support transactions between countries in the EEA,
* UK, and Switzerland.
*
* @return array
*/
public function get_countries() {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $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_Payments_Utils::get_european_economic_area_countries(),
[ Country_Code::SWITZERLAND, Country_Code::UNITED_KINGDOM ]
);
// If the merchant is in the EEA, UK, or Switzerland, only the countries that have the same domestic currency as the store currency will be supported.
if ( in_array( $account_country, $eea_countries, true ) ) {
$store_currency = strtoupper( get_woocommerce_currency() );
$countries_that_support_store_currency = array_keys( $this->limits_per_currency[ $store_currency ] );
return array_values( array_intersect( $eea_countries, $countries_that_support_store_currency ) );
}
return parent::get_countries();
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Class CC_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Currency_Code;
/**
* Link Payment Method class extending UPE base class
*/
class Link_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'link';
/**
* Constructor for link payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = true;
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/link.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Link', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,45 @@
<?php
/**
* Class P24_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* P24 Payment Method class extending UPE base class
*/
class P24_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'p24';
/**
* Constructor for P24 payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Przelewy24 (P24)';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO, Currency_Code::POLISH_ZLOTY ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/p24.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::POLAND ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,49 @@
<?php
/**
* Class Sepa_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Sepa Payment Method class extending UPE base class
*/
class Sepa_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'sepa_debit';
/**
* Constructor for Sepa payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'SEPA Direct Debit';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/sepa-debit.svg', WCPAY_PLUGIN_FILE );
// https://stripe.com/en-br/resources/more/sepa-country-list#list-of-sepa-countries.
$eu_countries = [ Country_Code::AUSTRIA, Country_Code::BELGIUM, Country_Code::BULGARIA, Country_Code::CROATIA, Country_Code::CYPRUS, Country_Code::CZECHIA, Country_Code::DENMARK, Country_Code::ESTONIA, Country_Code::FINLAND, Country_Code::FRANCE, Country_Code::GERMANY, Country_Code::GREECE, Country_Code::HUNGARY, Country_Code::IRELAND, Country_Code::ITALY, Country_Code::LATVIA, Country_Code::LITHUANIA, Country_Code::LUXEMBOURG, Country_Code::MALTA, Country_Code::NETHERLANDS, Country_Code::POLAND, Country_Code::PORTUGAL, Country_Code::ROMANIA, Country_Code::SLOVAKIA, Country_Code::SLOVENIA, Country_Code::SPAIN, Country_Code::SWEDEN ];
$additional_sepa_countries = [ Country_Code::SWITZERLAND, Country_Code::UNITED_KINGDOM, Country_Code::SAN_MARINO, Country_Code::VATICAN_CITY, Country_Code::ANDORRA, Country_Code::MONACO, Country_Code::LIECHTENSTEIN, Country_Code::NORWAY, Country_Code::ICELAND ];
$this->countries = array_merge( $eu_countries, $additional_sepa_countries );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return __( '<strong>Test mode:</strong> use the test account number <number>AT611904300234573201</number>. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a>here</a>.', 'woocommerce-payments' );
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Class Sofort_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WCPay\Constants\Country_Code;
use WP_User;
use WC_Payments_Token_Service;
use WCPay\Constants\Currency_Code;
/**
* Sofort Payment Method class extending UPE base class
*/
class Sofort_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'sofort';
/**
* Constructor for Sofort payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Sofort';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/sofort.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRIA, Country_Code::BELGIUM, Country_Code::GERMANY, Country_Code::NETHERLANDS, Country_Code::SPAIN ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
}
@@ -0,0 +1,348 @@
<?php
/**
* Abstract UPE Payment Method class
*
* Handles general functionality for UPE payment methods
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Utils;
use WCPay\MultiCurrency\MultiCurrency;
use WP_User;
use WC_Payments_Token_Service;
use WC_Payment_Token_CC;
use WC_Payment_Token_WCPay_SEPA;
use WC_Payments_Subscriptions_Utilities;
use WCPay\Logger;
/**
* Extendable abstract class for payment methods.
*/
abstract class UPE_Payment_Method {
use WC_Payments_Subscriptions_Utilities;
/**
* Stripe key name
*
* @var string
*/
protected $stripe_id;
/**
* Display title
*
* @var string
*/
protected $title;
/**
* Can payment method be saved or reused?
*
* @var bool
*/
protected $is_reusable;
/**
* Instance of WC Payments Token Service to save payment method
*
* @var WC_Payments_Token_Service
*/
protected $token_service;
/**
* Supported presentment currencies for which charges for a payment method can be processed
* Empty if all currencies are supported
*
* @var string[]
*/
protected $currencies;
/**
* Should payment method be restricted to only domestic payments.
* E.g. only to Stripe's connected account currency.
*
* @var boolean
*/
protected $accept_only_domestic_payment = false;
/**
* Represent payment total limitations for the payment method (per-currency).
*
* @var array<string,array<string,array<string,int>>>
*/
protected $limits_per_currency = [];
/**
* Payment method icon URL
*
* @var string
*/
protected $icon_url;
/**
* Payment method icon URL for dark themes (optional)
*
* @var string
*/
protected $dark_icon_url;
/**
* Is the payment method a BNPL (Buy Now Pay Later) method?
*
* @var boolean
*/
protected $is_bnpl = false;
/**
* Supported customer locations for which charges for a payment method can be processed
* Empty if all customer locations are supported
*
* @var string[]
*/
protected $countries = [];
/**
* Create instance of payment method
*
* @param WC_Payments_Token_Service $token_service Instance of WC_Payments_Token_Service.
*/
public function __construct( $token_service ) {
$this->token_service = $token_service;
}
/**
* Returns payment method ID
*
* @return string
*/
public function get_id() {
return $this->stripe_id;
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return $this->title;
}
/**
* Returns payment method currencies
*
* @return array
*/
public function get_currencies() {
return $this->currencies;
}
/**
* Determines whether the payment method is restricted to the Stripe account's currency.
* E.g.: Afterpay/Clearpay and Affirm only supports domestic payments; Klarna also implements a simplified version of these market restrictions.
*
* @return bool
*/
public function has_domestic_transactions_restrictions() {
return $this->accept_only_domestic_payment;
}
/**
* Returns boolean dependent on whether payment method
* can be used at checkout
*
* @param string $account_country Country of merchants account.
*
* @return bool
*/
public function is_enabled_at_checkout( string $account_country ) {
if ( $this->is_subscription_item_in_cart() || $this->is_changing_payment_method_for_subscription() ) {
return $this->is_reusable();
}
// This part ensures that when payment limits for the currency declared, those will be respected (e.g. BNPLs).
if ( [] !== $this->limits_per_currency ) {
$order = null;
if ( is_wc_endpoint_url( 'order-pay' ) ) {
$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
$order = is_a( $order, 'WC_Order' ) ? $order : null;
}
$currency = get_woocommerce_currency();
if ( $order ) {
$currency = $order->get_currency();
}
// If the currency limits are not defined, we allow the PM for now (gateway has similar validation for limits).
$total = null;
if ( $order ) {
$total = $order->get_total();
} elseif ( isset( WC()->cart ) ) {
$total = WC()->cart->get_total( '' );
}
if ( isset( $this->limits_per_currency[ $currency ], WC()->cart ) && ! empty( $total ) ) {
$amount = WC_Payments_Utils::prepare_amount( $total, $currency );
if ( $amount > 0 ) {
$range = null;
if ( isset( $this->limits_per_currency[ $currency ][ $account_country ] ) ) {
$range = $this->limits_per_currency[ $currency ][ $account_country ];
} elseif ( isset( $this->limits_per_currency[ $currency ]['default'] ) ) {
$range = $this->limits_per_currency[ $currency ]['default'];
}
// If there is no range specified for the currency-country pair we don't support it and return false.
if ( null === $range ) {
return false;
}
$is_valid_minimum = null === $range['min'] || $amount >= $range['min'];
$is_valid_maximum = null === $range['max'] || $amount <= $range['max'];
return $is_valid_minimum && $is_valid_maximum;
}
}
}
return true;
}
/**
* Returns boolean dependent on whether payment method
* will support saved payments/subscription payments
*
* @return bool
*/
public function is_reusable() {
return $this->is_reusable;
}
/**
* Returns boolean dependent on whether payment method
* will support BNPL (Buy Now Pay Later) payments
*
* @return bool
*/
public function is_bnpl() {
return $this->is_bnpl;
}
/**
* Returns boolean dependent on whether payment method will accept charges
* with chosen currency
*
* @param string $account_domestic_currency Domestic currency of the account.
* @param int|null $order_id Optional order ID, if order currency should take precedence.
*
* @return bool
*/
public function is_currency_valid( string $account_domestic_currency, $order_id = null ) {
$current_store_currency = $this->get_currency( $order_id );
if ( $this->has_domestic_transactions_restrictions() ) {
if ( strtolower( $current_store_currency ) !== strtolower( $account_domestic_currency ) ) {
return false;
}
}
return empty( $this->currencies ) || in_array( $current_store_currency, $this->currencies, true );
}
/**
* Add payment method to user and return WC payment token
*
* @param WP_User $user User to get payment token from.
* @param string $payment_method_id Stripe payment method ID string.
*
* @return WC_Payment_Token_CC|WC_Payment_Token_WCPay_SEPA WC object for payment token.
*/
public function get_payment_token_for_user( $user, $payment_method_id ) {
return $this->token_service->add_payment_method_to_user( $payment_method_id, $user );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
abstract public function get_testing_instructions( string $account_country );
/**
* Returns the payment method icon URL or an empty string.
*
* @param string|null $account_country Optional account country.
* @return string
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_icon( ?string $account_country = null ) {
return isset( $this->icon_url ) ? $this->icon_url : '';
}
/**
* Returns icon to use on dark themes.
*
* @param string|null $account_country Optional account country.
* @return string
*/
public function get_dark_icon( ?string $account_country = null ) {
return isset( $this->dark_icon_url ) ? $this->dark_icon_url : $this->get_icon( $account_country );
}
/**
* Gets the theme appropriate icon for the payment method for a given location and context.
*
* @param string $location The location to get the icon for.
* @param boolean $is_blocks Whether the icon is for blocks.
* @param string $account_country Optional account country.
* @return string
*/
public function get_payment_method_icon_for_location( string $location = 'checkout', bool $is_blocks = true, ?string $account_country = null ) {
$appearance_theme = WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, $is_blocks ? 'blocks' : 'classic' );
if ( 'night' === $appearance_theme ) {
return $this->get_dark_icon( $account_country );
}
return $this->get_icon( $account_country );
}
/**
* Returns payment method supported countries
*
* @return array
*/
public function get_countries() {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
return $this->has_domestic_transactions_restrictions() ? [ $account_country ] : $this->countries;
}
/**
* Returns valid currency to use to filter payment methods.
*
* @param int $order_id Optional order ID, if order currency should take precedence.
*
* @return string
*/
private function get_currency( $order_id = null ) {
if ( is_wc_endpoint_url( 'order-pay' ) || null !== $order_id ) {
global $wp;
if ( null === $order_id ) {
$order_id = absint( $wp->query_vars['order-pay'] );
}
$order = wc_get_order( $order_id );
return $order->get_currency();
}
return get_woocommerce_currency();
}
}