PluginProbe
MultiSafepay plugin for WooCommerce / trunk
MultiSafepay plugin for WooCommerce vtrunk
6.11.1 6.12.0 6.13.0 6.2.0 6.2.1 6.3.0 6.3.1 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.6.0 6.6.1 6.6.2 6.7.0 6.7.1 6.7.2 6.7.3 6.8.0 6.8.1 6.8.2 6.8.3 6.9.0 All 84 releases
multisafepay / src / Utils / PaymentMethodTitleBuilder.php

PaymentMethodTitleBuilder.php in MultiSafepay plugin for WooCommerce trunk, at src/Utils/PaymentMethodTitleBuilder.php

62 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 namespace MultiSafepay\WooCommerce\Utils;
4
5 /**
6 * Build display labels for payment methods based on wallet and instrument details.
7 */
8 class PaymentMethodTitleBuilder {
9
10 /**
11 * Normalize known payment instrument labels for display.
12 *
13 * The same keys are reused to validate whether wallet + instrument titles can be combined.
14 */
15 private const PAYMENT_INSTRUMENT_TITLE_MAP = array(
16 'VISA' => 'Visa',
17 'AMEX' => 'American Express',
18 'MASTERCARD' => 'Mastercard',
19 );
20
21 /**
22 * Return the underlying payment instrument label
23 *
24 * @param string $payment_instrument_gateway_code
25 * @return string
26 */
27 public function get_underlying_payment_method_title( string $payment_instrument_gateway_code ): string {
28 $trimmed_payment_method_gateway_code = trim( $payment_instrument_gateway_code );
29
30 return self::PAYMENT_INSTRUMENT_TITLE_MAP[ $trimmed_payment_method_gateway_code ] ?? $trimmed_payment_method_gateway_code;
31 }
32
33 /**
34 * Check whether wallet and payment instrument titles can be combined.
35 *
36 * @param string $payment_instrument_gateway_code
37 * @return bool
38 */
39 public function can_build_wallet_combined_payment_method_title( string $payment_instrument_gateway_code ): bool {
40 return isset( self::PAYMENT_INSTRUMENT_TITLE_MAP[ trim( $payment_instrument_gateway_code ) ] );
41 }
42
43 /**
44 * Build the combined payment method title, e.g., Google Pay (Visa)
45 *
46 * @param string $wallet_title
47 * @param string $payment_instrument_title
48 * @return string
49 */
50 public function build_combined_payment_method_title( string $wallet_title, string $payment_instrument_title ): string {
51 if ( '' === $wallet_title ) {
52 return $payment_instrument_title;
53 }
54
55 if ( '' === $payment_instrument_title ) {
56 return $wallet_title;
57 }
58
59 return $wallet_title . ' (' . $payment_instrument_title . ')';
60 }
61 }
62