| 1 |
<?php |
| 2 |
class hyperpay_main |
| 3 |
{ |
| 4 |
/** |
| 5 |
* Payment gateway classes. |
| 6 |
* all new class should added here |
| 7 |
* @var array |
| 8 |
*/ |
| 9 |
protected static $HP_gateways = [ |
| 10 |
// Add Class Here |
| 11 |
'WC_Hyperpay_Zoodpay_Gateway', |
| 12 |
'WC_Hyperpay_Gateway', |
| 13 |
'WC_Hyperpay_STCPay_Gateway', |
| 14 |
'WC_Hyperpay_Mada_Gateway', |
| 15 |
'WC_Hyperpay_ApplePay_Gateway' |
| 16 |
]; |
| 17 |
|
| 18 |
/** |
| 19 |
* First function fire when click on active plugin |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
|
| 24 |
public static function load(): void |
| 25 |
{ |
| 26 |
foreach (self::$HP_gateways as $names) { // <== looping over all regestered class in $HP_gateways array |
| 27 |
include_once HYPERPAY_ABSPATH . "gateways/$names.php"; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* this filter documented in woocommerce to asign all gateways to [payments tab] insude woocommerce settings |
| 32 |
* |
| 33 |
* @param string filter_name |
| 34 |
* @param array[class_name,function_name] |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
|
| 38 |
add_filter('woocommerce_payment_gateways', ['hyperpay_main', 'get_gateways']); |
| 39 |
self::run_migration(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* CREATE tabe on database to store users transaction mode |
| 44 |
*/ |
| 45 |
public static function run_migration(): void |
| 46 |
{ |
| 47 |
|
| 48 |
global $wpdb; |
| 49 |
$sql_raw = "CREATE TABLE {$wpdb->prefix}woocommerce_saving_cards ( |
| 50 |
`id` INT AUTO_INCREMENT, |
| 51 |
`registration_id` VARCHAR(255) NOT NULL, |
| 52 |
`customer_id` VARCHAR(255) NOT NULL, |
| 53 |
`mode` int (10) NOT NULL, |
| 54 |
PRIMARY KEY (`id`) |
| 55 |
) ENGINE=INNODB |
| 56 |
DEFAULT CHARACTER SET utf8 |
| 57 |
COLLATE utf8_unicode_520_ci;"; |
| 58 |
|
| 59 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 60 |
dbDelta($sql_raw, true); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Merge the previous gateways with hyperPay gatways |
| 65 |
* |
| 66 |
* @param array $gateways |
| 67 |
* @return array $updated_gateways |
| 68 |
*/ |
| 69 |
|
| 70 |
public static function get_gateways(array $gateways): array |
| 71 |
{ |
| 72 |
|
| 73 |
return array_merge($gateways, self::$HP_gateways); |
| 74 |
} |
| 75 |
} |
| 76 |
|