Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

refactor: remove Afterpay_Payment_Method in favor of AfterpayDefinition
2 changes: 2 additions & 0 deletions client/checkout/blocks/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ button.wcpay-stripelink-modal-trigger:hover {
#radio-control-wc-payment-method-options-woocommerce_payments_affirm__label
img {
min-width: 50px;
height: auto;
}
/* stylelint-disable-next-line selector-id-pattern */
#radio-control-wc-payment-method-options-woocommerce_payments_afterpay_clearpay__label
img {
min-width: 64px;
height: auto;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes the icons appearing "squished" on checkout

Image Image

}
}

Expand Down
11 changes: 4 additions & 7 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\Afterpay_Payment_Method;
use WCPay\Payment_Methods\Becs_Payment_Method;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Payment_Methods\Klarna_Payment_Method;
Expand Down Expand Up @@ -93,12 +92,10 @@ private function search_for_additional_payment_methods() {
* As payment methods are converted to use definitions, they need to be removed from the list below.
*/
$keywords = [
'sepa' => Sepa_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'becs' => Becs_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,
'grabpay' => Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'sepa' => Sepa_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'becs' => Becs_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'klarna' => Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
'grabpay' => Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID,
];

// Get all payment method definitions.
Expand Down
21 changes: 1 addition & 20 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
use WCPay\Tracker;
use WCPay\Internal\Service\Level3Service;
use WCPay\Internal\Service\OrderService;
use WCPay\Payment_Methods\Afterpay_Payment_Method;
use WCPay\Payment_Methods\Becs_Payment_Method;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Payment_Methods\Klarna_Payment_Method;
Expand Down Expand Up @@ -378,7 +377,7 @@ public function __construct(
*/
public function get_title() {
if ( ! $this->title ) {
$this->title = $this->payment_method->get_title();
$this->title = $this->payment_method->get_title( $this->get_account_country() );
$this->method_title = "WooPayments ($this->title)";
}
return parent::get_title();
Expand Down Expand Up @@ -568,7 +567,6 @@ public function get_form_fields() {
* @return void
*/
public function init_hooks() {
add_action( 'init', [ $this, 'maybe_update_properties_with_country' ] );
// Only add certain actions/filter if this is the main gateway (i.e. not split UPE).
if ( self::GATEWAY_ID === $this->id ) {
add_action( 'woocommerce_order_actions', [ $this, 'add_order_actions' ] );
Expand Down Expand Up @@ -601,22 +599,6 @@ public function init_hooks() {
$this->maybe_init_subscriptions_hooks();
}

/**
* Updates icon and title using the account country.
* This method runs on init is not in the controller because get_account_country might
* make a request to the API if the account data is not cached.
*
* @return void
*/
public function maybe_update_properties_with_country(): void {
if ( Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID !== $this->stripe_id ) {
return;
}
$account_country = $this->get_account_country();
$this->icon = $this->payment_method->get_icon( $account_country );
$this->title = $this->payment_method->get_title( $account_country );
}
Comment on lines -611 to -618
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 was being executed only for Afterpay.
It was needed because when the payment method was initialized, we needed to ensure its icon/title matched the correct country.
But it's no longer needed.


/**
* Displays HTML tags for WC payment gateway radio button content.
*/
Expand Down Expand Up @@ -4085,7 +4067,6 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Becs_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Sepa_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Link_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Multibanco_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
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 @@ -24,7 +24,6 @@
use WCPay\WooPay\WooPay_Utilities;
use WCPay\WooPay\WooPay_Order_Status_Sync;
use WCPay\Payment_Methods\Link_Payment_Method;
use WCPay\Payment_Methods\Afterpay_Payment_Method;
use WCPay\Session_Rate_Limiter;
use WCPay\Database_Cache;
use WCPay\WC_Payments_Checkout;
Expand Down Expand Up @@ -432,7 +431,6 @@ public static function init() {
include_once __DIR__ . '/payment-methods/class-sepa-payment-method.php';
include_once __DIR__ . '/payment-methods/class-becs-payment-method.php';
include_once __DIR__ . '/payment-methods/class-link-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';
include_once __DIR__ . '/payment-methods/class-grabpay-payment-method.php';
Expand Down Expand Up @@ -574,7 +572,6 @@ public static function init() {
Sepa_Payment_Method::class,
Becs_Payment_Method::class,
Link_Payment_Method::class,
Afterpay_Payment_Method::class,
Klarna_Payment_Method::class,
Multibanco_Payment_Method::class,
Grabpay_Payment_Method::class,
Expand Down
259 changes: 259 additions & 0 deletions includes/payment-methods/Configs/Definitions/AfterpayDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
<?php
/**
* Afterpay Payment Method Definition
*
* @package WCPay\PaymentMethods\Configs\Definitions
*/

namespace WCPay\PaymentMethods\Configs\Definitions;

use WC_Payments_Utils;
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 Afterpay payment method definition.
*/
class AfterpayDefinition implements PaymentMethodDefinitionInterface {

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

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

/**
* Get the Stripe payment method ID
*
* @return string
*/
public static function get_stripe_id(): string {
return 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 {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}

if ( Country_Code::UNITED_STATES === $account_country ) {
return __( 'Cash App Afterpay', 'woocommerce-payments' );
}

return __( 'Afterpay', '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 {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return __( 'Allow customers to pay over time with Clearpay.', 'woocommerce-payments' );
}

return __( 'Allow customers to pay over time with Afterpay.', 'woocommerce-payments' );
}

/**
* 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,
Currency_Code::AUSTRALIAN_DOLLAR,
Currency_Code::NEW_ZEALAND_DOLLAR,
Currency_Code::POUND_STERLING,
];
}

/**
* 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,
Country_Code::AUSTRALIA,
Country_Code::NEW_ZEALAND,
Country_Code::UNITED_KINGDOM,
];
}

/**
* Get the payment method capabilities
*
* @return string[]
*/
public static function get_capabilities(): array {
return [
PaymentMethodCapability::BUY_NOW_PAY_LATER,
PaymentMethodCapability::REFUNDS,
PaymentMethodCapability::DOMESTIC_TRANSACTIONS_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 {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}

if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-logo.svg', WCPAY_PLUGIN_FILE );
}

return plugins_url( 'assets/images/payment-methods/afterpay-badge.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 {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay-dark.svg', WCPAY_PLUGIN_FILE );
}

if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-logo-dark.svg', WCPAY_PLUGIN_FILE );
}

return plugins_url( 'assets/images/payment-methods/afterpay-badge-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 {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}

if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-badge.svg', WCPAY_PLUGIN_FILE );
}

return plugins_url( 'assets/images/payment-methods/afterpay-logo.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_stripe_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 {
return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country );
}

/**
* 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();

if ( isset( $limits[ $currency ][ $country ]['min'] ) ) {
return $limits[ $currency ][ $country ]['min'];
}

return 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();

if ( isset( $limits[ $currency ][ $country ]['max'] ) ) {
return $limits[ $currency ][ $country ]['max'];
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace WCPay\PaymentMethods\Configs\Registry;

use WCPay\PaymentMethods\Configs\Definitions\AffirmDefinition;
use WCPay\PaymentMethods\Configs\Definitions\AfterpayDefinition;
use WCPay\PaymentMethods\Configs\Definitions\AlipayDefinition;
use WCPay\PaymentMethods\Configs\Definitions\ApplePayDefinition;
use WCPay\PaymentMethods\Configs\Definitions\GooglePayDefinition;
Expand Down Expand Up @@ -40,6 +41,7 @@ class PaymentMethodDefinitionRegistry {
private $available_definitions = [
// Add new payment method definitions here.
AffirmDefinition::class,
AfterpayDefinition::class,
AlipayDefinition::class,
BancontactDefinition::class,
EpsDefinition::class,
Expand Down
Loading
Loading