wp-parsidate
/
inc
/
App
/
Integration
/
WooCommerce
/
wc-gateways
/
blocks
/
wpp-melli-pg-block.php
wpp-mellat-pg-block.php
1 month ago
wpp-melli-pg-block.php
1 month ago
wpp-parsian-pg-block.php
1 month ago
wpp-pasargad-pg-block.php
1 month ago
wpp-melli-pg-block.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; |
| 6 | use WPParsidate\Helper\Assets; |
| 7 | |
| 8 | if ( ! class_exists( 'WPP_WC_Melli_Gateway_Blocks' ) ) { |
| 9 | final class WPP_WC_Melli_Gateway_Blocks extends AbstractPaymentMethodType { |
| 10 | |
| 11 | private $gateway; |
| 12 | |
| 13 | /** |
| 14 | * Payment method name/id/slug. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $name = 'melli'; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Initializes the payment method type. |
| 23 | */ |
| 24 | public function initialize() { |
| 25 | $class_name = get_class( $this ); |
| 26 | $this->settings = get_option( "woocommerce_{$this->name}_settings", [] ); |
| 27 | $this->gateway = new $class_name; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Returns if this payment method should be active. If false, the scripts will not be enqueued. |
| 32 | * |
| 33 | * @return boolean |
| 34 | */ |
| 35 | public function is_active() { |
| 36 | return filter_var( $this->get_setting( 'enabled', true ), FILTER_VALIDATE_BOOLEAN ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns an array of scripts/handles to be registered for this payment method. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public function get_payment_method_script_handles() { |
| 45 | $script_id = "wpp-wc-$this->name-blocks-integration"; |
| 46 | $script_name = "wpp-wc-$this->name-pg.js"; |
| 47 | |
| 48 | wp_register_script( |
| 49 | $script_id, |
| 50 | Assets::url( "js-admin/wc-pg-blocks/$script_name" ), |
| 51 | array( |
| 52 | 'wc-blocks-registry', |
| 53 | 'wc-settings', |
| 54 | 'wp-element', |
| 55 | 'wp-html-entities', |
| 56 | 'wp-i18n', |
| 57 | ), |
| 58 | Assets::getVersion(), |
| 59 | true |
| 60 | ); |
| 61 | |
| 62 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| 63 | wp_set_script_translations( $script_id, 'wp-parsidate', WP_PARSI_DIR . 'languages/' ); |
| 64 | } |
| 65 | |
| 66 | return array( $script_id ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns an array of key=>value pairs of data made available to the payment methods script. |
| 71 | * |
| 72 | * @return array |
| 73 | */ |
| 74 | public function get_payment_method_data() { |
| 75 | return array( |
| 76 | 'title' => $this->get_setting( 'title' ), |
| 77 | 'description' => $this->get_setting( 'description' ), |
| 78 | 'supports' => $this->get_supported_features(), |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 |