Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Bitcoin_Gateway_Blocks_Checkout_Support | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| initialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| is_active | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_payment_method_script_handles | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| get_payment_method_data | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Make the payment gateway available to the new WooCommerce Blocks checkout. |
| 4 | * |
| 5 | * Mostly just registers a script. |
| 6 | * |
| 7 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 8 | */ |
| 9 | |
| 10 | namespace BrianHenryIE\WP_Bitcoin_Gateway\WooCommerce; |
| 11 | |
| 12 | use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; |
| 13 | use Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry; |
| 14 | use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; |
| 15 | use BrianHenryIE\WP_Bitcoin_Gateway\Settings_Interface; |
| 16 | |
| 17 | /** |
| 18 | * Instance of the class expected by PaymentMethodRegistry. |
| 19 | * |
| 20 | * @see PaymentMethodRegistry::register() |
| 21 | * @see IntegrationRegistry::initialize() |
| 22 | */ |
| 23 | class Bitcoin_Gateway_Blocks_Checkout_Support extends AbstractPaymentMethodType { |
| 24 | |
| 25 | /** |
| 26 | * Used to get the plugin URL. |
| 27 | */ |
| 28 | protected Settings_Interface $plugin_settings; |
| 29 | |
| 30 | /** |
| 31 | * The gateway instance. |
| 32 | * |
| 33 | * @var Bitcoin_Gateway |
| 34 | */ |
| 35 | protected $gateway; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * |
| 40 | * @param Bitcoin_Gateway $gateway The gateway instance. |
| 41 | * @param Settings_Interface $plugin_settings The plugin settings. |
| 42 | */ |
| 43 | public function __construct( Bitcoin_Gateway $gateway, Settings_Interface $plugin_settings ) { |
| 44 | $this->plugin_settings = $plugin_settings; |
| 45 | $this->gateway = $gateway; |
| 46 | $this->name = $gateway->id; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Initializes the payment method type. |
| 51 | * |
| 52 | * @see IntegrationInterface::initialize() |
| 53 | */ |
| 54 | public function initialize(): void { |
| 55 | $this->settings = $this->gateway->settings; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns if this payment method should be active. If false, the scripts will not be enqueued. |
| 60 | */ |
| 61 | public function is_active(): bool { |
| 62 | return $this->gateway->is_available(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns an array of scripts/handles to be registered for this payment method. |
| 67 | * |
| 68 | * @return array<string> |
| 69 | */ |
| 70 | public function get_payment_method_script_handles(): array { |
| 71 | |
| 72 | $handle = 'bh-wp-bitcoin-gateway-blocks'; |
| 73 | |
| 74 | $script_url = $this->plugin_settings->get_plugin_url() . 'assets/js/frontend/blocks/checkout/bh-wp-bitcoin-gateway-blocks-checkout.min.js'; |
| 75 | |
| 76 | $dependencies = array( 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n' ); |
| 77 | $version = $this->plugin_settings->get_plugin_version(); |
| 78 | |
| 79 | wp_register_script( $handle, $script_url, $dependencies, $version, true ); |
| 80 | |
| 81 | wp_set_script_translations( $handle, 'bh-wp-bitcoin-gateway', $this->plugin_settings->get_plugin_url() . 'languages/' ); |
| 82 | |
| 83 | return array( $handle ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns an array of key=>value pairs of data made available to the payment methods script. |
| 88 | * |
| 89 | * Filters the `WC_Payment_Gateway::$supports` array using the instance's `supports()` function. |
| 90 | * |
| 91 | * @see \WC_Payment_Gateway::supports() |
| 92 | * |
| 93 | * @return array{title:string, description:string, supports:array<string>} |
| 94 | */ |
| 95 | public function get_payment_method_data(): array { |
| 96 | return array( |
| 97 | 'title' => $this->get_setting( 'title' ), |
| 98 | 'description' => $this->get_setting( 'description' ), |
| 99 | 'supports' => array_filter( $this->gateway->supports, array( $this->gateway, 'supports' ) ), |
| 100 | ); |
| 101 | } |
| 102 | } |