| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; |
| 8 |
|
| 9 |
/** |
| 10 |
* Paykeeper Payments Blocks integration |
| 11 |
* |
| 12 |
* @since 2.0.0 |
| 13 |
*/ |
| 14 |
final class WC_Paykeeper_Blocks extends AbstractPaymentMethodType { |
| 15 |
|
| 16 |
/** |
| 17 |
* The gateway instance. |
| 18 |
* |
| 19 |
* @var WC_PK_Gateway |
| 20 |
*/ |
| 21 |
private $gateway; |
| 22 |
|
| 23 |
/** |
| 24 |
* Payment method name/id/slug. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
protected $name = 'paykeeper'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Initializes the payment method type. |
| 32 |
*/ |
| 33 |
public function initialize() { |
| 34 |
$this->settings = get_option( 'woocommerce_' . $this->name . '_settings', [] ); |
| 35 |
$gateways = WC()->payment_gateways->payment_gateways(); |
| 36 |
$this->gateway = $gateways[$this->name]; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns if this payment method should be active. If false, the scripts will not be enqueued. |
| 41 |
* |
| 42 |
* @return boolean |
| 43 |
*/ |
| 44 |
public function is_active() { |
| 45 |
return $this->gateway->is_available(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns an array of scripts/handles to be registered for this payment method. |
| 50 |
* |
| 51 |
* @return array |
| 52 |
*/ |
| 53 |
public function get_payment_method_script_handles() { |
| 54 |
|
| 55 |
wp_register_script( |
| 56 |
'paykeeper-blocks-integration', |
| 57 |
plugin_dir_url(__FILE__) . 'checkout.js', |
| 58 |
[ |
| 59 |
'wc-blocks-registry', |
| 60 |
'wc-settings', |
| 61 |
'wp-element', |
| 62 |
'wp-html-entities', |
| 63 |
'wp-i18n', |
| 64 |
], |
| 65 |
null, |
| 66 |
true |
| 67 |
); |
| 68 |
if( function_exists( 'wp_set_script_translations' ) ) { |
| 69 |
wp_set_script_translations( 'paykeeper-blocks-integration'); |
| 70 |
|
| 71 |
} |
| 72 |
return [ 'paykeeper-blocks-integration' ]; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Returns an array of key=>value pairs of data made available to the payment methods script. |
| 77 |
* |
| 78 |
* @return array |
| 79 |
*/ |
| 80 |
public function get_payment_method_data() { |
| 81 |
return [ |
| 82 |
'title' => $this->gateway->title, |
| 83 |
'description' => $this->gateway->description, |
| 84 |
'supports' => array_filter( $this->gateway->supports, [ $this->gateway, 'supports' ] ) |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
?> |