<?php 
// version 1.0
require_once(dirname(__FILE__)."/functions.php");
require_once(dirname(__FILE__)."/actions.php");
require_once(dirname(__FILE__)."/do-action.php");
require_once(dirname(__FILE__)."/filters.php");

class paystack_gateway {

	public static $plugin_name = "paystack_gateway";
	public static $plugin_root = 'contents\plugins\paystack_gateway';
	public static $plugin_ref = "Paystack Gateway";

	public function __construct () {
		
	}

	public static function install() {
		$common_access = ['paystack', 'process_paystack'];
		add_common_access($common_access);
		$super_admin = []; //content owner
		$super_admin_tech = ['paystack_settings']; //technical owner
		$admin = ['paystack', 'process_paystack']; //content owner
		$admin_tech = ['paystack', 'process_paystack']; //technical owner
		$member = ['paystack', 'process_paystack'];
		$se = [];
		$pending = ['paystack', 'process_paystack'];
		$unverified = [];
		update_role('software_engineer', array_unique(array_merge($super_admin, $admin, $super_admin_tech, $admin_tech, $member, $se, $pending)));
		update_role('super_admin', $super_admin);
		update_role('admin', $admin);
		update_role('super_admin_tech', $super_admin_tech);
		update_role('admin_tech', $admin_tech);
		update_role('member', $member);
		update_role('pending', $pending);
		update_role('unverified', $unverified);

		$post = new post;
		if(!$post->search_post_by_permalink('paystack')) :
			register_admin_page(array(
					'title' => 'Paystack',
					'callback' => 'paystack_cb',
					'access' => 'paystack',
					'permalink' => 'paystack'
				));
		endif;

		if(!$post->search_post_by_permalink('process-paystack')) :
			register_admin_page(array(
					'title' => 'Payment Receipt',
					'callback' => 'process_paystack_cb',
					'access' => 'process_paystack',
					'permalink' => 'process-paystack'
				));
		endif;
		add_action('payment_method_display', 'paystack_payment_method');
		add_action('more_settings_field_right', 'paystack_settings_fields');
		add_action('save_more_settings_field', 'save_paystack_settings');
		add_filter("_pm_attachments_filter", "paystack_attachments_filter");
		add_action("pm_list_payment_method", "paystack_pm_list_payment_method");
		$args = [
					'gateway_name' => 'Debit/Credit Card',
					'gateway_description' => 'Debit/Credit Card payment will be processed securely through paystack payment gateway. This gateway also enables you to pay with just your bank account number.',
					'gateway_icon' => 'contents/plugins/paystack_gateway/img/card-72x72.png',
					'gateway_page' => 'paystack',
					'gateway_id' => 'paystack'
				];
		update_option("gtw_meta-paystack", $args);
	}

	public static function uninstall() {
		unregister_admin_page([
			'paystack', 'process-paystack'
		]);

		remove_action('payment_method_display', 'paystack_payment_method');
		remove_action('more_settings_field_right', 'paystack_settings_fields');
		remove_action('save_more_settings_field', 'save_paystack_settings');
	}
}