PluginProbe
Payment Button for PayPal / trunk
Payment Button for PayPal vtrunk
1.2.3.44 trunk 1.0.2 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.2.7 1.2.3.38 1.2.3.39 1.2.3.40 1.2.3.41 1.2.3.42 1.2.3.43
wp-paypal / wp-paypal.php

wp-paypal.php in Payment Button for PayPal trunk, at wp-paypal.php

1,731 lines 96.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP PayPal
4 Version: 1.2.3.46
5 Plugin URI: https://wphowto.net/wordpress-paypal-plugin-732
6 Author: naa986
7 Author URI: https://wphowto.net/
8 Description: Easily accept PayPal payments in WordPress
9 Text Domain: wp-paypal
10 Domain Path: /languages
11 */
12
13 if (!defined('ABSPATH')){
14 exit;
15 }
16
17 class WP_PAYPAL {
18
19 var $plugin_version = '1.2.3.46';
20 var $db_version = '1.0.2';
21 var $plugin_url;
22 var $plugin_path;
23
24 function __construct() {
25 define('WP_PAYPAL_VERSION', $this->plugin_version);
26 define('WP_PAYPAL_DB_VERSION', $this->db_version);
27 define('WP_PAYPAL_SITE_URL', site_url());
28 define('WP_PAYPAL_HOME_URL', home_url());
29 define('WP_PAYPAL_URL', $this->plugin_url());
30 define('WP_PAYPAL_PATH', $this->plugin_path());
31 $debug_enabled = get_option('wp_paypal_enable_debug');
32 if (isset($debug_enabled) && !empty($debug_enabled)) {
33 define('WP_PAYPAL_DEBUG', true);
34 } else {
35 define('WP_PAYPAL_DEBUG', false);
36 }
37 $use_sandbox = get_option('wp_paypal_enable_testmode');
38 if (isset($use_sandbox) && !empty($use_sandbox)) {
39 define('WP_PAYPAL_USE_SANDBOX', true);
40 } else {
41 define('WP_PAYPAL_USE_SANDBOX', false);
42 }
43 define('WP_PAYPAL_DEBUG_LOG_PATH', $this->debug_log_path());
44 $this->plugin_includes();
45 $this->loader_operations();
46 }
47
48 function plugin_includes() {
49 include_once('wp-paypal-order.php');
50 include_once('wp-paypal-product.php');
51 include_once('wp-paypal-checkout-api.php');
52 include_once('wp-paypal-checkout.php');
53 include_once('paypal-ipn.php');
54 if(is_admin()){
55 include_once('addons/wp-paypal-addons-menu.php');
56 }
57 }
58
59 function loader_operations() {
60 register_activation_hook(__FILE__, array($this, 'activate_handler'));
61 add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
62 add_action('admin_notices', array($this, 'admin_notice'));
63 add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
64 add_action('wp_enqueue_scripts', array($this, 'plugin_scripts'));
65 add_action('admin_menu', array($this, 'add_options_menu'));
66 add_action('init', array($this, 'plugin_init'));
67 add_action('add_meta_boxes_wp_paypal_order', 'wppaypal_order_meta_boxes');
68 add_filter('manage_wp_paypal_order_posts_columns', 'wp_paypal_order_columns');
69 add_action('manage_wp_paypal_order_posts_custom_column', 'wp_paypal_custom_column', 10, 2);
70 add_action('add_meta_boxes_wp_paypal_product', 'wppaypal_product_meta_boxes');
71 add_filter('manage_wp_paypal_product_posts_columns', 'wp_paypal_product_columns');
72 add_action('manage_wp_paypal_product_posts_custom_column', 'wp_paypal_product_custom_column', 10, 2);
73 //add_shortcode('wp_paypal', 'wp_paypal_button_handler');
74 add_shortcode('wp_paypal_product', 'wp_paypal_product_button_handler');
75 add_shortcode('wp_paypal_checkout', 'wp_paypal_checkout_button_handler');
76 }
77
78 function plugins_loaded_handler() { //Runs when plugins_loaded action gets fired
79 if(is_admin() && current_user_can('manage_options')){
80 add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2);
81 }
82 load_plugin_textdomain( 'wp-paypal', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
83 $this->check_upgrade();
84 }
85
86 function admin_notice() {
87 $message = '';
88 if (WP_PAYPAL_DEBUG) { //debug is enabled. Check to make sure log file is writable
89 $log_file = WP_PAYPAL_DEBUG_LOG_PATH;
90 if(file_exists($log_file) && !is_writeable($log_file)){
91 $message .= '<div class="updated"><p>' . __('WP PayPal Debug log file is not writable. Please check to make sure that it has the correct file permission (ideally 644). Otherwise the plugin will not be able to write to the log file. The log file can be found in the root directory of the plugin - ', 'wp-paypal') . '<code>' . WP_PAYPAL_URL . '</code></p></div>';
92 }
93 }
94 $options = wp_paypal_checkout_get_option();
95 if(isset($options['app_client_id']) && !empty($options['app_client_id'])){
96 if(!isset($options['app_secret_key']) || empty($options['app_secret_key'])){
97 $message .= '<div class="error"><p>' . __('To use Checkout, WP PayPal plugin requires your Client ID and Secret Key in the settings. Once you have updated the settings, click a PayPal checkout button on your site to ensure everything is working.', 'wp-paypal').'</p></div>';
98 }
99 }
100 if(empty($message)){
101 return;
102 }
103 echo $message;
104 }
105
106 function activate_handler() {
107 add_option('wp_paypal_db_version', $this->db_version);
108 add_option('wp_paypal_email', get_bloginfo('admin_email'));
109 add_option('wp_paypal_currency_code', 'USD');
110 add_option('wp_paypal_enable_ipn_validation', '1');
111 add_option('wp_paypal_enable_receiver_check', '1');
112 wp_paypal_set_default_email_options();
113 }
114
115 function check_upgrade() {
116 if (is_admin()) {
117 $db_version = get_option('wp_paypal_db_version');
118 if (!isset($db_version) || $db_version != $this->db_version) {
119 $this->activate_handler();
120 update_option('wp_paypal_db_version', $this->db_version);
121 }
122 }
123 }
124
125 function plugin_init() {
126 //register orders
127 wp_paypal_order_page();
128 //register products
129 wp_paypal_product_page();
130 //process PayPal IPN
131 //wp_paypal_process_ipn();
132 }
133
134 function enqueue_admin_scripts($hook) {
135 if('wp_paypal_order_page_wp-paypal-addons' != $hook) {
136 return;
137 }
138 wp_register_style('wp-paypal-addons-menu', WP_PAYPAL_URL.'/addons/wp-paypal-addons-menu.css');
139 wp_enqueue_style('wp-paypal-addons-menu');
140 }
141
142 function plugin_scripts() {
143 if (is_404()) {
144 return;
145 }
146 if (!is_admin()) {
147 $checkout_load_scripts_globally = get_option('wp_paypal_checkout_load_scripts_globally');
148 if(isset($checkout_load_scripts_globally) && !empty($checkout_load_scripts_globally)){
149 $this->load_scripts();
150 return;
151 }
152 global $post;
153 if(!is_a($post, 'WP_Post')){
154 return;
155 }
156 $is_js_required = false;
157 if(has_shortcode($post->post_content, 'wp_paypal_checkout')){
158 $is_js_required = true;
159 }
160 if(has_shortcode(get_post_meta($post->ID, 'wp-paypal-custom-field', true), 'wp_paypal_checkout')){
161 $is_js_required = true;
162 }
163 if($is_js_required){
164 $this->load_scripts();
165 }
166 }
167 }
168
169 function load_scripts(){
170 $options = wp_paypal_checkout_get_option();
171 if(!is_wp_paypal_checkout_configured()){
172 return;
173 }
174 $client_id = '';
175 if(isset($options['app_client_id']) && !empty($options['app_client_id'])){
176 $client_id = $options['app_client_id'];
177 }
178 if(isset($options['test_mode']) && $options['test_mode'] == "1"){
179 if(isset($options['app_sandbox_client_id']) && !empty($options['app_sandbox_client_id'])){
180 $client_id = $options['app_sandbox_client_id'];
181 }
182 }
183 if(!isset($client_id) || empty($client_id)){
184 return;
185 }
186 $args = array(
187 'client-id' => $client_id,
188 'currency' => $options['currency_code'],
189 );
190 if(isset($options['enable_funding']) && !empty($options['enable_funding'])){
191 $args['enable-funding'] = $options['enable_funding'];
192 }
193 if(isset($options['disable_funding']) && !empty($options['disable_funding'])){
194 $args['disable-funding'] = $options['disable_funding'];
195 }
196 $sdk_js_url = add_query_arg($args, 'https://www.paypal.com/sdk/js');
197 wp_enqueue_script('jquery');
198 wp_register_script('wp-paypal', $sdk_js_url, array('jquery'), null);
199 wp_enqueue_script('wp-paypal');
200 }
201
202 function plugin_url() {
203 if ($this->plugin_url){
204 return $this->plugin_url;
205 }
206 return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__));
207 }
208
209 function plugin_path() {
210 if ($this->plugin_path){
211 return $this->plugin_path;
212 }
213 return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__));
214 }
215
216 function debug_log_path() {
217 return WP_PAYPAL_PATH . '/logs/'. $this->debug_log_file_name();
218 }
219
220 function debug_log_file_name() {
221 return 'log-'.$this->debug_log_file_suffix().'.txt';
222 }
223
224 function debug_log_file_suffix() {
225 $suffix = get_option('wppaypal_logfile_suffix');
226 if(isset($suffix) && !empty($suffix)) {
227 return $suffix;
228 }
229 $suffix = uniqid();
230 update_option('wppaypal_logfile_suffix', $suffix);
231 return $suffix;
232 }
233
234 function add_plugin_action_links($links, $file) {
235 if ($file == plugin_basename(dirname(__FILE__) . '/wp-paypal.php')) {
236 $links[] = '<a href="'.esc_url(admin_url('edit.php?post_type=wp_paypal_order&page=wp-paypal-settings')).'">'.__('Settings', 'wp-paypal').'</a>';
237 }
238 return $links;
239 }
240
241 function add_options_menu() {
242 if (is_admin()) {
243 add_submenu_page('edit.php?post_type=wp_paypal_order', __('Settings', 'wp-paypal'), __('Settings', 'wp-paypal'), 'manage_options', 'wp-paypal-settings', array($this, 'options_page'));
244 add_submenu_page('edit.php?post_type=wp_paypal_order', __('Debug', 'wp-paypal'), __('Debug', 'wp-paypal'), 'manage_options', 'wp-paypal-debug', array($this, 'debug_page'));
245 add_submenu_page('edit.php?post_type=wp_paypal_order', __('Add-ons', 'wp-paypal'), __('Add-ons', 'wp-paypal'), 'manage_options', 'wp-paypal-addons', 'wp_paypal_display_addons_menu');
246 global $submenu;
247 unset($submenu['edit.php?post_type=wp_paypal_order'][10]);
248 }
249 }
250
251 function options_page() {
252 $plugin_tabs = array(
253 'wp-paypal-settings' => __('General', 'wp-paypal'),
254 'wp-paypal-settings&tab=emails' => __('Emails', 'wp-paypal')
255 );
256 echo '<div class="wrap"><h2>'.__('WP PayPal', 'wp-paypal').' v' . WP_PAYPAL_VERSION . '</h2>';
257 $url = 'https://wphowto.net/wordpress-paypal-plugin-732';
258 $link_msg = sprintf(__('Please visit the <a target="_blank" href="%s">WP PayPal</a> documentation page for setup instructions.', 'wp-paypal'), esc_url($url));
259 $allowed_html_tags = array(
260 'a' => array(
261 'href' => array(),
262 'target' => array()
263 )
264 );
265 echo '<div class="update-nag">'.wp_kses($link_msg, $allowed_html_tags).'</div>';
266 $current = '';
267 $tab = '';
268 if (isset($_GET['page'])) {
269 $current = sanitize_text_field($_GET['page']);
270 if (isset($_GET['tab'])) {
271 $tab = sanitize_text_field($_GET['tab']);
272 $current .= "&tab=" . $tab;
273 }
274 }
275 $content = '';
276 $content .= '<h2 class="nav-tab-wrapper">';
277 foreach ($plugin_tabs as $location => $tabname) {
278 if ($current == $location) {
279 $class = ' nav-tab-active';
280 } else {
281 $class = '';
282 }
283 $content .= '<a class="nav-tab' . $class . '" href="?post_type=wp_paypal_order&page=' . $location . '">' . $tabname . '</a>';
284 }
285 $content .= '</h2>';
286 $allowed_html_tags = array(
287 'a' => array(
288 'href' => array(),
289 'class' => array()
290 ),
291 'h2' => array(
292 'href' => array(),
293 'class' => array()
294 )
295 );
296 echo wp_kses($content, $allowed_html_tags);
297
298 if(!empty($tab))
299 {
300 switch ($tab)
301 {
302 case 'emails':
303 $this->email_settings();
304 break;
305 }
306 }
307 else
308 {
309 $this->general_settings();
310 }
311
312 echo '</div>';
313 }
314
315 function general_settings() {
316 if (isset($_POST['wp_paypal_update_settings'])) {
317 $nonce = $_REQUEST['_wpnonce'];
318 if (!wp_verify_nonce($nonce, 'wp_paypal_general_settings')) {
319 wp_die('Error! Nonce Security Check Failed! please save the settings again.');
320 }
321 //
322 $checkout_api_key_present_msg = 'Saved. Enter only if you need to update.';
323 $checkout_test_mode = (isset($_POST['checkout_test_mode']) && $_POST['checkout_test_mode'] == '1') ? '1' : '';
324 $checkout_app_sandbox_client_id = '';
325 if(isset($_POST['checkout_app_sandbox_client_id']) && !empty($_POST['checkout_app_sandbox_client_id'])){
326 $checkout_app_sandbox_client_id = sanitize_text_field($_POST['checkout_app_sandbox_client_id']);
327 }
328 $checkout_app_sandbox_secret_key = '';
329 $update_checkout_app_sandbox_secret_key = false;
330 if(isset($_POST['checkout_app_sandbox_secret_key']) && !empty($_POST['checkout_app_sandbox_secret_key']) && $_POST['checkout_app_sandbox_secret_key'] != $checkout_api_key_present_msg){
331 $checkout_app_sandbox_secret_key = sanitize_text_field($_POST['checkout_app_sandbox_secret_key']);
332 $checkout_app_sandbox_secret_key = base64_encode($checkout_app_sandbox_secret_key);
333 $update_checkout_app_sandbox_secret_key = true;
334 }
335 $checkout_app_client_id = '';
336 if(isset($_POST['checkout_app_client_id']) && !empty($_POST['checkout_app_client_id'])){
337 $checkout_app_client_id = sanitize_text_field($_POST['checkout_app_client_id']);
338 }
339 $checkout_app_secret_key = '';
340 $update_checkout_app_secret_key = false;
341 if(isset($_POST['checkout_app_secret_key']) && !empty($_POST['checkout_app_secret_key']) && $_POST['checkout_app_secret_key'] != $checkout_api_key_present_msg){
342 $checkout_app_secret_key = sanitize_text_field($_POST['checkout_app_secret_key']);
343 $checkout_app_secret_key = base64_encode($checkout_app_secret_key);
344 $update_checkout_app_secret_key = true;
345 }
346 //
347 $checkout_currency_code = '';
348 if(isset($_POST['checkout_currency_code']) && !empty($_POST['checkout_currency_code'])){
349 $checkout_currency_code = sanitize_text_field($_POST['checkout_currency_code']);
350 }
351 $checkout_return_url = '';
352 if(isset($_POST['checkout_return_url']) && !empty($_POST['checkout_return_url'])){
353 $checkout_return_url = esc_url_raw($_POST['checkout_return_url']);
354 }
355 $checkout_cancel_url = '';
356 if(isset($_POST['checkout_cancel_url']) && !empty($_POST['checkout_cancel_url'])){
357 $checkout_cancel_url = esc_url_raw($_POST['checkout_cancel_url']);
358 }
359 $checkout_page_url = '';
360 if(isset($_POST['checkout_page_url']) && !empty($_POST['checkout_page_url'])){
361 $checkout_page_url = esc_url_raw($_POST['checkout_page_url']);
362 }
363 $checkout_enable_funding = '';
364 if(isset($_POST['checkout_enable_funding'])){
365 $checkout_enable_funding = sanitize_text_field($_POST['checkout_enable_funding']);
366 }
367 $checkout_disable_funding = '';
368 if(isset($_POST['checkout_disable_funding'])){
369 $checkout_disable_funding = sanitize_text_field($_POST['checkout_disable_funding']);
370 }
371 $paypal_checkout_options = array();
372 $paypal_checkout_options['test_mode'] = $checkout_test_mode;
373 $paypal_checkout_options['app_sandbox_client_id'] = $checkout_app_sandbox_client_id;
374 if($update_checkout_app_sandbox_secret_key){
375 $paypal_checkout_options['app_sandbox_secret_key'] = $checkout_app_sandbox_secret_key;
376 }
377 $paypal_checkout_options['app_client_id'] = $checkout_app_client_id;
378 if($update_checkout_app_secret_key){
379 $paypal_checkout_options['app_secret_key'] = $checkout_app_secret_key;
380 }
381 $paypal_checkout_options['currency_code'] = $checkout_currency_code;
382 $paypal_checkout_options['return_url'] = $checkout_return_url;
383 $paypal_checkout_options['cancel_url'] = $checkout_cancel_url;
384 $paypal_checkout_options['checkout_page_url'] = $checkout_page_url;
385 $paypal_checkout_options['enable_funding'] = $checkout_enable_funding;
386 $paypal_checkout_options['disable_funding'] = $checkout_disable_funding;
387 $checkout_load_scripts_globally = (isset($_POST['checkout_load_scripts_globally']) && $_POST['checkout_load_scripts_globally'] == '1') ? '1' : '';
388 update_option('wp_paypal_checkout_load_scripts_globally', $checkout_load_scripts_globally);
389 wp_paypal_checkout_update_option($paypal_checkout_options);
390 //
391 /*
392 update_option('wp_paypal_enable_testmode', (isset($_POST["enable_testmode"]) && $_POST["enable_testmode"] == '1') ? '1' : '');
393 update_option('wp_paypal_merchant_id', sanitize_text_field($_POST["paypal_merchant_id"]));
394 update_option('wp_paypal_email', sanitize_email($_POST["paypal_email"]));
395 update_option('wp_paypal_currency_code', sanitize_text_field($_POST["currency_code"]));
396 update_option('wp_paypal_enable_ipn_validation', (isset($_POST["enable_ipn_validation"]) && $_POST["enable_ipn_validation"] == '1') ? '1' : '');
397 update_option('wp_paypal_enable_receiver_check', (isset($_POST["enable_receiver_check"]) && $_POST["enable_receiver_check"] == '1') ? '1' : '');
398 */
399 //
400 echo '<div id="message" class="updated fade"><p><strong>';
401 echo __('Settings Saved', 'wp-paypal').'!';
402 echo '</strong></p></div>';
403 }
404 $paypal_checkout_options = wp_paypal_checkout_get_option();
405 //these options may not be set as they were added later
406 $checkout_test_mode = '';
407 if(isset($paypal_checkout_options['test_mode']) && !empty($paypal_checkout_options['test_mode'])){
408 $checkout_test_mode = $paypal_checkout_options['test_mode'];
409 }
410 $checkout_app_sandbox_client_id = (isset($paypal_checkout_options['app_sandbox_client_id']) && !empty($paypal_checkout_options['app_sandbox_client_id'])) ? $paypal_checkout_options['app_sandbox_client_id'] : '';
411 $checkout_app_sandbox_secret_key_msg = '';
412 if(isset($paypal_checkout_options['app_sandbox_secret_key']) && !empty($paypal_checkout_options['app_sandbox_secret_key'])){
413 $checkout_app_sandbox_secret_key_msg = 'Saved. Enter only if you need to update.';
414 }
415 $checkout_app_secret_key_msg = '';
416 if(isset($paypal_checkout_options['app_secret_key']) && !empty($paypal_checkout_options['app_secret_key'])){
417 $checkout_app_secret_key_msg = 'Saved. Enter only if you need to update.';
418 }
419 if(!isset($paypal_checkout_options['enable_funding']) || empty($paypal_checkout_options['enable_funding'])){
420 $paypal_checkout_options['enable_funding'] = '';
421 }
422 if(!isset($paypal_checkout_options['disable_funding']) || empty($paypal_checkout_options['disable_funding'])){
423 $paypal_checkout_options['disable_funding'] = '';
424 }
425 $checkout_load_scripts_globally = get_option('wp_paypal_checkout_load_scripts_globally');
426 if(!isset($checkout_load_scripts_globally) || empty($checkout_load_scripts_globally)){
427 $checkout_load_scripts_globally = '';
428 }
429 //
430 $funding_src_url = "https://wphowto.net/wordpress-paypal-plugin-732";
431 $funding_src_link = sprintf(__('You can find the full list of funding sources <a target="_blank" href="%s">here</a>.', 'wp-paypal'), esc_url($funding_src_url));
432 $allowed_html_tags = array(
433 'a' => array(
434 'href' => array(),
435 'title' => array()
436 )
437 );
438
439 ?>
440 <table class="wppaypal-general-settings-table">
441 <tbody>
442 <tr>
443 <td valign="top">
444 <form method="post" action="">
445 <?php wp_nonce_field('wp_paypal_general_settings'); ?>
446
447 <table class="form-table">
448
449 <tbody>
450
451 <tr valign="top">
452 <th scope="row"><?php _e('Test mode', 'wp-paypal');?></th>
453 <td> <fieldset><legend class="screen-reader-text"><span>Test mode</span></legend><label for="test_mode">
454 <input name="checkout_test_mode" type="checkbox" id="checkout_test_mode" <?php if ($checkout_test_mode == '1') echo ' checked="checked"'; ?> value="1">
455 <?php _e("Check this option to run transactions in test mode with your PayPal sandbox API credentials.", 'wp-paypal');?></label>
456 </fieldset></td>
457 </tr>
458
459 <tr valign="top">
460 <th scope="row"><label for="checkout_app_sandbox_client_id"><?php _e('Sandbox Client ID', 'wp-paypal');?></label></th>
461 <td><input name="checkout_app_sandbox_client_id" type="text" id="checkout_app_sandbox_client_id" value="<?php echo esc_attr($checkout_app_sandbox_client_id); ?>" class="regular-text">
462 <p class="description"><?php _e('The sandbox client ID for your PayPal REST API app (required)', 'wp-paypal');?></p></td>
463 </tr>
464
465 <tr valign="top">
466 <th scope="row"><label for="checkout_app_sandbox_secret_key"><?php _e('Sandbox Secret Key', 'wp-paypal');?></label></th>
467 <td><input name="checkout_app_sandbox_secret_key" type="text" id="checkout_app_sandbox_secret_key" value="<?php echo esc_attr($checkout_app_sandbox_secret_key_msg); ?>" class="regular-text">
468 <p class="description"><?php _e('The sandbox secret key for your PayPal REST API app (required)', 'wp-paypal');?></p></td>
469 </tr>
470
471 <tr valign="top">
472 <th scope="row"><label for="checkout_app_client_id"><?php _e('Live Client ID', 'wp-paypal');?></label></th>
473 <td><input name="checkout_app_client_id" type="text" id="checkout_app_client_id" value="<?php echo esc_attr($paypal_checkout_options['app_client_id']); ?>" class="regular-text">
474 <p class="description"><?php _e('The client ID for your PayPal REST API app (required)', 'wp-paypal');?></p></td>
475 </tr>
476
477 <tr valign="top">
478 <th scope="row"><label for="checkout_app_secret_key"><?php _e('Live Secret Key', 'wp-paypal');?></label></th>
479 <td><input name="checkout_app_secret_key" type="text" id="checkout_app_secret_key" value="<?php echo esc_attr($checkout_app_secret_key_msg); ?>" class="regular-text">
480 <p class="description"><?php _e('The secret key for your PayPal REST API app (required)', 'wp-paypal');?></p></td>
481 </tr>
482
483 <tr valign="top">
484 <th scope="row"><label for="checkout_currency_code"><?php _e('Currency Code', 'wp-paypal');?></label></th>
485 <td><input name="checkout_currency_code" type="text" id="checkout_currency_code" value="<?php echo esc_attr($paypal_checkout_options['currency_code']); ?>" class="regular-text">
486 <p class="description"><?php _e('The default currency of the payment (required)', 'wp-paypal');?> (<?php _e('example', 'wp-paypal');?>: USD, CAD, GBP, EUR)</p></td>
487 </tr>
488
489 <tr valign="top">
490 <th scope="row"><label for="checkout_return_url"><?php _e('Return URL', 'wp-paypal');?></label></th>
491 <td><input name="checkout_return_url" type="text" id="checkout_return_url" value="<?php echo esc_url($paypal_checkout_options['return_url']); ?>" class="regular-text">
492 <p class="description"><?php _e('The page URL to which the customer will be redirected after a successful payment (required)', 'wp-paypal');?></p></td>
493 </tr>
494
495 <tr valign="top">
496 <th scope="row"><label for="checkout_cancel_url"><?php _e('Cancel URL', 'wp-paypal');?></label></th>
497 <td><input name="checkout_cancel_url" type="text" id="checkout_cancel_url" value="<?php echo esc_url($paypal_checkout_options['cancel_url']); ?>" class="regular-text">
498 <p class="description"><?php _e('The page URL to which the customer will be redirected when a payment is cancelled (required)', 'wp-paypal');?></p></td>
499 </tr>
500
501 <tr valign="top">
502 <th scope="row"><label for="checkout_page_url"><?php _e('Checkout Page URL', 'wp-paypal');?></label></th>
503 <td><input name="checkout_page_url" type="text" id="checkout_page_url" value="<?php echo esc_url(isset($paypal_checkout_options['checkout_page_url']) ? $paypal_checkout_options['checkout_page_url'] : ''); ?>" class="regular-text">
504 <p class="description"><?php _e('The URL of your PayPal checkout page where the [wp_paypal_checkout] shortcode is placed (required)', 'wp-paypal');?></p></td>
505 </tr>
506
507 <tr valign="top">
508 <th scope="row"><label for="checkout_enable_funding"><?php _e('Enabled Funding Sources', 'wp-paypal');?></label></th>
509 <td><textarea name="checkout_enable_funding" id="checkout_enable_funding" class="large-text"><?php echo esc_html($paypal_checkout_options['enable_funding']); ?></textarea>
510 <p class="description"><?php echo __('Enabled funding sources in comma-separated format (optional)', 'wp-paypal').' ';?>(Example: <strong>venmo</strong> or <strong>venmo,credit</strong> or <strong>venmo,credit,paylater</strong>).<?php echo ' '.__('This is not required as the eligibility is determined automatically. However, this field can be used to ensure a funding source is always rendered, if eligible.', 'wp-paypal').' '.wp_kses($funding_src_link, $allowed_html_tags);?></p></td>
511 </tr>
512
513 <tr valign="top">
514 <th scope="row"><label for="checkout_disable_funding"><?php _e('Disabled Funding Sources', 'wp-paypal');?></label></th>
515 <td><textarea name="checkout_disable_funding" id="checkout_disable_funding" class="large-text"><?php echo esc_html($paypal_checkout_options['disable_funding']); ?></textarea>
516 <p class="description"><?php echo __('Disabled funding sources in comma-separated format (optional)', 'wp-paypal').' ';?>(Example: <strong>credit</strong> or <strong>card,credit</strong> or <strong>card,credit,paylater</strong>).<?php echo ' '.__('Any funding sources that you enter here are not displayed as buttons at checkout.', 'wp-paypal').' '.wp_kses($funding_src_link, $allowed_html_tags);?></p></td>
517 </tr>
518
519 <tr valign="top">
520 <th scope="row"><?php _e('Load Scripts Globally', 'wp-paypal');?></th>
521 <td> <fieldset><legend class="screen-reader-text"><span>Load Scripts Globally</span></legend><label for="checkout_load_scripts_globally">
522 <input name="checkout_load_scripts_globally" type="checkbox" id="checkout_load_scripts_globally" <?php if ($checkout_load_scripts_globally == '1') echo ' checked="checked"'; ?> value="1">
523 <?php _e("Check this option if you want to load PayPal Checkout scripts on every page. By default, the scripts are loaded only when a shortcode is present.", 'wp-paypal');?></label>
524 </fieldset></td>
525 </tr>
526
527 </tbody>
528
529 </table>
530 <!--
531 <h2><?php _e('PayPal Payments Standard', 'wp-paypal');?></h2>
532 <p><?php printf(__('These settings apply to %s shortcode buttons', 'wp-paypal'), '[wp_paypal]');?></p>
533 <table class="form-table">
534
535 <tbody>
536
537 <tr valign="top">
538 <th scope="row"><?php _e('Enable Test Mode', 'wp-paypal');?></th>
539 <td> <fieldset><legend class="screen-reader-text"><span>Enable Test Mode</span></legend><label for="enable_testmode">
540 <input name="enable_testmode" type="checkbox" id="enable_testmode" <?php if (get_option('wp_paypal_enable_testmode') == '1') echo ' checked="checked"'; ?> value="1">
541 <?php _e('Check this option if you want to enable PayPal sandbox for testing', 'wp-paypal');?></label>
542 </fieldset></td>
543 </tr>
544
545 <tr valign="top">
546 <th scope="row"><label for="paypal_merchant_id"><?php _e('PayPal Merchant ID', 'wp-paypal');?></label></th>
547 <td><input name="paypal_merchant_id" type="text" id="paypal_merchant_id" value="<?php echo esc_attr(get_option('wp_paypal_merchant_id')); ?>" class="regular-text">
548 <p class="description"><?php _e('Your PayPal Merchant ID', 'wp-paypal');?></p></td>
549 </tr>
550
551 <tr valign="top">
552 <th scope="row"><label for="paypal_email"><?php _e('PayPal Email', 'wp-paypal');?></label></th>
553 <td><input name="paypal_email" type="text" id="paypal_email" value="<?php echo esc_attr(get_option('wp_paypal_email')); ?>" class="regular-text">
554 <p class="description"><?php _e('Your PayPal email address', 'wp-paypal');?></p></td>
555 </tr>
556
557 <tr valign="top">
558 <th scope="row"><label for="currency_code"><?php _e('Currency Code', 'wp-paypal');?></label></th>
559 <td><input name="currency_code" type="text" id="currency_code" value="<?php echo esc_attr(get_option('wp_paypal_currency_code')); ?>" class="regular-text">
560 <p class="description"><?php _e('The currency of the payment', 'wp-paypal');?> (<?php _e('example', 'wp-paypal');?>: USD, CAD, GBP, EUR)</p></td>
561 </tr>
562
563 <tr valign="top">
564 <th scope="row"><?php _e('Enable IPN Validation', 'wp-paypal');?></th>
565 <td> <fieldset><legend class="screen-reader-text"><span>Enable IPN Validation</span></legend><label for="enable_ipn_validation">
566 <input name="enable_ipn_validation" type="checkbox" id="enable_ipn_validation" <?php if (get_option('wp_paypal_enable_ipn_validation') == '1') echo ' checked="checked"'; ?> value="1">
567 <?php _e('Check this option if you want to send the IPN data to PayPal for validation', 'wp-paypal');?></label>
568 </fieldset></td>
569 </tr>
570
571 <tr valign="top">
572 <th scope="row"><?php _e('Enable Receiver Check', 'wp-paypal');?></th>
573 <td> <fieldset><legend class="screen-reader-text"><span>Enable Receiver Check</span></legend><label for="enable_receiver_check">
574 <input name="enable_receiver_check" type="checkbox" id="enable_receiver_check" <?php if (get_option('wp_paypal_enable_receiver_check') == '1') echo ' checked="checked"'; ?> value="1">
575 <?php _e('Check this option if you want the seller account in the settings to match the receiver account when processing a payment. This option should be disabled when accepting payments on separate accounts.', 'wp-paypal');?></label>
576 </fieldset></td>
577 </tr>
578
579 </tbody>
580
581 </table>
582 -->
583 <p class="submit"><input type="submit" name="wp_paypal_update_settings" id="wp_paypal_update_settings" class="button button-primary" value="<?php _e('Save Changes', 'wp-paypal');?>"></p></form>
584 </td>
585 <td valign="top" style="width: 300px">
586 <div style="background: #ffc; border: 1px solid #333; margin: 2px; padding: 3px 15px">
587 <h3><?php _e('Need More Features?', 'wp-paypal')?></h3>
588 <ol>
589 <li><?php printf(__('Check out the <a href="%s">plugin add-ons</a>.', 'wp-paypal'), 'edit.php?post_type=wp_paypal_order&page=wp-paypal-addons');?></li>
590 </ol>
591 <h3><?php _e('Need Help?', 'wp-paypal')?></h3>
592 <ol>
593 <li><?php printf(__('Use the <a href="%s">Debug</a> menu for diagnostics.', 'wp-paypal'), 'edit.php?post_type=wp_paypal_order&page=wp-paypal-debug');?></li>
594 <li><?php printf(__('Check out the <a target="_blank" href="%s">support forum</a> and <a target="_blank" href="%s">FAQ</a>.', 'wp-paypal'), 'https://wordpress.org/support/plugin/wp-paypal/', 'https://wordpress.org/plugins/wp-paypal/#faq');?></li>
595 <li><?php printf(__('Visit the <a target="_blank" href="%s">plugin homepage</a>.', 'wp-paypal'), 'https://wphowto.net/wordpress-paypal-plugin-732');?></li>
596 </ol>
597 <h3><?php _e('Rate This Plugin', 'wp-paypal')?></h3>
598 <p><?php printf(__('Please <a target="_blank" href="%s">rate us</a> and give feedback.', 'wp-paypal'), 'https://wordpress.org/support/plugin/wp-paypal/reviews?rate=5#new-post');?></p>
599 </div>
600 </td>
601 </tr>
602 </tbody>
603 </table>
604 <?php
605 }
606
607 function email_settings()
608 {
609 if (isset($_POST['wp_paypal_update_email_settings']))
610 {
611 $nonce = $_REQUEST['_wpnonce'];
612 if (!wp_verify_nonce($nonce, 'wp_paypal_email_settings_nonce')) {
613 wp_die(__('Error! Nonce Security Check Failed! please save the email settings again.', 'wp-paypal'));
614 }
615 $_POST = stripslashes_deep($_POST);
616 $email_from_name = '';
617 if(isset($_POST['email_from_name']) && !empty($_POST['email_from_name'])){
618 $email_from_name = sanitize_text_field($_POST['email_from_name']);
619 }
620 $email_from_address= '';
621 if(isset($_POST['email_from_address']) && !empty($_POST['email_from_address'])){
622 $email_from_address = sanitize_email($_POST['email_from_address']);
623 }
624 $purchase_email_enabled = (isset($_POST["purchase_email_enabled"]) && $_POST["purchase_email_enabled"] == '1') ? '1' : '';
625 $purchase_email_subject = '';
626 if(isset($_POST['purchase_email_subject']) && !empty($_POST['purchase_email_subject'])){
627 $purchase_email_subject = sanitize_text_field($_POST['purchase_email_subject']);
628 }
629 $purchase_email_type = '';
630 if(isset($_POST['purchase_email_type']) && !empty($_POST['purchase_email_type'])){
631 $purchase_email_type = sanitize_text_field($_POST['purchase_email_type']);
632 }
633 $purchase_email_body = '';
634 if(isset($_POST['purchase_email_body']) && !empty($_POST['purchase_email_body'])){
635 $purchase_email_body = wp_kses_post($_POST['purchase_email_body']);
636 }
637 $sale_notification_email_enabled = (isset($_POST["sale_notification_email_enabled"]) && $_POST["sale_notification_email_enabled"] == '1') ? '1' : '';
638 $sale_notification_email_recipient = '';
639 if(isset($_POST['sale_notification_email_recipient']) && !empty($_POST['sale_notification_email_recipient'])){
640 $sale_notification_email_recipient = sanitize_text_field($_POST['sale_notification_email_recipient']);
641 }
642 $sale_notification_email_subject = '';
643 if(isset($_POST['sale_notification_email_subject']) && !empty($_POST['sale_notification_email_subject'])){
644 $sale_notification_email_subject = sanitize_text_field($_POST['sale_notification_email_subject']);
645 }
646 $sale_notification_email_type = '';
647 if(isset($_POST['sale_notification_email_type']) && !empty($_POST['sale_notification_email_type'])){
648 $sale_notification_email_type = sanitize_text_field($_POST['sale_notification_email_type']);
649 }
650 $sale_notification_email_body = '';
651 if(isset($_POST['sale_notification_email_body']) && !empty($_POST['sale_notification_email_body'])){
652 $sale_notification_email_body = wp_kses_post($_POST['sale_notification_email_body']);
653 }
654 $sale_notification_email_append_purchase_email = (isset($_POST["sale_notification_email_append_purchase_email"]) && $_POST["sale_notification_email_append_purchase_email"] == '1') ? '1' : '';
655 $paypal_options = array();
656 $paypal_options['email_from_name'] = $email_from_name;
657 $paypal_options['email_from_address'] = $email_from_address;
658 $paypal_options['purchase_email_enabled'] = $purchase_email_enabled;
659 $paypal_options['purchase_email_subject'] = $purchase_email_subject;
660 $paypal_options['purchase_email_type'] = $purchase_email_type;
661 $paypal_options['purchase_email_body'] = $purchase_email_body;
662 $paypal_options['sale_notification_email_enabled'] = $sale_notification_email_enabled;
663 $paypal_options['sale_notification_email_recipient'] = $sale_notification_email_recipient;
664 $paypal_options['sale_notification_email_subject'] = $sale_notification_email_subject;
665 $paypal_options['sale_notification_email_type'] = $sale_notification_email_type;
666 $paypal_options['sale_notification_email_body'] = $sale_notification_email_body;
667 $paypal_options['sale_notification_email_append_purchase_email'] = $sale_notification_email_append_purchase_email;
668 wp_paypal_update_email_option($paypal_options);
669 echo '<div id="message" class="updated fade"><p><strong>';
670 echo __('Settings Saved', 'wp-paypal').'!';
671 echo '</strong></p></div>';
672 }
673
674 $paypal_options = wp_paypal_get_email_option();
675
676 $email_tags_url = "https://wphowto.net/wordpress-paypal-plugin-732";
677 $email_tags_link = sprintf(__('You can find the full list of available email tags <a target="_blank" href="%s">here</a>.', 'wp-paypal'), esc_url($email_tags_url));
678 $allowed_html_tags = array(
679 'a' => array(
680 'href' => array(),
681 'title' => array()
682 )
683 );
684 ?>
685 <table class="wppaypal-email-settings-table">
686 <tbody>
687 <tr>
688 <td valign="top">
689 <form method="post" action="">
690 <?php wp_nonce_field('wp_paypal_email_settings_nonce'); ?>
691
692 <h2><?php _e('Email Sender Options', 'wp-paypal');?></h2>
693 <table class="form-table">
694 <tbody>
695 <tr valign="top">
696 <th scope="row"><label for="email_from_name"><?php _e('From Name', 'wp-paypal');?></label></th>
697 <td><input name="email_from_name" type="text" id="email_from_name" value="<?php echo esc_attr($paypal_options['email_from_name']); ?>" class="regular-text">
698 <p class="description"><?php _e('The sender name that appears in outgoing emails. Leave empty to use the default.', 'wp-paypal');?></p></td>
699 </tr>
700 <tr valign="top">
701 <th scope="row"><label for="email_from_address"><?php _e('From Email Address', 'wp-paypal');?></label></th>
702 <td><input name="email_from_address" type="text" id="email_from_address" value="<?php echo esc_attr($paypal_options['email_from_address']); ?>" class="regular-text">
703 <p class="description"><?php _e('The sender email that appears in outgoing emails. Leave empty to use the default.', 'wp-paypal');?></p></td>
704 </tr>
705 </tbody>
706 </table>
707 <h2><?php _e('Purchase Receipt Email', 'wp-paypal');?></h2>
708 <p><?php _e('A purchase receipt email is sent to the customer after completion of a successful purchase', 'wp-paypal');?></p>
709 <table class="form-table">
710 <tbody>
711 <tr valign="top">
712 <th scope="row"><?php _e('Enable/Disable', 'wp-paypal');?></th>
713 <td> <fieldset><legend class="screen-reader-text"><span>Enable/Disable</span></legend><label for="purchase_email_enabled">
714 <input name="purchase_email_enabled" type="checkbox" id="purchase_email_enabled" <?php if ($paypal_options['purchase_email_enabled'] == '1') echo ' checked="checked"'; ?> value="1">
715 <?php _e('Enable this email notification', 'wp-paypal');?></label>
716 </fieldset></td>
717 </tr>
718 <tr valign="top">
719 <th scope="row"><label for="purchase_email_subject"><?php _e('Subject', 'wp-paypal');?></label></th>
720 <td><input name="purchase_email_subject" type="text" id="purchase_email_subject" value="<?php echo esc_attr($paypal_options['purchase_email_subject']); ?>" class="regular-text">
721 <p class="description"><?php _e('The subject line for the purchase receipt email.', 'wp-paypal');?></p></td>
722 </tr>
723 <tr valign="top">
724 <th scope="row"><label for="purchase_email_type"><?php _e('Email Type', 'wp-paypal');?></label></th>
725 <td>
726 <select name="purchase_email_type" id="purchase_email_type">
727 <option <?php echo ($paypal_options['purchase_email_type'] === 'plain')?'selected="selected"':'';?> value="plain"><?php _e('Plain Text', 'wp-paypal')?></option>
728 <option <?php echo ($paypal_options['purchase_email_type'] === 'html')?'selected="selected"':'';?> value="html"><?php _e('HTML', 'wp-paypal')?></option>
729 </select>
730 <p class="description"><?php _e('The content type of the purchase receipt email.', 'wp-paypal')?></p>
731 </td>
732 </tr>
733 <tr valign="top">
734 <th scope="row"><label for="purchase_email_body"><?php _e('Email Body', 'wp-paypal');?></label></th>
735 <td><?php wp_editor($paypal_options['purchase_email_body'], 'purchase_email_body', array('textarea_name' => 'purchase_email_body'));?>
736 <p class="description"><?php echo __('The main content of the purchase receipt email.', 'wp-paypal').' '.wp_kses($email_tags_link, $allowed_html_tags);?></p></td>
737 </tr>
738 </tbody>
739 </table>
740 <h2><?php _e('Sale Notification Email', 'wp-paypal');?></h2>
741 <p><?php _e('A sale notification email is sent to the chosen recipient after completion of a successful purchase', 'wp-paypal');?></p>
742 <table class="form-table">
743 <tbody>
744 <tr valign="top">
745 <th scope="row"><?php _e('Enable/Disable', 'wp-paypal');?></th>
746 <td> <fieldset><legend class="screen-reader-text"><span>Enable/Disable</span></legend><label for="sale_notification_email_enabled">
747 <input name="sale_notification_email_enabled" type="checkbox" id="sale_notification_email_enabled" <?php if ($paypal_options['sale_notification_email_enabled'] == '1') echo ' checked="checked"'; ?> value="1">
748 <?php _e('Enable this email notification', 'wp-paypal');?></label>
749 </fieldset></td>
750 </tr>
751 <tr valign="top">
752 <th scope="row"><label for="sale_notification_email_recipient"><?php _e('Recipient', 'wp-paypal');?></label></th>
753 <td><input name="sale_notification_email_recipient" type="text" id="sale_notification_email_recipient" value="<?php echo esc_attr($paypal_options['sale_notification_email_recipient']); ?>" class="regular-text">
754 <p class="description"><?php _e('The email address that should receive a notification anytime a sale is made. Multiple recipients can be specified by separating the addresses with a comma.', 'wp-paypal');?></p></td>
755 </tr>
756 <tr valign="top">
757 <th scope="row"><label for="sale_notification_email_subject"><?php _e('Subject', 'wp-paypal');?></label></th>
758 <td><input name="sale_notification_email_subject" type="text" id="sale_notification_email_subject" value="<?php echo esc_attr($paypal_options['sale_notification_email_subject']); ?>" class="regular-text">
759 <p class="description"><?php _e('The subject line for the sale notification email.', 'wp-paypal');?></p></td>
760 </tr>
761 <tr valign="top">
762 <th scope="row"><label for="sale_notification_email_type"><?php _e('Email Type', 'wp-paypal');?></label></th>
763 <td>
764 <select name="sale_notification_email_type" id="sale_notification_email_type">
765 <option <?php echo ($paypal_options['sale_notification_email_type'] === 'plain')?'selected="selected"':'';?> value="plain"><?php _e('Plain Text', 'wp-paypal')?></option>
766 <option <?php echo ($paypal_options['sale_notification_email_type'] === 'html')?'selected="selected"':'';?> value="html"><?php _e('HTML', 'wp-paypal')?></option>
767 </select>
768 <p class="description"><?php _e('The content type of the sale notification email.', 'wp-paypal')?></p>
769 </td>
770 </tr>
771 <tr valign="top">
772 <th scope="row"><label for="sale_notification_email_body"><?php _e('Email Body', 'wp-paypal');?></label></th>
773 <td><?php wp_editor($paypal_options['sale_notification_email_body'], 'sale_notification_email_body', array('textarea_name' => 'sale_notification_email_body'));?>
774 <p class="description"><?php echo __('The main content of the sale notification email.', 'wp-paypal').' '.wp_kses($email_tags_link, $allowed_html_tags);?></p></td>
775 </tr>
776 <tr valign="top">
777 <th scope="row"><?php _e('Append Purchase Email', 'wp-paypal');?></th>
778 <td> <fieldset><legend class="screen-reader-text"><span>Append Purchase Email</span></legend><label for="sale_notification_email_append_purchase_email">
779 <input name="sale_notification_email_append_purchase_email" type="checkbox" id="sale_notification_email_append_purchase_email" <?php if (isset($paypal_options['sale_notification_email_append_purchase_email']) && $paypal_options['sale_notification_email_append_purchase_email'] == '1') echo ' checked="checked"'; ?> value="1">
780 <?php _e('When enabled, the body of the purchase receipt email will be appended to the sale notification email body', 'wp-paypal');?></label>
781 </fieldset></td>
782 </tr>
783 </tbody>
784 </table>
785
786 <p class="submit"><input type="submit" name="wp_paypal_update_email_settings" id="wp_paypal_update_email_settings" class="button button-primary" value="<?php _e('Save Changes', 'wp-paypal');?>"></p></form>
787 </td>
788 <td valign="top" style="width: 300px">
789 <div style="background: #ffc; border: 1px solid #333; margin: 2px; padding: 3px 15px">
790 <h3><?php _e('Need More Features?', 'wp-paypal')?></h3>
791 <ol>
792 <li><?php printf(__('Check out the <a href="%s">plugin add-ons</a>.', 'wp-paypal'), 'edit.php?post_type=wp_paypal_order&page=wp-paypal-addons');?></li>
793 </ol>
794 <h3><?php _e('Need Help?', 'wp-paypal')?></h3>
795 <ol>
796 <li><?php printf(__('Use the <a href="%s">Debug</a> menu for diagnostics.', 'wp-paypal'), 'edit.php?post_type=wp_paypal_order&page=wp-paypal-debug');?></li>
797 <li><?php printf(__('Check out the <a target="_blank" href="%s">support forum</a> and <a target="_blank" href="%s">FAQ</a>.', 'wp-paypal'), 'https://wordpress.org/support/plugin/wp-paypal/', 'https://wordpress.org/plugins/wp-paypal/#faq');?></li>
798 <li><?php printf(__('Visit the <a target="_blank" href="%s">plugin homepage</a>.', 'wp-paypal'), 'https://wphowto.net/wordpress-paypal-plugin-732');?></li>
799 </ol>
800 <h3><?php _e('Rate This Plugin', 'wp-paypal')?></h3>
801 <p><?php printf(__('Please <a target="_blank" href="%s">rate us</a> and give feedback.', 'wp-paypal'), 'https://wordpress.org/support/plugin/wp-paypal/reviews?rate=5#new-post');?></p>
802 </div>
803 </td>
804 </tr>
805 </tbody>
806 </table>
807 <?php
808 }
809
810 function debug_page() {
811 ?>
812 <div class="wrap">
813 <h2><?php _e('WP PayPal Debug Log', 'wp-paypal');?></h2>
814 <div id="poststuff">
815 <div id="post-body">
816 <?php
817 if (isset($_POST['wp_paypal_update_log_settings'])) {
818 $nonce = $_REQUEST['_wpnonce'];
819 if (!wp_verify_nonce($nonce, 'wp_paypal_debug_log_settings')) {
820 wp_die('Error! Nonce Security Check Failed! please save the settings again.');
821 }
822 update_option('wp_paypal_enable_debug', (isset($_POST["enable_debug"]) && $_POST["enable_debug"] == '1') ? '1' : '');
823 echo '<div id="message" class="updated fade"><p>'.__('Settings Saved', 'wp-paypal').'!</p></div>';
824 }
825 if (isset($_POST['wp_paypal_reset_log'])) {
826 $nonce = $_REQUEST['_wpnonce'];
827 if (!wp_verify_nonce($nonce, 'wp_paypal_reset_log_settings')) {
828 wp_die('Error! Nonce Security Check Failed! please save the settings again.');
829 }
830 if (wp_paypal_reset_log()) {
831 echo '<div id="message" class="updated fade"><p>'.__('Debug log file has been reset', 'wp-paypal').'!</p></div>';
832 } else {
833 echo '<div id="message" class="error"><p>'.__('Debug log file could not be reset', 'wp-paypal').'!</p></div>';
834 }
835 }
836 $log_file = WP_PAYPAL_DEBUG_LOG_PATH;
837 $content = '';
838 if(file_exists($log_file))
839 {
840 $content = file_get_contents($log_file);
841 }
842 ?>
843 <div id="template"><textarea cols="70" rows="25" name="wp_paypal_log" id="wp_paypal_log"><?php echo esc_textarea($content); ?></textarea></div>
844 <form method="post" action="">
845 <?php wp_nonce_field('wp_paypal_debug_log_settings'); ?>
846 <table class="form-table">
847 <tbody>
848 <tr valign="top">
849 <th scope="row"><?php _e('Enable Debug', 'wp-paypal');?></th>
850 <td> <fieldset><legend class="screen-reader-text"><span>Enable Debug</span></legend><label for="enable_debug">
851 <input name="enable_debug" type="checkbox" id="enable_debug" <?php if (get_option('wp_paypal_enable_debug') == '1') echo ' checked="checked"'; ?> value="1">
852 <?php _e('Check this option if you want to enable debug', 'wp-paypal');?></label>
853 </fieldset></td>
854 </tr>
855
856 </tbody>
857
858 </table>
859 <p class="submit"><input type="submit" name="wp_paypal_update_log_settings" id="wp_paypal_update_log_settings" class="button button-primary" value="<?php _e('Save Changes', 'wp-paypal');?>"></p>
860 </form>
861 <form method="post" action="">
862 <?php wp_nonce_field('wp_paypal_reset_log_settings'); ?>
863 <p class="submit"><input type="submit" name="wp_paypal_reset_log" id="wp_paypal_reset_log" class="button" value="<?php _e('Reset Log', 'wp-paypal');?>"></p>
864 </form>
865 </div>
866 </div>
867 </div>
868 <?php
869 }
870
871 }
872
873 $GLOBALS['wp_paypal'] = new WP_PAYPAL();
874
875 function wp_paypal_button_handler($atts) {
876 $atts = array_map('sanitize_text_field', $atts);
877 $testmode = get_option('wp_paypal_enable_testmode');
878 if (isset($testmode) && !empty($testmode)) {
879 $atts['env'] = "sandbox";
880 }
881 $notify_url = home_url() . '/?wp_paypal_ipn=1';
882 if(!isset($atts['notify_url']) || empty($atts['notify_url'])){
883 $atts['notify_url'] = $notify_url;
884 }
885 $paypal_email = get_option('wp_paypal_email');
886 $currency = get_option('wp_paypal_currency_code');
887 if (isset($atts['currency']) && !empty($atts['currency'])) {
888
889 } else {
890 $atts['currency'] = $currency;
891 }
892
893 if(isset($atts['button']) && $atts['button']=="cart"){
894 $button_code = wp_paypal_get_add_to_cart_button($atts);
895 }
896 else if(isset($atts['button']) && $atts['button']=="viewcart"){
897 $button_code = wp_paypal_get_view_cart_button($atts);
898 }
899 else if(isset($atts['button']) && $atts['button']=="buynow"){
900 $button_code = wp_paypal_get_buy_now_button($atts);
901 }
902 else if(isset($atts['button']) && $atts['button']=="donate"){
903 $button_code = wp_paypal_get_donate_button($atts);
904 }
905 else if(isset($atts['button']) && $atts['button']=="subscribe"){
906 $button_code = wp_paypal_get_subscribe_button($atts);
907 }
908 else{
909 $button_code = __('Please enter a correct button type', 'wp-paypal');
910 }
911 return $button_code;
912 }
913
914 function wp_paypal_get_add_to_cart_button($atts){
915 $button_code = '';
916 $action_url = 'https://www.paypal.com/cgi-bin/webscr';
917 if(isset($atts['env']) && $atts['env'] == "sandbox"){
918 $action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
919 }
920 $method = 'post';
921 $amp = false;
922 if(function_exists('amp_is_request') && amp_is_request()){
923 $method = 'get';
924 $amp = true;
925 }
926 $target = '';
927 if(isset($atts['target']) && !empty($atts['target'])) {
928 $target = 'target="'.esc_attr($atts['target']).'" ';
929 }
930 $form_class = '';
931 if(isset($atts['form_class']) && !empty($atts['form_class'])) {
932 $form_class = 'class="'.esc_attr($atts['form_class']).'" ';
933 }
934 $button_code .= '<form '.$form_class.$target.'action="'.esc_url($action_url).'" method="'.$method.'" >';
935 $button_code .= '<input type="hidden" name="charset" value="utf-8">';
936 $button_code .= '<input type="hidden" name="cmd" value="_cart">';
937 $button_code .= '<input type="hidden" name="add" value="1">';
938 $business = '';
939 $paypal_merchant_id = get_option('wp_paypal_merchant_id');
940 $paypal_email = get_option('wp_paypal_email');
941 if(isset($paypal_merchant_id) && !empty($paypal_merchant_id)) {
942 $business = $paypal_merchant_id;
943 }
944 else if(isset($paypal_email) && !empty($paypal_email)) {
945 $business = $paypal_email;
946 }
947 //
948 if(isset($atts['business']) && !empty($atts['business'])) {
949 $business = $atts['business'];
950 }
951 //
952 if(isset($business) && !empty($business)) {
953 $button_code .= '<input type="hidden" name="business" value="'.esc_attr($business).'">';
954 }
955 if(isset($atts['lc']) && !empty($atts['lc'])) {
956 $lc = $atts['lc'];
957 $button_code .= '<input type="hidden" name="lc" value="'.esc_attr($lc).'">';
958 }
959 if(isset($atts['name']) && !empty($atts['name'])) {
960 $name = $atts['name'];
961 $button_code .= '<input type="hidden" name="item_name" value="'.esc_attr($name).'">';
962 }
963 if(isset($atts['item_number']) && !empty($atts['item_number'])) {
964 $item_number = $atts['item_number'];
965 $button_code .= '<input type="hidden" name="item_number" value="'.esc_attr($item_number).'">';
966 }
967 if(isset($atts['amount']) && is_numeric($atts['amount'])) {
968 $amount = $atts['amount'];
969 $button_code .= '<input type="hidden" name="amount" value="'.esc_attr($amount).'">';
970 }
971 if(isset($atts['currency']) && !empty($atts['currency'])) {
972 $currency = $atts['currency'];
973 $button_code .= '<input type="hidden" name="currency_code" value="'.esc_attr($currency).'">';
974 }
975 $button_code .= '<input type="hidden" name="button_subtype" value="products">';
976 $no_note = 0; //default
977 if(isset($atts['no_note']) && is_numeric($atts['no_note'])) {
978 $no_note = $atts['no_note'];
979 $button_code .= '<input type="hidden" name="no_note" value="'.esc_attr($no_note).'">';
980 }
981 if(isset($atts['cn']) && !empty($atts['cn'])) {
982 $cn = $atts['cn'];
983 $button_code .= '<input type="hidden" name="cn" value="'.esc_attr($cn).'">';
984 }
985 $no_shipping = 0; //default
986 if(isset($atts['no_shipping']) && is_numeric($atts['no_shipping'])) {
987 $no_shipping = $atts['no_shipping'];
988 $button_code .= '<input type="hidden" name="no_shipping" value="'.esc_attr($no_shipping).'">';
989 }
990 if(isset($atts['shipping']) && is_numeric($atts['shipping'])) {
991 $shipping = $atts['shipping'];
992 $button_code .= '<input type="hidden" name="shipping" value="'.esc_attr($shipping).'">';
993 }
994 if(isset($atts['shipping2']) && is_numeric($atts['shipping2'])) {
995 $shipping2 = $atts['shipping2'];
996 $button_code .= '<input type="hidden" name="shipping2" value="'.esc_attr($shipping2).'">';
997 }
998 if(isset($atts['tax']) && is_numeric($atts['tax'])) {
999 $tax = $atts['tax'];
1000 $button_code .= '<input type="hidden" name="tax" value="'.esc_attr($tax).'">';
1001 }
1002 if(isset($atts['tax_rate']) && is_numeric($atts['tax_rate'])) {
1003 $tax_rate = $atts['tax_rate'];
1004 $button_code .= '<input type="hidden" name="tax_rate" value="'.esc_attr($tax_rate).'">';
1005 }
1006 if(isset($atts['handling']) && is_numeric($atts['handling'])) {
1007 $handling = $atts['handling'];
1008 $button_code .= '<input type="hidden" name="handling" value="'.esc_attr($handling).'">';
1009 }
1010 if(isset($atts['weight']) && is_numeric($atts['weight'])) {
1011 $weight = $atts['weight'];
1012 $button_code .= '<input type="hidden" name="weight" value="'.esc_attr($weight).'">';
1013 }
1014 if(isset($atts['weight_unit']) && !empty($atts['weight_unit'])) {
1015 $weight_unit = $atts['weight_unit'];
1016 $button_code .= '<input type="hidden" name="weight_unit" value="'.esc_attr($weight_unit).'">';
1017 }
1018 if(isset($atts['shopping_url']) && filter_var($atts['shopping_url'], FILTER_VALIDATE_URL)){
1019 $shopping_url = $atts['shopping_url'];
1020 $button_code .= '<input type="hidden" name="shopping_url" value="'.esc_attr($shopping_url).'">';
1021 }
1022 if(isset($atts['return']) && filter_var($atts['return'], FILTER_VALIDATE_URL)){
1023 $return = $atts['return'];
1024 $button_code .= '<input type="hidden" name="return" value="'.esc_attr($return).'">';
1025 }
1026 if(isset($atts['cancel_return']) && filter_var($atts['cancel_return'], FILTER_VALIDATE_URL)){
1027 $cancel_return = $atts['cancel_return'];
1028 $button_code .= '<input type="hidden" name="cancel_return" value="'.esc_attr($cancel_return).'">';
1029 }
1030 if(isset($atts['notify_url']) && !empty($atts['notify_url'])) {
1031 $notify_url = $atts['notify_url'];
1032 $button_code .= '<input type="hidden" name="notify_url" value="'.esc_attr($notify_url).'">';
1033 }
1034 $button_code = apply_filters('wppaypal_variations', $button_code, $atts);
1035 if(strpos($button_code, 'Error') !== false){
1036 return $button_code;
1037 }
1038 $custom_input_code = '';
1039 $custom_input_code = apply_filters('wppaypal_custom_input', $custom_input_code, $button_code, $atts);
1040 if(!empty($custom_input_code)){
1041 $button_code .= $custom_input_code;
1042 }
1043 else if(isset($atts['custom']) && !empty($atts['custom'])) {
1044 $custom = $atts['custom'];
1045 $button_code .= '<input type="hidden" name="custom" value="'.esc_attr($custom).'">';
1046 }
1047 $button_code .= '<input type="hidden" name="bn" value="WPPayPal_AddToCart_WPS_US">';
1048 $button_image_url = WP_PAYPAL_URL.'/images/add-to-cart.png';
1049 if(isset($atts['button_image']) && filter_var($atts['button_image'], FILTER_VALIDATE_URL)){
1050 $button_image_url = $atts['button_image'];
1051 }
1052 //$button_code .= '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1053 $button_submit_code = '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1054 $button_text = 'Add to Cart';
1055 if(isset($atts['button_text']) && !empty($atts['button_text'])){
1056 $button_text = $atts['button_text'];
1057 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1058 }
1059 //
1060 if($amp){
1061 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1062 }
1063 //
1064 $button_code .= $button_submit_code;
1065 $button_code .= '</form>';
1066 return $button_code;
1067 }
1068
1069 function wp_paypal_get_view_cart_button($atts){
1070 $button_code = '';
1071 $action_url = 'https://www.paypal.com/cgi-bin/webscr';
1072 if(isset($atts['env']) && $atts['env'] == "sandbox"){
1073 $action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
1074 }
1075 $method = 'post';
1076 $amp = false;
1077 if(function_exists('amp_is_request') && amp_is_request()){
1078 $method = 'get';
1079 $amp = true;
1080 }
1081 $target = '';
1082 if(isset($atts['target']) && !empty($atts['target'])) {
1083 $target = 'target="'.esc_attr($atts['target']).'" ';
1084 }
1085 $form_class = '';
1086 if(isset($atts['form_class']) && !empty($atts['form_class'])) {
1087 $form_class = 'class="'.esc_attr($atts['form_class']).'" ';
1088 }
1089 $button_code .= '<form '.$form_class.$target.'action="'.esc_url($action_url).'" method="'.$method.'" >';
1090 $button_code .= '<input type="hidden" name="charset" value="utf-8">';
1091 $button_code .= '<input type="hidden" name="cmd" value="_cart">';
1092 $button_code .= '<input type="hidden" name="display" value="1">';
1093 if(isset($atts['shopping_url']) && !empty($atts['shopping_url'])) {
1094 $shopping_url = $atts['shopping_url'];
1095 $button_code .= '<input type="hidden" name="shopping_url" value="'.esc_attr($shopping_url).'">';
1096 }
1097 $business = '';
1098 $paypal_merchant_id = get_option('wp_paypal_merchant_id');
1099 $paypal_email = get_option('wp_paypal_email');
1100 if(isset($paypal_merchant_id) && !empty($paypal_merchant_id)) {
1101 $business = $paypal_merchant_id;
1102 }
1103 else if(isset($paypal_email) && !empty($paypal_email)) {
1104 $business = $paypal_email;
1105 }
1106
1107 if(isset($business) && !empty($business)) {
1108 $button_code .= '<input type="hidden" name="business" value="'.esc_attr($business).'">';
1109 }
1110 $button_image_url = WP_PAYPAL_URL.'/images/view-cart.png';
1111 if(isset($atts['button_image']) && filter_var($atts['button_image'], FILTER_VALIDATE_URL)){
1112 $button_image_url = $atts['button_image'];
1113 }
1114 //$button_code .= '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1115 $button_submit_code = '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1116 $button_text = 'View Cart';
1117 if(isset($atts['button_text']) && !empty($atts['button_text'])){
1118 $button_text = $atts['button_text'];
1119 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1120 }
1121 //
1122 if($amp){
1123 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1124 }
1125 //
1126 $button_code .= $button_submit_code;
1127 $button_code .= '</form>';
1128 return $button_code;
1129 }
1130
1131 function wp_paypal_get_buy_now_button($atts){
1132 $button_code = '';
1133 $action_url = 'https://www.paypal.com/cgi-bin/webscr';
1134 if(isset($atts['env']) && $atts['env'] == "sandbox"){
1135 $action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
1136 }
1137 $method = 'post';
1138 $amp = false;
1139 if(function_exists('amp_is_request') && amp_is_request()){
1140 $method = 'get';
1141 $amp = true;
1142 }
1143 $target = '';
1144 if(isset($atts['target']) && !empty($atts['target'])) {
1145 $target = 'target="'.esc_attr($atts['target']).'" ';
1146 }
1147 $form_class = '';
1148 if(isset($atts['form_class']) && !empty($atts['form_class'])) {
1149 $form_class = 'class="'.esc_attr($atts['form_class']).'" ';
1150 }
1151 $button_code .= '<form '.$form_class.$target.'action="'.esc_url($action_url).'" method="'.$method.'" >';
1152 $button_code .= '<input type="hidden" name="charset" value="utf-8">';
1153 $button_code .= '<input type="hidden" name="cmd" value="_xclick">';
1154 $business = '';
1155 $paypal_merchant_id = get_option('wp_paypal_merchant_id');
1156 $paypal_email = get_option('wp_paypal_email');
1157 if(isset($paypal_merchant_id) && !empty($paypal_merchant_id)) {
1158 $business = $paypal_merchant_id;
1159 }
1160 else if(isset($paypal_email) && !empty($paypal_email)) {
1161 $business = $paypal_email;
1162 }
1163 //
1164 if(isset($atts['business']) && !empty($atts['business'])) {
1165 $business = $atts['business'];
1166 }
1167 //
1168 $price_variation = false;
1169 if(isset($atts['os0_amount0']) && is_numeric($atts['os0_amount0'])) {
1170 $price_variation = true;
1171 }
1172 if(isset($business) && !empty($business)) {
1173 $button_code .= '<input type="hidden" name="business" value="'.esc_attr($business).'">';
1174 }
1175 if(isset($atts['lc']) && !empty($atts['lc'])) {
1176 $lc = $atts['lc'];
1177 $button_code .= '<input type="hidden" name="lc" value="'.esc_attr($lc).'">';
1178 }
1179 /* product name sent via URL */
1180 if(isset($_GET['wppp_name']) && !empty($_GET['wppp_name']))
1181 {
1182 $atts['name'] = sanitize_text_field(stripslashes($_GET['wppp_name']));
1183 }
1184 /* end */
1185 if(isset($atts['name']) && !empty($atts['name'])) {
1186 $name = $atts['name'];
1187 $button_code .= '<input type="hidden" name="item_name" value="'.esc_attr($name).'">';
1188 }
1189 if(isset($atts['item_number']) && !empty($atts['item_number'])) {
1190 $item_number = $atts['item_number'];
1191 $button_code .= '<input type="hidden" name="item_number" value="'.esc_attr($item_number).'">';
1192 }
1193 if(!$price_variation){
1194 $amount_input_code = '';
1195 $amount_input_code = apply_filters('wppaypal_buynow_custom_amount', $amount_input_code, $button_code, $atts);
1196 if(!empty($amount_input_code)){
1197 $button_code .= $amount_input_code;
1198 }
1199 else{
1200 /* product amount sent via URL */
1201 if(isset($_GET['wppp_amount']) && !empty($_GET['wppp_amount']))
1202 {
1203 $atts['amount'] = sanitize_text_field($_GET['wppp_amount']);
1204 }
1205 /* end */
1206 if(isset($atts['amount']) && is_numeric($atts['amount']) && $atts['amount'] > 0) {
1207 $amount = $atts['amount'];
1208 $button_code .= '<input type="hidden" name="amount" value="'.esc_attr($amount).'">';
1209 }
1210 else{
1211 $error = __('Amount cannot be empty', 'wp-paypal');
1212 return $error;
1213 }
1214 }
1215 }
1216 if(isset($atts['currency']) && !empty($atts['currency'])) {
1217 $currency = $atts['currency'];
1218 $button_code .= '<input type="hidden" name="currency_code" value="'.esc_attr($currency).'">';
1219 }
1220 $no_shipping = 0; //default
1221 if(isset($atts['no_shipping']) && is_numeric($atts['no_shipping'])) {
1222 $no_shipping = $atts['no_shipping'];
1223 $button_code .= '<input type="hidden" name="no_shipping" value="'.esc_attr($no_shipping).'">';
1224 }
1225 if(isset($atts['shipping']) && is_numeric($atts['shipping'])) {
1226 $shipping = $atts['shipping'];
1227 $button_code .= '<input type="hidden" name="shipping" value="'.esc_attr($shipping).'">';
1228 }
1229 if(isset($atts['shipping2']) && is_numeric($atts['shipping2'])) {
1230 $shipping2 = $atts['shipping2'];
1231 $button_code .= '<input type="hidden" name="shipping2" value="'.esc_attr($shipping2).'">';
1232 }
1233 if(isset($atts['tax']) && is_numeric($atts['tax'])) {
1234 $tax = $atts['tax'];
1235 $button_code .= '<input type="hidden" name="tax" value="'.esc_attr($tax).'">';
1236 }
1237 if(isset($atts['tax_rate']) && is_numeric($atts['tax_rate'])) {
1238 $tax_rate = $atts['tax_rate'];
1239 $button_code .= '<input type="hidden" name="tax_rate" value="'.esc_attr($tax_rate).'">';
1240 }
1241 $button_code = apply_filters('wppaypal_enable_buynow_discount', $button_code, $atts);
1242 if(isset($atts['handling']) && is_numeric($atts['handling'])) {
1243 $handling = $atts['handling'];
1244 $button_code .= '<input type="hidden" name="handling" value="'.esc_attr($handling).'">';
1245 }
1246 if(isset($atts['quantity']) && empty($atts['quantity'])) {
1247 $quantity_input_code = '';
1248 $quantity_input_code = apply_filters('wppaypal_variable_quantity', $quantity_input_code, $button_code, $atts);
1249 if(!empty($quantity_input_code)){
1250 $button_code .= $quantity_input_code;
1251 }
1252 }
1253 if(isset($atts['undefined_quantity']) && is_numeric($atts['undefined_quantity'])) {
1254 $undefined_quantity = $atts['undefined_quantity'];
1255 $button_code .= '<input type="hidden" name="undefined_quantity" value="'.esc_attr($undefined_quantity).'">';
1256 }
1257 if(isset($atts['weight']) && is_numeric($atts['weight'])) {
1258 $weight = $atts['weight'];
1259 $button_code .= '<input type="hidden" name="weight" value="'.esc_attr($weight).'">';
1260 }
1261 if(isset($atts['weight_unit']) && !empty($atts['weight_unit'])) {
1262 $weight_unit = $atts['weight_unit'];
1263 $button_code .= '<input type="hidden" name="weight_unit" value="'.esc_attr($weight_unit).'">';
1264 }
1265 if(isset($atts['return']) && filter_var($atts['return'], FILTER_VALIDATE_URL)){
1266 $return = $atts['return'];
1267 $button_code .= '<input type="hidden" name="return" value="'.esc_attr($return).'">';
1268 }
1269 if(isset($atts['cancel_return']) && filter_var($atts['cancel_return'], FILTER_VALIDATE_URL)){
1270 $cancel_return = $atts['cancel_return'];
1271 $button_code .= '<input type="hidden" name="cancel_return" value="'.esc_attr($cancel_return).'">';
1272 }
1273 if(isset($atts['notify_url']) && !empty($atts['notify_url'])) {
1274 $notify_url = $atts['notify_url'];
1275 $button_code .= '<input type="hidden" name="notify_url" value="'.esc_attr($notify_url).'">';
1276 }
1277 $button_code = apply_filters('wppaypal_variations', $button_code, $atts);
1278 if(strpos($button_code, 'Error') !== false){
1279 return $button_code;
1280 }
1281 $custom_input_code = '';
1282 $custom_input_code = apply_filters('wppaypal_custom_input', $custom_input_code, $button_code, $atts);
1283 if(!empty($custom_input_code)){
1284 $button_code .= $custom_input_code;
1285 }
1286 else if(isset($atts['custom']) && !empty($atts['custom'])) {
1287 $custom = $atts['custom'];
1288 $button_code .= '<input type="hidden" name="custom" value="'.esc_attr($custom).'">';
1289 }
1290 $button_code .= '<input type="hidden" name="bn" value="WPPayPal_BuyNow_WPS_US">';
1291 $button_image_url = WP_PAYPAL_URL.'/images/buy-now.png';
1292 if(isset($atts['button_image']) && filter_var($atts['button_image'], FILTER_VALIDATE_URL)){
1293 $button_image_url = $atts['button_image'];
1294 }
1295 //$button_code .= '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1296 $button_submit_code = '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1297 $button_text = 'Buy Now';
1298 if(isset($atts['button_text']) && !empty($atts['button_text'])){
1299 $button_text = $atts['button_text'];
1300 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1301 }
1302 //
1303 if($amp){
1304 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1305 }
1306 //
1307 $button_code .= $button_submit_code;
1308 $button_code .= '</form>';
1309 return $button_code;
1310 }
1311
1312 function wp_paypal_get_donate_button($atts){
1313 $button_code = '';
1314 $action_url = 'https://www.paypal.com/cgi-bin/webscr';
1315 if(isset($atts['env']) && $atts['env'] == "sandbox"){
1316 $action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
1317 }
1318 $method = 'post';
1319 $amp = false;
1320 if(function_exists('amp_is_request') && amp_is_request()){
1321 $method = 'get';
1322 $amp = true;
1323 }
1324 $target = '';
1325 if(isset($atts['target']) && !empty($atts['target'])) {
1326 $target = 'target="'.esc_attr($atts['target']).'" ';
1327 }
1328 $form_class = '';
1329 if(isset($atts['form_class']) && !empty($atts['form_class'])) {
1330 $form_class = 'class="'.esc_attr($atts['form_class']).'" ';
1331 }
1332 $button_code .= '<form '.$form_class.$target.'action="'.esc_url($action_url).'" method="'.$method.'" >';
1333 $button_code .= '<input type="hidden" name="charset" value="utf-8">';
1334 $button_code .= '<input type="hidden" name="cmd" value="_donations">';
1335 $business = '';
1336 $paypal_merchant_id = get_option('wp_paypal_merchant_id');
1337 $paypal_email = get_option('wp_paypal_email');
1338 if(isset($paypal_merchant_id) && !empty($paypal_merchant_id)) {
1339 $business = $paypal_merchant_id;
1340 }
1341 else if(isset($paypal_email) && !empty($paypal_email)) {
1342 $business = $paypal_email;
1343 }
1344 //
1345 if(isset($atts['business']) && !empty($atts['business'])) {
1346 $business = $atts['business'];
1347 }
1348 //
1349 if(isset($business) && !empty($business)) {
1350 $button_code .= '<input type="hidden" name="business" value="'.esc_attr($business).'">';
1351 }
1352 if(isset($atts['lc']) && !empty($atts['lc'])) {
1353 $lc = $atts['lc'];
1354 $button_code .= '<input type="hidden" name="lc" value="'.esc_attr($lc).'">';
1355 }
1356 if(isset($atts['name']) && !empty($atts['name'])) {
1357 $name = $atts['name'];
1358 $button_code .= '<input type="hidden" name="item_name" value="'.esc_attr($name).'">';
1359 }
1360 if(isset($atts['item_number']) && !empty($atts['item_number'])) {
1361 $item_number = $atts['item_number'];
1362 $button_code .= '<input type="hidden" name="item_number" value="'.esc_attr($item_number).'">';
1363 }
1364 //
1365 $amount_input_code = '';
1366 $amount_input_code = apply_filters('wppaypal_custom_donations', $amount_input_code, $button_code, $atts);
1367 if(!empty($amount_input_code)){
1368 $button_code .= $amount_input_code;
1369 }
1370 else{
1371 if(isset($atts['amount']) && is_numeric($atts['amount']) && $atts['amount'] > 0) {
1372 $amount = $atts['amount'];
1373 $button_code .= '<input type="hidden" name="amount" value="'.esc_attr($amount).'">';
1374 }
1375 }
1376 //
1377 if(isset($atts['currency']) && !empty($atts['currency'])) {
1378 $currency = $atts['currency'];
1379 $button_code .= '<input type="hidden" name="currency_code" value="'.esc_attr($currency).'">';
1380 }
1381 $no_shipping = 0; //default
1382 if(isset($atts['no_shipping']) && is_numeric($atts['no_shipping'])) {
1383 $no_shipping = $atts['no_shipping'];
1384 $button_code .= '<input type="hidden" name="no_shipping" value="'.esc_attr($no_shipping).'">';
1385 }
1386 if(isset($atts['return']) && filter_var($atts['return'], FILTER_VALIDATE_URL)){
1387 $return = $atts['return'];
1388 $button_code .= '<input type="hidden" name="return" value="'.esc_attr($return).'">';
1389 }
1390 if(isset($atts['cancel_return']) && filter_var($atts['cancel_return'], FILTER_VALIDATE_URL)){
1391 $cancel_return = $atts['cancel_return'];
1392 $button_code .= '<input type="hidden" name="cancel_return" value="'.esc_attr($cancel_return).'">';
1393 }
1394 if(isset($atts['notify_url']) && !empty($atts['notify_url'])) {
1395 $notify_url = $atts['notify_url'];
1396 $button_code .= '<input type="hidden" name="notify_url" value="'.esc_attr($notify_url).'">';
1397 }
1398 $custom_input_code = '';
1399 $custom_input_code = apply_filters('wppaypal_custom_input', $custom_input_code, $button_code, $atts);
1400 if(!empty($custom_input_code)){
1401 $button_code .= $custom_input_code;
1402 }
1403 else if(isset($atts['custom']) && !empty($atts['custom'])) {
1404 $custom = $atts['custom'];
1405 $button_code .= '<input type="hidden" name="custom" value="'.esc_attr($custom).'">';
1406 }
1407 $button_code .= '<input type="hidden" name="bn" value="WPPayPal_Donate_WPS_US">';
1408 $button_image_url = WP_PAYPAL_URL.'/images/donate.png';
1409 if(isset($atts['button_image']) && filter_var($atts['button_image'], FILTER_VALIDATE_URL)){
1410 $button_image_url = $atts['button_image'];
1411 }
1412 //$button_code .= '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1413 $button_submit_code = '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1414 $button_text = 'Donate';
1415 if(isset($atts['button_text']) && !empty($atts['button_text'])){
1416 $button_text = $atts['button_text'];
1417 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1418 }
1419 //
1420 if($amp){
1421 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1422 }
1423 //
1424 $button_code .= $button_submit_code;
1425 $button_code .= '</form>';
1426 return $button_code;
1427 }
1428
1429 function wp_paypal_get_subscribe_button($atts){
1430 $button_code = '';
1431 $action_url = 'https://www.paypal.com/cgi-bin/webscr';
1432 if(isset($atts['env']) && $atts['env'] == "sandbox"){
1433 $action_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
1434 }
1435 $method = 'post';
1436 $amp = false;
1437 if(function_exists('amp_is_request') && amp_is_request()){
1438 $method = 'get';
1439 $amp = true;
1440 }
1441 $target = '';
1442 if(isset($atts['target']) && !empty($atts['target'])) {
1443 $target = 'target="'.esc_attr($atts['target']).'" ';
1444 }
1445 $form_class = '';
1446 if(isset($atts['form_class']) && !empty($atts['form_class'])) {
1447 $form_class = 'class="'.esc_attr($atts['form_class']).'" ';
1448 }
1449 $button_code .= '<form '.$form_class.$target.'action="'.esc_url($action_url).'" method="'.$method.'" >';
1450 $button_code .= '<input type="hidden" name="charset" value="utf-8">';
1451 $button_code .= '<input type="hidden" name="cmd" value="_xclick-subscriptions">';
1452 $business = '';
1453 $paypal_merchant_id = get_option('wp_paypal_merchant_id');
1454 $paypal_email = get_option('wp_paypal_email');
1455 if(isset($paypal_merchant_id) && !empty($paypal_merchant_id)) {
1456 $business = $paypal_merchant_id;
1457 }
1458 else if(isset($paypal_email) && !empty($paypal_email)) {
1459 $business = $paypal_email;
1460 }
1461 //
1462 if(isset($atts['business']) && !empty($atts['business'])) {
1463 $business = $atts['business'];
1464 }
1465 //
1466 if(isset($business) && !empty($business)) {
1467 $button_code .= '<input type="hidden" name="business" value="'.esc_attr($business).'">';
1468 }
1469 if(isset($atts['lc']) && !empty($atts['lc'])) {
1470 $lc = $atts['lc'];
1471 $button_code .= '<input type="hidden" name="lc" value="'.esc_attr($lc).'">';
1472 }
1473 if(isset($atts['name']) && !empty($atts['name'])) {
1474 $name = $atts['name'];
1475 $button_code .= '<input type="hidden" name="item_name" value="'.esc_attr($name).'">';
1476 }
1477 if(isset($atts['item_number']) && !empty($atts['item_number'])) {
1478 $item_number = $atts['item_number'];
1479 $button_code .= '<input type="hidden" name="item_number" value="'.esc_attr($item_number).'">';
1480 }
1481 if(isset($atts['a1']) && is_numeric($atts['a1'])) {
1482 $a1 = $atts['a1'];
1483 $button_code .= '<input type="hidden" name="a1" value="'.esc_attr($a1).'">';
1484 if(isset($atts['p1']) && is_numeric($atts['p1'])) {
1485 $p1 = $atts['p1'];
1486 $button_code .= '<input type="hidden" name="p1" value="'.esc_attr($p1).'">';
1487 }
1488 else{
1489 $button_code = __('Please enter a trial period duration p1', 'wp-paypal');
1490 return $button_code;
1491 }
1492 if(isset($atts['t1']) && !empty($atts['t1'])) {
1493 $t1 = $atts['t1'];
1494 $button_code .= '<input type="hidden" name="t1" value="'.esc_attr($t1).'">';
1495 }
1496 else{
1497 $button_code = __('Please enter a trial period units of duration t1', 'wp-paypal');
1498 return $button_code;
1499 }
1500 }
1501 if(isset($atts['a2']) && is_numeric($atts['a2'])) {
1502 $a2 = $atts['a2'];
1503 $button_code .= '<input type="hidden" name="a2" value="'.esc_attr($a2).'">';
1504 if(isset($atts['p2']) && is_numeric($atts['p2'])) {
1505 $p2 = $atts['p2'];
1506 $button_code .= '<input type="hidden" name="p2" value="'.esc_attr($p2).'">';
1507 }
1508 else{
1509 $button_code = __('Please enter a trial period 2 duration p2', 'wp-paypal');
1510 return $button_code;
1511 }
1512 if(isset($atts['t2']) && !empty($atts['t2'])) {
1513 $t2 = $atts['t2'];
1514 $button_code .= '<input type="hidden" name="t2" value="'.esc_attr($t2).'">';
1515 }
1516 else{
1517 $button_code = __('Please enter a trial period 2 units of duration t1', 'wp-paypal');
1518 return $button_code;
1519 }
1520 }
1521 $a3_input_code = '';
1522 $a3_input_code = apply_filters('wppaypal_subscribe_a3', $a3_input_code, $button_code, $atts);
1523 if(!empty($a3_input_code)){
1524 $button_code .= $a3_input_code;
1525 }
1526 else{
1527 if(isset($atts['a3']) && is_numeric($atts['a3']) && $atts['a3'] > 0) {
1528 $a3 = $atts['a3'];
1529 $button_code .= '<input type="hidden" name="a3" value="'.esc_attr($a3).'">';
1530 }
1531 else{
1532 $error = __('Please enter a regular subscription price a3', 'wp-paypal');
1533 return $error;
1534 }
1535 }
1536 if(isset($atts['p3']) && is_numeric($atts['p3'])) {
1537 $p3 = $atts['p3'];
1538 $button_code .= '<input type="hidden" name="p3" value="'.esc_attr($p3).'">';
1539 }
1540 else{
1541 $button_code = __('Please enter a subscription duration p3', 'wp-paypal');
1542 return $button_code;
1543 }
1544 if(isset($atts['t3']) && !empty($atts['t3'])) {
1545 $t3 = $atts['t3'];
1546 $button_code .= '<input type="hidden" name="t3" value="'.esc_attr($t3).'">';
1547 }
1548 else{
1549 $button_code = __('Please enter a subscription units of duration t3', 'wp-paypal');
1550 return $button_code;
1551 }
1552 if(isset($atts['src']) && is_numeric($atts['src'])) {
1553 $src = $atts['src'];
1554 $button_code .= '<input type="hidden" name="src" value="'.esc_attr($src).'">';
1555 if($src == '1'){
1556 if(isset($atts['srt']) && is_numeric($atts['srt'])) {
1557 $srt = $atts['srt'];
1558 $button_code .= '<input type="hidden" name="srt" value="'.esc_attr($srt).'">';
1559 }
1560 }
1561 }
1562 if(isset($atts['sra']) && is_numeric($atts['sra'])) {
1563 $sra = $atts['sra'];
1564 $button_code .= '<input type="hidden" name="sra" value="'.esc_attr($sra).'">';
1565 }
1566 if(isset($atts['currency']) && !empty($atts['currency'])) {
1567 $currency = $atts['currency'];
1568 $button_code .= '<input type="hidden" name="currency_code" value="'.esc_attr($currency).'">';
1569 }
1570 $button_code .= '<input type="hidden" name="no_note" value="1">'; //For Subscribe buttons, always set no_note to 1
1571 $no_shipping = 0; //default
1572 if(isset($atts['no_shipping']) && is_numeric($atts['no_shipping'])) {
1573 $no_shipping = $atts['no_shipping'];
1574 $button_code .= '<input type="hidden" name="no_shipping" value="'.esc_attr($no_shipping).'">';
1575 }
1576 if(isset($atts['return']) && filter_var($atts['return'], FILTER_VALIDATE_URL)){
1577 $return = $atts['return'];
1578 $button_code .= '<input type="hidden" name="return" value="'.esc_attr($return).'">';
1579 }
1580 if(isset($atts['cancel_return']) && filter_var($atts['cancel_return'], FILTER_VALIDATE_URL)){
1581 $cancel_return = $atts['cancel_return'];
1582 $button_code .= '<input type="hidden" name="cancel_return" value="'.esc_attr($cancel_return).'">';
1583 }
1584 if(isset($atts['notify_url']) && !empty($atts['notify_url'])) {
1585 $notify_url = $atts['notify_url'];
1586 $button_code .= '<input type="hidden" name="notify_url" value="'.esc_attr($notify_url).'">';
1587 }
1588 $custom_input_code = '';
1589 $custom_input_code = apply_filters('wppaypal_custom_input', $custom_input_code, $button_code, $atts);
1590 if(!empty($custom_input_code)){
1591 $button_code .= $custom_input_code;
1592 }
1593 else if(isset($atts['custom']) && !empty($atts['custom'])) {
1594 $custom = $atts['custom'];
1595 $button_code .= '<input type="hidden" name="custom" value="'.esc_attr($custom).'">';
1596 }
1597 $button_code .= '<input type="hidden" name="bn" value="WPPayPal_Subscribe_WPS_US">';
1598 $button_image_url = WP_PAYPAL_URL.'/images/subscribe.png';
1599 if(isset($atts['button_image']) && filter_var($atts['button_image'], FILTER_VALIDATE_URL)){
1600 $button_image_url = $atts['button_image'];
1601 }
1602 //$button_code .= '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1603 $button_submit_code = '<input type="image" src="'.esc_url($button_image_url).'" border="0" name="submit">';
1604 $button_text = 'Subscribe';
1605 if(isset($atts['button_text']) && !empty($atts['button_text'])){
1606 $button_text = $atts['button_text'];
1607 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1608 }
1609 //
1610 if($amp){
1611 $button_submit_code = '<input type="submit" value="'.esc_attr($button_text).'">';
1612 }
1613 //
1614 $button_code .= $button_submit_code;
1615 $button_code .= '</form>';
1616 return $button_code;
1617 }
1618
1619 function wp_paypal_get_email_option(){
1620 $options = get_option('wp_paypal_email_options');
1621 if(!is_array($options)){
1622 $options = wp_paypal_get_empty_email_options_array();
1623 }
1624 return $options;
1625 }
1626
1627 function wp_paypal_update_email_option($new_options){
1628 $empty_options = wp_paypal_get_empty_email_options_array();
1629 $options = wp_paypal_get_email_option();
1630 if(is_array($options)){
1631 $current_options = array_merge($empty_options, $options);
1632 $updated_options = array_merge($current_options, $new_options);
1633 update_option('wp_paypal_email_options', $updated_options);
1634 }
1635 else{
1636 $updated_options = array_merge($empty_options, $new_options);
1637 update_option('wp_paypal_email_options', $updated_options);
1638 }
1639 }
1640
1641 function wp_paypal_get_empty_email_options_array(){
1642 $options = array();
1643 $options['email_from_name'] = '';
1644 $options['email_from_address'] = '';
1645 $options['purchase_email_enabled'] = '';
1646 $options['purchase_email_subject'] = '';
1647 $options['purchase_email_type'] = '';
1648 $options['purchase_email_body'] = '';
1649 $options['sale_notification_email_enabled'] = '';
1650 $options['sale_notification_email_recipient'] = '';
1651 $options['sale_notification_email_subject'] = '';
1652 $options['sale_notification_email_type'] = '';
1653 $options['sale_notification_email_body'] = '';
1654 $options['sale_notification_email_append_purchase_email'] = '';
1655 return $options;
1656 }
1657
1658 function wp_paypal_set_default_email_options(){
1659 $options = wp_paypal_get_email_option();
1660 $options['purchase_email_type'] = 'plain';
1661 $options['purchase_email_subject'] = __("Purchase Receipt", "wp-paypal");
1662 $purchage_email_body = __("Dear", "wp-paypal")." {first_name},\n\n";
1663 $purchage_email_body .= __("Thank you for your purchase. Your purchase details are shown below for your reference:", "wp-paypal")."\n\n";
1664 $purchage_email_body .= __("Transaction ID:", "wp-paypal")." {txn_id}\n";
1665 $purchage_email_body .= __("Product(s):", "wp-paypal")." {item_names}\n";
1666 $purchage_email_body .= __("Total:", "wp-paypal")." {mc_currency} {mc_gross}";
1667 $options['purchase_email_body'] = $purchage_email_body;
1668 $options['sale_notification_email_recipient'] = get_bloginfo('admin_email');
1669 $options['sale_notification_email_subject'] = __("New Customer Order", "wp-paypal");
1670 $options['sale_notification_email_type'] = 'plain';
1671 $sale_notification_email_body = __("Hello", "wp-paypal")."\n\n";
1672 $sale_notification_email_body .= __("A purchase has been made.", "wp-paypal")."\n\n";
1673 $sale_notification_email_body .= __("Purchased by:", "wp-paypal")." {first_name} {last_name}\n";
1674 $sale_notification_email_body .= __("Product(s) sold:", "wp-paypal")." {item_names}\n";
1675 $sale_notification_email_body .= __("Total:", "wp-paypal")." {mc_currency} {mc_gross}\n\n";
1676 $sale_notification_email_body .= __("Thank you", "wp-paypal");
1677 $options['sale_notification_email_body'] = $sale_notification_email_body;
1678 add_option('wp_paypal_email_options', $options);
1679 }
1680
1681
1682 function wp_paypal_debug_log($msg, $success, $end = false) {
1683 if (!WP_PAYPAL_DEBUG) {
1684 return;
1685 }
1686 $date_time = date('F j, Y g:i a');//the_date('F j, Y g:i a', '', '', FALSE);
1687 $text = '[' . $date_time . '] - ' . (($success) ? 'SUCCESS :' : 'FAILURE :') . $msg . "\n";
1688 if ($end) {
1689 $text .= "\n------------------------------------------------------------------\n\n";
1690 }
1691 // Write to log.txt file
1692 $fp = fopen(WP_PAYPAL_DEBUG_LOG_PATH, 'a');
1693 fwrite($fp, $text);
1694 fclose($fp); // close file
1695 }
1696
1697 function wp_paypal_debug_log_array($array_msg, $success, $end = false) {
1698 if (!WP_PAYPAL_DEBUG) {
1699 return;
1700 }
1701 $date_time = date('F j, Y g:i a');//the_date('F j, Y g:i a', '', '', FALSE);
1702 $text = '[' . $date_time . '] - ' . (($success) ? 'SUCCESS :' : 'FAILURE :') . "\n";
1703 ob_start();
1704 print_r($array_msg);
1705 $var = ob_get_contents();
1706 ob_end_clean();
1707 $text .= $var;
1708 if ($end) {
1709 $text .= "\n------------------------------------------------------------------\n\n";
1710 }
1711 // Write to log.txt file
1712 $fp = fopen(WP_PAYPAL_DEBUG_LOG_PATH, 'a');
1713 fwrite($fp, $text);
1714 fclose($fp); // close filee
1715 }
1716
1717 function wp_paypal_reset_log() {
1718 $log_reset = true;
1719 $date_time = date('F j, Y g:i a');//the_date('F j, Y g:i a', '', '', FALSE);
1720 $text = '[' . $date_time . '] - SUCCESS : Log reset';
1721 $text .= "\n------------------------------------------------------------------\n\n";
1722 $fp = fopen(WP_PAYPAL_DEBUG_LOG_PATH, 'w');
1723 if ($fp != FALSE) {
1724 @fwrite($fp, $text);
1725 @fclose($fp);
1726 } else {
1727 $log_reset = false;
1728 }
1729 return $log_reset;
1730 }
1731