Skip to content

Commit

Permalink
Updating title and name with country on init
Browse files Browse the repository at this point in the history
  • Loading branch information
gpressutto5 committed Jan 22, 2024
1 parent b4b3996 commit 9cf0059
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 16 additions & 3 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,13 @@ 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( $account_country );
$this->icon = $payment_method->get_icon();
$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( $account_country );
$this->title = $payment_method->get_title();
$this->description = '';
$this->supports = [
'products',
Expand Down Expand Up @@ -498,6 +497,7 @@ public function __construct(
* @return void
*/
public function init_hooks() {
add_action( 'init', [ $this, '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 @@ -527,6 +527,19 @@ 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 update_properties_with_country(): void {
$account_country = $this->get_account_country();
$this->icon = $this->payment_method->get_icon( $account_country );
$this->title = $this->payment_method->get_title( $account_country );
}

/**
* Displays HTML tags for WC payment gateway radio button content.
*/
Expand Down
8 changes: 4 additions & 4 deletions includes/payment-methods/class-afterpay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function __construct( $token_service ) {
/**
* Returns payment method title.
*
* @param string $account_country Country of merchants account.
* @param string|null $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 ) {
public function get_title( string $account_country = null, $payment_details = false ) {
if ( 'GB' === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}
Expand All @@ -83,10 +83,10 @@ public function get_title( string $account_country, $payment_details = false ) {
/**
* Returns payment method icon.
*
* @param string $account_country Country of merchants account.
* @param string|null $account_country Country of merchants account.
* @return string|null
*/
public function get_icon( string $account_country ) {
public function get_icon( string $account_country = null ) {
if ( 'GB' === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}
Expand Down
4 changes: 2 additions & 2 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 string $account_country Account country.
* @param string|null $account_country Account country.
* @param array|false $payment_details Payment details.
* @return string
*/
public function get_title( string $account_country, $payment_details = false ) {
public function get_title( string $account_country = null, $payment_details = false ) {
if ( ! $payment_details ) {
return $this->title;
}
Expand Down
8 changes: 4 additions & 4 deletions includes/payment-methods/class-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public function get_id() {
/**
* Returns payment method title
*
* @param string $account_country Country of merchants account.
* @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, $payment_details = false ) {
public function get_title( string $account_country = null, $payment_details = false ) {
return $this->title;
}

Expand Down Expand Up @@ -225,10 +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.
* @param string|null $account_country Optional account country.
* @return string
*/
public function get_icon( string $account_country ) {
public function get_icon( string $account_country = null ) {
return isset( $this->icon_url ) ? $this->icon_url : '';
}

Expand Down

0 comments on commit 9cf0059

Please sign in to comment.