Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/refactor-affirm-payment-method-definition
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: chore: migrate from Affirm_Payment_Method:class to AffirmDefinition


2 changes: 0 additions & 2 deletions includes/class-duplicates-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
250 changes: 250 additions & 0 deletions includes/payment-methods/Configs/Definitions/AffirmDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php
/**
* Affirm Payment Method Definition
*
* @package WCPay\PaymentMethods\Configs\Definitions
*/

namespace WCPay\PaymentMethods\Configs\Definitions;

use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
use WCPay\PaymentMethods\Configs\Utils\PaymentMethodUtils;

/**
* Class implementing the Affirm payment method definition.
*/
class AffirmDefinition implements PaymentMethodDefinitionInterface {

/**
* Get the internal ID for the payment method
*
* @return string
*/
public static function get_id(): string {
return 'affirm';
}

/**
* Get the keywords for the payment method. These are used by the duplicates detection service.
*
* @return string[]
*/
public static function get_keywords(): array {
return [ 'affirm' ];
}

/**
* Get the Stripe payment method ID
*
* @return string
*/
public static function get_stripe_id(): string {
return PaymentMethodUtils::get_stripe_id( self::get_id() );
}

/**
* Get the customer-facing title of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_title( ?string $account_country = null ): string {
return __( 'Affirm', 'woocommerce-payments' );
}

/**
* Get the title of the payment method for the settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_label( ?string $account_country = null ): string {
return self::get_title( $account_country );
}

/**
* Get the customer-facing description of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_description( ?string $account_country = null ): string {
return __( 'Allow customers to pay over time with Affirm.', 'woocommerce-payments' );
}

/**
* Is the payment method a BNPL (Buy Now Pay Later) payment method?
*
* @return boolean
*/
public static function is_bnpl(): bool {
return PaymentMethodUtils::is_bnpl( self::get_capabilities() );
}

/**
* Is the payment method a reusable payment method?
*
* @return boolean
*/
public static function is_reusable(): bool {
return PaymentMethodUtils::is_reusable( self::get_capabilities() );
}

/**
* Does the payment method accept only domestic payments?
*
* @return boolean
*/
public static function accepts_only_domestic_payments(): bool {
return PaymentMethodUtils::accepts_only_domestic_payments( self::get_capabilities() );
}

/**
* Does the payment method allow manual capture?
*
* @return boolean
*/
public static function allows_manual_capture(): bool {
return PaymentMethodUtils::allows_manual_capture( self::get_capabilities() );
}

/**
* Get the list of supported currencies
*
* @return string[] Array of currency codes
*/
public static function get_supported_currencies(): array {
return [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR ];
}

/**
* Get the list of supported countries
*
* @return string[] Array of country codes
*/
public static function get_supported_countries(): array {
return [ Country_Code::UNITED_STATES, Country_Code::CANADA ];
}

/**
* Get the payment method capabilities
*
* @return string[]
*/
public static function get_capabilities(): array {
return [
PaymentMethodCapability::REFUNDS,
PaymentMethodCapability::MULTI_CURRENCY,
PaymentMethodCapability::BNPL,
PaymentMethodCapability::DOMESTIC_PAYMENTS_ONLY,
];
}

/**
* Get the URL for the payment method's icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/affirm-logo.svg', WCPAY_PLUGIN_FILE );
}

/**
* Get the URL for the payment method's dark mode icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string Returns regular icon URL if no dark mode icon exists
*/
public static function get_dark_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/affirm-logo-dark.svg', WCPAY_PLUGIN_FILE );
}

/**
* Get the URL for the payment method's settings icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/affirm-badge.svg', WCPAY_PLUGIN_FILE );
}

/**
* Get the testing instructions for the payment method
*
* @param string $account_country The merchant's account country.
* @return string HTML string containing testing instructions
*/
public static function get_testing_instructions( string $account_country ): string {
return '';
}

/**
* Get the currency limits for the payment method
*
* @return array<string,array<string,array{min:int,max:int}>>
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,6 +31,7 @@ class PaymentMethodDefinitionRegistry {
private $available_definitions = [
// Add new payment method definitions here.
AlipayDefinition::class,
AffirmDefinition::class,
];

/**
Expand Down
Loading
Loading