Skip to content

Commit

Permalink
Displaying Clearpay instead of Afterpay for UK based stores (#7995)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesco <[email protected]>
  • Loading branch information
2 people authored and Jinksi committed Jan 30, 2024
1 parent 67da1e7 commit c100a58
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 71 deletions.
5 changes: 0 additions & 5 deletions assets/images/payment-methods/afterpay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/images/payment-methods/clearpay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions changelog/afterpay-clearpay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Displaying Clearpay instead of Afterpay for UK based stores
7 changes: 6 additions & 1 deletion client/connect-account-page/payment-methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import './style.scss';
import {
AffirmIcon,
AfterpayIcon,
ClearpayIcon,
AmericanExpressIcon,
ApplePayIcon,
DinersClubIcon,
Expand All @@ -38,7 +39,11 @@ const PaymentMethods: React.FC = () => {
<UnionPayIcon />
<JCBIcon />
<AffirmIcon />
<AfterpayIcon />
{ 'GB' === wcpaySettings?.connect?.country ? (
<ClearpayIcon />
) : (
<AfterpayIcon />
) }
<span>& more.</span>
</div>
</>
Expand Down
5 changes: 5 additions & 0 deletions client/payment-methods-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IdealAsset from 'assets/images/payment-methods/ideal.svg?asset';
import BankDebitAsset from 'assets/images/payment-methods/bank-debit.svg?asset';
import AffirmAsset from 'assets/images/payment-methods/affirm.svg?asset';
import AfterpayAsset from 'assets/images/payment-methods/afterpay.svg?asset';
import ClearpayAsset from 'assets/images/payment-methods/clearpay.svg?asset';
import JCBAsset from 'assets/images/payment-methods/jcb.svg?asset';
import KlarnaAsset from 'assets/images/payment-methods/klarna.svg?asset';
import VisaAsset from 'assets/images/cards/visa.svg?asset';
Expand Down Expand Up @@ -57,6 +58,10 @@ export const AfterpayIcon = iconComponent(
AfterpayAsset,
__( 'Afterpay', 'woocommerce-payments' )
);
export const ClearpayIcon = iconComponent(
ClearpayAsset,
__( 'Clearpay', 'woocommerce-payments' )
);
export const AmericanExpressIcon = iconComponent(
AmexAsset,
__( 'American Express', 'woocommerce-payments' )
Expand Down
42 changes: 34 additions & 8 deletions client/payment-methods-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { __ } from '@wordpress/i18n';
import {
AffirmIcon,
AfterpayIcon,
ClearpayIcon,
BancontactIcon,
BankDebitIcon,
CreditCardIcon,
Expand All @@ -23,6 +24,18 @@ import {
SofortIcon,
} from 'wcpay/payment-methods-icons';

declare global {
interface Window {
wcpaySettings: {
accountStatus: {
country: string;
};
};
}
}

const accountCountry = window.wcpaySettings?.accountStatus?.country || 'US';

export interface PaymentMethodMapEntry {
id: string;
label: string;
Expand Down Expand Up @@ -208,16 +221,29 @@ const PaymentMethodInformationObject: Record<
},
afterpay_clearpay: {
id: 'afterpay_clearpay',
label: __( 'Afterpay', 'woocommerce-payments' ),
label:
'GB' === accountCountry
? __( 'Clearpay', 'woocommerce-payments' )
: __( 'Afterpay', 'woocommerce-payments' ),
brandTitles: {
afterpay_clearpay: __( 'Afterpay', 'woocommerce-payments' ),
afterpay_clearpay:
'GB' === accountCountry
? __( 'Clearpay', 'woocommerce-payments' )
: __( 'Afterpay', 'woocommerce-payments' ),
},
description: __(
// translators: %s is the store currency.
'Allow customers to pay over time with Afterpay. Available to all customers paying in %s.',
'woocommerce-payments'
),
icon: AfterpayIcon,
description:
'GB' === accountCountry
? __(
// translators: %s is the store currency.
'Allow customers to pay over time with Clearpay. Available to all customers paying in %s.',
'woocommerce-payments'
)
: __(
// translators: %s is the store currency.
'Allow customers to pay over time with Afterpay. Available to all customers paying in %s.',
'woocommerce-payments'
),
icon: 'GB' === accountCountry ? ClearpayIcon : AfterpayIcon,
currencies: [ 'USD', 'AUD', 'CAD', 'NZD', 'GBP', 'EUR' ],
stripe_key: 'afterpay_clearpay_payments',
allows_manual_capture: false,
Expand Down
9 changes: 5 additions & 4 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ public function __construct(
$this->localization_service = $localization_service;
$this->fraud_service = $fraud_service;

$account_country = $this->get_account_country();
$this->id = static::GATEWAY_ID;
$this->icon = $payment_method->get_icon();
$this->icon = $payment_method->get_icon( $account_country );
$this->has_fields = true;
$this->method_title = 'WooPayments';
$this->method_description = __( 'Payments made simple, with no monthly fees - designed exclusively for WooCommerce stores. Accept credit cards, debit cards, and other popular payment methods.', 'woocommerce-payments' );

$this->title = $payment_method->get_title();
$this->title = $payment_method->get_title( $account_country );
$this->description = '';
$this->supports = [
'products',
Expand Down Expand Up @@ -2052,7 +2053,7 @@ public function set_payment_method_title_for_order( $order, $payment_method_type
return;
}

$payment_method_title = $payment_method->get_title( $payment_method_details );
$payment_method_title = $payment_method->get_title( $this->get_account_country(), $payment_method_details );

$payment_gateway = in_array( $payment_method->get_id(), [ Payment_Method::CARD, Payment_Method::LINK ], true ) ? self::GATEWAY_ID : self::GATEWAY_ID . '_' . $payment_method_type;

Expand Down Expand Up @@ -2871,7 +2872,7 @@ protected function get_deposit_delay_days( int $default_value = 7 ): int {
*
* @return string code of the country.
*/
protected function get_account_country( string $default_value = 'US' ): string {
public function get_account_country( string $default_value = 'US' ): string {
try {
if ( $this->is_connected() ) {
return $this->account->get_account_country() ?? $default_value;
Expand Down
5 changes: 3 additions & 2 deletions includes/class-wc-payments-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ public function get_enabled_payment_method_config() {
}

$payment_method = $this->gateway->wc_payments_get_payment_method_by_id( $payment_method_id );
$account_country = $this->account->get_account_country();
$settings[ $payment_method_id ] = [
'isReusable' => $payment_method->is_reusable(),
'title' => $payment_method->get_title(),
'icon' => $payment_method->get_icon(),
'title' => $payment_method->get_title( $account_country ),
'icon' => $payment_method->get_icon( $account_country ),
'showSaveOption' => $this->should_upe_payment_method_show_save_option( $payment_method ),
'countries' => $payment_method->get_countries(),
];
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ public static function init() {
include_once __DIR__ . '/class-wc-payments-utils.php';
include_once __DIR__ . '/core/class-mode.php';

self::$mode = new Mode();

include_once __DIR__ . '/class-database-cache.php';
self::$database_cache = new Database_Cache();
self::$database_cache->init_hooks();
Expand Down Expand Up @@ -538,8 +540,6 @@ public static function init() {
self::$card_gateway->init_hooks();
self::$wc_payments_checkout->init_hooks();

self::$mode = new Mode();

self::$webhook_processing_service = new WC_Payments_Webhook_Processing_Service( self::$api_client, self::$db_helper, self::$account, self::$remote_note_service, self::$order_service, self::$in_person_payments_receipts_service, self::get_gateway(), self::$customer_service, self::$database_cache );
self::$webhook_reliability_service = new WC_Payments_Webhook_Reliability_Service( self::$api_client, self::$action_scheduler_service, self::$webhook_processing_service );

Expand Down
2 changes: 1 addition & 1 deletion includes/multi-currency/PaymentMethodsCompatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function ( $result, $method ) {

$result[ $method ] = [
'currencies' => $payment_method_instance->get_currencies(),
'title' => $payment_method_instance->get_title(),
'title' => $payment_method_instance->get_title( $this->gateway->get_account_country() ),
];

return $result;
Expand Down
29 changes: 29 additions & 0 deletions includes/payment-methods/class-afterpay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ public function __construct( $token_service ) {
];
}

/**
* Returns payment method title.
*
* @param string $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
* @return string|null
*/
public function get_title( string $account_country, $payment_details = false ) {
if ( 'GB' === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}

return __( 'Afterpay', 'woocommerce-payments' );
}

/**
* Returns payment method icon.
*
* @param string $account_country Country of merchants account.
* @return string|null
*/
public function get_icon( string $account_country ) {
if ( 'GB' === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}

return plugins_url( 'assets/images/payment-methods/afterpay.svg', WCPAY_PLUGIN_FILE );
}

/**
* Returns testing credentials to be printed at checkout in test mode.
*
Expand Down
6 changes: 3 additions & 3 deletions includes/payment-methods/class-cc-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function __construct( $token_service ) {
/**
* Returns payment method title
*
* @param array|bool $payment_details Optional payment details from charge object.
*
* @param string $account_country Account country.
* @param array|false $payment_details Payment details.
* @return string
*/
public function get_title( $payment_details = false ) {
public function get_title( string $account_country, $payment_details = false ) {
if ( ! $payment_details ) {
return $this->title;
}
Expand Down
8 changes: 5 additions & 3 deletions includes/payment-methods/class-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ public function get_id() {
/**
* Returns payment method title
*
* @param array|bool $payment_details Optional payment details from charge object.
* @param string $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( $payment_details = false ) {
public function get_title( string $account_country, $payment_details = false ) {
return $this->title;
}

Expand Down Expand Up @@ -224,9 +225,10 @@ abstract public function get_testing_instructions();
/**
* Returns the payment method icon URL or an empty string.
*
* @param string $account_country Optional account country.
* @return string
*/
public function get_icon() {
public function get_icon( string $account_country ) {
return isset( $this->icon_url ) ? $this->icon_url : '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public function set_up() {
->setMethods(
[
'get_upe_enabled_payment_method_ids',
'get_account_country',
]
)
->getMock();
$this->gateway_mock->method( 'get_account_country' )->willReturn( 'US' );

$this->payment_methods_compatibility = new \WCPay\MultiCurrency\PaymentMethodsCompatibility( $this->multi_currency_mock, $this->gateway_mock );
$this->payment_methods_compatibility->init_hooks();
Expand Down
Loading

0 comments on commit c100a58

Please sign in to comment.