Skip to content

Commit 5561d51

Browse files
authored
Merge pull request #3891 from woocommerce/PCP-5571-block-checkout-missing-description-for-apm-gateway-except-for-crypto
Refactor APM gateway initialization with centralized defaults (5571)
2 parents dd2f5a1 + 3fe7f93 commit 5561d51

File tree

11 files changed

+336
-112
lines changed

11 files changed

+336
-112
lines changed
Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
export function APM( { config, components } ) {
22
const { PaymentMethodIcons } = components;
33

4-
return (
5-
<div>
6-
<div
7-
className="wc-block-components-payment-method-icons wc-block-components-payment-method-icons--align-right">
8-
<img
9-
className={`wc-block-components-payment-method-icon wc-block-components-payment-method-icon--${config.id}`}
10-
src={config.icon}
11-
alt={config.title}
12-
/>
13-
</div>
14-
</div>
15-
);
4+
return (
5+
<>
6+
{ config.description && (
7+
<div
8+
dangerouslySetInnerHTML={ { __html: config.description } }
9+
/>
10+
) }
11+
{ config.icon && (
12+
<div className="wc-block-components-payment-method-icons wc-block-components-payment-method-icons--align-right">
13+
<img
14+
className={ `wc-block-components-payment-method-icon wc-block-components-payment-method-icon--${ config.id }` }
15+
src={ config.icon }
16+
alt={ config.title }
17+
/>
18+
</div>
19+
) }
20+
</>
21+
);
1622
}

modules/ppcp-local-alternative-payment-methods/src/BancontactGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'Bancontact (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'A popular and trusted electronic payment method in Belgium, used by Belgian customers with Bancontact cards issued by local banks. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'Bancontact', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_bancontact_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -236,4 +235,24 @@ public function get_transaction_url( $order ): string {
236235

237236
return parent::get_transaction_url( $order );
238237
}
238+
239+
/**
240+
* Initialize APM gateway defaults from centralized definition.
241+
*/
242+
private function init_apm_defaults(): void {
243+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
244+
245+
$this->method_title = $defaults['method_title'];
246+
$this->method_description = $defaults['method_description'];
247+
}
248+
249+
/**
250+
* Load saved settings and override defaults.
251+
*/
252+
private function init_apm_settings(): void {
253+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
254+
255+
$this->title = $this->get_option( 'title', $defaults['title'] );
256+
$this->description = $this->get_option( 'description', $defaults['description'] );
257+
}
239258
}

modules/ppcp-local-alternative-payment-methods/src/BlikGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'Blik (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'Blik', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_blik_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -237,4 +236,24 @@ public function get_transaction_url( $order ): string {
237236

238237
return parent::get_transaction_url( $order );
239238
}
239+
240+
/**
241+
* Initialize APM gateway defaults from centralized definition.
242+
*/
243+
private function init_apm_defaults(): void {
244+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
245+
246+
$this->method_title = $defaults['method_title'];
247+
$this->method_description = $defaults['method_description'];
248+
}
249+
250+
/**
251+
* Load saved settings and override defaults.
252+
*/
253+
private function init_apm_settings(): void {
254+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
255+
256+
$this->title = $this->get_option( 'title', $defaults['title'] );
257+
$this->description = $this->get_option( 'description', $defaults['description'] );
258+
}
240259
}

modules/ppcp-local-alternative-payment-methods/src/EPSGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'EPS (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'EPS', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_eps_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -236,4 +235,24 @@ public function get_transaction_url( $order ): string {
236235

237236
return parent::get_transaction_url( $order );
238237
}
238+
239+
/**
240+
* Initialize APM gateway defaults from centralized definition.
241+
*/
242+
private function init_apm_defaults(): void {
243+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
244+
245+
$this->method_title = $defaults['method_title'];
246+
$this->method_description = $defaults['method_description'];
247+
}
248+
249+
/**
250+
* Load saved settings and override defaults.
251+
*/
252+
private function init_apm_settings(): void {
253+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
254+
255+
$this->title = $this->get_option( 'title', $defaults['title'] );
256+
$this->description = $this->get_option( 'description', $defaults['description'] );
257+
}
239258
}

modules/ppcp-local-alternative-payment-methods/src/IDealGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'iDeal (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'The most common payment method in the Netherlands, allowing Dutch buyers to pay directly through their preferred bank. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'iDeal', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_ideal_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -234,4 +233,24 @@ public function get_transaction_url( $order ): string {
234233

235234
return parent::get_transaction_url( $order );
236235
}
236+
237+
/**
238+
* Initialize APM gateway defaults from centralized definition.
239+
*/
240+
private function init_apm_defaults(): void {
241+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
242+
243+
$this->method_title = $defaults['method_title'];
244+
$this->method_description = $defaults['method_description'];
245+
}
246+
247+
/**
248+
* Load saved settings and override defaults.
249+
*/
250+
private function init_apm_settings(): void {
251+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
252+
253+
$this->title = $this->get_option( 'title', $defaults['title'] );
254+
$this->description = $this->get_option( 'description', $defaults['description'] );
255+
}
237256
}

modules/ppcp-local-alternative-payment-methods/src/MultibancoGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'Multibanco (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'Multibanco', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_multibanco_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -242,4 +241,24 @@ public function get_transaction_url( $order ): string {
242241

243242
return parent::get_transaction_url( $order );
244243
}
244+
245+
/**
246+
* Initialize APM gateway defaults from centralized definition.
247+
*/
248+
private function init_apm_defaults(): void {
249+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
250+
251+
$this->method_title = $defaults['method_title'];
252+
$this->method_description = $defaults['method_description'];
253+
}
254+
255+
/**
256+
* Load saved settings and override defaults.
257+
*/
258+
private function init_apm_settings(): void {
259+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
260+
261+
$this->title = $this->get_option( 'title', $defaults['title'] );
262+
$this->description = $this->get_option( 'description', $defaults['description'] );
263+
}
245264
}

modules/ppcp-local-alternative-payment-methods/src/MyBankGateway.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExperienceContextBuilder;
1515
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
1616
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
17+
use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition;
1718
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
1819
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
1920
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@@ -81,17 +82,15 @@ public function __construct(
8182
'products',
8283
);
8384

84-
$this->method_title = __( 'MyBank (via PayPal)', 'woocommerce-paypal-payments' );
85-
$this->method_description = __( 'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.', 'woocommerce-paypal-payments' );
86-
87-
$this->title = $this->get_option( 'title', __( 'MyBank', 'woocommerce-paypal-payments' ) );
88-
$this->description = $this->get_option( 'description', '' );
85+
$this->init_apm_defaults();
8986

9087
$this->icon = esc_url( 'https://www.paypalobjects.com/images/checkout/alternative_payments/paypal_mybank_color.svg' );
9188

9289
$this->init_form_fields();
9390
$this->init_settings();
9491

92+
$this->init_apm_settings();
93+
9594
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
9695

9796
$this->orders_endpoint = $orders_endpoint;
@@ -236,4 +235,24 @@ public function get_transaction_url( $order ): string {
236235

237236
return parent::get_transaction_url( $order );
238237
}
238+
239+
/**
240+
* Initialize APM gateway defaults from centralized definition.
241+
*/
242+
private function init_apm_defaults(): void {
243+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
244+
245+
$this->method_title = $defaults['method_title'];
246+
$this->method_description = $defaults['method_description'];
247+
}
248+
249+
/**
250+
* Load saved settings and override defaults.
251+
*/
252+
private function init_apm_settings(): void {
253+
$defaults = PaymentMethodsDefinition::get_apm_defaults()[ self::ID ];
254+
255+
$this->title = $this->get_option( 'title', $defaults['title'] );
256+
$this->description = $this->get_option( 'description', $defaults['description'] );
257+
}
239258
}

0 commit comments

Comments
 (0)