-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrazorpay-payment-buttons.php
167 lines (138 loc) · 5.52 KB
/
razorpay-payment-buttons.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
<?php
/**
* Plugin Name: Razorpay Payment Button for Elementor
* Plugin URI: https://github.com/razorpay/payment-button-elementor-plugin
* Description: Razorpay Payment Button for Elementor
* Version: 1.2.7
* Author: Razorpay
* Author URI: https://razorpay.com
*/
require_once __DIR__.'/razorpay-sdk/Razorpay.php';
require_once __DIR__.'/includes/rzp-btn-view.php';
require_once __DIR__.'/includes/rzp-btn-action.php';
require_once __DIR__.'/includes/rzp-btn-settings.php';
require_once __DIR__.'/includes/rzp-payment-buttons.php';
require_once __DIR__.'/widget/Widget.php';
use Razorpay\Api\Api;
use Razorpay\Api\Errors;
add_action('admin_enqueue_scripts', 'bootstrap_scripts_enqueue_elementor', 0);
add_action('admin_post_rzp_btn_elementor_action', 'razorpay_payment_button_elementor_action', 0);
function bootstrap_scripts_enqueue_elementor($admin_page)
{
if ($admin_page != 'admin_page_rzp_button_view_elementor')
{
return;
}
wp_register_style('bootstrap-css-elementor', plugin_dir_url(__FILE__) . 'public/css/bootstrap.min.css',
null, null);
wp_register_style('button-css-elementor', plugin_dir_url(__FILE__) . 'public/css/button.css',
null, null);
wp_enqueue_style('bootstrap-css-elementor');
wp_enqueue_style('button-css-elementor');
wp_enqueue_script('jquery');
}
/**
* This is the RZP Payment button loader class.
*
* @package RZP WP List Table
*/
if (!class_exists('RZP_Payment_Button_Elementor_Loader'))
{
// Adding constants
if (!defined('RZP_PAYMENT_ELEMENTOR_BASE_NAME'))
{
define('RZP_PAYMENT_ELEMENTOR_BASE_NAME', plugin_basename(__FILE__));
}
if (!defined('RZP_REDIRECT_URL'))
{
// admin-post.php is a file that contains methods for us to process HTTP requests
define('RZP_REDIRECT_URL', esc_url(admin_url('admin-post.php')));
}
class RZP_Payment_Button_Elementor_Loader
{
/**
* Start up
*/
public function __construct()
{
add_action('admin_menu', array($this, 'rzp_add_plugin_page'));
add_filter('plugin_action_links_' . RZP_PAYMENT_ELEMENTOR_BASE_NAME, array($this, 'razorpay_plugin_links'));
$this->settings = new RZP_Payment_Button_Elementor_Setting();
}
/**
* Creating the menu for plugin after load
**/
public function rzp_add_plugin_page()
{
/* add pages & menu items */
add_menu_page(esc_attr__('Razorpay Payment Button', 'textdomain'), esc_html__('Razorpay Buttons Elementor', 'textdomain'),
'administrator','razorpay_button_elementor',array($this, 'rzp_view_buttons_page'), '', 10);
add_submenu_page(esc_attr__('razorpay_button_elementor', 'textdomain'), esc_html__('Razorpay Settings', 'textdomain'),
'Settings', 'administrator','razorpay_elementor_settings', array($this, 'razorpay_elementor_settings'));
add_submenu_page(esc_attr__('', 'textdomain'), esc_html__('Razorpay Buttons Elementor', 'textdomain'),
'Razorpay Buttons Elementor', 'administrator','rzp_button_view_elementor', array($this, 'rzp_button_view_elementor'));
}
/**
* Initialize razorpay api instance
**/
public function get_razorpay_api_instance()
{
$key = get_option('key_id_field');
$secret = get_option('key_secret_field');
if(empty($key) === false and empty($secret) === false)
{
return new Api($key, $secret);
}
wp_die('<div class="error notice">
<p>RAZORPAY ERROR: Please set Razorpay Key Id and Secret in plugin settings.</p>
</div>');
}
/**
* Creating the settings link from the plug ins page
**/
function razorpay_plugin_links($links)
{
$pluginLinks = array(
'settings' => '<a href="'. esc_url(admin_url('admin.php?page=razorpay_elementor_settings')) .'">Settings</a>',
'docs' => '<a href="https://razorpay.com/docs/payment-button/supported-platforms/wordpress/elementor/">Docs</a>',
'support' => '<a href="https://razorpay.com/contact/">Support</a>'
);
$links = array_merge($links, $pluginLinks);
return $links;
}
/**
* Razorpay Payment Button Page
*/
public function rzp_view_buttons_page()
{
$rzp_payment_buttons = new RZP_Payment_Buttons_Elementor();
$rzp_payment_buttons->rzp_buttons();
}
/**
* Razorpay Setting Page
*/
public function razorpay_elementor_settings()
{
$this->settings->razorpaySettings();
}
/**
* Razorpay Setting Page
*/
public function rzp_button_view_elementor()
{
$new_button = new RZP_View_Button_Elementor();
$new_button->razorpay_view_button();
}
}
}
/**
* Instantiate the loader class.
*
* @since 2.0
*/
$RZP_Payment_Button_Elementor_Loader = new RZP_Payment_Button_Elementor_Loader();
function razorpay_payment_button_elementor_action()
{
$btn_action = new RZP_Button_Action_Elementor();
$btn_action->process();
}