AbstractPaymentMethodType.php
2 years ago
BankTransfer.php
1 year ago
CashOnDelivery.php
1 year ago
Cheque.php
1 year ago
PayPal.php
4 months ago
Cheque.php
79 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\Payments\Integrations; |
| 3 | |
| 4 | use Exception; |
| 5 | use Automattic\WooCommerce\Blocks\Assets\Api; |
| 6 | use WC_Gateway_Cheque; |
| 7 | |
| 8 | /** |
| 9 | * Cheque payment method integration |
| 10 | * |
| 11 | * @since 2.6.0 |
| 12 | */ |
| 13 | final class Cheque extends AbstractPaymentMethodType { |
| 14 | /** |
| 15 | * Payment method name defined by payment methods extending this class. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $name = WC_Gateway_Cheque::ID; |
| 20 | |
| 21 | /** |
| 22 | * An instance of the Asset Api |
| 23 | * |
| 24 | * @var Api |
| 25 | */ |
| 26 | private $asset_api; |
| 27 | |
| 28 | /** |
| 29 | * Constructor |
| 30 | * |
| 31 | * @param Api $asset_api An instance of Api. |
| 32 | */ |
| 33 | public function __construct( Api $asset_api ) { |
| 34 | $this->asset_api = $asset_api; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Initializes the payment method type. |
| 39 | */ |
| 40 | public function initialize() { |
| 41 | $this->settings = get_option( 'woocommerce_cheque_settings', [] ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns if this payment method should be active. If false, the scripts will not be enqueued. |
| 46 | * |
| 47 | * @return boolean |
| 48 | */ |
| 49 | public function is_active() { |
| 50 | return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns an array of scripts/handles to be registered for this payment method. |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function get_payment_method_script_handles() { |
| 59 | $this->asset_api->register_script( |
| 60 | 'wc-payment-method-cheque', |
| 61 | 'assets/client/blocks/wc-payment-method-cheque.js' |
| 62 | ); |
| 63 | return [ 'wc-payment-method-cheque' ]; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns an array of key=>value pairs of data made available to the payment methods script. |
| 68 | * |
| 69 | * @return array |
| 70 | */ |
| 71 | public function get_payment_method_data() { |
| 72 | return [ |
| 73 | 'title' => $this->get_setting( 'title' ), |
| 74 | 'description' => $this->get_setting( 'description' ), |
| 75 | 'supports' => $this->get_supported_features(), |
| 76 | ]; |
| 77 | } |
| 78 | } |
| 79 |