PluginProbe
HyperPay Payments / 3.0.5
HyperPay Payments v3.0.5
6.6.0 trunk 1.7 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.5 4.0.0 4.0.2 All 34 releases
hyperpay-gateways / src / Main.php

Main.php in HyperPay Payments 3.0.5, at src/Main.php

114 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Hyperpay\Gateways;
3 //use class here
4
5 use Hyperpay\Gateways\App\Log;
6 use Hyperpay\Gateways\App\Webhook;
7 use Hyperpay\Gateways\Brands\ApplePay;
8 use Hyperpay\Gateways\Brands\Cliq;
9 use Hyperpay\Gateways\Brands\CreditCard;
10 use Hyperpay\Gateways\Brands\Mada;
11 use Hyperpay\Gateways\Brands\STCPay;
12 use Hyperpay\Gateways\Brands\Tabby;
13 use Hyperpay\Gateways\Brands\Tamara;
14 use Hyperpay\Gateways\Brands\UrPay;
15
16 class Main
17 {
18 /**
19 * Payment gateway classes.
20 * all new class should added here
21 * @var array
22 */
23 protected static $HP_gateways = [
24 // Add Class Here
25 UrPay::class,
26 Tabby::class,
27 Tamara::class,
28 Cliq::class,
29 STCPay::class,
30 Mada::class,
31 ApplePay::class,
32 CreditCard::class
33 ];
34
35 public const ROOT_PATH = __DIR__;
36 /**
37 * First function fire when click on active plugin
38 *
39 * @return void
40 */
41
42 public static function load(): void
43 {
44
45 // do not load the plugin if wooCommerce not installed
46 if(!self::isWooCommerceLoaded()) return;
47
48
49 /**
50 * this filter documented in wooCommerce to assign all gateways to [payments tab] inside wooCommerce settings
51 *
52 * @param string filter_name
53 * @param array[class_name,function_name]
54 * @return void
55 */
56
57 add_filter('woocommerce_payment_gateways', [self::class, 'get_gateways']);
58 add_action('rest_api_init', [Webhook::class, 'hyperpay_rest_orders']);//register the webhook class
59
60 if(is_admin()){
61 add_action('admin_menu', function () {
62 add_options_page('Hyperpay logs', 'Hyperpay logs', 'manage_options', 'hyperpay-logs', [Log::class, "load"]);
63 });
64 }
65
66 }
67
68 /**
69 * Check if the wooCommerce plugin is installed and active
70 * @return boolean
71 */
72
73 private static function isWooCommerceLoaded()
74 {
75 if (!class_exists( 'woocommerce' )) {
76
77 add_action(
78 'admin_notices',
79 function() {
80 ?>
81 <div class="notice notice-error">
82 <p>
83 <?php
84 printf(
85 esc_html__( 'Hyperpay plugin could not be loaded without wooCommerce %1$splease install wooCommerce first %2$s', 'hyperpay-payments' ),
86 '<a href="' . esc_url( '/wp-admin/plugin-install.php?s=WooCommerce&tab=search&type=term' ) . '" rel="noopener noreferrer">',
87 '</a>'
88 );
89 ?>
90 </p>
91 </div>
92 <?php
93 }
94 );
95 return false;
96 }
97 return true;
98 }
99
100
101 /**
102 * Merge the previous gateways with hyperPay gateways
103 *
104 * @param array $gateways
105 * @return array $updated_gateways
106 */
107
108 public static function get_gateways(array $gateways): array
109 {
110
111 return array_merge($gateways, self::$HP_gateways);
112 }
113 }
114