PluginProbe
MONEI Payments for WooCommerce / trunk
MONEI Payments for WooCommerce vtrunk
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / src / Helpers / CardBrandHelper.php

CardBrandHelper.php in MONEI Payments for WooCommerce trunk, at src/Helpers/CardBrandHelper.php

65 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Monei\Helpers;
4
5 use Monei\Services\PaymentMethodsService;
6
7 class CardBrandHelper {
8
9 private $paymentMethodsService;
10
11 public function __construct( PaymentMethodsService $paymentMethodsService ) {
12 $this->paymentMethodsService = $paymentMethodsService;
13 }
14
15 /**
16 * Get card brand configuration for JavaScript.
17 *
18 * @return array Array of brand configs with url, width, height, title.
19 */
20 public function getCardBrandsConfig(): array {
21 $brands = $this->paymentMethodsService->getCardBrands();
22 $config = array();
23
24 foreach ( $brands as $brand ) {
25 $config[ $brand ] = array(
26 'url' => WC_Monei()->image_url( "cards/{$brand}.svg" ),
27 'width' => 40,
28 'height' => 24,
29 'title' => $this->getBrandTitle( $brand ),
30 );
31 }
32
33 // Add default fallback
34 $config['default'] = array(
35 'url' => WC_Monei()->image_url( 'cards/default.svg' ),
36 'width' => 40,
37 'height' => 24,
38 'title' => __( 'Card', 'monei' ),
39 );
40
41 return $config;
42 }
43
44 /**
45 * Get human-readable brand title.
46 *
47 * @param string $brand Brand code.
48 * @return string Brand title.
49 */
50 private function getBrandTitle( string $brand ): string {
51 $titles = array(
52 'visa' => 'Visa',
53 'mastercard' => 'Mastercard',
54 'amex' => 'American Express',
55 'discover' => 'Discover',
56 'diners' => 'Diners Club',
57 'jcb' => 'JCB',
58 'maestro' => 'Maestro',
59 'unionpay' => 'UnionPay',
60 );
61
62 return $titles[ $brand ] ?? ucfirst( $brand );
63 }
64 }
65