| 1 |
<?php |
| 2 |
|
| 3 |
namespace SpringDevs\Subscription\Illuminate\Gateways\Paypal; |
| 4 |
|
| 5 |
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; |
| 6 |
|
| 7 |
/** |
| 8 |
* Paypal Blocks Integration Class |
| 9 |
* This class integrates the PayPal payment gateway with WooCommerce Blocks. |
| 10 |
* |
| 11 |
* @package SpringDevs\Subscription\Illuminate\Gateways\Paypal |
| 12 |
*/ |
| 13 |
final class Paypal_Blocks_Integration extends AbstractPaymentMethodType { |
| 14 |
|
| 15 |
/** |
| 16 |
* The gateway instance. |
| 17 |
* |
| 18 |
* @var Paypal |
| 19 |
*/ |
| 20 |
private $gateway; |
| 21 |
|
| 22 |
/** |
| 23 |
* Payment method name/id/slug. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected $name = 'wp_subscription_paypal'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Initialize the gateway. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function initialize() { |
| 35 |
$this->settings = get_option( 'woocommerce_wp_subscription_paypal_settings', [] ); |
| 36 |
$this->gateway = Paypal::get_instance(); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Check if the gateway is active. |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
public function is_active() { |
| 45 |
return $this->gateway->is_available(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get the payment method title. |
| 50 |
* |
| 51 |
* @return string |
| 52 |
*/ |
| 53 |
public function get_payment_method_script_handles() { |
| 54 |
wp_register_script( |
| 55 |
'wp_subscription_paypal-blocks-integration', |
| 56 |
SUBSCRPT_URL . '/assets/js/wp_subscription_paypal-block.js', |
| 57 |
[ 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n' ], |
| 58 |
1, |
| 59 |
true |
| 60 |
); |
| 61 |
if ( function_exists( 'wp_set_script_translations' ) ) { |
| 62 |
wp_set_script_translations( 'wp_subscription_paypal-blocks-integration', 'subscription', SUBSCRPT_PATH . '/languages' ); |
| 63 |
} |
| 64 |
|
| 65 |
return array( 'wp_subscription_paypal-blocks-integration' ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Get the payment method title. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
public function get_payment_method_data() { |
| 74 |
return [ |
| 75 |
'title' => $this->gateway->title, |
| 76 |
'description' => $this->gateway->description, |
| 77 |
'icon' => $this->gateway->icon, |
| 78 |
'features' => $this->gateway->supports, |
| 79 |
]; |
| 80 |
} |
| 81 |
} |
| 82 |
|