| 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 |
|