| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDesk\GatewayWPPay\Blocks; |
| 4 |
|
| 5 |
use \Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; |
| 6 |
|
| 7 |
|
| 8 |
abstract class PaymentBlock extends AbstractPaymentMethodType { |
| 9 |
|
| 10 |
/** |
| 11 |
* @var string |
| 12 |
*/ |
| 13 |
protected $script_url; |
| 14 |
|
| 15 |
/** |
| 16 |
* @var \WC_Payment_Gateway |
| 17 |
*/ |
| 18 |
protected $gateway; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var \WC_Payment_Gateway |
| 22 |
*/ |
| 23 |
protected $icon_url; |
| 24 |
|
| 25 |
protected const JAVASCRIPT_FILE_SUFFIX = '.js'; |
| 26 |
protected const ASSET_FILE_SUFFIX = '.asset.php'; |
| 27 |
protected const SCRIPT_HANDLE_SUFFIX = '_handle'; |
| 28 |
protected const SCRIPT_VERSION = '2.1.0'; |
| 29 |
|
| 30 |
public function __construct( \WC_Payment_Gateway $gateway, string $script_url, string $icon_url = '' ) { |
| 31 |
$this->script_url = $script_url; |
| 32 |
$this->gateway = $gateway; |
| 33 |
$this->icon_url = $icon_url; |
| 34 |
} |
| 35 |
|
| 36 |
public function initialize() { |
| 37 |
// TODO: Implement initialize() method. |
| 38 |
} |
| 39 |
|
| 40 |
public function is_active(): bool { |
| 41 |
return $this->gateway->is_available(); |
| 42 |
} |
| 43 |
|
| 44 |
public function get_payment_method_script_handles() { |
| 45 |
$script_handle = $this->name . self::SCRIPT_HANDLE_SUFFIX; |
| 46 |
|
| 47 |
$javascript_block_path = $this->script_url . self::JAVASCRIPT_FILE_SUFFIX; |
| 48 |
$block_assets_path = $this->script_url . self::ASSET_FILE_SUFFIX; |
| 49 |
|
| 50 |
$script_asset = file_exists( $block_assets_path ) |
| 51 |
? require( $block_assets_path ) |
| 52 |
: [ |
| 53 |
'dependencies' => [], |
| 54 |
'version' => self::SCRIPT_VERSION, |
| 55 |
]; |
| 56 |
$script_asset['version'] = self::SCRIPT_VERSION . '.' . $script_asset['version']; |
| 57 |
|
| 58 |
wp_register_script( |
| 59 |
$script_handle, |
| 60 |
$javascript_block_path, |
| 61 |
$script_asset['dependencies'], |
| 62 |
$script_asset['version'], |
| 63 |
true |
| 64 |
); |
| 65 |
|
| 66 |
return [ $script_handle ]; |
| 67 |
} |
| 68 |
|
| 69 |
public function get_payment_method_data() { |
| 70 |
return [ |
| 71 |
'label' => $this->gateway->get_title(), |
| 72 |
'description' => $this->gateway->get_description(), |
| 73 |
'supports' => $this->gateway->supports, |
| 74 |
'icon_url' => $this->icon_url, |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|