PluginProbe
Mintpay / trunk
Mintpay vtrunk
2.2.3 2.2.2 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 2.0.4 2.0.6 2.1.0 2.1.1 2.2.0 2.2.1
mintpay / index.php

index.php in Mintpay trunk, at index.php

148 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Mintpay
4 * Plugin URI: https://mintpay.lk
5 * Description: WooCommerce plugin of Mintpay. Sri Lanka's first buy now pay later platform, that allows consumers to split their payment into 3 interst-free installments.
6 * Version: 2.2.3
7 * Author: Mintpay (Private) Limited
8 * Author URI: https://mintpay.lk
9 * License: GPL-3.0
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
11 * Text Domain: mintpay
12 * Domain Path: /languages
13 *
14 * @package Mintpay
15 */
16
17
18
19 // Exit if accessed directly.
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * WooCommerce Mintpay Gateway main class.
26 *
27 * @class WC_MintPay
28 */
29 class WC_Mintpay {
30 /**
31 * Plugin bootstrap.
32 */
33 public static function init(): void {
34 // Mintpay Gateway class.
35 add_action( 'plugins_loaded', array( __CLASS__, 'include_gateway_class' ), 0 );
36
37 // Add the gateway to WooCommerce.
38 add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'add_gateway' ) );
39
40 // Add action links.
41 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'plugin_action_links' ) );
42
43 // Registers WooCommerce Blocks integration.
44 add_action( 'woocommerce_blocks_loaded', array(
45 __CLASS__,
46 'woocommerce_gateway_mintpay_woocommerce_block_support'
47 ) );
48
49 // Mintpay Price Breakdown.
50 add_action( 'plugins_loaded', array( __CLASS__, 'include_price_breakdown' ), 0 );
51 }
52
53 /**
54 * Include the Mintpay Gateway class.
55 */
56 public static function include_gateway_class(): void {
57
58 // Make the WC_Gateway_Dummy class available.
59 if ( class_exists( 'WC_Payment_Gateway' ) ) {
60 require_once dirname( __FILE__ ) . '/gateway/index.php';
61 }
62 }
63
64 /**
65 * Include the Price Breakdown file.
66 */
67 public static function include_price_breakdown(): void {
68 // Make the WC_Gateway_Dummy class available.
69 if ( class_exists( 'WC_Payment_Gateway' ) ) {
70 require_once dirname( __FILE__ ) . '/price-breakdown/index.php';
71 }
72 }
73
74
75 /**
76 * Add the gateway to WooCommerce.
77 *
78 * @param array $methods Payment methods.
79 *
80 * @return array Payment methods.
81 */
82 public static function add_gateway( array $methods ): array {
83 $methods[] = 'Mintpay_Gateway';
84
85 return $methods;
86 }
87
88 /**
89 * Custom action links.
90 *
91 * @param array $links Plugin action links.
92 *
93 */
94 public static function plugin_action_links( array $links ): array {
95 $plugin_links = array(
96 '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=mintpay' ) . '">Settings</a>',
97 );
98
99 return array_merge( $plugin_links, $links );
100 }
101
102 /**
103 * Plugin url.
104 *
105 * @return string
106 */
107 public static function plugin_url() {
108 return untrailingslashit( plugins_url( '/', __FILE__ ) );
109 }
110
111 /**
112 * Plugin url.
113 *
114 * @return string
115 */
116 public static function plugin_abspath() {
117 return trailingslashit( plugin_dir_path( __FILE__ ) );
118 }
119
120 public static function woocommerce_gateway_mintpay_woocommerce_block_support() {
121 if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
122 require_once dirname( __FILE__ ) . '/gateway/blocks.php';
123 add_action(
124 'woocommerce_blocks_payment_method_type_registration',
125 function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
126 $payment_method_registry->register( new WC_Mintpay_Blocks() );
127 }
128 );
129 }
130 }
131
132 }
133
134 // Check if WooCommerce is active.
135 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
136 WC_Mintpay::init();
137 } else {
138 add_action(
139 'admin_notices',
140 function () {
141 ?>
142 <div class="notice notice-error is-dismissible">
143 <p><?php echo 'Mintpay Plugin requires WooCommerce to be installed and active.'; ?></p>
144 </div>
145 <?php
146 }
147 );
148 }