-
Notifications
You must be signed in to change notification settings - Fork 23
/
paddle-woo-checkout.php
executable file
·121 lines (101 loc) · 2.83 KB
/
paddle-woo-checkout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
* Plugin Name: Paddle
* Plugin URI: https://github.com/hasinhayder/paddle-woocommerce-3
* Description: Paddle Payment Gateway for WooCommerce
* Version: 3.0.1
* Author: Paddle.com (Improvements by ThemeBucket)
* Author URI: https://github.com/hasinhayder
*/
defined('ABSPATH') or die("Plugin must be run as part of wordpress");
if (!class_exists('Paddle_WC')) :
/**
* Main Paddle_WC Class.
*
* @class Paddle_WC
* @version 3.0.0
*/
final class Paddle_WC {
/**
* Instance of our settings object.
*
* @var Paddle_WC_Settings
*/
private $settings;
/**
* Instance of our checkout handler.
*
* @var Paddle_WC_Checkout
*/
private $checkout;
/**
* The gateway that handles the payments and the admin setup.
*
* @var Paddle_WC_Gateway
*/
private $gateway;
/**
* The single instance of the class.
*
* @var Paddle_WC
*/
private static $_instance = null;
/**
* Main Paddle_WC Instance.
* Ensures only one instance of WooCommerce is loaded or can be loaded.
*
* @static
* @return Paddle_WC - Main instance.
*/
public static function instance() {
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Paddle_WC Constructor.
*/
public function __construct() {
$this->register_init_callback();
}
/**
* Registers the init callback for when WP is done loading plugins.
*/
private function register_init_callback() {
add_action('plugins_loaded', array($this, 'on_wp_plugins_loaded'));
}
/**
* Callback called during plugin load to setup the Paddle_WC.
*/
public function on_wp_plugins_loaded() {
// Don't load extension if WooCommerce is not active
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
include_once('models/api.php');
include_once('models/checkout.php');
include_once('models/gateway.php');
include_once('models/settings.php');
// Register the Paddle gateway with WC
add_filter('woocommerce_payment_gateways', array($this, 'on_register_woocommerce_gateways'));
// Add the checkout scripts and actions, if enabled
$this->settings = new Paddle_WC_Settings();
if($this->settings->get('enabled') == 'yes') {
// Setup checkout object and register intercepts to render page content
$this->checkout = new Paddle_WC_Checkout($this->settings);
$this->checkout->register_callbacks();
}
// Always setup the gateway as its needed to change admin settings
$this->gateway = new Paddle_WC_Gateway($this->settings);
$this->gateway->register_callbacks();
}
}
/**
* Callback called during plugin load to setup the Paddle_WC.
*/
public function on_register_woocommerce_gateways($methods) {
$methods[] = 'Paddle_WC_Gateway';
return $methods;
}
}
endif;
$GLOBALS['paddle_wc'] = Paddle_WC::instance();