Integrations
1 year ago
Api.php
2 years ago
PaymentMethodRegistry.php
2 years ago
PaymentMethodTypeInterface.php
2 years ago
PaymentMethodRegistry.php
68 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\Payments; |
| 3 | |
| 4 | use Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry; |
| 5 | |
| 6 | /** |
| 7 | * Class used for interacting with payment method types. |
| 8 | * |
| 9 | * @since 2.6.0 |
| 10 | */ |
| 11 | final class PaymentMethodRegistry extends IntegrationRegistry { |
| 12 | /** |
| 13 | * Integration identifier is used to construct hook names and is given when the integration registry is initialized. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $registry_identifier = 'payment_method_type'; |
| 18 | |
| 19 | /** |
| 20 | * Retrieves all registered payment methods that are also active. |
| 21 | * |
| 22 | * @return PaymentMethodTypeInterface[] |
| 23 | */ |
| 24 | public function get_all_active_registered() { |
| 25 | return array_filter( |
| 26 | $this->get_all_registered(), |
| 27 | function( $payment_method ) { |
| 28 | return $payment_method->is_active(); |
| 29 | } |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Gets an array of all registered payment method script handles, but only for active payment methods. |
| 35 | * |
| 36 | * @return string[] |
| 37 | */ |
| 38 | public function get_all_active_payment_method_script_dependencies() { |
| 39 | $script_handles = []; |
| 40 | $payment_methods = $this->get_all_active_registered(); |
| 41 | |
| 42 | foreach ( $payment_methods as $payment_method ) { |
| 43 | $script_handles = array_merge( |
| 44 | $script_handles, |
| 45 | is_admin() ? $payment_method->get_payment_method_script_handles_for_admin() : $payment_method->get_payment_method_script_handles() |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | return array_unique( array_filter( $script_handles ) ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Gets an array of all registered payment method script data, but only for active payment methods. |
| 54 | * |
| 55 | * @return array |
| 56 | */ |
| 57 | public function get_all_registered_script_data() { |
| 58 | $script_data = []; |
| 59 | $payment_methods = $this->get_all_active_registered(); |
| 60 | |
| 61 | foreach ( $payment_methods as $payment_method ) { |
| 62 | $script_data[ $payment_method->get_name() ] = $payment_method->get_payment_method_data(); |
| 63 | } |
| 64 | |
| 65 | return array( 'paymentMethodData' => array_filter( $script_data ) ); |
| 66 | } |
| 67 | } |
| 68 |