diff --git a/changelog/refactor-affirm-payment-method-definition b/changelog/refactor-affirm-payment-method-definition new file mode 100644 index 00000000000..38ee5edaa74 --- /dev/null +++ b/changelog/refactor-affirm-payment-method-definition @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: chore: migrate from Affirm_Payment_Method:class to AffirmDefinition + + diff --git a/includes/class-duplicates-detection-service.php b/includes/class-duplicates-detection-service.php index 446275aad5a..4ae5af6a13a 100644 --- a/includes/class-duplicates-detection-service.php +++ b/includes/class-duplicates-detection-service.php @@ -12,7 +12,6 @@ } use WC_Payments; -use WCPay\Payment_Methods\Affirm_Payment_Method; use WCPay\Payment_Methods\Afterpay_Payment_Method; use WCPay\Payment_Methods\Bancontact_Payment_Method; use WCPay\Payment_Methods\Becs_Payment_Method; @@ -106,7 +105,6 @@ private function search_for_additional_payment_methods() { 'ideal' => Ideal_Payment_Method::PAYMENT_METHOD_STRIPE_ID, 'becs' => Becs_Payment_Method::PAYMENT_METHOD_STRIPE_ID, 'eps' => Eps_Payment_Method::PAYMENT_METHOD_STRIPE_ID, - 'affirm' => Affirm_Payment_Method::PAYMENT_METHOD_STRIPE_ID, 'afterpay' => Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID, 'clearpay' => Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID, 'klarna' => Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID, diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 30cd2730d79..fc9b4fb1cae 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -56,7 +56,6 @@ use WCPay\Tracker; use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; -use WCPay\Payment_Methods\Affirm_Payment_Method; use WCPay\Payment_Methods\Afterpay_Payment_Method; use WCPay\Payment_Methods\Bancontact_Payment_Method; use WCPay\Payment_Methods\Becs_Payment_Method; diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index 35c1ac8aadc..ca805fbba8f 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -29,7 +29,6 @@ use WCPay\WooPay\WooPay_Utilities; use WCPay\WooPay\WooPay_Order_Status_Sync; use WCPay\Payment_Methods\Link_Payment_Method; -use WCPay\Payment_Methods\Affirm_Payment_Method; use WCPay\Payment_Methods\Afterpay_Payment_Method; use WCPay\Session_Rate_Limiter; use WCPay\Database_Cache; @@ -438,7 +437,6 @@ public static function init() { include_once __DIR__ . '/payment-methods/class-becs-payment-method.php'; include_once __DIR__ . '/payment-methods/class-eps-payment-method.php'; include_once __DIR__ . '/payment-methods/class-link-payment-method.php'; - include_once __DIR__ . '/payment-methods/class-affirm-payment-method.php'; include_once __DIR__ . '/payment-methods/class-afterpay-payment-method.php'; include_once __DIR__ . '/payment-methods/class-klarna-payment-method.php'; include_once __DIR__ . '/payment-methods/class-multibanco-payment-method.php'; @@ -586,7 +584,6 @@ public static function init() { Becs_Payment_Method::class, Eps_Payment_Method::class, Link_Payment_Method::class, - Affirm_Payment_Method::class, Afterpay_Payment_Method::class, Klarna_Payment_Method::class, Multibanco_Payment_Method::class, diff --git a/includes/payment-methods/Configs/Definitions/AffirmDefinition.php b/includes/payment-methods/Configs/Definitions/AffirmDefinition.php new file mode 100644 index 00000000000..6a212d02015 --- /dev/null +++ b/includes/payment-methods/Configs/Definitions/AffirmDefinition.php @@ -0,0 +1,250 @@ +> + */ + public static function get_limits_per_currency(): array { + return \WC_Payments_Utils::get_bnpl_limits_per_currency( self::get_id() ); + } + + /** + * Whether this payment method is available for the given currency and country + * + * @param string $currency The currency code to check. + * @param string $account_country The merchant's account country. + * + * @return bool + */ + public static function is_available_for( string $currency, string $account_country ): bool { + if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ) ) { + return false; + } + + return true; + } + + /** + * Whether this payment method should be enabled by default + * + * @return bool + */ + public static function is_enabled_by_default(): bool { + return false; + } + + /** + * Get the minimum amount for this payment method for a given currency and country + * + * @param string $currency The currency code. + * @param string $country The country code. + * + * @return int|null The minimum amount or null if no minimum. + */ + public static function get_minimum_amount( string $currency, string $country ): ?int { + $limits = self::get_limits_per_currency(); + return $limits[ $currency ][ $country ]['min'] ?? null; + } + + /** + * Get the maximum amount for this payment method for a given currency and country + * + * @param string $currency The currency code. + * @param string $country The country code. + * + * @return int|null The maximum amount or null if no maximum. + */ + public static function get_maximum_amount( string $currency, string $country ): ?int { + $limits = self::get_limits_per_currency(); + return $limits[ $currency ][ $country ]['max'] ?? null; + } +} diff --git a/includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php b/includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php index da70308275e..9c0c326c965 100644 --- a/includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php +++ b/includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php @@ -7,6 +7,7 @@ namespace WCPay\PaymentMethods\Configs\Registry; +use WCPay\PaymentMethods\Configs\Definitions\AffirmDefinition; use WCPay\PaymentMethods\Configs\Definitions\AlipayDefinition; use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface; @@ -30,6 +31,7 @@ class PaymentMethodDefinitionRegistry { private $available_definitions = [ // Add new payment method definitions here. AlipayDefinition::class, + AffirmDefinition::class, ]; /** diff --git a/includes/payment-methods/class-affirm-payment-method.php b/includes/payment-methods/class-affirm-payment-method.php deleted file mode 100644 index 05c6aa8609e..00000000000 --- a/includes/payment-methods/class-affirm-payment-method.php +++ /dev/null @@ -1,85 +0,0 @@ -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 ''; - } - - /** - * Returns payment method description for the settings page. - * - * @param string|null $account_country Country of merchants account. - * - * @return string - */ - public function get_description( ?string $account_country = null ) { - return __( - 'Allow customers to pay over time with Affirm.', - 'woocommerce-payments' - ); - } - - /** - * Returns payment method settings icon. - * - * @param string|null $account_country Country of merchants account. - * @return string - */ - public function get_settings_icon_url( ?string $account_country = null ) { - return plugins_url( 'assets/images/payment-methods/affirm-badge.svg', WCPAY_PLUGIN_FILE ); - } -} diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php index d37033667e8..2fe907ca880 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php @@ -254,7 +254,6 @@ public function set_up() { Sepa_Payment_Method::class, Becs_Payment_Method::class, Link_Payment_Method::class, - Affirm_Payment_Method::class, Afterpay_Payment_Method::class, ]; diff --git a/tests/unit/payment-methods/test-class-upe-payment-method.php b/tests/unit/payment-methods/test-class-upe-payment-method.php index bb986dd2c97..484a6e48e63 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-method.php +++ b/tests/unit/payment-methods/test-class-upe-payment-method.php @@ -81,7 +81,6 @@ public function set_up() { Sepa_Payment_Method::class, Becs_Payment_Method::class, Link_Payment_Method::class, - Affirm_Payment_Method::class, Afterpay_Payment_Method::class, Klarna_Payment_Method::class, ]; diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay.php b/tests/unit/test-class-wc-payment-gateway-wcpay.php index 02fb62b9f94..f4b0a40b733 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay.php @@ -27,7 +27,6 @@ use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; use WCPay\Payment_Information; -use WCPay\Payment_Methods\Affirm_Payment_Method; use WCPay\Payment_Methods\Afterpay_Payment_Method; use WCPay\Payment_Methods\Bancontact_Payment_Method; use WCPay\Payment_Methods\Becs_Payment_Method; @@ -3985,7 +3984,6 @@ private function init_payment_methods() { Becs_Payment_Method::class, Eps_Payment_Method::class, Link_Payment_Method::class, - Affirm_Payment_Method::class, Afterpay_Payment_Method::class, Klarna_Payment_Method::class, Grabpay_Payment_Method::class,