-
Notifications
You must be signed in to change notification settings - Fork 5
/
wp-payment-form-pro.php
238 lines (204 loc) · 8.85 KB
/
wp-payment-form-pro.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* Plugin Name: WPPayForm Pro
* Plugin URI: https://wppayform.wpmanageninja.com/
* Description: Create and Accept Payments in minutes with Stripe, PayPal with built-in form builder
* Author: WPManageNinja LLC
* Author URI: https://wpmanageninja.com
* Version: 2.1.0
* Text Domain: wppayform
*/
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright 2019 WPManageNinja LLC. All rights reserved.
*/
if (!defined('ABSPATH')) {
exit;
}
define('WPPAYFORM_PRO_INSTALLED', true);
if (!defined('WPPAYFORM_VERSION_LITE')) {
define('WPPAYFORM_VERSION', '2.1.0');
define('WPPAYFORM_DB_VERSION', 120);
// Stripe API version should be in 'YYYY-MM-DD' format.
define('WPPAYFORM_STRIPE_API_VERSION', '2019-05-16');
define('WPPAYFORM_MAIN_FILE', __FILE__);
define('WPPAYFORM_URL', plugin_dir_url(__FILE__));
define('WPPAYFORM_DIR', plugin_dir_path(__FILE__));
if (!defined('WPPAYFORM_UPLOAD_DIR')) {
define('WPPAYFORM_UPLOAD_DIR', '/wppayform');
}
class WPPayForm
{
public function boot()
{
$this->textDomain();
$this->loadDependecies();
if (is_admin()) {
$this->adminHooks();
}
$this->commonActions();
$this->registerShortcodes();
$this->loadComponents();
}
public function adminHooks()
{
// Init The Classes
// Register Post Type
new \WPPayForm\Classes\PostType();
// Register Admin menu
$menu = new \WPPayForm\Classes\Menu();
$menu->register();
add_action('wppayform/render_admin_app', function () {
$adminApp = new \WPPayForm\Classes\AdminApp();
$adminApp->bootView();
});
// Top Level Ajax Handlers
$ajaxHandler = new \WPPayForm\Classes\AdminAjaxHandler();
$ajaxHandler->registerEndpoints();
// Top Level discounts Handlers
$discounts = new \WPPayForm\Pro\Classes\Coupons\Coupon();
$discounts->registerEndpoints();
// Submission Ajax Handler
$submissionHandler = new \WPPayForm\Classes\SubmissionView();
$submissionHandler->registerEndpoints();
// General Settings Handler
$globalSettingHandler = new \WPPayForm\Classes\GlobalSettingsHandler();
$globalSettingHandler->registerHooks();
// Handle Globla Tools
$globalTools = new \WPPayForm\Classes\Tools\GlobalTools();
$globalTools->registerEndpoints();
// Handle Demo Forms
$demoForms = new \WPPayForm\Classes\Tools\DemoForms();
$demoForms->registerEndpoints();
// init tinymce
$tinyMCE = new \WPPayForm\Classes\Integrations\TinyMceBlock();
$tinyMCE->register();
// Dashboard Widget Here
$dashboardWidget = new \WPPayForm\Classes\DashboardWidgetModule();
$dashboardWidget->register();
// disabled update-nag
add_action('admin_init', function () {
$disablePages = [
'wppayform.php',
];
if (isset($_GET['page']) && in_array($_GET['page'], $disablePages)) {
remove_all_actions('admin_notices');
}
});
}
public function registerShortcodes()
{
// Register the shortcode
add_shortcode('wppayform', function ($args) {
$args = shortcode_atts(array(
'id' => '',
'show_title' => false,
'show_description' => false
), $args);
if (!$args['id']) {
return;
}
$builder = new \WPPayForm\Classes\Builder\Render();
return $builder->render($args['id'], $args['show_title'], $args['show_description']);
});
add_shortcode('wppayform_reciept', function ($atts) {
$args = shortcode_atts(array(
'hash' => ''
), $atts, 'wppayform_reciept');
if (!$args['hash']) {
$hash = \WPPayForm\Classes\ArrayHelper::get($_REQUEST, 'wpf_submission');
if (!$hash) {
$hash = \WPPayForm\Classes\ArrayHelper::get($_REQUEST, 'wpf_hash');
}
} else {
$hash = $args['hash'];
}
if ($hash) {
$submission = wpPayFormDB()->table('wpf_submissions')
->where('submission_hash', '=', $hash)
->first();
if ($submission) {
$receiptHandler = new \WPPayForm\Classes\Builder\PaymentReceipt();
return $receiptHandler->render($submission->id);
}
}
return '<p class="wpf_no_recipt_found">' . __('Sorry, no submission receipt found, Please check your receipt URL', 'wppayform') . '</p>';
});
}
public function commonActions()
{
// Form Submission Handler
$submissionHandler = new \WPPayForm\Classes\SubmissionHandler();
add_action('wp_ajax_wpf_submit_form', array($submissionHandler, 'handleSubmission'));
add_action('wp_ajax_nopriv_wpf_submit_form', array($submissionHandler, 'handleSubmission'));
// coupon actions
$CouponController = new \WPPayForm\Pro\Classes\Coupons\CouponController();
add_action('wp_ajax_wpf_coupon_apply', array($CouponController, 'validateCoupon'));
add_action('wp_ajax_nopriv_wpf_coupon_apply', array($CouponController, 'validateCoupon'));
// Stripe Payment Method Init Here
$stripe = new \WPPayForm\Classes\PaymentMethods\Stripe\Stripe();
$stripe->registerHooks();
// Stripe Inline Handler
$stripeInlineHandler = new \WPPayForm\Classes\PaymentMethods\Stripe\StripeInlineHandler();
$stripeInlineHandler->registerHooks();
// Stripe Hosted Checkout Handler
$stripeHostedHandler = new \WPPayForm\Classes\PaymentMethods\Stripe\StripeHostedHandler();
$stripeHostedHandler->registerHooks();
// Handle Extrior Pages
add_action('init', function () {
$demoPage = new \WPPayForm\Classes\Extorior\ProcessDemoPage();
$demoPage->handleExteriorPages();
$frameLessPage = new \WPPayForm\Classes\Extorior\FramelessProcessor();
$frameLessPage->init();
});
}
public function loadComponents()
{
require_once WPPAYFORM_DIR . 'includes/Classes/FormComponents/init.php';
}
public function textDomain()
{
load_plugin_textdomain('wppayform', false, basename(dirname(__FILE__)) . '/languages');
}
public function loadDependecies()
{
require_once(WPPAYFORM_DIR . 'includes/autoload.php');
require_once WPPAYFORM_DIR . 'includes/Pro/init.php';
}
}
require_once WPPAYFORM_DIR . 'includes/Pro/libs/updater/wppayform_pro_updater.php';
add_action('plugins_loaded', function () {
(new WPPayForm())->boot();
});
register_activation_hook(__FILE__, function ($newWorkWide) {
require_once(WPPAYFORM_DIR . 'includes/Classes/Activator.php');
$activator = new \WPPayForm\Classes\Activator();
$activator->migrateDatabases($newWorkWide);
});
// Handle Network new Site Activation
add_action('wp_insert_site', function ($blogId) {
require_once(WPPAYFORM_DIR . 'includes/Classes/Activator.php');
switch_to_blog($blogId->blog_id);
(new \WPPayForm\Classes\Activator())->migrate();
restore_current_blog();
});
} else {
add_action('admin_notices', function () {
$class = 'notice notice-error';
$message = 'Please deactivate WPPayForm Free version';
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
});
}