@@ -34,12 +34,12 @@ |
||
34 | 34 | // Prepare pagination |
35 | 35 | $pagination = paginate_links( |
36 | 36 | array( |
37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | - 'format' => '', |
|
39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
40 | - 'next_text' => __( '»', 'invoicing' ), |
|
41 | - 'total' => ceil( $total_logs / $per_page ), |
|
42 | - 'current' => $page, |
|
37 | + 'base' => add_query_arg( 'paged', '%#%' ), |
|
38 | + 'format' => '', |
|
39 | + 'prev_text' => __( '«', 'invoicing' ), |
|
40 | + 'next_text' => __( '»', 'invoicing' ), |
|
41 | + 'total' => ceil( $total_logs / $per_page ), |
|
42 | + 'current' => $page, |
|
43 | 43 | ) |
44 | 44 | ); |
45 | 45 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 2.8.22 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * GetPaid_Anonymization_Logs Class |
@@ -19,89 +19,89 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function display_logs() { |
21 | 21 | // Check user capabilities |
22 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
22 | + if (!current_user_can('manage_options')) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | 26 | // Get current page number |
27 | - $page = isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
27 | + $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
28 | 28 | $per_page = 20; |
29 | 29 | |
30 | 30 | // Fetch logs |
31 | - $logs = $this->get_logs( $page, $per_page ); |
|
31 | + $logs = $this->get_logs($page, $per_page); |
|
32 | 32 | $total_logs = $this->get_total_logs(); |
33 | 33 | |
34 | 34 | // Prepare pagination |
35 | 35 | $pagination = paginate_links( |
36 | 36 | array( |
37 | - 'base' => add_query_arg( 'paged', '%#%' ), |
|
37 | + 'base' => add_query_arg('paged', '%#%'), |
|
38 | 38 | 'format' => '', |
39 | - 'prev_text' => __( '«', 'invoicing' ), |
|
40 | - 'next_text' => __( '»', 'invoicing' ), |
|
41 | - 'total' => ceil( $total_logs / $per_page ), |
|
39 | + 'prev_text' => __('«', 'invoicing'), |
|
40 | + 'next_text' => __('»', 'invoicing'), |
|
41 | + 'total' => ceil($total_logs / $per_page), |
|
42 | 42 | 'current' => $page, |
43 | 43 | ) |
44 | 44 | ); |
45 | 45 | |
46 | 46 | ?> |
47 | 47 | <div class="wrap getpaid-anonymization-logs"> |
48 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
48 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
49 | 49 | <div class="tablenav top"> |
50 | 50 | <div class="alignleft actions"> |
51 | 51 | <form method="get"> |
52 | 52 | <input type="hidden" name="page" value="wpinv-anonymization-logs"> |
53 | - <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date', 'invoicing' ); ?></label> |
|
53 | + <label for="filter-by-date" class="screen-reader-text"><?php _e('Filter by date', 'invoicing'); ?></label> |
|
54 | 54 | <select name="m" id="filter-by-date"> |
55 | - <option value="0"><?php _e( 'All dates', 'invoicing' ); ?></option> |
|
55 | + <option value="0"><?php _e('All dates', 'invoicing'); ?></option> |
|
56 | 56 | <?php |
57 | 57 | $months = $this->get_log_months(); |
58 | - foreach ( $months as $month ) { |
|
59 | - $selected = ( isset( $_GET['m'] ) && $_GET['m'] == $month->month ) ? ' selected="selected"' : ''; |
|
60 | - echo '<option value="' . esc_attr( $month->month ) . '"' . $selected . '>' . esc_html( $month->month_name . ' ' . $month->year ) . '</option>'; |
|
58 | + foreach ($months as $month) { |
|
59 | + $selected = (isset($_GET['m']) && $_GET['m'] == $month->month) ? ' selected="selected"' : ''; |
|
60 | + echo '<option value="' . esc_attr($month->month) . '"' . $selected . '>' . esc_html($month->month_name . ' ' . $month->year) . '</option>'; |
|
61 | 61 | } |
62 | 62 | ?> |
63 | 63 | </select> |
64 | - <?php submit_button( __( 'Filter', 'invoicing' ), '', 'filter_action', false ); ?> |
|
64 | + <?php submit_button(__('Filter', 'invoicing'), '', 'filter_action', false); ?> |
|
65 | 65 | </form> |
66 | 66 | </div> |
67 | 67 | </div> |
68 | 68 | <table class="wp-list-table widefat fixed striped"> |
69 | 69 | <thead> |
70 | 70 | <tr> |
71 | - <th><?php _e( 'Log ID', 'invoicing' ); ?></th> |
|
72 | - <th><?php _e( 'User', 'invoicing' ); ?></th> |
|
73 | - <th><?php _e( 'Action', 'invoicing' ); ?></th> |
|
74 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
75 | - <th><?php _e( 'Details', 'invoicing' ); ?></th> |
|
71 | + <th><?php _e('Log ID', 'invoicing'); ?></th> |
|
72 | + <th><?php _e('User', 'invoicing'); ?></th> |
|
73 | + <th><?php _e('Action', 'invoicing'); ?></th> |
|
74 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
75 | + <th><?php _e('Details', 'invoicing'); ?></th> |
|
76 | 76 | </tr> |
77 | 77 | </thead> |
78 | 78 | <tbody> |
79 | - <?php if ( empty( $logs ) ) : ?> |
|
79 | + <?php if (empty($logs)) : ?> |
|
80 | 80 | <tr> |
81 | - <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
|
81 | + <td colspan="5"><?php _e('No anonymization logs found.', 'invoicing'); ?></td> |
|
82 | 82 | </tr> |
83 | 83 | <?php else : ?> |
84 | 84 | <?php |
85 | - foreach ( $logs as $log ) : |
|
86 | - $additional_info = json_decode( $log->additional_info, true ); |
|
85 | + foreach ($logs as $log) : |
|
86 | + $additional_info = json_decode($log->additional_info, true); |
|
87 | 87 | ?> |
88 | 88 | <tr> |
89 | - <td><?php echo esc_html( $log->log_id ); ?></td> |
|
89 | + <td><?php echo esc_html($log->log_id); ?></td> |
|
90 | 90 | <td> |
91 | 91 | <?php |
92 | - $user_edit_link = get_edit_user_link( $log->user_id ); |
|
93 | - if ( $user_edit_link ) { |
|
94 | - echo '<a href="' . esc_url( $user_edit_link ) . '">' . esc_html( $log->user_id ) . '</a>'; |
|
92 | + $user_edit_link = get_edit_user_link($log->user_id); |
|
93 | + if ($user_edit_link) { |
|
94 | + echo '<a href="' . esc_url($user_edit_link) . '">' . esc_html($log->user_id) . '</a>'; |
|
95 | 95 | } else { |
96 | - echo esc_html( $log->user_id ); |
|
96 | + echo esc_html($log->user_id); |
|
97 | 97 | } |
98 | 98 | ?> |
99 | 99 | </td> |
100 | - <td><?php echo esc_html( ucfirst( $log->action ) ); ?></td> |
|
101 | - <td><?php echo esc_html( get_date_from_gmt( $log->timestamp, 'F j, Y g:i a' ) ); ?></td> |
|
100 | + <td><?php echo esc_html(ucfirst($log->action)); ?></td> |
|
101 | + <td><?php echo esc_html(get_date_from_gmt($log->timestamp, 'F j, Y g:i a')); ?></td> |
|
102 | 102 | <td> |
103 | 103 | <button class="button-link toggle-details" type="button" aria-expanded="false"> |
104 | - <span class="screen-reader-text"><?php _e( 'Show more details', 'invoicing' ); ?></span> |
|
104 | + <span class="screen-reader-text"><?php _e('Show more details', 'invoicing'); ?></span> |
|
105 | 105 | <span class="dashicons dashicons-arrow-down-alt2"></span> |
106 | 106 | </button> |
107 | 107 | </td> |
@@ -112,19 +112,19 @@ discard block |
||
112 | 112 | <table class="widefat fixed"> |
113 | 113 | <tbody> |
114 | 114 | <tr> |
115 | - <th><?php _e( 'Data Type', 'invoicing' ); ?></th> |
|
116 | - <td><?php echo esc_html( $log->data_type ); ?></td> |
|
115 | + <th><?php _e('Data Type', 'invoicing'); ?></th> |
|
116 | + <td><?php echo esc_html($log->data_type); ?></td> |
|
117 | 117 | </tr> |
118 | - <?php if ( is_array( $additional_info ) ) : ?> |
|
118 | + <?php if (is_array($additional_info)) : ?> |
|
119 | 119 | <tr> |
120 | - <th><?php _e( 'Additional Information', 'invoicing' ); ?></th> |
|
120 | + <th><?php _e('Additional Information', 'invoicing'); ?></th> |
|
121 | 121 | <td> |
122 | 122 | <table class="widefat fixed"> |
123 | 123 | <tbody> |
124 | - <?php foreach ( $additional_info as $key => $value ) : ?> |
|
124 | + <?php foreach ($additional_info as $key => $value) : ?> |
|
125 | 125 | <tr> |
126 | - <th><?php echo esc_html( $key ); ?></th> |
|
127 | - <td><?php echo esc_html( $value ); ?></td> |
|
126 | + <th><?php echo esc_html($key); ?></th> |
|
127 | + <td><?php echo esc_html($value); ?></td> |
|
128 | 128 | </tr> |
129 | 129 | <?php endforeach; ?> |
130 | 130 | </tbody> |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | <?php endif; ?> |
142 | 142 | </tbody> |
143 | 143 | </table> |
144 | - <?php if ( $pagination ) : ?> |
|
144 | + <?php if ($pagination) : ?> |
|
145 | 145 | <div class="tablenav bottom"> |
146 | 146 | <div class="tablenav-pages"> |
147 | 147 | <?php echo $pagination; ?> |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * @param int $per_page Number of logs per page |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - private function get_logs( $page, $per_page ) { |
|
162 | + private function get_logs($page, $per_page) { |
|
163 | 163 | global $wpdb; |
164 | 164 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
165 | - $offset = ( $page - 1 ) * $per_page; |
|
165 | + $offset = ($page - 1) * $per_page; |
|
166 | 166 | |
167 | 167 | $query = $wpdb->prepare( |
168 | 168 | "SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT %d OFFSET %d", |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $offset |
171 | 171 | ); |
172 | 172 | |
173 | - return $wpdb->get_results( $query ); |
|
173 | + return $wpdb->get_results($query); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | private function get_total_logs() { |
182 | 182 | global $wpdb; |
183 | 183 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
184 | - return $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
184 | + return $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -80,10 +80,12 @@ |
||
80 | 80 | <tr> |
81 | 81 | <td colspan="5"><?php _e( 'No anonymization logs found.', 'invoicing' ); ?></td> |
82 | 82 | </tr> |
83 | - <?php else : ?> |
|
83 | + <?php else { |
|
84 | + : ?> |
|
84 | 85 | <?php |
85 | 86 | foreach ( $logs as $log ) : |
86 | 87 | $additional_info = json_decode( $log->additional_info, true ); |
88 | +} |
|
87 | 89 | ?> |
88 | 90 | <tr> |
89 | 91 | <td><?php echo esc_html( $log->log_id ); ?></td> |
@@ -291,18 +291,18 @@ |
||
291 | 291 | |
292 | 292 | $user_meta_data = array( |
293 | 293 | 'nickname', |
294 | - 'description', |
|
295 | - 'rich_editing', |
|
296 | - 'syntax_highlighting', |
|
297 | - 'comment_shortcuts', |
|
294 | + 'description', |
|
295 | + 'rich_editing', |
|
296 | + 'syntax_highlighting', |
|
297 | + 'comment_shortcuts', |
|
298 | 298 | 'admin_color', |
299 | - 'use_ssl', |
|
300 | - 'show_admin_bar_front', |
|
301 | - 'locale', |
|
302 | - 'wp_capabilities', |
|
299 | + 'use_ssl', |
|
300 | + 'show_admin_bar_front', |
|
301 | + 'locale', |
|
302 | + 'wp_capabilities', |
|
303 | 303 | 'wp_user_level', |
304 | - 'dismissed_wp_pointers', |
|
305 | - 'show_welcome_panel', |
|
304 | + 'dismissed_wp_pointers', |
|
305 | + 'show_welcome_panel', |
|
306 | 306 | ); |
307 | 307 | |
308 | 308 | /** |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 2.8.22 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Data_Retention Class. |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | * Class constructor. |
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | - add_filter( 'wpinv_settings_misc', array( $this, 'add_data_retention_settings' ) ); |
|
38 | + add_filter('wpinv_settings_misc', array($this, 'add_data_retention_settings')); |
|
39 | 39 | |
40 | - add_action( 'wpmu_delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
41 | - add_action( 'delete_user', array( $this, 'maybe_handle_user_deletion' ), 1 ); |
|
42 | - add_filter( 'wp_privacy_personal_data_erasure_request', array( $this, 'handle_erasure_request' ), 10, 2 ); |
|
40 | + add_action('wpmu_delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
41 | + add_action('delete_user', array($this, 'maybe_handle_user_deletion'), 1); |
|
42 | + add_filter('wp_privacy_personal_data_erasure_request', array($this, 'handle_erasure_request'), 10, 2); |
|
43 | 43 | |
44 | - add_action( 'getpaid_daily_maintenance', array( $this, 'perform_data_retention_cleanup' ) ); |
|
44 | + add_action('getpaid_daily_maintenance', array($this, 'perform_data_retention_cleanup')); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,43 +50,43 @@ discard block |
||
50 | 50 | * @param array $misc_settings Existing misc settings. |
51 | 51 | * @return array Updated misc settings. |
52 | 52 | */ |
53 | - public function add_data_retention_settings( $misc_settings ) { |
|
53 | + public function add_data_retention_settings($misc_settings) { |
|
54 | 54 | $misc_settings['data_retention'] = array( |
55 | 55 | 'id' => 'data_retention', |
56 | - 'name' => '<h3>' . __( 'Data Retention', 'invoicing' ) . '</h3>', |
|
56 | + 'name' => '<h3>' . __('Data Retention', 'invoicing') . '</h3>', |
|
57 | 57 | 'type' => 'header', |
58 | 58 | ); |
59 | 59 | |
60 | 60 | $misc_settings['data_retention_method'] = array( |
61 | 61 | 'id' => 'data_retention_method', |
62 | - 'name' => __( 'Data Handling', 'invoicing' ), |
|
63 | - 'desc' => __( 'Choose how to handle user data when deletion is required.', 'invoicing' ), |
|
62 | + 'name' => __('Data Handling', 'invoicing'), |
|
63 | + 'desc' => __('Choose how to handle user data when deletion is required.', 'invoicing'), |
|
64 | 64 | 'type' => 'select', |
65 | 65 | 'options' => array( |
66 | - 'anonymize' => __( 'Anonymize data', 'invoicing' ), |
|
67 | - 'delete' => __( 'Delete data without anonymization', 'invoicing' ), |
|
66 | + 'anonymize' => __('Anonymize data', 'invoicing'), |
|
67 | + 'delete' => __('Delete data without anonymization', 'invoicing'), |
|
68 | 68 | ), |
69 | 69 | 'std' => 'anonymize', |
70 | - 'tooltip' => __( 'Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing' ), |
|
70 | + 'tooltip' => __('Anonymization replaces personal data with non-identifiable information. Direct deletion removes all data permanently.', 'invoicing'), |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | $misc_settings['data_retention_period'] = array( |
74 | 74 | 'id' => 'data_retention_period', |
75 | - 'name' => __( 'Retention Period', 'invoicing' ), |
|
76 | - 'desc' => __( 'Specify how long to retain customer data after processing.', 'invoicing' ), |
|
75 | + 'name' => __('Retention Period', 'invoicing'), |
|
76 | + 'desc' => __('Specify how long to retain customer data after processing.', 'invoicing'), |
|
77 | 77 | 'type' => 'select', |
78 | 78 | 'options' => array( |
79 | - 'never' => __( 'Never delete (retain indefinitely)', 'invoicing' ), |
|
80 | - '30' => __( '30 days', 'invoicing' ), |
|
81 | - '90' => __( '90 days', 'invoicing' ), |
|
82 | - '180' => __( '6 months', 'invoicing' ), |
|
83 | - '365' => __( '1 year', 'invoicing' ), |
|
84 | - '730' => __( '2 years', 'invoicing' ), |
|
85 | - '1825' => __( '5 years', 'invoicing' ), |
|
86 | - '3650' => __( '10 years', 'invoicing' ), |
|
79 | + 'never' => __('Never delete (retain indefinitely)', 'invoicing'), |
|
80 | + '30' => __('30 days', 'invoicing'), |
|
81 | + '90' => __('90 days', 'invoicing'), |
|
82 | + '180' => __('6 months', 'invoicing'), |
|
83 | + '365' => __('1 year', 'invoicing'), |
|
84 | + '730' => __('2 years', 'invoicing'), |
|
85 | + '1825' => __('5 years', 'invoicing'), |
|
86 | + '3650' => __('10 years', 'invoicing'), |
|
87 | 87 | ), |
88 | 88 | 'std' => '3650', |
89 | - 'tooltip' => __( 'Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing' ), |
|
89 | + 'tooltip' => __('Choose how long to keep processed customer data before final action. This helps balance data minimization with business needs.', 'invoicing'), |
|
90 | 90 | ); |
91 | 91 | |
92 | 92 | return $misc_settings; |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param int $user_id The ID of the user being deleted. |
99 | 99 | */ |
100 | - public function maybe_handle_user_deletion( $user_id ) { |
|
101 | - if ( ! $this->handle_user_deletion ) { |
|
100 | + public function maybe_handle_user_deletion($user_id) { |
|
101 | + if (!$this->handle_user_deletion) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - if ( current_user_can( 'manage_options' ) ) { |
|
106 | - $this->handle_admin_user_deletion( $user_id ); |
|
105 | + if (current_user_can('manage_options')) { |
|
106 | + $this->handle_admin_user_deletion($user_id); |
|
107 | 107 | } else { |
108 | - $this->handle_self_account_deletion( $user_id ); |
|
108 | + $this->handle_self_account_deletion($user_id); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @since 2.8.22 |
116 | 116 | * @param int $user_id The ID of the user being deleted. |
117 | 117 | */ |
118 | - public function handle_admin_user_deletion( $user_id ) { |
|
119 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
120 | - $this->prevent_user_deletion( $user_id, 'active_subscriptions' ); |
|
118 | + public function handle_admin_user_deletion($user_id) { |
|
119 | + if ($this->has_active_subscriptions($user_id)) { |
|
120 | + $this->prevent_user_deletion($user_id, 'active_subscriptions'); |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
125 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
126 | - if ( 'anonymize' === $retention_method ) { |
|
127 | - $this->anonymize_user_data( $user_id ); |
|
128 | - $this->prevent_user_deletion( $user_id, 'paid_invoices' ); |
|
124 | + if ($this->has_paid_invoices($user_id)) { |
|
125 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
126 | + if ('anonymize' === $retention_method) { |
|
127 | + $this->anonymize_user_data($user_id); |
|
128 | + $this->prevent_user_deletion($user_id, 'paid_invoices'); |
|
129 | 129 | } else { |
130 | - $this->delete_user_data( $user_id ); |
|
130 | + $this->delete_user_data($user_id); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | } |
@@ -138,19 +138,19 @@ discard block |
||
138 | 138 | * @since 2.8.22 |
139 | 139 | * @param int $user_id The ID of the user being deleted. |
140 | 140 | */ |
141 | - public function handle_self_account_deletion( $user_id ) { |
|
142 | - $this->cancel_active_subscriptions( $user_id ); |
|
141 | + public function handle_self_account_deletion($user_id) { |
|
142 | + $this->cancel_active_subscriptions($user_id); |
|
143 | 143 | |
144 | - if ( $this->has_paid_invoices( $user_id ) ) { |
|
145 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
144 | + if ($this->has_paid_invoices($user_id)) { |
|
145 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
146 | 146 | |
147 | - if ( 'anonymize' === $retention_method ) { |
|
148 | - $user = get_userdata( $user_id ); |
|
147 | + if ('anonymize' === $retention_method) { |
|
148 | + $user = get_userdata($user_id); |
|
149 | 149 | |
150 | - $this->anonymize_user_data( $user_id ); |
|
150 | + $this->anonymize_user_data($user_id); |
|
151 | 151 | |
152 | - $message = apply_filters( 'uwp_get_account_deletion_message', '', $user ); |
|
153 | - do_action( 'uwp_send_account_deletion_emails', $user, $message ); |
|
152 | + $message = apply_filters('uwp_get_account_deletion_message', '', $user); |
|
153 | + do_action('uwp_send_account_deletion_emails', $user, $message); |
|
154 | 154 | |
155 | 155 | $this->end_user_session(); |
156 | 156 | } |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @param int $user_id The ID of the user being checked. |
165 | 165 | * @return bool True if user has active subscriptions, false otherwise. |
166 | 166 | */ |
167 | - private function has_active_subscriptions( $user_id ) { |
|
167 | + private function has_active_subscriptions($user_id) { |
|
168 | 168 | $subscriptions = getpaid_get_subscriptions( |
169 | 169 | array( |
170 | - 'customer_in' => array( (int) $user_id ), |
|
170 | + 'customer_in' => array((int) $user_id), |
|
171 | 171 | 'status' => 'active', |
172 | 172 | ) |
173 | 173 | ); |
174 | 174 | |
175 | - return ! empty( $subscriptions ); |
|
175 | + return !empty($subscriptions); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | * @since 2.8.22 |
182 | 182 | * @param int $user_id The ID of the user. |
183 | 183 | */ |
184 | - private function cancel_active_subscriptions( $user_id ) { |
|
184 | + private function cancel_active_subscriptions($user_id) { |
|
185 | 185 | $subscriptions = getpaid_get_subscriptions( |
186 | 186 | array( |
187 | - 'customer_in' => array( (int) $user_id ), |
|
187 | + 'customer_in' => array((int) $user_id), |
|
188 | 188 | 'status' => 'active', |
189 | 189 | ) |
190 | 190 | ); |
191 | 191 | |
192 | - foreach ( $subscriptions as $subscription ) { |
|
192 | + foreach ($subscriptions as $subscription) { |
|
193 | 193 | $subscription->cancel(); |
194 | 194 | } |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param int $user_id The ID of the user being checked. |
202 | 202 | * @return bool True if user has paid invoices, false otherwise. |
203 | 203 | */ |
204 | - private function has_paid_invoices( $user_id ) { |
|
204 | + private function has_paid_invoices($user_id) { |
|
205 | 205 | $invoices = wpinv_get_invoices( |
206 | 206 | array( |
207 | 207 | 'user' => (int) $user_id, |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | |
212 | - return ! empty( $invoices->total ); |
|
212 | + return !empty($invoices->total); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | * @param int $user_id The ID of the user being deleted. |
220 | 220 | * @param string $reason The reason for preventing deletion. |
221 | 221 | */ |
222 | - private function prevent_user_deletion( $user_id, $reason ) { |
|
223 | - $user = get_userdata( $user_id ); |
|
222 | + private function prevent_user_deletion($user_id, $reason) { |
|
223 | + $user = get_userdata($user_id); |
|
224 | 224 | |
225 | - if ( 'active_subscriptions' === $reason ) { |
|
225 | + if ('active_subscriptions' === $reason) { |
|
226 | 226 | $this->error_message = sprintf( |
227 | 227 | /* translators: %s: user login */ |
228 | - esc_html__( 'User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing' ), |
|
228 | + esc_html__('User deletion for %s has been halted. All active subscriptions should be cancelled first.', 'invoicing'), |
|
229 | 229 | $user->user_login |
230 | 230 | ); |
231 | 231 | } else { |
232 | 232 | $this->error_message = sprintf( |
233 | 233 | /* translators: %s: user login */ |
234 | - esc_html__( 'User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing' ), |
|
234 | + esc_html__('User deletion for %s has been halted due to paid invoices. Data will be anonymized instead.', 'invoicing'), |
|
235 | 235 | $user->user_login |
236 | 236 | ); |
237 | 237 | } |
238 | 238 | |
239 | - wp_die( $this->error_message, esc_html__( 'User Deletion Halted', 'invoicing' ), array( 'response' => 403 ) ); |
|
239 | + wp_die($this->error_message, esc_html__('User Deletion Halted', 'invoicing'), array('response' => 403)); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,17 +246,17 @@ discard block |
||
246 | 246 | * @param int $user_id The ID of the user to anonymize. |
247 | 247 | * @return bool True on success, false on failure. |
248 | 248 | */ |
249 | - private function anonymize_user_data( $user_id ) { |
|
249 | + private function anonymize_user_data($user_id) { |
|
250 | 250 | global $wpdb; |
251 | 251 | |
252 | - $user = get_userdata( $user_id ); |
|
253 | - if ( ! $user ) { |
|
252 | + $user = get_userdata($user_id); |
|
253 | + if (!$user) { |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | |
257 | 257 | $table_name = $wpdb->prefix . 'getpaid_customers'; |
258 | - $deletion_date = gmdate( 'Y-m-d', strtotime( '+10 years' ) ); |
|
259 | - $hashed_email = $this->hash_email( $user->user_email ); |
|
258 | + $deletion_date = gmdate('Y-m-d', strtotime('+10 years')); |
|
259 | + $hashed_email = $this->hash_email($user->user_email); |
|
260 | 260 | |
261 | 261 | $updated = $wpdb->update( |
262 | 262 | $table_name, |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | 'email_cc' => $hashed_email, |
268 | 268 | 'phone' => '', |
269 | 269 | ), |
270 | - array( 'user_id' => (int) $user->ID ) |
|
270 | + array('user_id' => (int) $user->ID) |
|
271 | 271 | ); |
272 | 272 | |
273 | - if ( false === $updated ) { |
|
273 | + if (false === $updated) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @since 2.8.22 |
288 | 288 | * @param int $user_id The ID of the user being anonymized. |
289 | 289 | */ |
290 | - do_action( 'wpinv_anonymize_user_meta_data', $user->ID ); |
|
290 | + do_action('wpinv_anonymize_user_meta_data', $user->ID); |
|
291 | 291 | |
292 | 292 | $user_meta_data = array( |
293 | 293 | 'nickname', |
@@ -312,13 +312,13 @@ discard block |
||
312 | 312 | * @param array $user_meta_data The meta fields to be anonymized. |
313 | 313 | * @param int $user_id The ID of the user being anonymized. |
314 | 314 | */ |
315 | - $user_meta_data = apply_filters( 'wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID ); |
|
315 | + $user_meta_data = apply_filters('wpinv_user_meta_data_to_anonymize', $user_meta_data, $user->ID); |
|
316 | 316 | |
317 | - foreach ( $user_meta_data as $meta_key ) { |
|
318 | - delete_user_meta( $user->ID, $meta_key ); |
|
317 | + foreach ($user_meta_data as $meta_key) { |
|
318 | + delete_user_meta($user->ID, $meta_key); |
|
319 | 319 | } |
320 | 320 | |
321 | - return $this->ensure_invoice_anonymization( $user->ID, 'anonymize' ); |
|
321 | + return $this->ensure_invoice_anonymization($user->ID, 'anonymize'); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -327,15 +327,15 @@ discard block |
||
327 | 327 | * @param int $user_id The ID of the user to delete. |
328 | 328 | * @return bool True on success, false on failure. |
329 | 329 | */ |
330 | - private function delete_user_data( $user_id ) { |
|
330 | + private function delete_user_data($user_id) { |
|
331 | 331 | // Delete associated invoices. |
332 | - $this->ensure_invoice_anonymization( $user_id, 'delete' ); |
|
332 | + $this->ensure_invoice_anonymization($user_id, 'delete'); |
|
333 | 333 | |
334 | 334 | // Delete the user. |
335 | - if ( is_multisite() ) { |
|
336 | - wpmu_delete_user( $user_id ); |
|
335 | + if (is_multisite()) { |
|
336 | + wpmu_delete_user($user_id); |
|
337 | 337 | } else { |
338 | - wp_delete_user( $user_id ); |
|
338 | + wp_delete_user($user_id); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @since 2.8.22 |
345 | 345 | * @param int $user_id The ID of the user being deleted. |
346 | 346 | */ |
347 | - do_action( 'wpinv_delete_user_data', $user_id ); |
|
347 | + do_action('wpinv_delete_user_data', $user_id); |
|
348 | 348 | |
349 | 349 | return true; |
350 | 350 | } |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | * @param string $action The action to perform (anonymize or delete). |
358 | 358 | * @return bool True on success, false on failure. |
359 | 359 | */ |
360 | - public function ensure_invoice_anonymization( $user_id, $action = 'anonymize' ) { |
|
361 | - $invoices = wpinv_get_invoices( array( 'user' => $user_id ) ); |
|
360 | + public function ensure_invoice_anonymization($user_id, $action = 'anonymize') { |
|
361 | + $invoices = wpinv_get_invoices(array('user' => $user_id)); |
|
362 | 362 | |
363 | 363 | /** |
364 | 364 | * Filters the invoice meta fields to be anonymized. |
@@ -367,22 +367,22 @@ discard block |
||
367 | 367 | * @param array $inv_meta_data The meta fields to be anonymized. |
368 | 368 | * @param int $user_id The ID of the user being processed. |
369 | 369 | */ |
370 | - $inv_meta_data = apply_filters( 'wpinv_invoice_meta_data_to_anonymize', array(), $user_id ); |
|
370 | + $inv_meta_data = apply_filters('wpinv_invoice_meta_data_to_anonymize', array(), $user_id); |
|
371 | 371 | |
372 | - foreach ( $invoices->invoices as $invoice ) { |
|
373 | - foreach ( $inv_meta_data as $meta_key ) { |
|
374 | - delete_post_meta( $invoice->get_id(), $meta_key ); |
|
372 | + foreach ($invoices->invoices as $invoice) { |
|
373 | + foreach ($inv_meta_data as $meta_key) { |
|
374 | + delete_post_meta($invoice->get_id(), $meta_key); |
|
375 | 375 | } |
376 | 376 | |
377 | - if ( 'anonymize' === $action ) { |
|
378 | - $hashed_inv_email = $this->hash_email( $invoice->get_email() ); |
|
379 | - $hashed_inv_email_cc = $this->hash_email( $invoice->get_email_cc() ); |
|
377 | + if ('anonymize' === $action) { |
|
378 | + $hashed_inv_email = $this->hash_email($invoice->get_email()); |
|
379 | + $hashed_inv_email_cc = $this->hash_email($invoice->get_email_cc()); |
|
380 | 380 | |
381 | - $invoice->set_email( $hashed_inv_email ); |
|
382 | - $invoice->set_email_cc( $hashed_inv_email_cc ); |
|
383 | - $invoice->set_phone( '' ); |
|
384 | - $invoice->set_ip( $this->anonymize_data( $invoice->get_ip() ) ); |
|
385 | - $invoice->set_is_anonymized( 1 ); |
|
381 | + $invoice->set_email($hashed_inv_email); |
|
382 | + $invoice->set_email_cc($hashed_inv_email_cc); |
|
383 | + $invoice->set_phone(''); |
|
384 | + $invoice->set_ip($this->anonymize_data($invoice->get_ip())); |
|
385 | + $invoice->set_is_anonymized(1); |
|
386 | 386 | |
387 | 387 | /** |
388 | 388 | * Fires when anonymizing additional invoice data. |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @param WPInv_Invoice $invoice The invoice being anonymized. |
392 | 392 | * @param string $action The action being performed (anonymize or delete). |
393 | 393 | */ |
394 | - do_action( 'wpinv_anonymize_invoice_data', $invoice, $action ); |
|
394 | + do_action('wpinv_anonymize_invoice_data', $invoice, $action); |
|
395 | 395 | |
396 | 396 | $invoice->save(); |
397 | 397 | } else { |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
402 | - return $this->log_deletion_action( $user_id, $invoices->invoices, $action ); |
|
402 | + return $this->log_deletion_action($user_id, $invoices->invoices, $action); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | * @param string $action The action being performed (anonymize or delete). |
412 | 412 | * @return bool True on success, false on failure. |
413 | 413 | */ |
414 | - private function log_deletion_action( $user_id, $invoices, $action ) { |
|
414 | + private function log_deletion_action($user_id, $invoices, $action) { |
|
415 | 415 | global $wpdb; |
416 | 416 | |
417 | 417 | $table_name = $wpdb->prefix . 'getpaid_anonymization_logs'; |
418 | - $user_data = get_userdata( $user_id ); |
|
418 | + $user_data = get_userdata($user_id); |
|
419 | 419 | |
420 | 420 | $additional_info = array( |
421 | 421 | 'Username' => $user_data ? $user_data->user_login : 'N/A', |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | 'First Name' => $user_data ? $user_data->first_name : 'N/A', |
425 | 425 | 'Last Name' => $user_data ? $user_data->last_name : 'N/A', |
426 | 426 | 'Registered' => $user_data ? $user_data->user_registered : 'N/A', |
427 | - 'invoice_count' => count( $invoices ), |
|
427 | + 'invoice_count' => count($invoices), |
|
428 | 428 | ); |
429 | 429 | |
430 | 430 | |
@@ -437,43 +437,43 @@ discard block |
||
437 | 437 | * @param array $invoices The invoices being processed. |
438 | 438 | * @param string $action The action being performed (anonymize or delete). |
439 | 439 | */ |
440 | - $additional_info = apply_filters( 'wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action ); |
|
440 | + $additional_info = apply_filters('wpinv_anonymization_log_additional_info', $additional_info, $user_id, $invoices, $action); |
|
441 | 441 | |
442 | 442 | $data = array( |
443 | 443 | 'user_id' => $user_id, |
444 | - 'action' => sanitize_text_field( $action ), |
|
444 | + 'action' => sanitize_text_field($action), |
|
445 | 445 | 'data_type' => 'User Invoices', |
446 | - 'timestamp' => current_time( 'mysql' ), |
|
447 | - 'additional_info' => wp_json_encode( $additional_info ), |
|
446 | + 'timestamp' => current_time('mysql'), |
|
447 | + 'additional_info' => wp_json_encode($additional_info), |
|
448 | 448 | ); |
449 | 449 | |
450 | 450 | $format = array( |
451 | - '%d', // user_id |
|
452 | - '%s', // action |
|
453 | - '%s', // data_type |
|
454 | - '%s', // timestamp |
|
455 | - '%s', // additional_info |
|
451 | + '%d', // user_id |
|
452 | + '%s', // action |
|
453 | + '%s', // data_type |
|
454 | + '%s', // timestamp |
|
455 | + '%s', // additional_info |
|
456 | 456 | ); |
457 | 457 | |
458 | - if ( ! empty( $user_id ) && ! empty( $action ) ) { |
|
458 | + if (!empty($user_id) && !empty($action)) { |
|
459 | 459 | $result = $wpdb->update( |
460 | 460 | $table_name, |
461 | 461 | $data, |
462 | 462 | array( |
463 | 463 | 'user_id' => (int) $user_id, |
464 | - 'action' => sanitize_text_field( $action ), |
|
464 | + 'action' => sanitize_text_field($action), |
|
465 | 465 | ), |
466 | 466 | $format, |
467 | - array( '%d', '%s' ) |
|
467 | + array('%d', '%s') |
|
468 | 468 | ); |
469 | 469 | |
470 | - if ( false === $result ) { |
|
470 | + if (false === $result) { |
|
471 | 471 | // If update fails, try to insert. |
472 | - $result = $wpdb->insert( $table_name, $data, $format ); |
|
472 | + $result = $wpdb->insert($table_name, $data, $format); |
|
473 | 473 | } |
474 | 474 | |
475 | - if ( false === $result ) { |
|
476 | - wpinv_error_log( sprintf( 'Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error ) ); |
|
475 | + if (false === $result) { |
|
476 | + wpinv_error_log(sprintf('Failed to log anonymization action for user ID: %d. Error: %s', $user_id, $wpdb->last_error)); |
|
477 | 477 | return false; |
478 | 478 | } |
479 | 479 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param string $action The action being performed (anonymize or delete). |
488 | 488 | * @param array $data The data that was inserted into the log. |
489 | 489 | */ |
490 | - do_action( 'wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data ); |
|
490 | + do_action('wpinv_after_log_deletion_action', $user_id, $invoices, $action, $data); |
|
491 | 491 | |
492 | 492 | return true; |
493 | 493 | } |
@@ -500,20 +500,20 @@ discard block |
||
500 | 500 | * @param int $user_id The ID of the user being erased. |
501 | 501 | * @return array The modified response. |
502 | 502 | */ |
503 | - public function handle_erasure_request( $response, $user_id ) { |
|
504 | - if ( $this->has_active_subscriptions( $user_id ) ) { |
|
505 | - $response['messages'][] = esc_html__( 'User has active subscriptions. Data cannot be erased at this time.', 'invoicing' ); |
|
503 | + public function handle_erasure_request($response, $user_id) { |
|
504 | + if ($this->has_active_subscriptions($user_id)) { |
|
505 | + $response['messages'][] = esc_html__('User has active subscriptions. Data cannot be erased at this time.', 'invoicing'); |
|
506 | 506 | $response['items_removed'] = false; |
507 | - } elseif ( $this->has_paid_invoices( $user_id ) ) { |
|
508 | - $retention_method = wpinv_get_option( 'data_retention_method', 'anonymize' ); |
|
509 | - if ( 'anonymize' === $retention_method ) { |
|
510 | - $this->anonymize_user_data( $user_id ); |
|
511 | - $response['messages'][] = esc_html__( 'User data has been anonymized due to existing paid invoices.', 'invoicing' ); |
|
507 | + } elseif ($this->has_paid_invoices($user_id)) { |
|
508 | + $retention_method = wpinv_get_option('data_retention_method', 'anonymize'); |
|
509 | + if ('anonymize' === $retention_method) { |
|
510 | + $this->anonymize_user_data($user_id); |
|
511 | + $response['messages'][] = esc_html__('User data has been anonymized due to existing paid invoices.', 'invoicing'); |
|
512 | 512 | $response['items_removed'] = false; |
513 | 513 | $response['items_retained'] = true; |
514 | 514 | } else { |
515 | - $this->delete_user_data( $user_id ); |
|
516 | - $response['messages'][] = esc_html__( 'User data has been deleted.', 'invoicing' ); |
|
515 | + $this->delete_user_data($user_id); |
|
516 | + $response['messages'][] = esc_html__('User data has been deleted.', 'invoicing'); |
|
517 | 517 | $response['items_removed'] = true; |
518 | 518 | $response['items_retained'] = false; |
519 | 519 | } |
@@ -529,18 +529,18 @@ discard block |
||
529 | 529 | * @param string $email The email to hash. |
530 | 530 | * @return string The hashed email. |
531 | 531 | */ |
532 | - private function hash_email( $email ) { |
|
532 | + private function hash_email($email) { |
|
533 | 533 | $site_url = get_site_url(); |
534 | - $domain = wp_parse_url( $site_url, PHP_URL_HOST ); |
|
534 | + $domain = wp_parse_url($site_url, PHP_URL_HOST); |
|
535 | 535 | |
536 | - if ( empty( $domain ) ) { |
|
536 | + if (empty($domain)) { |
|
537 | 537 | return $email; |
538 | 538 | } |
539 | 539 | |
540 | - $clean_email = sanitize_email( strtolower( trim( $email ) ) ); |
|
541 | - $hash = wp_hash( $clean_email ); |
|
542 | - $hash = substr( $hash, 0, 20 ); |
|
543 | - $anonymized_email = sprintf( '%s@%s', $hash, $domain ); |
|
540 | + $clean_email = sanitize_email(strtolower(trim($email))); |
|
541 | + $hash = wp_hash($clean_email); |
|
542 | + $hash = substr($hash, 0, 20); |
|
543 | + $anonymized_email = sprintf('%s@%s', $hash, $domain); |
|
544 | 544 | |
545 | 545 | /** |
546 | 546 | * Filters the anonymized email before returning. |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param string $anonymized_email The anonymized email address. |
550 | 550 | * @param string $email The original email address. |
551 | 551 | */ |
552 | - return apply_filters( 'wpinv_anonymized_email', $anonymized_email, $email ); |
|
552 | + return apply_filters('wpinv_anonymized_email', $anonymized_email, $email); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,12 +559,12 @@ discard block |
||
559 | 559 | * @param string $data The data to anonymize. |
560 | 560 | * @return string The anonymized data. |
561 | 561 | */ |
562 | - private function anonymize_data( $data ) { |
|
563 | - if ( empty( $data ) ) { |
|
562 | + private function anonymize_data($data) { |
|
563 | + if (empty($data)) { |
|
564 | 564 | return ''; |
565 | 565 | } |
566 | 566 | |
567 | - return wp_privacy_anonymize_data( 'text', $data ); |
|
567 | + return wp_privacy_anonymize_data('text', $data); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -578,17 +578,17 @@ discard block |
||
578 | 578 | public function perform_data_retention_cleanup() { |
579 | 579 | global $wpdb; |
580 | 580 | |
581 | - $retention_period = wpinv_get_option( 'data_retention_period', '3650' ); |
|
581 | + $retention_period = wpinv_get_option('data_retention_period', '3650'); |
|
582 | 582 | |
583 | 583 | // If retention period is set to 'never', exit the function. |
584 | - if ( 'never' === $retention_period ) { |
|
584 | + if ('never' === $retention_period) { |
|
585 | 585 | return; |
586 | 586 | } |
587 | 587 | |
588 | 588 | $customers_table = $wpdb->prefix . 'getpaid_customers'; |
589 | 589 | |
590 | 590 | // Calculate the cutoff date for data retention. |
591 | - $cutoff_date = gmdate( 'Y-m-d', strtotime( "-$retention_period days" ) ); |
|
591 | + $cutoff_date = gmdate('Y-m-d', strtotime("-$retention_period days")); |
|
592 | 592 | |
593 | 593 | $expired_records = $wpdb->get_results( |
594 | 594 | $wpdb->prepare( |
@@ -603,18 +603,18 @@ discard block |
||
603 | 603 | * @since 2.8.22 |
604 | 604 | * @param array $expired_records Array of customer records to be processed. |
605 | 605 | */ |
606 | - do_action( 'getpaid_data_retention_before_cleanup', $expired_records ); |
|
606 | + do_action('getpaid_data_retention_before_cleanup', $expired_records); |
|
607 | 607 | |
608 | - if ( ! empty( $expired_records ) ) { |
|
608 | + if (!empty($expired_records)) { |
|
609 | 609 | // Disable our custom user deletion handling. |
610 | 610 | $this->handle_user_deletion = false; |
611 | 611 | |
612 | - foreach ( $expired_records as $record ) { |
|
612 | + foreach ($expired_records as $record) { |
|
613 | 613 | // Delete associated invoices. |
614 | - $this->ensure_invoice_anonymization( (int) $record->user_id, 'delete' ); |
|
614 | + $this->ensure_invoice_anonymization((int) $record->user_id, 'delete'); |
|
615 | 615 | |
616 | 616 | // Delete the user. |
617 | - wp_delete_user( (int) $record->user_id ); |
|
617 | + wp_delete_user((int) $record->user_id); |
|
618 | 618 | |
619 | 619 | /** |
620 | 620 | * Fires after processing each expired record during cleanup. |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * @since 2.8.22 |
623 | 623 | * @param object $record The customer record being processed. |
624 | 624 | */ |
625 | - do_action( 'getpaid_data_retention_process_record', $record ); |
|
625 | + do_action('getpaid_data_retention_process_record', $record); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | // Re-enable our custom user deletion handling. |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * @since 2.8.22 |
635 | 635 | * @param array $expired_records Array of customer records that were processed. |
636 | 636 | */ |
637 | - do_action( 'getpaid_data_retention_after_cleanup', $expired_records ); |
|
637 | + do_action('getpaid_data_retention_after_cleanup', $expired_records); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * @param int $retention_period The current retention period in years. |
645 | 645 | * @param string $cutoff_date The cutoff date used for identifying expired records. |
646 | 646 | */ |
647 | - do_action( 'getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date ); |
|
647 | + do_action('getpaid_data_retention_cleanup_complete', $retention_period, $cutoff_date); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | |
658 | 658 | // Redirect after deletion. |
659 | 659 | $redirect_page = home_url(); |
660 | - wp_safe_redirect( $redirect_page ); |
|
660 | + wp_safe_redirect($redirect_page); |
|
661 | 661 | exit(); |
662 | 662 | } |
663 | 663 | } |
664 | 664 | \ No newline at end of file |
@@ -12,218 +12,218 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Reports_Report |
|
17 | - */ |
|
18 | - public $handler; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - $this->handler = new GetPaid_Reports_Report(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Prepares the datastore handler. |
|
30 | - * |
|
31 | - * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | - */ |
|
33 | - public function prepare_handler( $graph ) { |
|
34 | - |
|
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | - } |
|
38 | - |
|
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Prepares the output stream. |
|
45 | - * |
|
46 | - * @return resource |
|
47 | - */ |
|
48 | - public function prepare_output() { |
|
49 | - |
|
50 | - $output = fopen( 'php://output', 'w' ); |
|
51 | - |
|
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | - } |
|
55 | - |
|
56 | - return $output; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Prepares the file type. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function prepare_file_type( $graph ) { |
|
65 | - |
|
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | - |
|
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | - |
|
72 | - return $file_type; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Handles the actual download. |
|
77 | - * |
|
78 | - */ |
|
79 | - public function download( $graph ) { |
|
80 | - global $wpdb; |
|
81 | - |
|
82 | - $handler = $this->prepare_handler( $graph ); |
|
83 | - $stream = $this->prepare_output(); |
|
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
92 | - } else { |
|
93 | - $this->download_json( $stats, $stream, $headers ); |
|
94 | - } |
|
95 | - |
|
96 | - fclose( $stream ); |
|
97 | - exit; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Downloads graph as csv |
|
102 | - * |
|
103 | - * @param array $stats The stats being downloaded. |
|
104 | - * @param resource $stream The stream to output to. |
|
105 | - * @param array $headers The fields to stream. |
|
106 | - * @since 1.0.19 |
|
107 | - */ |
|
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
109 | - |
|
110 | - // Output the csv column headers. |
|
111 | - fputcsv( $stream, $headers ); |
|
112 | - |
|
113 | - // Loop through |
|
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Downloads graph as json |
|
124 | - * |
|
125 | - * @param array $stats The stats being downloaded. |
|
126 | - * @param resource $stream The stream to output to. |
|
127 | - * @param array $headers The fields to stream. |
|
128 | - * @since 1.0.19 |
|
129 | - */ |
|
130 | - public function download_json( $stats, $stream, $headers ) { |
|
131 | - |
|
132 | - $prepared = array(); |
|
133 | - |
|
134 | - // Loop through |
|
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | - } |
|
138 | - |
|
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Downloads graph as xml |
|
145 | - * |
|
146 | - * @param array $stats The stats being downloaded. |
|
147 | - * @param resource $stream The stream to output to. |
|
148 | - * @param array $headers The fields to stream. |
|
149 | - * @since 1.0.19 |
|
150 | - */ |
|
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
152 | - |
|
153 | - $prepared = array(); |
|
154 | - |
|
155 | - // Loop through |
|
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | - } |
|
159 | - |
|
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
162 | - |
|
163 | - fwrite( $stream, $xml->asXML() ); |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Converts stats array to xml |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @since 1.0.19 |
|
172 | - */ |
|
173 | - public function convert_array_xml( $data, $xml ) { |
|
174 | - |
|
175 | - // Loop through |
|
176 | - foreach ( $data as $key => $value ) { |
|
177 | - |
|
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | - |
|
180 | - if ( is_array( $value ) ) { |
|
181 | - |
|
182 | - if ( is_numeric( $key ) ) { |
|
183 | - $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | - } |
|
185 | - |
|
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
188 | - |
|
189 | - } else { |
|
190 | - $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | - } |
|
15 | + /** |
|
16 | + * @var GetPaid_Reports_Report |
|
17 | + */ |
|
18 | + public $handler; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + $this->handler = new GetPaid_Reports_Report(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Prepares the datastore handler. |
|
30 | + * |
|
31 | + * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
|
32 | + */ |
|
33 | + public function prepare_handler( $graph ) { |
|
34 | + |
|
35 | + if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | + wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
37 | + } |
|
38 | + |
|
39 | + return new $this->handler->views[ $graph ]['class'](); |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Prepares the output stream. |
|
45 | + * |
|
46 | + * @return resource |
|
47 | + */ |
|
48 | + public function prepare_output() { |
|
49 | + |
|
50 | + $output = fopen( 'php://output', 'w' ); |
|
51 | + |
|
52 | + if ( false === $output ) { |
|
53 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
54 | + } |
|
55 | + |
|
56 | + return $output; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Prepares the file type. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function prepare_file_type( $graph ) { |
|
65 | + |
|
66 | + $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | + $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
68 | + |
|
69 | + header( "Content-Type:application/$file_type" ); |
|
70 | + header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
71 | + |
|
72 | + return $file_type; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Handles the actual download. |
|
77 | + * |
|
78 | + */ |
|
79 | + public function download( $graph ) { |
|
80 | + global $wpdb; |
|
81 | + |
|
82 | + $handler = $this->prepare_handler( $graph ); |
|
83 | + $stream = $this->prepare_output(); |
|
84 | + $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | + $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | + $file_type = $this->prepare_file_type( $graph ); |
|
87 | + |
|
88 | + if ( 'csv' == $file_type ) { |
|
89 | + $this->download_csv( $stats, $stream, $headers ); |
|
90 | + } elseif ( 'xml' == $file_type ) { |
|
91 | + $this->download_xml( $stats, $stream, $headers ); |
|
92 | + } else { |
|
93 | + $this->download_json( $stats, $stream, $headers ); |
|
94 | + } |
|
95 | + |
|
96 | + fclose( $stream ); |
|
97 | + exit; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Downloads graph as csv |
|
102 | + * |
|
103 | + * @param array $stats The stats being downloaded. |
|
104 | + * @param resource $stream The stream to output to. |
|
105 | + * @param array $headers The fields to stream. |
|
106 | + * @since 1.0.19 |
|
107 | + */ |
|
108 | + public function download_csv( $stats, $stream, $headers ) { |
|
109 | + |
|
110 | + // Output the csv column headers. |
|
111 | + fputcsv( $stream, $headers ); |
|
112 | + |
|
113 | + // Loop through |
|
114 | + foreach ( $stats as $stat ) { |
|
115 | + $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | + $row = array_map( 'maybe_serialize', $row ); |
|
117 | + fputcsv( $stream, $row ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Downloads graph as json |
|
124 | + * |
|
125 | + * @param array $stats The stats being downloaded. |
|
126 | + * @param resource $stream The stream to output to. |
|
127 | + * @param array $headers The fields to stream. |
|
128 | + * @since 1.0.19 |
|
129 | + */ |
|
130 | + public function download_json( $stats, $stream, $headers ) { |
|
131 | + |
|
132 | + $prepared = array(); |
|
133 | + |
|
134 | + // Loop through |
|
135 | + foreach ( $stats as $stat ) { |
|
136 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
137 | + } |
|
138 | + |
|
139 | + fwrite( $stream, wp_json_encode( $prepared ) ); |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Downloads graph as xml |
|
145 | + * |
|
146 | + * @param array $stats The stats being downloaded. |
|
147 | + * @param resource $stream The stream to output to. |
|
148 | + * @param array $headers The fields to stream. |
|
149 | + * @since 1.0.19 |
|
150 | + */ |
|
151 | + public function download_xml( $stats, $stream, $headers ) { |
|
152 | + |
|
153 | + $prepared = array(); |
|
154 | + |
|
155 | + // Loop through |
|
156 | + foreach ( $stats as $stat ) { |
|
157 | + $prepared[] = $this->prepare_row( $stat, $headers ); |
|
158 | + } |
|
159 | + |
|
160 | + $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | + $this->convert_array_xml( $prepared, $xml ); |
|
162 | + |
|
163 | + fwrite( $stream, $xml->asXML() ); |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Converts stats array to xml |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @since 1.0.19 |
|
172 | + */ |
|
173 | + public function convert_array_xml( $data, $xml ) { |
|
174 | + |
|
175 | + // Loop through |
|
176 | + foreach ( $data as $key => $value ) { |
|
177 | + |
|
178 | + $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
179 | + |
|
180 | + if ( is_array( $value ) ) { |
|
181 | + |
|
182 | + if ( is_numeric( $key ) ) { |
|
183 | + $key = 'item' . $key; //dealing with <0/>..<n/> issues |
|
184 | + } |
|
185 | + |
|
186 | + $subnode = $xml->addChild( $key ); |
|
187 | + $this->convert_array_xml( $value, $subnode ); |
|
188 | + |
|
189 | + } else { |
|
190 | + $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Prepares a single row for download. |
|
198 | - * |
|
199 | - * @param stdClass|array $row The row to prepare.. |
|
200 | - * @param array $fields The fields to stream. |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function prepare_row( $row, $fields ) { |
|
196 | + /** |
|
197 | + * Prepares a single row for download. |
|
198 | + * |
|
199 | + * @param stdClass|array $row The row to prepare.. |
|
200 | + * @param array $fields The fields to stream. |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function prepare_row( $row, $fields ) { |
|
205 | 205 | |
206 | - $prepared = array(); |
|
207 | - $row = (array) $row; |
|
206 | + $prepared = array(); |
|
207 | + $row = (array) $row; |
|
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ( $fields as $field ) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | - continue; |
|
214 | - } |
|
211 | + if ( $field === 'total' ) { |
|
212 | + $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | - continue; |
|
219 | - } |
|
216 | + if ( $field === 'total_raw' ) { |
|
217 | + $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
218 | + continue; |
|
219 | + } |
|
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - return $prepared; |
|
226 | - } |
|
225 | + return $prepared; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Graph_Downloader Class. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return GetPaid_Reports_Report_Items|GetPaid_Reports_Report_Gateways|GetPaid_Reports_Report_Discounts |
32 | 32 | */ |
33 | - public function prepare_handler( $graph ) { |
|
33 | + public function prepare_handler($graph) { |
|
34 | 34 | |
35 | - if ( empty( $this->handler->views[ $graph ] ) ) { |
|
36 | - wp_die( esc_html__( 'Invalid Graph', 'invoicing' ), 400 ); |
|
35 | + if (empty($this->handler->views[$graph])) { |
|
36 | + wp_die(esc_html__('Invalid Graph', 'invoicing'), 400); |
|
37 | 37 | } |
38 | 38 | |
39 | - return new $this->handler->views[ $graph ]['class'](); |
|
39 | + return new $this->handler->views[$graph]['class'](); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function prepare_output() { |
49 | 49 | |
50 | - $output = fopen( 'php://output', 'w' ); |
|
50 | + $output = fopen('php://output', 'w'); |
|
51 | 51 | |
52 | - if ( false === $output ) { |
|
53 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
52 | + if (false === $output) { |
|
53 | + wp_die(esc_html__('Unsupported server', 'invoicing'), 500); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $output; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public function prepare_file_type( $graph ) { |
|
64 | + public function prepare_file_type($graph) { |
|
65 | 65 | |
66 | - $file_type = empty( $_REQUEST['file_type'] ) ? 'csv' : sanitize_text_field( $_REQUEST['file_type'] ); |
|
67 | - $file_name = wpinv_sanitize_key( "getpaid-$graph-" . current_time( 'Y-m-d' ) ); |
|
66 | + $file_type = empty($_REQUEST['file_type']) ? 'csv' : sanitize_text_field($_REQUEST['file_type']); |
|
67 | + $file_name = wpinv_sanitize_key("getpaid-$graph-" . current_time('Y-m-d')); |
|
68 | 68 | |
69 | - header( "Content-Type:application/$file_type" ); |
|
70 | - header( "Content-Disposition:attachment;filename=$file_name.$file_type" ); |
|
69 | + header("Content-Type:application/$file_type"); |
|
70 | + header("Content-Disposition:attachment;filename=$file_name.$file_type"); |
|
71 | 71 | |
72 | 72 | return $file_type; |
73 | 73 | } |
@@ -76,24 +76,24 @@ discard block |
||
76 | 76 | * Handles the actual download. |
77 | 77 | * |
78 | 78 | */ |
79 | - public function download( $graph ) { |
|
79 | + public function download($graph) { |
|
80 | 80 | global $wpdb; |
81 | 81 | |
82 | - $handler = $this->prepare_handler( $graph ); |
|
82 | + $handler = $this->prepare_handler($graph); |
|
83 | 83 | $stream = $this->prepare_output(); |
84 | - $stats = $wpdb->get_results( $handler->get_sql( $handler->get_range() ) ); |
|
85 | - $headers = array( $handler->field, 'total', 'total_raw' ); |
|
86 | - $file_type = $this->prepare_file_type( $graph ); |
|
87 | - |
|
88 | - if ( 'csv' == $file_type ) { |
|
89 | - $this->download_csv( $stats, $stream, $headers ); |
|
90 | - } elseif ( 'xml' == $file_type ) { |
|
91 | - $this->download_xml( $stats, $stream, $headers ); |
|
84 | + $stats = $wpdb->get_results($handler->get_sql($handler->get_range())); |
|
85 | + $headers = array($handler->field, 'total', 'total_raw'); |
|
86 | + $file_type = $this->prepare_file_type($graph); |
|
87 | + |
|
88 | + if ('csv' == $file_type) { |
|
89 | + $this->download_csv($stats, $stream, $headers); |
|
90 | + } elseif ('xml' == $file_type) { |
|
91 | + $this->download_xml($stats, $stream, $headers); |
|
92 | 92 | } else { |
93 | - $this->download_json( $stats, $stream, $headers ); |
|
93 | + $this->download_json($stats, $stream, $headers); |
|
94 | 94 | } |
95 | 95 | |
96 | - fclose( $stream ); |
|
96 | + fclose($stream); |
|
97 | 97 | exit; |
98 | 98 | } |
99 | 99 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param array $headers The fields to stream. |
106 | 106 | * @since 1.0.19 |
107 | 107 | */ |
108 | - public function download_csv( $stats, $stream, $headers ) { |
|
108 | + public function download_csv($stats, $stream, $headers) { |
|
109 | 109 | |
110 | 110 | // Output the csv column headers. |
111 | - fputcsv( $stream, $headers ); |
|
111 | + fputcsv($stream, $headers); |
|
112 | 112 | |
113 | 113 | // Loop through |
114 | - foreach ( $stats as $stat ) { |
|
115 | - $row = array_values( $this->prepare_row( $stat, $headers ) ); |
|
116 | - $row = array_map( 'maybe_serialize', $row ); |
|
117 | - fputcsv( $stream, $row ); |
|
114 | + foreach ($stats as $stat) { |
|
115 | + $row = array_values($this->prepare_row($stat, $headers)); |
|
116 | + $row = array_map('maybe_serialize', $row); |
|
117 | + fputcsv($stream, $row); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | * @param array $headers The fields to stream. |
128 | 128 | * @since 1.0.19 |
129 | 129 | */ |
130 | - public function download_json( $stats, $stream, $headers ) { |
|
130 | + public function download_json($stats, $stream, $headers) { |
|
131 | 131 | |
132 | 132 | $prepared = array(); |
133 | 133 | |
134 | 134 | // Loop through |
135 | - foreach ( $stats as $stat ) { |
|
136 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
135 | + foreach ($stats as $stat) { |
|
136 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
137 | 137 | } |
138 | 138 | |
139 | - fwrite( $stream, wp_json_encode( $prepared ) ); |
|
139 | + fwrite($stream, wp_json_encode($prepared)); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @param array $headers The fields to stream. |
149 | 149 | * @since 1.0.19 |
150 | 150 | */ |
151 | - public function download_xml( $stats, $stream, $headers ) { |
|
151 | + public function download_xml($stats, $stream, $headers) { |
|
152 | 152 | |
153 | 153 | $prepared = array(); |
154 | 154 | |
155 | 155 | // Loop through |
156 | - foreach ( $stats as $stat ) { |
|
157 | - $prepared[] = $this->prepare_row( $stat, $headers ); |
|
156 | + foreach ($stats as $stat) { |
|
157 | + $prepared[] = $this->prepare_row($stat, $headers); |
|
158 | 158 | } |
159 | 159 | |
160 | - $xml = new SimpleXMLElement( '<?xml version="1.0"?><data></data>' ); |
|
161 | - $this->convert_array_xml( $prepared, $xml ); |
|
160 | + $xml = new SimpleXMLElement('<?xml version="1.0"?><data></data>'); |
|
161 | + $this->convert_array_xml($prepared, $xml); |
|
162 | 162 | |
163 | - fwrite( $stream, $xml->asXML() ); |
|
163 | + fwrite($stream, $xml->asXML()); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * @access public |
171 | 171 | * @since 1.0.19 |
172 | 172 | */ |
173 | - public function convert_array_xml( $data, $xml ) { |
|
173 | + public function convert_array_xml($data, $xml) { |
|
174 | 174 | |
175 | 175 | // Loop through |
176 | - foreach ( $data as $key => $value ) { |
|
176 | + foreach ($data as $key => $value) { |
|
177 | 177 | |
178 | - $key = preg_replace( '/[^A-Za-z0-9_\-]/', '', $key ); |
|
178 | + $key = preg_replace('/[^A-Za-z0-9_\-]/', '', $key); |
|
179 | 179 | |
180 | - if ( is_array( $value ) ) { |
|
180 | + if (is_array($value)) { |
|
181 | 181 | |
182 | - if ( is_numeric( $key ) ) { |
|
182 | + if (is_numeric($key)) { |
|
183 | 183 | $key = 'item' . $key; //dealing with <0/>..<n/> issues |
184 | 184 | } |
185 | 185 | |
186 | - $subnode = $xml->addChild( $key ); |
|
187 | - $this->convert_array_xml( $value, $subnode ); |
|
186 | + $subnode = $xml->addChild($key); |
|
187 | + $this->convert_array_xml($value, $subnode); |
|
188 | 188 | |
189 | 189 | } else { |
190 | - $xml->addChild( $key, $value ? htmlspecialchars( $value ) : $value ); |
|
190 | + $xml->addChild($key, $value ? htmlspecialchars($value) : $value); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,24 +201,24 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function prepare_row( $row, $fields ) { |
|
204 | + public function prepare_row($row, $fields) { |
|
205 | 205 | |
206 | 206 | $prepared = array(); |
207 | 207 | $row = (array) $row; |
208 | 208 | |
209 | - foreach ( $fields as $field ) { |
|
209 | + foreach ($fields as $field) { |
|
210 | 210 | |
211 | - if ( $field === 'total' ) { |
|
212 | - $prepared[ $field ] = html_entity_decode( strip_tags( wpinv_price( $row['total'] ) ), ENT_QUOTES ); |
|
211 | + if ($field === 'total') { |
|
212 | + $prepared[$field] = html_entity_decode(strip_tags(wpinv_price($row['total'])), ENT_QUOTES); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - if ( $field === 'total_raw' ) { |
|
217 | - $prepared[ $field ] = wpinv_round_amount( wpinv_sanitize_amount( $row['total'] ) ); |
|
216 | + if ($field === 'total_raw') { |
|
217 | + $prepared[$field] = wpinv_round_amount(wpinv_sanitize_amount($row['total'])); |
|
218 | 218 | continue; |
219 | 219 | } |
220 | 220 | |
221 | - $prepared[ $field ] = strip_tags( $row[ $field ] ); |
|
221 | + $prepared[$field] = strip_tags($row[$field]); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 |
@@ -12,236 +12,236 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves invoices query args. |
|
17 | - * |
|
18 | - * @param string $post_type post type to retrieve. |
|
19 | - * @param array $args Args to search for. |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
23 | - |
|
24 | - $query_args = array( |
|
25 | - 'post_type' => $post_type, |
|
26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | - 'posts_per_page' => -1, |
|
28 | - 'no_found_rows' => true, |
|
29 | - 'update_post_term_cache' => false, |
|
30 | - 'fields' => 'ids', |
|
31 | - ); |
|
32 | - |
|
33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | - } |
|
36 | - |
|
37 | - $date_query = array(); |
|
38 | - if ( ! empty( $args['to_date'] ) ) { |
|
39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | - } |
|
41 | - |
|
42 | - if ( ! empty( $args['from_date'] ) ) { |
|
43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | - } |
|
45 | - |
|
46 | - if ( ! empty( $date_query ) ) { |
|
47 | - $date_query['inclusive'] = true; |
|
48 | - $query_args['date_query'] = array( $date_query ); |
|
49 | - } |
|
50 | - |
|
51 | - return $query_args; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Retrieves invoices. |
|
56 | - * |
|
57 | - * @param array $query_args WP_Query args. |
|
58 | - * @return WPInv_Invoice[] |
|
59 | - */ |
|
60 | - public function get_invoices( $query_args ) { |
|
61 | - |
|
62 | - // Get invoices. |
|
63 | - $invoices = new WP_Query( $query_args ); |
|
64 | - |
|
65 | - // Prepare the results. |
|
66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | - |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Handles the actual download. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function export( $post_type, $args ) { |
|
75 | - |
|
76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | - $stream = $this->prepare_output(); |
|
78 | - $headers = $this->get_export_fields( $post_type ); |
|
79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | - |
|
81 | - if ( 'csv' == $file_type ) { |
|
82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
83 | - } elseif ( 'xml' == $file_type ) { |
|
84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
85 | - } else { |
|
86 | - $this->download_json( $invoices, $stream, $headers ); |
|
87 | - } |
|
88 | - |
|
89 | - fclose( $stream ); |
|
90 | - exit; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Prepares a single invoice for download. |
|
95 | - * |
|
96 | - * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | - * @param array $fields The fields to stream. |
|
98 | - * @since 1.0.19 |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function prepare_row( $invoice, $fields ) { |
|
102 | - |
|
103 | - $prepared = array(); |
|
104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | - $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | - |
|
107 | - foreach ( $fields as $field ) { |
|
108 | - $value = ''; |
|
109 | - $method = "get_$field"; |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | - $value = $meta_fields[ $field ]; |
|
115 | - } |
|
116 | - |
|
117 | - if ( in_array( $field, $amount_fields ) ) { |
|
118 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | - } |
|
120 | - |
|
121 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | - |
|
123 | - } |
|
124 | - |
|
125 | - return $prepared; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves export fields. |
|
130 | - * |
|
131 | - * @param string $post_type |
|
132 | - * @since 1.0.19 |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_export_fields( $post_type ) { |
|
136 | - |
|
137 | - $fields = array( |
|
138 | - 'id', |
|
139 | - 'parent_id', |
|
140 | - 'status', |
|
141 | - 'date_created', |
|
142 | - 'date_modified', |
|
143 | - 'date_due', |
|
144 | - 'date_completed', |
|
145 | - 'number', |
|
146 | - 'key', |
|
147 | - 'description', |
|
148 | - 'post_type', |
|
149 | - 'mode', |
|
150 | - 'customer_id', |
|
151 | - 'customer_first_name', |
|
152 | - 'customer_last_name', |
|
153 | - 'customer_phone', |
|
154 | - 'customer_email', |
|
155 | - 'customer_country', |
|
156 | - 'customer_city', |
|
157 | - 'customer_state', |
|
158 | - 'customer_zip', |
|
159 | - 'customer_company', |
|
160 | - 'customer_vat_number', |
|
161 | - 'customer_address', |
|
162 | - 'subtotal', |
|
163 | - 'total_discount', |
|
164 | - 'total_tax', |
|
165 | - 'total_fees', |
|
166 | - 'fees', |
|
167 | - 'discounts', |
|
168 | - 'taxes', |
|
169 | - 'cart_details', |
|
170 | - 'item_ids', |
|
171 | - 'payment_form', |
|
172 | - 'discount_code', |
|
173 | - 'gateway', |
|
174 | - 'transaction_id', |
|
175 | - 'currency', |
|
176 | - 'disable_taxes', |
|
177 | - 'subscription_id', |
|
178 | - 'remote_subscription_id', |
|
179 | - 'is_viewed', |
|
180 | - 'email_cc', |
|
181 | - 'template', |
|
182 | - 'created_via', |
|
183 | - ); |
|
184 | - |
|
185 | - // Payment form meta fields. |
|
186 | - $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | - |
|
188 | - if ( ! empty( $meta_fields ) ) { |
|
189 | - foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | - $fields[] = $field_key; |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Retrieves amount fields. |
|
199 | - * |
|
200 | - * @param string $post_type |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function get_amount_fields( $post_type ) { |
|
205 | - |
|
206 | - $fields = array( |
|
207 | - 'subtotal', |
|
208 | - 'total_discount', |
|
209 | - 'total_tax', |
|
210 | - 'total_fees', |
|
211 | - ); |
|
212 | - |
|
213 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Retrieves payment form meta fields. |
|
218 | - * |
|
219 | - * @since 2.8.23 |
|
220 | - * |
|
221 | - * @return array |
|
222 | - */ |
|
223 | - public function get_payment_form_meta( $invoice ) { |
|
224 | - // Payment form meta fields. |
|
225 | - $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | - $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | - |
|
228 | - $field_values = array(); |
|
229 | - if ( ! empty( $field_keys ) ) { |
|
230 | - foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | - $value = ''; |
|
232 | - |
|
233 | - if ( ! empty( $meta ) ) { |
|
234 | - foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | - if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | - $value = $meta_value; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - $field_values[ $field_key ] = $value; |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - return $field_values; |
|
246 | - } |
|
15 | + /** |
|
16 | + * Retrieves invoices query args. |
|
17 | + * |
|
18 | + * @param string $post_type post type to retrieve. |
|
19 | + * @param array $args Args to search for. |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function get_invoice_query_args( $post_type, $args ) { |
|
23 | + |
|
24 | + $query_args = array( |
|
25 | + 'post_type' => $post_type, |
|
26 | + 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
27 | + 'posts_per_page' => -1, |
|
28 | + 'no_found_rows' => true, |
|
29 | + 'update_post_term_cache' => false, |
|
30 | + 'fields' => 'ids', |
|
31 | + ); |
|
32 | + |
|
33 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | + $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
35 | + } |
|
36 | + |
|
37 | + $date_query = array(); |
|
38 | + if ( ! empty( $args['to_date'] ) ) { |
|
39 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
40 | + } |
|
41 | + |
|
42 | + if ( ! empty( $args['from_date'] ) ) { |
|
43 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
44 | + } |
|
45 | + |
|
46 | + if ( ! empty( $date_query ) ) { |
|
47 | + $date_query['inclusive'] = true; |
|
48 | + $query_args['date_query'] = array( $date_query ); |
|
49 | + } |
|
50 | + |
|
51 | + return $query_args; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Retrieves invoices. |
|
56 | + * |
|
57 | + * @param array $query_args WP_Query args. |
|
58 | + * @return WPInv_Invoice[] |
|
59 | + */ |
|
60 | + public function get_invoices( $query_args ) { |
|
61 | + |
|
62 | + // Get invoices. |
|
63 | + $invoices = new WP_Query( $query_args ); |
|
64 | + |
|
65 | + // Prepare the results. |
|
66 | + return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
67 | + |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Handles the actual download. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function export( $post_type, $args ) { |
|
75 | + |
|
76 | + $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
77 | + $stream = $this->prepare_output(); |
|
78 | + $headers = $this->get_export_fields( $post_type ); |
|
79 | + $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
80 | + |
|
81 | + if ( 'csv' == $file_type ) { |
|
82 | + $this->download_csv( $invoices, $stream, $headers ); |
|
83 | + } elseif ( 'xml' == $file_type ) { |
|
84 | + $this->download_xml( $invoices, $stream, $headers ); |
|
85 | + } else { |
|
86 | + $this->download_json( $invoices, $stream, $headers ); |
|
87 | + } |
|
88 | + |
|
89 | + fclose( $stream ); |
|
90 | + exit; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Prepares a single invoice for download. |
|
95 | + * |
|
96 | + * @param WPInv_Invoice $invoice The invoice to prepare.. |
|
97 | + * @param array $fields The fields to stream. |
|
98 | + * @since 1.0.19 |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function prepare_row( $invoice, $fields ) { |
|
102 | + |
|
103 | + $prepared = array(); |
|
104 | + $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | + $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
106 | + |
|
107 | + foreach ( $fields as $field ) { |
|
108 | + $value = ''; |
|
109 | + $method = "get_$field"; |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | + $value = $meta_fields[ $field ]; |
|
115 | + } |
|
116 | + |
|
117 | + if ( in_array( $field, $amount_fields ) ) { |
|
118 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | + } |
|
120 | + |
|
121 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
122 | + |
|
123 | + } |
|
124 | + |
|
125 | + return $prepared; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves export fields. |
|
130 | + * |
|
131 | + * @param string $post_type |
|
132 | + * @since 1.0.19 |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_export_fields( $post_type ) { |
|
136 | + |
|
137 | + $fields = array( |
|
138 | + 'id', |
|
139 | + 'parent_id', |
|
140 | + 'status', |
|
141 | + 'date_created', |
|
142 | + 'date_modified', |
|
143 | + 'date_due', |
|
144 | + 'date_completed', |
|
145 | + 'number', |
|
146 | + 'key', |
|
147 | + 'description', |
|
148 | + 'post_type', |
|
149 | + 'mode', |
|
150 | + 'customer_id', |
|
151 | + 'customer_first_name', |
|
152 | + 'customer_last_name', |
|
153 | + 'customer_phone', |
|
154 | + 'customer_email', |
|
155 | + 'customer_country', |
|
156 | + 'customer_city', |
|
157 | + 'customer_state', |
|
158 | + 'customer_zip', |
|
159 | + 'customer_company', |
|
160 | + 'customer_vat_number', |
|
161 | + 'customer_address', |
|
162 | + 'subtotal', |
|
163 | + 'total_discount', |
|
164 | + 'total_tax', |
|
165 | + 'total_fees', |
|
166 | + 'fees', |
|
167 | + 'discounts', |
|
168 | + 'taxes', |
|
169 | + 'cart_details', |
|
170 | + 'item_ids', |
|
171 | + 'payment_form', |
|
172 | + 'discount_code', |
|
173 | + 'gateway', |
|
174 | + 'transaction_id', |
|
175 | + 'currency', |
|
176 | + 'disable_taxes', |
|
177 | + 'subscription_id', |
|
178 | + 'remote_subscription_id', |
|
179 | + 'is_viewed', |
|
180 | + 'email_cc', |
|
181 | + 'template', |
|
182 | + 'created_via', |
|
183 | + ); |
|
184 | + |
|
185 | + // Payment form meta fields. |
|
186 | + $meta_fields = getpaid_get_payment_form_custom_fields(); |
|
187 | + |
|
188 | + if ( ! empty( $meta_fields ) ) { |
|
189 | + foreach ( $meta_fields as $field_key => $field_label ) { |
|
190 | + $fields[] = $field_key; |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Retrieves amount fields. |
|
199 | + * |
|
200 | + * @param string $post_type |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function get_amount_fields( $post_type ) { |
|
205 | + |
|
206 | + $fields = array( |
|
207 | + 'subtotal', |
|
208 | + 'total_discount', |
|
209 | + 'total_tax', |
|
210 | + 'total_fees', |
|
211 | + ); |
|
212 | + |
|
213 | + return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Retrieves payment form meta fields. |
|
218 | + * |
|
219 | + * @since 2.8.23 |
|
220 | + * |
|
221 | + * @return array |
|
222 | + */ |
|
223 | + public function get_payment_form_meta( $invoice ) { |
|
224 | + // Payment form meta fields. |
|
225 | + $field_keys = getpaid_get_payment_form_custom_fields(); |
|
226 | + $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
227 | + |
|
228 | + $field_values = array(); |
|
229 | + if ( ! empty( $field_keys ) ) { |
|
230 | + foreach ( $field_keys as $field_key => $field_label ) { |
|
231 | + $value = ''; |
|
232 | + |
|
233 | + if ( ! empty( $meta ) ) { |
|
234 | + foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | + if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
236 | + $value = $meta_value; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + $field_values[ $field_key ] = $value; |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + return $field_values; |
|
246 | + } |
|
247 | 247 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * GetPaid_Invoice_Exporter Class. |
@@ -19,33 +19,33 @@ discard block |
||
19 | 19 | * @param array $args Args to search for. |
20 | 20 | * @return array |
21 | 21 | */ |
22 | - public function get_invoice_query_args( $post_type, $args ) { |
|
22 | + public function get_invoice_query_args($post_type, $args) { |
|
23 | 23 | |
24 | 24 | $query_args = array( |
25 | 25 | 'post_type' => $post_type, |
26 | - 'post_status' => array_keys( wpinv_get_invoice_statuses( true, false, $post_type ) ), |
|
26 | + 'post_status' => array_keys(wpinv_get_invoice_statuses(true, false, $post_type)), |
|
27 | 27 | 'posts_per_page' => -1, |
28 | 28 | 'no_found_rows' => true, |
29 | 29 | 'update_post_term_cache' => false, |
30 | 30 | 'fields' => 'ids', |
31 | 31 | ); |
32 | 32 | |
33 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], $query_args['post_status'], true ) ) { |
|
34 | - $query_args['post_status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
33 | + if (!empty($args['status']) && in_array($args['status'], $query_args['post_status'], true)) { |
|
34 | + $query_args['post_status'] = wpinv_clean(wpinv_parse_list($args['status'])); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $date_query = array(); |
38 | - if ( ! empty( $args['to_date'] ) ) { |
|
39 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
38 | + if (!empty($args['to_date'])) { |
|
39 | + $date_query['before'] = wpinv_clean($args['to_date']); |
|
40 | 40 | } |
41 | 41 | |
42 | - if ( ! empty( $args['from_date'] ) ) { |
|
43 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
42 | + if (!empty($args['from_date'])) { |
|
43 | + $date_query['after'] = wpinv_clean($args['from_date']); |
|
44 | 44 | } |
45 | 45 | |
46 | - if ( ! empty( $date_query ) ) { |
|
46 | + if (!empty($date_query)) { |
|
47 | 47 | $date_query['inclusive'] = true; |
48 | - $query_args['date_query'] = array( $date_query ); |
|
48 | + $query_args['date_query'] = array($date_query); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return $query_args; |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | * @param array $query_args WP_Query args. |
58 | 58 | * @return WPInv_Invoice[] |
59 | 59 | */ |
60 | - public function get_invoices( $query_args ) { |
|
60 | + public function get_invoices($query_args) { |
|
61 | 61 | |
62 | 62 | // Get invoices. |
63 | - $invoices = new WP_Query( $query_args ); |
|
63 | + $invoices = new WP_Query($query_args); |
|
64 | 64 | |
65 | 65 | // Prepare the results. |
66 | - return array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
66 | + return array_map('wpinv_get_invoice', $invoices->posts); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -71,22 +71,22 @@ discard block |
||
71 | 71 | * Handles the actual download. |
72 | 72 | * |
73 | 73 | */ |
74 | - public function export( $post_type, $args ) { |
|
74 | + public function export($post_type, $args) { |
|
75 | 75 | |
76 | - $invoices = $this->get_invoices( $this->get_invoice_query_args( $post_type, $args ) ); |
|
76 | + $invoices = $this->get_invoices($this->get_invoice_query_args($post_type, $args)); |
|
77 | 77 | $stream = $this->prepare_output(); |
78 | - $headers = $this->get_export_fields( $post_type ); |
|
79 | - $file_type = $this->prepare_file_type( strtolower( getpaid_get_post_type_label( $post_type ) ) ); |
|
78 | + $headers = $this->get_export_fields($post_type); |
|
79 | + $file_type = $this->prepare_file_type(strtolower(getpaid_get_post_type_label($post_type))); |
|
80 | 80 | |
81 | - if ( 'csv' == $file_type ) { |
|
82 | - $this->download_csv( $invoices, $stream, $headers ); |
|
83 | - } elseif ( 'xml' == $file_type ) { |
|
84 | - $this->download_xml( $invoices, $stream, $headers ); |
|
81 | + if ('csv' == $file_type) { |
|
82 | + $this->download_csv($invoices, $stream, $headers); |
|
83 | + } elseif ('xml' == $file_type) { |
|
84 | + $this->download_xml($invoices, $stream, $headers); |
|
85 | 85 | } else { |
86 | - $this->download_json( $invoices, $stream, $headers ); |
|
86 | + $this->download_json($invoices, $stream, $headers); |
|
87 | 87 | } |
88 | 88 | |
89 | - fclose( $stream ); |
|
89 | + fclose($stream); |
|
90 | 90 | exit; |
91 | 91 | } |
92 | 92 | |
@@ -98,27 +98,27 @@ discard block |
||
98 | 98 | * @since 1.0.19 |
99 | 99 | * @return array |
100 | 100 | */ |
101 | - public function prepare_row( $invoice, $fields ) { |
|
101 | + public function prepare_row($invoice, $fields) { |
|
102 | 102 | |
103 | 103 | $prepared = array(); |
104 | - $amount_fields = $this->get_amount_fields( $invoice->get_post_type() ); |
|
105 | - $meta_fields = $this->get_payment_form_meta( $invoice ); |
|
104 | + $amount_fields = $this->get_amount_fields($invoice->get_post_type()); |
|
105 | + $meta_fields = $this->get_payment_form_meta($invoice); |
|
106 | 106 | |
107 | - foreach ( $fields as $field ) { |
|
107 | + foreach ($fields as $field) { |
|
108 | 108 | $value = ''; |
109 | 109 | $method = "get_$field"; |
110 | 110 | |
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } else if( strpos( $field, '_' ) === 0 && isset( $meta_fields[ $field ] ) ) { |
|
114 | - $value = $meta_fields[ $field ]; |
|
111 | + if (method_exists($invoice, $method)) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } else if (strpos($field, '_') === 0 && isset($meta_fields[$field])) { |
|
114 | + $value = $meta_fields[$field]; |
|
115 | 115 | } |
116 | 116 | |
117 | - if ( in_array( $field, $amount_fields ) ) { |
|
118 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
117 | + if (in_array($field, $amount_fields)) { |
|
118 | + $value = wpinv_round_amount(wpinv_sanitize_amount($value)); |
|
119 | 119 | } |
120 | 120 | |
121 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
121 | + $prepared[$field] = wpinv_clean($value); |
|
122 | 122 | |
123 | 123 | } |
124 | 124 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @since 1.0.19 |
133 | 133 | * @return array |
134 | 134 | */ |
135 | - public function get_export_fields( $post_type ) { |
|
135 | + public function get_export_fields($post_type) { |
|
136 | 136 | |
137 | 137 | $fields = array( |
138 | 138 | 'id', |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | // Payment form meta fields. |
186 | 186 | $meta_fields = getpaid_get_payment_form_custom_fields(); |
187 | 187 | |
188 | - if ( ! empty( $meta_fields ) ) { |
|
189 | - foreach ( $meta_fields as $field_key => $field_label ) { |
|
188 | + if (!empty($meta_fields)) { |
|
189 | + foreach ($meta_fields as $field_key => $field_label) { |
|
190 | 190 | $fields[] = $field_key; |
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - return apply_filters( 'getpaid_invoice_exporter_get_fields', $fields, $post_type ); |
|
194 | + return apply_filters('getpaid_invoice_exporter_get_fields', $fields, $post_type); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @since 1.0.19 |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function get_amount_fields( $post_type ) { |
|
204 | + public function get_amount_fields($post_type) { |
|
205 | 205 | |
206 | 206 | $fields = array( |
207 | 207 | 'subtotal', |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | 'total_fees', |
211 | 211 | ); |
212 | 212 | |
213 | - return apply_filters( 'getpaid_invoice_exporter_get_amount_fields', $fields, $post_type ); |
|
213 | + return apply_filters('getpaid_invoice_exporter_get_amount_fields', $fields, $post_type); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -220,25 +220,25 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return array |
222 | 222 | */ |
223 | - public function get_payment_form_meta( $invoice ) { |
|
223 | + public function get_payment_form_meta($invoice) { |
|
224 | 224 | // Payment form meta fields. |
225 | 225 | $field_keys = getpaid_get_payment_form_custom_fields(); |
226 | - $meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true ); |
|
226 | + $meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true); |
|
227 | 227 | |
228 | 228 | $field_values = array(); |
229 | - if ( ! empty( $field_keys ) ) { |
|
230 | - foreach ( $field_keys as $field_key => $field_label ) { |
|
229 | + if (!empty($field_keys)) { |
|
230 | + foreach ($field_keys as $field_key => $field_label) { |
|
231 | 231 | $value = ''; |
232 | 232 | |
233 | - if ( ! empty( $meta ) ) { |
|
234 | - foreach ( $meta as $meta_label => $meta_value ) { |
|
235 | - if ( getpaid_strtolower( wpinv_clean( wp_unslash( $meta_label ) ) ) == getpaid_strtolower( $field_label ) ) { |
|
233 | + if (!empty($meta)) { |
|
234 | + foreach ($meta as $meta_label => $meta_value) { |
|
235 | + if (getpaid_strtolower(wpinv_clean(wp_unslash($meta_label))) == getpaid_strtolower($field_label)) { |
|
236 | 236 | $value = $meta_value; |
237 | 237 | } |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - $field_values[ $field_key ] = $value; |
|
241 | + $field_values[$field_key] = $value; |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 |
@@ -4,40 +4,40 @@ |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | global $aui_bs5; |
10 | 10 | ?> |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | 12 | <div class="text-center card-body"> |
13 | - <h1 class="h3"><?php esc_html_e( 'Awesome, you are ready to Get Paid', 'invoicing' ); ?></h1> |
|
13 | + <h1 class="h3"><?php esc_html_e('Awesome, you are ready to Get Paid', 'invoicing'); ?></h1> |
|
14 | 14 | |
15 | 15 | <div class="geodirectory-message geodirectory-tracker"> |
16 | - <p><?php esc_html_e( 'Thank you for choosing GetPaid!', 'invoicing' ); ?> <i class="far fa-smile-beam"></i></p> |
|
16 | + <p><?php esc_html_e('Thank you for choosing GetPaid!', 'invoicing'); ?> <i class="far fa-smile-beam"></i></p> |
|
17 | 17 | </div> |
18 | 18 | |
19 | 19 | <div class="gp-setup-next-steps"> |
20 | 20 | <div class="gp-setup-next-steps-first mb-4"> |
21 | 21 | <div> |
22 | - <h2 class="h3"><i class="fas fa-arrow-down"></i> <?php esc_html_e( 'Watch This', 'invoicing' ); ?> <i class="fas fa-arrow-down"></i></h2> |
|
23 | - <div class="<?php echo( $aui_bs5 ? 'ratio ratio-16x9' : 'embed-responsive embed-responsive-16by9' ); ?> mb-4"> |
|
24 | - <iframe class="<?php echo( $aui_bs5 ? '' : 'embed-responsive-item' ); ?>" src="https://www.youtube.com/embed/TXZuPXHjt9E?rel=0" allowfullscreen></iframe> |
|
22 | + <h2 class="h3"><i class="fas fa-arrow-down"></i> <?php esc_html_e('Watch This', 'invoicing'); ?> <i class="fas fa-arrow-down"></i></h2> |
|
23 | + <div class="<?php echo($aui_bs5 ? 'ratio ratio-16x9' : 'embed-responsive embed-responsive-16by9'); ?> mb-4"> |
|
24 | + <iframe class="<?php echo($aui_bs5 ? '' : 'embed-responsive-item'); ?>" src="https://www.youtube.com/embed/TXZuPXHjt9E?rel=0" allowfullscreen></iframe> |
|
25 | 25 | </div> |
26 | 26 | </div> |
27 | - <h2 class="h3"><?php esc_html_e( 'Next steps', 'invoicing' ); ?></h2> |
|
27 | + <h2 class="h3"><?php esc_html_e('Next steps', 'invoicing'); ?></h2> |
|
28 | 28 | |
29 | 29 | <div class="d-flex justify-content-between"> |
30 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_item' ) ); ?>"><span class="h1 d-block"><i class="fas fa-box-open"></i></span> <?php esc_html_e( 'Create Item', 'invoicing' ); ?></a> |
|
31 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_payment_form' ) ); ?>"><span class="h1 d-block"><i class="fas fa-align-justify"></i></span> <?php esc_html_e( 'Create Payment Form', 'invoicing' ); ?></a> |
|
32 | - <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url( admin_url( 'post-new.php?post_type=wpi_invoice' ) ); ?>"><span class="h1 d-block"><i class="fas fa-file-alt"></i></span> <?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a> |
|
30 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_item')); ?>"><span class="h1 d-block"><i class="fas fa-box-open"></i></span> <?php esc_html_e('Create Item', 'invoicing'); ?></a> |
|
31 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_payment_form')); ?>"><span class="h1 d-block"><i class="fas fa-align-justify"></i></span> <?php esc_html_e('Create Payment Form', 'invoicing'); ?></a> |
|
32 | + <a class="btn btn-outline-primary btn-sm" href="<?php echo esc_url(admin_url('post-new.php?post_type=wpi_invoice')); ?>"><span class="h1 d-block"><i class="fas fa-file-alt"></i></span> <?php esc_html_e('Create Invoice', 'invoicing'); ?></a> |
|
33 | 33 | </div> |
34 | 34 | |
35 | - <h2 class="h3 mt-4"><?php esc_html_e( 'Learn more', 'invoicing' ); ?></h2> |
|
35 | + <h2 class="h3 mt-4"><?php esc_html_e('Learn more', 'invoicing'); ?></h2> |
|
36 | 36 | <div class="gp-setup-next-steps-last mt-2 d-flex justify-content-between"> |
37 | - <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/collection/114-getting-started?utm_source=setupwizard&utm_medium=product&utm_content=getting-started&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e( 'Getting Started', 'invoicing' ); ?></a> |
|
38 | - <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e( 'Documentation', 'invoicing' ); ?></a> |
|
39 | - <a class="btn btn-outline-primary btn-sm" href="https://wpgetpaid.com/support/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e( 'Support', 'invoicing' ); ?></a> |
|
40 | - <a class="btn btn-outline-primary btn-sm" href="https://demos.ayecode.io/getpaid/?utm_source=setupwizard&utm_medium=product&utm_content=demos&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e( 'Demos', 'invoicing' ); ?></a> |
|
37 | + <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/collection/114-getting-started?utm_source=setupwizard&utm_medium=product&utm_content=getting-started&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e('Getting Started', 'invoicing'); ?></a> |
|
38 | + <a class="btn btn-outline-primary btn-sm" href="https://docs.wpgetpaid.com/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingplugin" target="_blank"><?php esc_html_e('Documentation', 'invoicing'); ?></a> |
|
39 | + <a class="btn btn-outline-primary btn-sm" href="https://wpgetpaid.com/support/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e('Support', 'invoicing'); ?></a> |
|
40 | + <a class="btn btn-outline-primary btn-sm" href="https://demos.ayecode.io/getpaid/?utm_source=setupwizard&utm_medium=product&utm_content=demos&utm_campaign=invoicingyplugin" target="_blank"><?php esc_html_e('Demos', 'invoicing'); ?></a> |
|
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | </div> |
@@ -4,31 +4,31 @@ |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | global $aui_bs5; |
10 | 10 | ?> |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | - <form method="post" class="text-center card-body" action="<?php echo esc_url( admin_url() ); ?>"> |
|
13 | - <?php getpaid_hidden_field( 'getpaid-admin-action', 'install_plugin' ); ?> |
|
14 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
15 | - <?php getpaid_hidden_field( 'redirect', $next_url ); ?> |
|
12 | + <form method="post" class="text-center card-body" action="<?php echo esc_url(admin_url()); ?>"> |
|
13 | + <?php getpaid_hidden_field('getpaid-admin-action', 'install_plugin'); ?> |
|
14 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
15 | + <?php getpaid_hidden_field('redirect', $next_url); ?> |
|
16 | 16 | <div class="gd-wizard-recommend"> |
17 | - <h2 class="gd-settings-title h3"><?php esc_html_e( 'Recommended Plugins', 'invoicing' ); ?></h2> |
|
18 | - <p><?php esc_html_e( 'Below are a few of our own plugins that may help you.', 'invoicing' ); ?></p> |
|
17 | + <h2 class="gd-settings-title h3"><?php esc_html_e('Recommended Plugins', 'invoicing'); ?></h2> |
|
18 | + <p><?php esc_html_e('Below are a few of our own plugins that may help you.', 'invoicing'); ?></p> |
|
19 | 19 | <ul class="list-group"> |
20 | - <?php foreach ( $recommended_plugins as $key => $plugin ) : ?> |
|
21 | - <li class="list-group-item d-flex justify-content-between align-items-center flex-wrap <?php echo( $aui_bs5 ? 'text-start' : 'text-left' ); ?>"> |
|
22 | - <span class="mr-auto"><?php echo esc_html( $plugin['name'] ); ?></span> |
|
23 | - <div class="<?php echo( $aui_bs5 ? 'form-check form-switch me-n2' : 'custom-control custom-switch mr-n2 getpaid-install-plugin-siwtch-div' ); ?>"> |
|
24 | - <input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="<?php echo ( $aui_bs5 ? 'form-check-input' : 'custom-control-input' ); ?>" <?php if ( is_plugin_active( $plugin['file'] ) ) { echo 'checked';}?> id="ac-setting-updates<?php echo esc_attr( $key ); ?>"> |
|
25 | - <label class="<?php echo ( $aui_bs5 ? 'form-check-label' : 'custom-control-label' ); ?>" for="ac-setting-updates<?php echo esc_attr( $key ); ?>"></label> |
|
20 | + <?php foreach ($recommended_plugins as $key => $plugin) : ?> |
|
21 | + <li class="list-group-item d-flex justify-content-between align-items-center flex-wrap <?php echo($aui_bs5 ? 'text-start' : 'text-left'); ?>"> |
|
22 | + <span class="mr-auto"><?php echo esc_html($plugin['name']); ?></span> |
|
23 | + <div class="<?php echo($aui_bs5 ? 'form-check form-switch me-n2' : 'custom-control custom-switch mr-n2 getpaid-install-plugin-siwtch-div'); ?>"> |
|
24 | + <input type="checkbox" name="plugins[<?php echo esc_attr($plugin['slug']); ?>]" value="<?php echo esc_attr($plugin['file']); ?>" class="<?php echo ($aui_bs5 ? 'form-check-input' : 'custom-control-input'); ?>" <?php if (is_plugin_active($plugin['file'])) { echo 'checked'; }?> id="ac-setting-updates<?php echo esc_attr($key); ?>"> |
|
25 | + <label class="<?php echo ($aui_bs5 ? 'form-check-label' : 'custom-control-label'); ?>" for="ac-setting-updates<?php echo esc_attr($key); ?>"></label> |
|
26 | 26 | </div> |
27 | - <small class="w-100"><?php echo esc_attr( $plugin['desc'] ); ?></small> |
|
27 | + <small class="w-100"><?php echo esc_attr($plugin['desc']); ?></small> |
|
28 | 28 | </li> |
29 | 29 | <?php endforeach; ?> |
30 | 30 | </ul> |
31 | - <p class="gp-setup-actions step text-center mt-4"><input type="submit" class="btn btn-primary button-next" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" name="save_step"/></p> |
|
31 | + <p class="gp-setup-actions step text-center mt-4"><input type="submit" class="btn btn-primary button-next" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" name="save_step"/></p> |
|
32 | 32 | </div> |
33 | 33 | </form> |
34 | 34 | </div> |
35 | 35 | \ No newline at end of file |
@@ -10,227 +10,227 @@ |
||
10 | 10 | */ |
11 | 11 | class GetPaid_PayPal_API { |
12 | 12 | |
13 | - /** |
|
14 | - * Retrieves the bearer token. |
|
15 | - * |
|
13 | + /** |
|
14 | + * Retrieves the bearer token. |
|
15 | + * |
|
16 | 16 | * @return string|\WP_Error |
17 | - */ |
|
18 | - public static function get_token( $mode = 'live' ) { |
|
17 | + */ |
|
18 | + public static function get_token( $mode = 'live' ) { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
23 | - return $token; |
|
24 | - } |
|
22 | + if ( $token ) { |
|
23 | + return $token; |
|
24 | + } |
|
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | + $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
29 | 29 | |
30 | 30 | if ( empty( $client_id ) || empty( $secret_key ) ) { |
31 | 31 | return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
35 | - 'method' => 'POST', |
|
36 | - 'timeout' => 30, |
|
37 | - 'headers' => array( |
|
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | - 'Accept' => 'application/json', |
|
40 | - 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | - ), |
|
42 | - ); |
|
43 | - |
|
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | - |
|
46 | - if ( is_wp_error( $response ) ) { |
|
47 | - return $response; |
|
48 | - } |
|
49 | - |
|
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | - } |
|
53 | - |
|
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | - return $response->access_token; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Retrieves the PayPal API URL. |
|
60 | - * |
|
61 | - * @param string $endpoint |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
66 | - return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Handles a post request. |
|
71 | - * |
|
72 | - * @param string $path The path to the endpoint. |
|
73 | - * @param mixed $data The data to send. |
|
74 | - * @param string $method The method to use. |
|
75 | - * |
|
76 | - * @return true|\WP_Error |
|
77 | - */ |
|
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | - |
|
80 | - $access_token = self::get_token( $mode ); |
|
81 | - |
|
82 | - if ( is_wp_error( $access_token ) ) { |
|
83 | - return $access_token; |
|
84 | - } |
|
85 | - |
|
86 | - $url = self::get_api_url( $path, $mode ); |
|
87 | - $args = array( |
|
88 | - 'method' => $method, |
|
89 | - 'headers' => array( |
|
90 | - 'Authorization' => 'Bearer ' . $access_token, |
|
91 | - 'Content-Type' => 'application/json', |
|
92 | - ), |
|
93 | - ); |
|
94 | - |
|
95 | - if( ! empty( $data )) { |
|
96 | - $args['body'] = wp_json_encode( $data ); |
|
97 | - } |
|
98 | - |
|
99 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Handles a get request. |
|
104 | - * |
|
105 | - * @param string $path The path to the endpoint. |
|
106 | - * @param string $method |
|
107 | - * @return object|\WP_Error |
|
108 | - */ |
|
109 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | - |
|
111 | - $access_token = self::get_token( $mode ); |
|
112 | - |
|
113 | - if ( is_wp_error( $access_token ) ) { |
|
114 | - return $access_token; |
|
115 | - } |
|
116 | - |
|
117 | - $url = self::get_api_url( $path, $mode ); |
|
118 | - $args = array( |
|
119 | - 'method' => $method, |
|
120 | - 'headers' => array( |
|
121 | - 'Authorization' => 'Bearer ' . $access_token, |
|
122 | - ), |
|
123 | - ); |
|
124 | - |
|
125 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns the response body |
|
130 | - * |
|
131 | - * @since 1.0.0 |
|
132 | - * @version 1.0.0 |
|
133 | - * @param \WP_Error|array $response |
|
134 | - * @return \WP_Error|object |
|
135 | - */ |
|
136 | - public static function response_or_error( $response ) { |
|
137 | - |
|
138 | - if ( is_wp_error( $response ) ) { |
|
139 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | - } |
|
141 | - |
|
142 | - if ( empty( $response['body'] ) ) { |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | - |
|
148 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | - |
|
150 | - // Normal errors. |
|
151 | - if ( $response_body && isset( $response_body->message ) ) { |
|
152 | - $error_message = $response_body->message; |
|
153 | - |
|
154 | - // Identity errors. |
|
155 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | - $error_message = $response_body->error_description; |
|
157 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | - } else { |
|
159 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | - } |
|
161 | - |
|
162 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | - } |
|
164 | - |
|
165 | - return $response_body; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Fetches an order. |
|
170 | - * |
|
171 | - * @since 1.0.0 |
|
172 | - * @version 1.0.0 |
|
173 | - * @param string $order_id |
|
174 | - * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | - * @return \WP_Error|object |
|
176 | - */ |
|
177 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Fetches a subscription. |
|
183 | - * |
|
184 | - * @since 1.0.0 |
|
185 | - * @version 1.0.0 |
|
186 | - * @param string $subscription_id |
|
187 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | - * @return \WP_Error|object |
|
189 | - */ |
|
190 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | - * |
|
197 | - * @since 1.0.0 |
|
198 | - * @version 1.0.0 |
|
199 | - * @param string $subscription_id |
|
200 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | - * @return \WP_Error|object |
|
202 | - */ |
|
203 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Refunds a capture. |
|
211 | - * |
|
212 | - * @since 1.0.0 |
|
213 | - * @version 1.0.0 |
|
214 | - * @param string $capture_id |
|
215 | - * @param array $args |
|
216 | - * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | - * @return \WP_Error|object |
|
218 | - */ |
|
219 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Cancels a subscription. |
|
225 | - * |
|
226 | - * @since 2.8.24 |
|
227 | - * @version 2.8.24 |
|
228 | - * @param string $subscription_id |
|
229 | - * @param array $args |
|
230 | - * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | - * @return \WP_Error|object |
|
232 | - */ |
|
233 | - public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | - return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | - } |
|
34 | + $args = array( |
|
35 | + 'method' => 'POST', |
|
36 | + 'timeout' => 30, |
|
37 | + 'headers' => array( |
|
38 | + 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | + 'Accept' => 'application/json', |
|
40 | + 'Content-Type' => 'application/x-www-form-urlencoded', |
|
41 | + ), |
|
42 | + ); |
|
43 | + |
|
44 | + $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
45 | + |
|
46 | + if ( is_wp_error( $response ) ) { |
|
47 | + return $response; |
|
48 | + } |
|
49 | + |
|
50 | + if ( ! isset( $response->access_token ) ) { |
|
51 | + return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
52 | + } |
|
53 | + |
|
54 | + set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
55 | + return $response->access_token; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Retrieves the PayPal API URL. |
|
60 | + * |
|
61 | + * @param string $endpoint |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | + $endpoint = ltrim( $endpoint, '/' ); |
|
66 | + return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Handles a post request. |
|
71 | + * |
|
72 | + * @param string $path The path to the endpoint. |
|
73 | + * @param mixed $data The data to send. |
|
74 | + * @param string $method The method to use. |
|
75 | + * |
|
76 | + * @return true|\WP_Error |
|
77 | + */ |
|
78 | + public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
79 | + |
|
80 | + $access_token = self::get_token( $mode ); |
|
81 | + |
|
82 | + if ( is_wp_error( $access_token ) ) { |
|
83 | + return $access_token; |
|
84 | + } |
|
85 | + |
|
86 | + $url = self::get_api_url( $path, $mode ); |
|
87 | + $args = array( |
|
88 | + 'method' => $method, |
|
89 | + 'headers' => array( |
|
90 | + 'Authorization' => 'Bearer ' . $access_token, |
|
91 | + 'Content-Type' => 'application/json', |
|
92 | + ), |
|
93 | + ); |
|
94 | + |
|
95 | + if( ! empty( $data )) { |
|
96 | + $args['body'] = wp_json_encode( $data ); |
|
97 | + } |
|
98 | + |
|
99 | + return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Handles a get request. |
|
104 | + * |
|
105 | + * @param string $path The path to the endpoint. |
|
106 | + * @param string $method |
|
107 | + * @return object|\WP_Error |
|
108 | + */ |
|
109 | + public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
110 | + |
|
111 | + $access_token = self::get_token( $mode ); |
|
112 | + |
|
113 | + if ( is_wp_error( $access_token ) ) { |
|
114 | + return $access_token; |
|
115 | + } |
|
116 | + |
|
117 | + $url = self::get_api_url( $path, $mode ); |
|
118 | + $args = array( |
|
119 | + 'method' => $method, |
|
120 | + 'headers' => array( |
|
121 | + 'Authorization' => 'Bearer ' . $access_token, |
|
122 | + ), |
|
123 | + ); |
|
124 | + |
|
125 | + return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns the response body |
|
130 | + * |
|
131 | + * @since 1.0.0 |
|
132 | + * @version 1.0.0 |
|
133 | + * @param \WP_Error|array $response |
|
134 | + * @return \WP_Error|object |
|
135 | + */ |
|
136 | + public static function response_or_error( $response ) { |
|
137 | + |
|
138 | + if ( is_wp_error( $response ) ) { |
|
139 | + return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
140 | + } |
|
141 | + |
|
142 | + if ( empty( $response['body'] ) ) { |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
147 | + |
|
148 | + if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
149 | + |
|
150 | + // Normal errors. |
|
151 | + if ( $response_body && isset( $response_body->message ) ) { |
|
152 | + $error_message = $response_body->message; |
|
153 | + |
|
154 | + // Identity errors. |
|
155 | + } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
156 | + $error_message = $response_body->error_description; |
|
157 | + return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
158 | + } else { |
|
159 | + $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
160 | + } |
|
161 | + |
|
162 | + return new \WP_Error( 'paypal_error', $error_message ); |
|
163 | + } |
|
164 | + |
|
165 | + return $response_body; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Fetches an order. |
|
170 | + * |
|
171 | + * @since 1.0.0 |
|
172 | + * @version 1.0.0 |
|
173 | + * @param string $order_id |
|
174 | + * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
175 | + * @return \WP_Error|object |
|
176 | + */ |
|
177 | + public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | + return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Fetches a subscription. |
|
183 | + * |
|
184 | + * @since 1.0.0 |
|
185 | + * @version 1.0.0 |
|
186 | + * @param string $subscription_id |
|
187 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
|
188 | + * @return \WP_Error|object |
|
189 | + */ |
|
190 | + public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | + return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Fetches a subscription's latest transactions (limits search to last one day). |
|
196 | + * |
|
197 | + * @since 1.0.0 |
|
198 | + * @version 1.0.0 |
|
199 | + * @param string $subscription_id |
|
200 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
|
201 | + * @return \WP_Error|object |
|
202 | + */ |
|
203 | + public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | + $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | + $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | + return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Refunds a capture. |
|
211 | + * |
|
212 | + * @since 1.0.0 |
|
213 | + * @version 1.0.0 |
|
214 | + * @param string $capture_id |
|
215 | + * @param array $args |
|
216 | + * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
|
217 | + * @return \WP_Error|object |
|
218 | + */ |
|
219 | + public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | + return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Cancels a subscription. |
|
225 | + * |
|
226 | + * @since 2.8.24 |
|
227 | + * @version 2.8.24 |
|
228 | + * @param string $subscription_id |
|
229 | + * @param array $args |
|
230 | + * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
|
231 | + * @return \WP_Error|object |
|
232 | + */ |
|
233 | + public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | + return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
235 | + } |
|
236 | 236 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly. |
4 | -defined( 'ABSPATH' ) || exit; |
|
4 | +defined('ABSPATH') || exit; |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * PayPal API handler. |
@@ -15,43 +15,43 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return string|\WP_Error |
17 | 17 | */ |
18 | - public static function get_token( $mode = 'live' ) { |
|
18 | + public static function get_token($mode = 'live') { |
|
19 | 19 | |
20 | - $token = get_transient( 'getpaid_paypal_' . $mode . '_token' ); |
|
20 | + $token = get_transient('getpaid_paypal_' . $mode . '_token'); |
|
21 | 21 | |
22 | - if ( $token ) { |
|
22 | + if ($token) { |
|
23 | 23 | return $token; |
24 | 24 | } |
25 | 25 | |
26 | - $client_id = 'live' === $mode ? wpinv_get_option( 'paypal_client_id' ) : wpinv_get_option( 'paypal_sandbox_client_id' ); |
|
27 | - $secret_key = 'live' === $mode ? wpinv_get_option( 'paypal_secret' ) : wpinv_get_option( 'paypal_sandbox_secret' ); |
|
28 | - $url = self::get_api_url( 'v1/oauth2/token?grant_type=client_credentials', $mode ); |
|
26 | + $client_id = 'live' === $mode ? wpinv_get_option('paypal_client_id') : wpinv_get_option('paypal_sandbox_client_id'); |
|
27 | + $secret_key = 'live' === $mode ? wpinv_get_option('paypal_secret') : wpinv_get_option('paypal_sandbox_secret'); |
|
28 | + $url = self::get_api_url('v1/oauth2/token?grant_type=client_credentials', $mode); |
|
29 | 29 | |
30 | - if ( empty( $client_id ) || empty( $secret_key ) ) { |
|
31 | - return new \WP_Error( 'invalid_request', 'Missing client id or secret key.', array( 'status' => 400 ) ); |
|
30 | + if (empty($client_id) || empty($secret_key)) { |
|
31 | + return new \WP_Error('invalid_request', 'Missing client id or secret key.', array('status' => 400)); |
|
32 | 32 | } |
33 | 33 | |
34 | - $args = array( |
|
34 | + $args = array( |
|
35 | 35 | 'method' => 'POST', |
36 | 36 | 'timeout' => 30, |
37 | 37 | 'headers' => array( |
38 | - 'Authorization' => 'Basic ' . base64_encode( $client_id . ':' . $secret_key ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
38 | + 'Authorization' => 'Basic ' . base64_encode($client_id . ':' . $secret_key), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
|
39 | 39 | 'Accept' => 'application/json', |
40 | 40 | 'Content-Type' => 'application/x-www-form-urlencoded', |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - $response = self::response_or_error( wp_remote_post( $url, $args ) ); |
|
44 | + $response = self::response_or_error(wp_remote_post($url, $args)); |
|
45 | 45 | |
46 | - if ( is_wp_error( $response ) ) { |
|
46 | + if (is_wp_error($response)) { |
|
47 | 47 | return $response; |
48 | 48 | } |
49 | 49 | |
50 | - if ( ! isset( $response->access_token ) ) { |
|
51 | - return new \WP_Error( 'invalid_request', 'Could not create token.', array( 'status' => 400 ) ); |
|
50 | + if (!isset($response->access_token)) { |
|
51 | + return new \WP_Error('invalid_request', 'Could not create token.', array('status' => 400)); |
|
52 | 52 | } |
53 | 53 | |
54 | - set_transient( 'getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600 ); |
|
54 | + set_transient('getpaid_paypal_' . $mode . '_token', $response->access_token, $response->expires_in - 600); |
|
55 | 55 | return $response->access_token; |
56 | 56 | } |
57 | 57 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string $endpoint |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public static function get_api_url( $endpoint = '', $mode = 'live' ) { |
|
65 | - $endpoint = ltrim( $endpoint, '/' ); |
|
64 | + public static function get_api_url($endpoint = '', $mode = 'live') { |
|
65 | + $endpoint = ltrim($endpoint, '/'); |
|
66 | 66 | return 'live' === $mode ? 'https://api-m.paypal.com/' . $endpoint : 'https://api-m.sandbox.paypal.com/' . $endpoint; |
67 | 67 | } |
68 | 68 | |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return true|\WP_Error |
77 | 77 | */ |
78 | - public static function post( $path, $data, $mode = 'live', $method = 'POST' ) { |
|
78 | + public static function post($path, $data, $mode = 'live', $method = 'POST') { |
|
79 | 79 | |
80 | - $access_token = self::get_token( $mode ); |
|
80 | + $access_token = self::get_token($mode); |
|
81 | 81 | |
82 | - if ( is_wp_error( $access_token ) ) { |
|
82 | + if (is_wp_error($access_token)) { |
|
83 | 83 | return $access_token; |
84 | 84 | } |
85 | 85 | |
86 | - $url = self::get_api_url( $path, $mode ); |
|
86 | + $url = self::get_api_url($path, $mode); |
|
87 | 87 | $args = array( |
88 | 88 | 'method' => $method, |
89 | 89 | 'headers' => array( |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | ), |
93 | 93 | ); |
94 | 94 | |
95 | - if( ! empty( $data )) { |
|
96 | - $args['body'] = wp_json_encode( $data ); |
|
95 | + if (!empty($data)) { |
|
96 | + $args['body'] = wp_json_encode($data); |
|
97 | 97 | } |
98 | 98 | |
99 | - return self::response_or_error( wp_remote_post( $url, $args ) ); |
|
99 | + return self::response_or_error(wp_remote_post($url, $args)); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * @param string $method |
107 | 107 | * @return object|\WP_Error |
108 | 108 | */ |
109 | - public static function get( $path, $mode = 'live', $method = 'GET' ) { |
|
109 | + public static function get($path, $mode = 'live', $method = 'GET') { |
|
110 | 110 | |
111 | - $access_token = self::get_token( $mode ); |
|
111 | + $access_token = self::get_token($mode); |
|
112 | 112 | |
113 | - if ( is_wp_error( $access_token ) ) { |
|
113 | + if (is_wp_error($access_token)) { |
|
114 | 114 | return $access_token; |
115 | 115 | } |
116 | 116 | |
117 | - $url = self::get_api_url( $path, $mode ); |
|
117 | + $url = self::get_api_url($path, $mode); |
|
118 | 118 | $args = array( |
119 | 119 | 'method' => $method, |
120 | 120 | 'headers' => array( |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ), |
123 | 123 | ); |
124 | 124 | |
125 | - return self::response_or_error( wp_remote_get( $url, $args ) ); |
|
125 | + return self::response_or_error(wp_remote_get($url, $args)); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -133,33 +133,33 @@ discard block |
||
133 | 133 | * @param \WP_Error|array $response |
134 | 134 | * @return \WP_Error|object |
135 | 135 | */ |
136 | - public static function response_or_error( $response ) { |
|
136 | + public static function response_or_error($response) { |
|
137 | 137 | |
138 | - if ( is_wp_error( $response ) ) { |
|
139 | - return new \WP_Error( 'paypal_error', __( 'There was a problem connecting to the PayPal API endpoint.', 'invoicing' ) ); |
|
138 | + if (is_wp_error($response)) { |
|
139 | + return new \WP_Error('paypal_error', __('There was a problem connecting to the PayPal API endpoint.', 'invoicing')); |
|
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $response['body'] ) ) { |
|
142 | + if (empty($response['body'])) { |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | - $response_body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
146 | + $response_body = json_decode(wp_remote_retrieve_body($response)); |
|
147 | 147 | |
148 | - if ( wp_remote_retrieve_response_code( $response ) > 299 ) { |
|
148 | + if (wp_remote_retrieve_response_code($response) > 299) { |
|
149 | 149 | |
150 | 150 | // Normal errors. |
151 | - if ( $response_body && isset( $response_body->message ) ) { |
|
151 | + if ($response_body && isset($response_body->message)) { |
|
152 | 152 | $error_message = $response_body->message; |
153 | 153 | |
154 | 154 | // Identity errors. |
155 | - } elseif ( $response_body && isset( $response_body->error_description ) ) { |
|
155 | + } elseif ($response_body && isset($response_body->error_description)) { |
|
156 | 156 | $error_message = $response_body->error_description; |
157 | - return new \WP_Error( 'paypal_error', wp_kses_post( $response_body->error_description ) ); |
|
157 | + return new \WP_Error('paypal_error', wp_kses_post($response_body->error_description)); |
|
158 | 158 | } else { |
159 | - $error_message = __( 'There was an error connecting to the PayPal API endpoint.', 'invoicing' ); |
|
159 | + $error_message = __('There was an error connecting to the PayPal API endpoint.', 'invoicing'); |
|
160 | 160 | } |
161 | 161 | |
162 | - return new \WP_Error( 'paypal_error', $error_message ); |
|
162 | + return new \WP_Error('paypal_error', $error_message); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $response_body; |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * @link https://developer.paypal.com/docs/api/orders/v2/#orders_get |
175 | 175 | * @return \WP_Error|object |
176 | 176 | */ |
177 | - public static function get_order( $order_id, $mode = 'live' ) { |
|
178 | - return self::get( '/v2/checkout/orders/' . $order_id, $mode ); |
|
177 | + public static function get_order($order_id, $mode = 'live') { |
|
178 | + return self::get('/v2/checkout/orders/' . $order_id, $mode); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get |
188 | 188 | * @return \WP_Error|object |
189 | 189 | */ |
190 | - public static function get_subscription( $subscription_id, $mode = 'live' ) { |
|
191 | - return self::get( '/v1/billing/subscriptions/' . $subscription_id, $mode ); |
|
190 | + public static function get_subscription($subscription_id, $mode = 'live') { |
|
191 | + return self::get('/v1/billing/subscriptions/' . $subscription_id, $mode); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions |
201 | 201 | * @return \WP_Error|object |
202 | 202 | */ |
203 | - public static function get_subscription_transaction( $subscription_id, $mode = 'live' ) { |
|
204 | - $start_time = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( '-1 day' ) ); |
|
205 | - $end_time = gmdate( 'Y-m-d\TH:i:s\Z' ); |
|
206 | - return self::get( "/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode ); |
|
203 | + public static function get_subscription_transaction($subscription_id, $mode = 'live') { |
|
204 | + $start_time = gmdate('Y-m-d\TH:i:s\Z', strtotime('-1 day')); |
|
205 | + $end_time = gmdate('Y-m-d\TH:i:s\Z'); |
|
206 | + return self::get("/v1/billing/subscriptions/$subscription_id/transactions?start_time=$start_time&end_time=$end_time", $mode); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -216,8 +216,8 @@ discard block |
||
216 | 216 | * @link https://developer.paypal.com/docs/api/payments/v2/#captures_refund |
217 | 217 | * @return \WP_Error|object |
218 | 218 | */ |
219 | - public static function refund_capture( $capture_id, $args = array(), $mode = 'live' ) { |
|
220 | - return self::post( '/v2/payments/captures/' . $capture_id . '/refund', $args, $mode ); |
|
219 | + public static function refund_capture($capture_id, $args = array(), $mode = 'live') { |
|
220 | + return self::post('/v2/payments/captures/' . $capture_id . '/refund', $args, $mode); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @link https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel |
231 | 231 | * @return \WP_Error|object |
232 | 232 | */ |
233 | - public static function cancel_subscription( $subscription_id, $args = array(), $mode = 'live' ) { |
|
234 | - return self::post( '/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode ); |
|
233 | + public static function cancel_subscription($subscription_id, $args = array(), $mode = 'live') { |
|
234 | + return self::post('/v1/billing/subscriptions/' . $subscription_id . '/cancel', $args, $mode); |
|
235 | 235 | } |
236 | 236 | } |
@@ -13,103 +13,103 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group', 'refunds' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
82 | - parent::__construct(); |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | + parent::__construct(); |
|
83 | 83 | |
84 | 84 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
86 | 86 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
87 | 87 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
88 | 88 | |
89 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | - |
|
95 | - if ( $this->enabled ) { |
|
96 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | - add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | - add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | - add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | - } |
|
89 | + add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | + |
|
95 | + if ( $this->enabled ) { |
|
96 | + add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | + add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | + add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | + add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | - * Process Payment. |
|
105 | - * |
|
106 | - * |
|
107 | - * @param WPInv_Invoice $invoice Invoice. |
|
108 | - * @param array $submission_data Posted checkout fields. |
|
109 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | + * Process Payment. |
|
105 | + * |
|
106 | + * |
|
107 | + * @param WPInv_Invoice $invoice Invoice. |
|
108 | + * @param array $submission_data Posted checkout fields. |
|
109 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
113 | 113 | |
114 | 114 | // Get redirect url. |
115 | 115 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Get the PayPal request URL for an invoice. |
|
136 | - * |
|
137 | - * @param WPInv_Invoice $invoice Invoice object. |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function get_request_url( $invoice ) { |
|
135 | + * Get the PayPal request URL for an invoice. |
|
136 | + * |
|
137 | + * @param WPInv_Invoice $invoice Invoice object. |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function get_request_url( $invoice ) { |
|
141 | 141 | |
142 | 142 | // Endpoint for this request |
143 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
143 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
144 | 144 | |
145 | 145 | // Retrieve paypal args. |
146 | 146 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -153,45 +153,45 @@ discard block |
||
153 | 153 | |
154 | 154 | return add_query_arg( $paypal_args, $this->endpoint ); |
155 | 155 | |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | 158 | /** |
159 | - * Get PayPal Args for passing to PP. |
|
160 | - * |
|
161 | - * @param WPInv_Invoice $invoice Invoice object. |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function get_paypal_args( $invoice ) { |
|
159 | + * Get PayPal Args for passing to PP. |
|
160 | + * |
|
161 | + * @param WPInv_Invoice $invoice Invoice object. |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function get_paypal_args( $invoice ) { |
|
165 | 165 | |
166 | 166 | // Whether or not to send the line items as one item. |
167 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | - |
|
169 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | - $force_one_line_item = true; |
|
171 | - } |
|
172 | - |
|
173 | - $paypal_args = apply_filters( |
|
174 | - 'getpaid_paypal_args', |
|
175 | - array_merge( |
|
176 | - $this->get_transaction_args( $invoice ), |
|
177 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | - ), |
|
179 | - $invoice |
|
180 | - ); |
|
181 | - |
|
182 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
167 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
168 | + |
|
169 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
170 | + $force_one_line_item = true; |
|
171 | + } |
|
172 | + |
|
173 | + $paypal_args = apply_filters( |
|
174 | + 'getpaid_paypal_args', |
|
175 | + array_merge( |
|
176 | + $this->get_transaction_args( $invoice ), |
|
177 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
178 | + ), |
|
179 | + $invoice |
|
180 | + ); |
|
181 | + |
|
182 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Get transaction args for paypal request. |
|
187 | - * |
|
188 | - * @param WPInv_Invoice $invoice Invoice object. |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function get_transaction_args( $invoice ) { |
|
186 | + * Get transaction args for paypal request. |
|
187 | + * |
|
188 | + * @param WPInv_Invoice $invoice Invoice object. |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function get_transaction_args( $invoice ) { |
|
192 | 192 | |
193 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | - return array( |
|
193 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
194 | + return array( |
|
195 | 195 | 'cmd' => '_cart', |
196 | 196 | 'business' => $email, |
197 | 197 | 'no_shipping' => '1', |
@@ -216,16 +216,16 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Get line item args for paypal request. |
|
220 | - * |
|
221 | - * @param WPInv_Invoice $invoice Invoice object. |
|
222 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | + * Get line item args for paypal request. |
|
220 | + * |
|
221 | + * @param WPInv_Invoice $invoice Invoice object. |
|
222 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
226 | 226 | |
227 | 227 | // Maybe send invoice as a single item. |
228 | - if ( $force_one_line_item ) { |
|
228 | + if ( $force_one_line_item ) { |
|
229 | 229 | return $this->get_line_item_args_single_item( $invoice ); |
230 | 230 | } |
231 | 231 | |
@@ -245,134 +245,134 @@ discard block |
||
245 | 245 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
246 | 246 | } |
247 | 247 | |
248 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
248 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * Get line item args for paypal request as a single line item. |
|
254 | - * |
|
255 | - * @param WPInv_Invoice $invoice Invoice object. |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - protected function get_line_item_args_single_item( $invoice ) { |
|
259 | - $this->delete_line_items(); |
|
253 | + * Get line item args for paypal request as a single line item. |
|
254 | + * |
|
255 | + * @param WPInv_Invoice $invoice Invoice object. |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + protected function get_line_item_args_single_item( $invoice ) { |
|
259 | + $this->delete_line_items(); |
|
260 | 260 | |
261 | 261 | $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
262 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
262 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
263 | 263 | |
264 | - return $this->get_line_items(); |
|
264 | + return $this->get_line_items(); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | - * Return all line items. |
|
269 | - */ |
|
270 | - protected function get_line_items() { |
|
271 | - return $this->line_items; |
|
272 | - } |
|
268 | + * Return all line items. |
|
269 | + */ |
|
270 | + protected function get_line_items() { |
|
271 | + return $this->line_items; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | /** |
275 | - * Remove all line items. |
|
276 | - */ |
|
277 | - protected function delete_line_items() { |
|
278 | - $this->line_items = array(); |
|
275 | + * Remove all line items. |
|
276 | + */ |
|
277 | + protected function delete_line_items() { |
|
278 | + $this->line_items = array(); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Prepare line items to send to paypal. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - */ |
|
286 | - protected function prepare_line_items( $invoice ) { |
|
287 | - $this->delete_line_items(); |
|
288 | - |
|
289 | - // Items. |
|
290 | - foreach ( $invoice->get_items() as $item ) { |
|
291 | - $amount = $item->get_price(); |
|
292 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
282 | + * Prepare line items to send to paypal. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + */ |
|
286 | + protected function prepare_line_items( $invoice ) { |
|
287 | + $this->delete_line_items(); |
|
288 | + |
|
289 | + // Items. |
|
290 | + foreach ( $invoice->get_items() as $item ) { |
|
291 | + $amount = $item->get_price(); |
|
292 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
293 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Fees. |
297 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
297 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
298 | 298 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
299 | 299 | } |
300 | 300 | |
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Add PayPal Line Item. |
|
305 | - * |
|
306 | - * @param string $item_name Item name. |
|
307 | - * @param float $quantity Item quantity. |
|
308 | - * @param float $amount Amount. |
|
309 | - * @param string $item_number Item number. |
|
310 | - */ |
|
311 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | - |
|
314 | - /** |
|
315 | - * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | - */ |
|
317 | - $item_name = str_replace( "#", "", $item_name ); |
|
318 | - |
|
319 | - $item = apply_filters( |
|
320 | - 'getpaid_paypal_line_item', |
|
321 | - array( |
|
322 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | - 'quantity' => (float) $quantity, |
|
324 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | - 'item_number' => $item_number, |
|
326 | - ), |
|
327 | - $item_name, |
|
328 | - $quantity, |
|
329 | - $amount, |
|
330 | - $item_number |
|
331 | - ); |
|
332 | - |
|
333 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
304 | + * Add PayPal Line Item. |
|
305 | + * |
|
306 | + * @param string $item_name Item name. |
|
307 | + * @param float $quantity Item quantity. |
|
308 | + * @param float $amount Amount. |
|
309 | + * @param string $item_number Item number. |
|
310 | + */ |
|
311 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
313 | + |
|
314 | + /** |
|
315 | + * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
|
316 | + */ |
|
317 | + $item_name = str_replace( "#", "", $item_name ); |
|
318 | + |
|
319 | + $item = apply_filters( |
|
320 | + 'getpaid_paypal_line_item', |
|
321 | + array( |
|
322 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
323 | + 'quantity' => (float) $quantity, |
|
324 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
325 | + 'item_number' => $item_number, |
|
326 | + ), |
|
327 | + $item_name, |
|
328 | + $quantity, |
|
329 | + $amount, |
|
330 | + $item_number |
|
331 | + ); |
|
332 | + |
|
333 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
334 | 334 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
335 | 335 | |
336 | 336 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
337 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
337 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | - * |
|
344 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | - * |
|
346 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | - $max_paypal_length = 2083; |
|
352 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | - |
|
354 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | - return $paypal_args; |
|
356 | - } |
|
357 | - |
|
358 | - return apply_filters( |
|
359 | - 'getpaid_paypal_args', |
|
360 | - array_merge( |
|
361 | - $this->get_transaction_args( $invoice ), |
|
362 | - $this->get_line_item_args( $invoice, true ) |
|
363 | - ), |
|
364 | - $invoice |
|
365 | - ); |
|
342 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
343 | + * |
|
344 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
345 | + * |
|
346 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
347 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
351 | + $max_paypal_length = 2083; |
|
352 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
353 | + |
|
354 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
355 | + return $paypal_args; |
|
356 | + } |
|
357 | + |
|
358 | + return apply_filters( |
|
359 | + 'getpaid_paypal_args', |
|
360 | + array_merge( |
|
361 | + $this->get_transaction_args( $invoice ), |
|
362 | + $this->get_line_item_args( $invoice, true ) |
|
363 | + ), |
|
364 | + $invoice |
|
365 | + ); |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
370 | - * Processes recurring invoices. |
|
371 | - * |
|
372 | - * @param array $paypal_args PayPal args. |
|
373 | - * @param WPInv_Invoice $invoice Invoice object. |
|
374 | - */ |
|
375 | - public function process_subscription( $paypal_args, $invoice ) { |
|
370 | + * Processes recurring invoices. |
|
371 | + * |
|
372 | + * @param array $paypal_args PayPal args. |
|
373 | + * @param WPInv_Invoice $invoice Invoice object. |
|
374 | + */ |
|
375 | + public function process_subscription( $paypal_args, $invoice ) { |
|
376 | 376 | |
377 | 377 | // Make sure this is a subscription. |
378 | 378 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -393,21 +393,21 @@ discard block |
||
393 | 393 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
394 | 394 | $subscription_item = $invoice->get_recurring( true ); |
395 | 395 | |
396 | - // Convert 365 days to 1 year. |
|
397 | - if ( 'D' == $period && 365 == $interval ) { |
|
398 | - $period = 'Y'; |
|
399 | - $interval = 1; |
|
400 | - } |
|
396 | + // Convert 365 days to 1 year. |
|
397 | + if ( 'D' == $period && 365 == $interval ) { |
|
398 | + $period = 'Y'; |
|
399 | + $interval = 1; |
|
400 | + } |
|
401 | 401 | |
402 | 402 | if ( $subscription_item->has_free_trial() ) { |
403 | 403 | |
404 | 404 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
405 | 405 | |
406 | - // Trial period length. |
|
407 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
406 | + // Trial period length. |
|
407 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
408 | 408 | |
409 | - // Trial period. |
|
410 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
409 | + // Trial period. |
|
410 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
411 | 411 | |
412 | 412 | } elseif ( $initial_amount != $recurring_amount ) { |
413 | 413 | |
@@ -430,40 +430,40 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | // We have a recurring payment |
433 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
433 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
434 | 434 | |
435 | - // Subscription price |
|
436 | - $paypal_args['a3'] = $recurring_amount; |
|
435 | + // Subscription price |
|
436 | + $paypal_args['a3'] = $recurring_amount; |
|
437 | 437 | |
438 | - // Subscription duration |
|
439 | - $paypal_args['p3'] = $interval; |
|
438 | + // Subscription duration |
|
439 | + $paypal_args['p3'] = $interval; |
|
440 | 440 | |
441 | - // Subscription period |
|
442 | - $paypal_args['t3'] = $period; |
|
441 | + // Subscription period |
|
442 | + $paypal_args['t3'] = $period; |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Recurring payments |
447 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
447 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
448 | 448 | |
449 | - // Non-recurring payments |
|
450 | - $paypal_args['src'] = 0; |
|
449 | + // Non-recurring payments |
|
450 | + $paypal_args['src'] = 0; |
|
451 | 451 | |
452 | - } else { |
|
452 | + } else { |
|
453 | 453 | |
454 | - $paypal_args['src'] = 1; |
|
454 | + $paypal_args['src'] = 1; |
|
455 | 455 | |
456 | - if ( $bill_times > 0 ) { |
|
456 | + if ( $bill_times > 0 ) { |
|
457 | 457 | |
458 | - // An initial period is being used to charge a sign-up fee |
|
459 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | - $bill_times--; |
|
461 | - } |
|
458 | + // An initial period is being used to charge a sign-up fee |
|
459 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
460 | + $bill_times--; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | // Make sure it's not over the max of 52 |
464 | 464 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // Force return URL so that order description & instructions display |
@@ -475,115 +475,115 @@ discard block |
||
475 | 475 | if ( isset( $paypal_args[ $arg ] ) ) { |
476 | 476 | unset( $paypal_args[ $arg ] ); |
477 | 477 | } |
478 | - } |
|
478 | + } |
|
479 | 479 | |
480 | 480 | return apply_filters( |
481 | - 'getpaid_paypal_subscription_args', |
|
482 | - $paypal_args, |
|
483 | - $invoice |
|
481 | + 'getpaid_paypal_subscription_args', |
|
482 | + $paypal_args, |
|
483 | + $invoice |
|
484 | + ); |
|
485 | + |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Refunds an invoice remotely. |
|
490 | + * |
|
491 | + * @since 2.8.24 |
|
492 | + * @param WPInv_Invoice $invoice Invoice object. |
|
493 | + */ |
|
494 | + public function refund_invoice( $invoice ) { |
|
495 | + |
|
496 | + if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | + return; |
|
498 | + } |
|
499 | + |
|
500 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | + $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | + |
|
503 | + if ( is_wp_error( $result ) ) { |
|
504 | + $invoice->add_system_note( |
|
505 | + sprintf( |
|
506 | + // translators: %s is the error message. |
|
507 | + __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | + $invoice->get_id(), |
|
509 | + $result->get_error_message() |
|
510 | + ) |
|
511 | + ); |
|
512 | + } else { |
|
513 | + $invoice->add_system_note( |
|
514 | + sprintf( |
|
515 | + // translators: %s is the refund ID. |
|
516 | + __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | + $invoice->get_id(), |
|
518 | + $result->id |
|
519 | + ) |
|
520 | + ); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Cancels a subscription remotely. |
|
526 | + * |
|
527 | + * @since 2.8.24 |
|
528 | + * @param WPInv_Subscription $subscription Subscription object. |
|
529 | + */ |
|
530 | + public function subscription_cancelled( $subscription ) { |
|
531 | + |
|
532 | + if ( $subscription->get_gateway() != $this->id ) { |
|
533 | + return; |
|
534 | + } |
|
535 | + |
|
536 | + $invoice = $subscription->get_parent_invoice(); |
|
537 | + |
|
538 | + // Abort if the parent invoice does not exist. |
|
539 | + if ( ! $invoice->exists() ) { |
|
540 | + return; |
|
541 | + } |
|
542 | + |
|
543 | + $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | + $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | + $invoice->get_remote_subscription_id(), |
|
546 | + array( |
|
547 | + 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | + ), |
|
549 | + $mode |
|
484 | 550 | ); |
485 | 551 | |
552 | + if ( is_wp_error( $result ) ) { |
|
553 | + |
|
554 | + $error = sprintf( |
|
555 | + // translators: %s is the subscription ID. |
|
556 | + __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | + $subscription->get_id() |
|
558 | + ); |
|
559 | + |
|
560 | + getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | + |
|
562 | + if ( ! is_admin() ) { |
|
563 | + wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | + } |
|
565 | + |
|
566 | + return; |
|
567 | + } |
|
568 | + |
|
569 | + if ( is_admin() ) { |
|
570 | + getpaid_admin()->show_success( |
|
571 | + sprintf( |
|
572 | + // translators: %s is the subscription ID. |
|
573 | + __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | + $subscription->get_id() |
|
575 | + ) |
|
576 | + ); |
|
577 | + } |
|
578 | + |
|
486 | 579 | } |
487 | 580 | |
488 | - /** |
|
489 | - * Refunds an invoice remotely. |
|
490 | - * |
|
491 | - * @since 2.8.24 |
|
492 | - * @param WPInv_Invoice $invoice Invoice object. |
|
493 | - */ |
|
494 | - public function refund_invoice( $invoice ) { |
|
495 | - |
|
496 | - if ( $invoice->get_gateway() !== $this->id ) { |
|
497 | - return; |
|
498 | - } |
|
499 | - |
|
500 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | - $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
502 | - |
|
503 | - if ( is_wp_error( $result ) ) { |
|
504 | - $invoice->add_system_note( |
|
505 | - sprintf( |
|
506 | - // translators: %s is the error message. |
|
507 | - __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
508 | - $invoice->get_id(), |
|
509 | - $result->get_error_message() |
|
510 | - ) |
|
511 | - ); |
|
512 | - } else { |
|
513 | - $invoice->add_system_note( |
|
514 | - sprintf( |
|
515 | - // translators: %s is the refund ID. |
|
516 | - __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
517 | - $invoice->get_id(), |
|
518 | - $result->id |
|
519 | - ) |
|
520 | - ); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Cancels a subscription remotely. |
|
526 | - * |
|
527 | - * @since 2.8.24 |
|
528 | - * @param WPInv_Subscription $subscription Subscription object. |
|
529 | - */ |
|
530 | - public function subscription_cancelled( $subscription ) { |
|
531 | - |
|
532 | - if ( $subscription->get_gateway() != $this->id ) { |
|
533 | - return; |
|
534 | - } |
|
535 | - |
|
536 | - $invoice = $subscription->get_parent_invoice(); |
|
537 | - |
|
538 | - // Abort if the parent invoice does not exist. |
|
539 | - if ( ! $invoice->exists() ) { |
|
540 | - return; |
|
541 | - } |
|
542 | - |
|
543 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
544 | - $result = GetPaid_PayPal_API::cancel_subscription( |
|
545 | - $invoice->get_remote_subscription_id(), |
|
546 | - array( |
|
547 | - 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
548 | - ), |
|
549 | - $mode |
|
550 | - ); |
|
551 | - |
|
552 | - if ( is_wp_error( $result ) ) { |
|
553 | - |
|
554 | - $error = sprintf( |
|
555 | - // translators: %s is the subscription ID. |
|
556 | - __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
557 | - $subscription->get_id() |
|
558 | - ); |
|
559 | - |
|
560 | - getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
561 | - |
|
562 | - if ( ! is_admin() ) { |
|
563 | - wpinv_set_error( $result->get_error_code(), $error ); |
|
564 | - } |
|
565 | - |
|
566 | - return; |
|
567 | - } |
|
568 | - |
|
569 | - if ( is_admin() ) { |
|
570 | - getpaid_admin()->show_success( |
|
571 | - sprintf( |
|
572 | - // translators: %s is the subscription ID. |
|
573 | - __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
574 | - $subscription->get_id() |
|
575 | - ) |
|
576 | - ); |
|
577 | - } |
|
578 | - |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Processes ipns and marks payments as complete. |
|
583 | - * |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - public function verify_ipn() { |
|
581 | + /** |
|
582 | + * Processes ipns and marks payments as complete. |
|
583 | + * |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + public function verify_ipn() { |
|
587 | 587 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
588 | 588 | } |
589 | 589 | |
@@ -593,19 +593,19 @@ discard block |
||
593 | 593 | public function sandbox_notice() { |
594 | 594 | |
595 | 595 | return sprintf( |
596 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | - '</a>' |
|
599 | - ); |
|
596 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
597 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
598 | + '</a>' |
|
599 | + ); |
|
600 | 600 | |
601 | 601 | } |
602 | 602 | |
603 | - /** |
|
604 | - * Filters the gateway settings. |
|
605 | - * |
|
606 | - * @param array $admin_settings |
|
607 | - */ |
|
608 | - public function admin_settings( $admin_settings ) { |
|
603 | + /** |
|
604 | + * Filters the gateway settings. |
|
605 | + * |
|
606 | + * @param array $admin_settings |
|
607 | + */ |
|
608 | + public function admin_settings( $admin_settings ) { |
|
609 | 609 | |
610 | 610 | $currencies = sprintf( |
611 | 611 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -615,66 +615,66 @@ discard block |
||
615 | 615 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
616 | 616 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
617 | 617 | |
618 | - // Access tokens. |
|
619 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
618 | + // Access tokens. |
|
619 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
621 | 621 | |
622 | - $admin_settings['paypal_connect'] = array( |
|
623 | - 'type' => 'hook', |
|
624 | - 'id' => 'paypal_connect', |
|
625 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | - ); |
|
622 | + $admin_settings['paypal_connect'] = array( |
|
623 | + 'type' => 'hook', |
|
624 | + 'id' => 'paypal_connect', |
|
625 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
626 | + ); |
|
627 | 627 | |
628 | 628 | $admin_settings['paypal_email'] = array( |
629 | 629 | 'type' => 'text', |
630 | - 'class' => 'live-auth-data', |
|
630 | + 'class' => 'live-auth-data', |
|
631 | 631 | 'id' => 'paypal_email', |
632 | 632 | 'name' => __( 'Live Email Address', 'invoicing' ), |
633 | 633 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
634 | 634 | ); |
635 | 635 | |
636 | - $admin_settings['paypal_sandbox_email'] = array( |
|
636 | + $admin_settings['paypal_sandbox_email'] = array( |
|
637 | 637 | 'type' => 'text', |
638 | - 'class' => 'sandbox-auth-data', |
|
638 | + 'class' => 'sandbox-auth-data', |
|
639 | 639 | 'id' => 'paypal_sandbox_email', |
640 | 640 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
641 | 641 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
642 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
642 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
643 | + ); |
|
644 | + |
|
645 | + // Client ID and secret. |
|
646 | + $admin_settings['paypal_client_id'] = array( |
|
647 | + 'type' => 'text', |
|
648 | + 'class' => 'live-auth-data', |
|
649 | + 'id' => 'paypal_client_id', |
|
650 | + 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | + 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | + ); |
|
653 | + |
|
654 | + $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | + 'type' => 'text', |
|
656 | + 'class' => 'sandbox-auth-data', |
|
657 | + 'id' => 'paypal_sandbox_client_id', |
|
658 | + 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | + 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | + 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
643 | 661 | ); |
644 | 662 | |
645 | - // Client ID and secret. |
|
646 | - $admin_settings['paypal_client_id'] = array( |
|
647 | - 'type' => 'text', |
|
648 | - 'class' => 'live-auth-data', |
|
649 | - 'id' => 'paypal_client_id', |
|
650 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
652 | - ); |
|
653 | - |
|
654 | - $admin_settings['paypal_sandbox_client_id'] = array( |
|
655 | - 'type' => 'text', |
|
656 | - 'class' => 'sandbox-auth-data', |
|
657 | - 'id' => 'paypal_sandbox_client_id', |
|
658 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
661 | - ); |
|
662 | - |
|
663 | - $admin_settings['paypal_secret'] = array( |
|
664 | - 'type' => 'text', |
|
665 | - 'class' => 'live-auth-data', |
|
666 | - 'id' => 'paypal_secret', |
|
667 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | - ); |
|
670 | - |
|
671 | - $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | - 'type' => 'text', |
|
673 | - 'class' => 'sandbox-auth-data', |
|
674 | - 'id' => 'paypal_sandbox_secret', |
|
675 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | - ); |
|
663 | + $admin_settings['paypal_secret'] = array( |
|
664 | + 'type' => 'text', |
|
665 | + 'class' => 'live-auth-data', |
|
666 | + 'id' => 'paypal_secret', |
|
667 | + 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | + 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
669 | + ); |
|
670 | + |
|
671 | + $admin_settings['paypal_sandbox_secret'] = array( |
|
672 | + 'type' => 'text', |
|
673 | + 'class' => 'sandbox-auth-data', |
|
674 | + 'id' => 'paypal_sandbox_secret', |
|
675 | + 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | + 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
677 | + ); |
|
678 | 678 | |
679 | 679 | $admin_settings['paypal_ipn_url'] = array( |
680 | 680 | 'type' => 'ipn_url', |
@@ -685,57 +685,57 @@ discard block |
||
685 | 685 | 'readonly' => true, |
686 | 686 | ); |
687 | 687 | |
688 | - return $admin_settings; |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Retrieves the URL to cancel a subscription. |
|
693 | - * |
|
694 | - * @param string $url |
|
695 | - * @param WPInv_Subscription $subscription |
|
696 | - */ |
|
697 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | - |
|
699 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | - return $url; |
|
701 | - } |
|
702 | - |
|
703 | - // Get the PayPal profile ID. |
|
704 | - $profile_id = $subscription->get_profile_id(); |
|
705 | - |
|
706 | - // Bail if no profile ID. |
|
707 | - if ( empty( $profile_id ) ) { |
|
708 | - return $url; |
|
709 | - } |
|
710 | - |
|
711 | - $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | - $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | - } |
|
715 | - |
|
716 | - return sprintf( $cancel_url, $profile_id ); |
|
717 | - } |
|
718 | - |
|
719 | - /** |
|
720 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | - * |
|
722 | - * |
|
688 | + return $admin_settings; |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Retrieves the URL to cancel a subscription. |
|
693 | + * |
|
694 | + * @param string $url |
|
695 | + * @param WPInv_Subscription $subscription |
|
696 | + */ |
|
697 | + public function filter_cancel_subscription_url( $url, $subscription ) { |
|
698 | + |
|
699 | + if ( $this->id !== $subscription->get_gateway() ) { |
|
700 | + return $url; |
|
701 | + } |
|
702 | + |
|
703 | + // Get the PayPal profile ID. |
|
704 | + $profile_id = $subscription->get_profile_id(); |
|
705 | + |
|
706 | + // Bail if no profile ID. |
|
707 | + if ( empty( $profile_id ) ) { |
|
708 | + return $url; |
|
709 | + } |
|
710 | + |
|
711 | + $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
712 | + if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
713 | + $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
714 | + } |
|
715 | + |
|
716 | + return sprintf( $cancel_url, $profile_id ); |
|
717 | + } |
|
718 | + |
|
719 | + /** |
|
720 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
721 | + * |
|
722 | + * |
|
723 | 723 | * @param array $data |
724 | 724 | * @return string |
725 | - */ |
|
726 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Retrieves the PayPal connect URL. |
|
732 | - * |
|
733 | - * |
|
725 | + */ |
|
726 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Retrieves the PayPal connect URL. |
|
732 | + * |
|
733 | + * |
|
734 | 734 | * @param bool $is_sandbox |
735 | - * @param string $redirect |
|
735 | + * @param string $redirect |
|
736 | 736 | * @return string |
737 | - */ |
|
738 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
737 | + */ |
|
738 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
739 | 739 | |
740 | 740 | $redirect_url = add_query_arg( |
741 | 741 | array( |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | 'tab' => 'gateways', |
746 | 746 | 'section' => 'paypal', |
747 | 747 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
748 | - 'redirect' => urlencode( $redirect ), |
|
748 | + 'redirect' => urlencode( $redirect ), |
|
749 | 749 | ), |
750 | 750 | admin_url( 'admin.php' ) |
751 | 751 | ); |
@@ -760,12 +760,12 @@ discard block |
||
760 | 760 | |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Generates settings page js. |
|
765 | - * |
|
763 | + /** |
|
764 | + * Generates settings page js. |
|
765 | + * |
|
766 | 766 | * @return void |
767 | - */ |
|
768 | - public static function display_connect_buttons() { |
|
767 | + */ |
|
768 | + public static function display_connect_buttons() { |
|
769 | 769 | |
770 | 770 | ?> |
771 | 771 | <div class="wpinv-paypal-connect-live"> |
@@ -807,70 +807,70 @@ discard block |
||
807 | 807 | <?php |
808 | 808 | } |
809 | 809 | |
810 | - /** |
|
811 | - * Connects to PayPal. |
|
812 | - * |
|
813 | - * @param array $data Connection data. |
|
814 | - * @return void |
|
815 | - */ |
|
816 | - public function connect_paypal( $data ) { |
|
817 | - |
|
818 | - $sandbox = $this->is_sandbox(); |
|
819 | - $data = wp_unslash( $data ); |
|
820 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | - |
|
822 | - if ( isset( $data['live_mode'] ) ) { |
|
823 | - $sandbox = empty( $data['live_mode'] ); |
|
824 | - } |
|
825 | - |
|
826 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | - wpinv_update_option( 'paypal_active', 1 ); |
|
828 | - |
|
829 | - if ( ! empty( $data['error_description'] ) ) { |
|
830 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | - } else { |
|
832 | - |
|
833 | - // Retrieve the user info. |
|
834 | - $user_info = wp_remote_get( |
|
835 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | - array( |
|
837 | - |
|
838 | - 'headers' => array( |
|
839 | - 'Authorization' => 'Bearer ' . $access_token, |
|
840 | - 'Content-type' => 'application/json', |
|
841 | - ), |
|
842 | - |
|
843 | - ) |
|
844 | - ); |
|
845 | - |
|
846 | - if ( is_wp_error( $user_info ) ) { |
|
847 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | - } else { |
|
849 | - |
|
850 | - // Create application. |
|
851 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | - |
|
853 | - if ( $sandbox ) { |
|
854 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | - } else { |
|
859 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | - } |
|
864 | - } |
|
865 | - } |
|
866 | - |
|
867 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | - |
|
869 | - if ( isset( $data['step'] ) ) { |
|
870 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | - } |
|
872 | - wp_redirect( $redirect ); |
|
873 | - exit; |
|
874 | - } |
|
810 | + /** |
|
811 | + * Connects to PayPal. |
|
812 | + * |
|
813 | + * @param array $data Connection data. |
|
814 | + * @return void |
|
815 | + */ |
|
816 | + public function connect_paypal( $data ) { |
|
817 | + |
|
818 | + $sandbox = $this->is_sandbox(); |
|
819 | + $data = wp_unslash( $data ); |
|
820 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
821 | + |
|
822 | + if ( isset( $data['live_mode'] ) ) { |
|
823 | + $sandbox = empty( $data['live_mode'] ); |
|
824 | + } |
|
825 | + |
|
826 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | + wpinv_update_option( 'paypal_active', 1 ); |
|
828 | + |
|
829 | + if ( ! empty( $data['error_description'] ) ) { |
|
830 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
831 | + } else { |
|
832 | + |
|
833 | + // Retrieve the user info. |
|
834 | + $user_info = wp_remote_get( |
|
835 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | + array( |
|
837 | + |
|
838 | + 'headers' => array( |
|
839 | + 'Authorization' => 'Bearer ' . $access_token, |
|
840 | + 'Content-type' => 'application/json', |
|
841 | + ), |
|
842 | + |
|
843 | + ) |
|
844 | + ); |
|
845 | + |
|
846 | + if ( is_wp_error( $user_info ) ) { |
|
847 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
848 | + } else { |
|
849 | + |
|
850 | + // Create application. |
|
851 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
852 | + |
|
853 | + if ( $sandbox ) { |
|
854 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
858 | + } else { |
|
859 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
863 | + } |
|
864 | + } |
|
865 | + } |
|
866 | + |
|
867 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
868 | + |
|
869 | + if ( isset( $data['step'] ) ) { |
|
870 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
871 | + } |
|
872 | + wp_redirect( $redirect ); |
|
873 | + exit; |
|
874 | + } |
|
875 | 875 | |
876 | 876 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group', 'refunds' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group', 'refunds'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -81,22 +81,22 @@ discard block |
||
81 | 81 | public function __construct() { |
82 | 82 | parent::__construct(); |
83 | 83 | |
84 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
86 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
87 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
88 | - |
|
89 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
90 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
94 | - |
|
95 | - if ( $this->enabled ) { |
|
96 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
97 | - add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) ); |
|
98 | - add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) ); |
|
99 | - add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) ); |
|
84 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
86 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
87 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
88 | + |
|
89 | + add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2); |
|
90 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
91 | + add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2); |
|
92 | + add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal')); |
|
93 | + add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons')); |
|
94 | + |
|
95 | + if ($this->enabled) { |
|
96 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
97 | + add_action('getpaid_paypal_subscription_cancelled', array($this, 'subscription_cancelled')); |
|
98 | + add_action('getpaid_delete_subscription', array($this, 'subscription_cancelled')); |
|
99 | + add_action('getpaid_refund_invoice_remotely', array($this, 'refund_invoice')); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -109,16 +109,16 @@ discard block |
||
109 | 109 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
112 | + public function process_payment($invoice, $submission_data, $submission) { |
|
113 | 113 | |
114 | 114 | // Get redirect url. |
115 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
115 | + $paypal_redirect = $this->get_request_url($invoice); |
|
116 | 116 | |
117 | 117 | // Add a note about the request url. |
118 | 118 | $invoice->add_note( |
119 | 119 | sprintf( |
120 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
121 | - esc_url( $paypal_redirect ) |
|
120 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
121 | + esc_url($paypal_redirect) |
|
122 | 122 | ), |
123 | 123 | false, |
124 | 124 | false, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ); |
127 | 127 | |
128 | 128 | // Redirect to PayPal |
129 | - wp_redirect( $paypal_redirect ); |
|
129 | + wp_redirect($paypal_redirect); |
|
130 | 130 | exit; |
131 | 131 | |
132 | 132 | } |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | * @param WPInv_Invoice $invoice Invoice object. |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function get_request_url( $invoice ) { |
|
140 | + public function get_request_url($invoice) { |
|
141 | 141 | |
142 | 142 | // Endpoint for this request |
143 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
143 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
144 | 144 | |
145 | 145 | // Retrieve paypal args. |
146 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
146 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
147 | 147 | |
148 | - if ( $invoice->is_recurring() ) { |
|
148 | + if ($invoice->is_recurring()) { |
|
149 | 149 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
150 | 150 | } else { |
151 | 151 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
152 | 152 | } |
153 | 153 | |
154 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
154 | + return add_query_arg($paypal_args, $this->endpoint); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -161,25 +161,25 @@ discard block |
||
161 | 161 | * @param WPInv_Invoice $invoice Invoice object. |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - protected function get_paypal_args( $invoice ) { |
|
164 | + protected function get_paypal_args($invoice) { |
|
165 | 165 | |
166 | 166 | // Whether or not to send the line items as one item. |
167 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
167 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
168 | 168 | |
169 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
169 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
170 | 170 | $force_one_line_item = true; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $paypal_args = apply_filters( |
174 | 174 | 'getpaid_paypal_args', |
175 | 175 | array_merge( |
176 | - $this->get_transaction_args( $invoice ), |
|
177 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
176 | + $this->get_transaction_args($invoice), |
|
177 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
178 | 178 | ), |
179 | 179 | $invoice |
180 | 180 | ); |
181 | 181 | |
182 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
182 | + return $this->fix_request_length($invoice, $paypal_args); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @param WPInv_Invoice $invoice Invoice object. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - protected function get_transaction_args( $invoice ) { |
|
191 | + protected function get_transaction_args($invoice) { |
|
192 | 192 | |
193 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
193 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
194 | 194 | return array( |
195 | 195 | 'cmd' => '_cart', |
196 | 196 | 'business' => $email, |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | 'rm' => is_ssl() ? 2 : 1, |
202 | 202 | 'upload' => 1, |
203 | 203 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
204 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
205 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
206 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
207 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
204 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
205 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
206 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
207 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
208 | 208 | 'custom' => $invoice->get_id(), |
209 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
210 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
211 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
212 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
213 | - 'cbt' => get_bloginfo( 'name' ), |
|
209 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
210 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
211 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
212 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
213 | + 'cbt' => get_bloginfo('name'), |
|
214 | 214 | ); |
215 | 215 | |
216 | 216 | } |
@@ -222,30 +222,30 @@ discard block |
||
222 | 222 | * @param bool $force_one_line_item Create only one item for this invoice. |
223 | 223 | * @return array |
224 | 224 | */ |
225 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
225 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
226 | 226 | |
227 | 227 | // Maybe send invoice as a single item. |
228 | - if ( $force_one_line_item ) { |
|
229 | - return $this->get_line_item_args_single_item( $invoice ); |
|
228 | + if ($force_one_line_item) { |
|
229 | + return $this->get_line_item_args_single_item($invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | // Send each line item individually. |
233 | 233 | $line_item_args = array(); |
234 | 234 | |
235 | 235 | // Prepare line items. |
236 | - $this->prepare_line_items( $invoice ); |
|
236 | + $this->prepare_line_items($invoice); |
|
237 | 237 | |
238 | 238 | // Add taxes to the cart |
239 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
240 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
239 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
240 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Add discount. |
244 | - if ( $invoice->get_total_discount() > 0 ) { |
|
245 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
244 | + if ($invoice->get_total_discount() > 0) { |
|
245 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
246 | 246 | } |
247 | 247 | |
248 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
248 | + return array_merge($line_item_args, $this->get_line_items()); |
|
249 | 249 | |
250 | 250 | } |
251 | 251 | |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | * @param WPInv_Invoice $invoice Invoice object. |
256 | 256 | * @return array |
257 | 257 | */ |
258 | - protected function get_line_item_args_single_item( $invoice ) { |
|
258 | + protected function get_line_item_args_single_item($invoice) { |
|
259 | 259 | $this->delete_line_items(); |
260 | 260 | |
261 | - $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
|
262 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
261 | + $item_name = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number()); |
|
262 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
263 | 263 | |
264 | 264 | return $this->get_line_items(); |
265 | 265 | } |
@@ -283,19 +283,19 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | */ |
286 | - protected function prepare_line_items( $invoice ) { |
|
286 | + protected function prepare_line_items($invoice) { |
|
287 | 287 | $this->delete_line_items(); |
288 | 288 | |
289 | 289 | // Items. |
290 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | + foreach ($invoice->get_items() as $item) { |
|
291 | 291 | $amount = $item->get_price(); |
292 | 292 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
293 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
293 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Fees. |
297 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
298 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
297 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
298 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | } |
@@ -308,20 +308,20 @@ discard block |
||
308 | 308 | * @param float $amount Amount. |
309 | 309 | * @param string $item_number Item number. |
310 | 310 | */ |
311 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
312 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
311 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
312 | + $index = (count($this->line_items) / 4) + 1; |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)" |
316 | 316 | */ |
317 | - $item_name = str_replace( "#", "", $item_name ); |
|
317 | + $item_name = str_replace("#", "", $item_name); |
|
318 | 318 | |
319 | 319 | $item = apply_filters( |
320 | 320 | 'getpaid_paypal_line_item', |
321 | 321 | array( |
322 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
322 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
323 | 323 | 'quantity' => (float) $quantity, |
324 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
324 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
325 | 325 | 'item_number' => $item_number, |
326 | 326 | ), |
327 | 327 | $item_name, |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | $item_number |
331 | 331 | ); |
332 | 332 | |
333 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
334 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
333 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
334 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
335 | 335 | |
336 | 336 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
337 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
338 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
337 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
338 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -347,19 +347,19 @@ discard block |
||
347 | 347 | * @param array $paypal_args Arguments sent to Paypal in the request. |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
350 | + protected function fix_request_length($invoice, $paypal_args) { |
|
351 | 351 | $max_paypal_length = 2083; |
352 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
352 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
353 | 353 | |
354 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
354 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
355 | 355 | return $paypal_args; |
356 | 356 | } |
357 | 357 | |
358 | 358 | return apply_filters( |
359 | 359 | 'getpaid_paypal_args', |
360 | 360 | array_merge( |
361 | - $this->get_transaction_args( $invoice ), |
|
362 | - $this->get_line_item_args( $invoice, true ) |
|
361 | + $this->get_transaction_args($invoice), |
|
362 | + $this->get_line_item_args($invoice, true) |
|
363 | 363 | ), |
364 | 364 | $invoice |
365 | 365 | ); |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | * @param array $paypal_args PayPal args. |
373 | 373 | * @param WPInv_Invoice $invoice Invoice object. |
374 | 374 | */ |
375 | - public function process_subscription( $paypal_args, $invoice ) { |
|
375 | + public function process_subscription($paypal_args, $invoice) { |
|
376 | 376 | |
377 | 377 | // Make sure this is a subscription. |
378 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
378 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
379 | 379 | return $paypal_args; |
380 | 380 | } |
381 | 381 | |
@@ -383,23 +383,23 @@ discard block |
||
383 | 383 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
384 | 384 | |
385 | 385 | // Subscription name. |
386 | - $paypal_args['item_name'] = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() ); |
|
386 | + $paypal_args['item_name'] = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number()); |
|
387 | 387 | |
388 | 388 | // Get subscription args. |
389 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1 ) ); |
|
389 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
390 | 390 | $interval = (int) $subscription->get_frequency(); |
391 | 391 | $bill_times = (int) $subscription->get_bill_times(); |
392 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
393 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
394 | - $subscription_item = $invoice->get_recurring( true ); |
|
392 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
393 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
394 | + $subscription_item = $invoice->get_recurring(true); |
|
395 | 395 | |
396 | 396 | // Convert 365 days to 1 year. |
397 | - if ( 'D' == $period && 365 == $interval ) { |
|
397 | + if ('D' == $period && 365 == $interval) { |
|
398 | 398 | $period = 'Y'; |
399 | 399 | $interval = 1; |
400 | 400 | } |
401 | 401 | |
402 | - if ( $subscription_item->has_free_trial() ) { |
|
402 | + if ($subscription_item->has_free_trial()) { |
|
403 | 403 | |
404 | 404 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
405 | 405 | |
@@ -409,28 +409,28 @@ discard block |
||
409 | 409 | // Trial period. |
410 | 410 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
411 | 411 | |
412 | - } elseif ( $initial_amount != $recurring_amount ) { |
|
412 | + } elseif ($initial_amount != $recurring_amount) { |
|
413 | 413 | |
414 | 414 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
415 | 415 | |
416 | - if ( 1 == $bill_times ) { |
|
416 | + if (1 == $bill_times) { |
|
417 | 417 | $param_number = 3; |
418 | 418 | } else { |
419 | 419 | $param_number = 1; |
420 | 420 | } |
421 | 421 | |
422 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
422 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
423 | 423 | |
424 | 424 | // Sign Up interval |
425 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
425 | + $paypal_args['p' . $param_number] = $interval; |
|
426 | 426 | |
427 | 427 | // Sign Up unit of duration |
428 | - $paypal_args[ 't' . $param_number ] = $period; |
|
428 | + $paypal_args['t' . $param_number] = $period; |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | |
432 | 432 | // We have a recurring payment |
433 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
433 | + if (!isset($param_number) || 1 == $param_number) { |
|
434 | 434 | |
435 | 435 | // Subscription price |
436 | 436 | $paypal_args['a3'] = $recurring_amount; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } |
445 | 445 | |
446 | 446 | // Recurring payments |
447 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
447 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
448 | 448 | |
449 | 449 | // Non-recurring payments |
450 | 450 | $paypal_args['src'] = 0; |
@@ -453,15 +453,15 @@ discard block |
||
453 | 453 | |
454 | 454 | $paypal_args['src'] = 1; |
455 | 455 | |
456 | - if ( $bill_times > 0 ) { |
|
456 | + if ($bill_times > 0) { |
|
457 | 457 | |
458 | 458 | // An initial period is being used to charge a sign-up fee |
459 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
459 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
460 | 460 | $bill_times--; |
461 | 461 | } |
462 | 462 | |
463 | 463 | // Make sure it's not over the max of 52 |
464 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
464 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
465 | 465 | |
466 | 466 | } |
467 | 467 | } |
@@ -470,10 +470,10 @@ discard block |
||
470 | 470 | $paypal_args['rm'] = 2; |
471 | 471 | |
472 | 472 | // Get rid of redudant items. |
473 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
473 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
474 | 474 | |
475 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
476 | - unset( $paypal_args[ $arg ] ); |
|
475 | + if (isset($paypal_args[$arg])) { |
|
476 | + unset($paypal_args[$arg]); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
@@ -491,20 +491,20 @@ discard block |
||
491 | 491 | * @since 2.8.24 |
492 | 492 | * @param WPInv_Invoice $invoice Invoice object. |
493 | 493 | */ |
494 | - public function refund_invoice( $invoice ) { |
|
494 | + public function refund_invoice($invoice) { |
|
495 | 495 | |
496 | - if ( $invoice->get_gateway() !== $this->id ) { |
|
496 | + if ($invoice->get_gateway() !== $this->id) { |
|
497 | 497 | return; |
498 | 498 | } |
499 | 499 | |
500 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
501 | - $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode ); |
|
500 | + $mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live'; |
|
501 | + $result = GetPaid_PayPal_API::refund_capture($invoice->get_transaction_id(), array(), $mode); |
|
502 | 502 | |
503 | - if ( is_wp_error( $result ) ) { |
|
503 | + if (is_wp_error($result)) { |
|
504 | 504 | $invoice->add_system_note( |
505 | 505 | sprintf( |
506 | 506 | // translators: %s is the error message. |
507 | - __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ), |
|
507 | + __('An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing'), |
|
508 | 508 | $invoice->get_id(), |
509 | 509 | $result->get_error_message() |
510 | 510 | ) |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $invoice->add_system_note( |
514 | 514 | sprintf( |
515 | 515 | // translators: %s is the refund ID. |
516 | - __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ), |
|
516 | + __('Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing'), |
|
517 | 517 | $invoice->get_id(), |
518 | 518 | $result->id |
519 | 519 | ) |
@@ -527,50 +527,50 @@ discard block |
||
527 | 527 | * @since 2.8.24 |
528 | 528 | * @param WPInv_Subscription $subscription Subscription object. |
529 | 529 | */ |
530 | - public function subscription_cancelled( $subscription ) { |
|
530 | + public function subscription_cancelled($subscription) { |
|
531 | 531 | |
532 | - if ( $subscription->get_gateway() != $this->id ) { |
|
532 | + if ($subscription->get_gateway() != $this->id) { |
|
533 | 533 | return; |
534 | 534 | } |
535 | 535 | |
536 | 536 | $invoice = $subscription->get_parent_invoice(); |
537 | 537 | |
538 | 538 | // Abort if the parent invoice does not exist. |
539 | - if ( ! $invoice->exists() ) { |
|
539 | + if (!$invoice->exists()) { |
|
540 | 540 | return; |
541 | 541 | } |
542 | 542 | |
543 | - $mode = $this->is_sandbox( $invoice ) ? 'sandbox' : 'live'; |
|
543 | + $mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live'; |
|
544 | 544 | $result = GetPaid_PayPal_API::cancel_subscription( |
545 | 545 | $invoice->get_remote_subscription_id(), |
546 | 546 | array( |
547 | - 'reason' => __(' Customer requested cancellation', 'invoicing' ), |
|
547 | + 'reason' => __(' Customer requested cancellation', 'invoicing'), |
|
548 | 548 | ), |
549 | 549 | $mode |
550 | 550 | ); |
551 | 551 | |
552 | - if ( is_wp_error( $result ) ) { |
|
552 | + if (is_wp_error($result)) { |
|
553 | 553 | |
554 | 554 | $error = sprintf( |
555 | 555 | // translators: %s is the subscription ID. |
556 | - __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ), |
|
556 | + __('An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing'), |
|
557 | 557 | $subscription->get_id() |
558 | 558 | ); |
559 | 559 | |
560 | - getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() ); |
|
560 | + getpaid_admin()->show_error($error . ' ' . $result->get_error_message()); |
|
561 | 561 | |
562 | - if ( ! is_admin() ) { |
|
563 | - wpinv_set_error( $result->get_error_code(), $error ); |
|
562 | + if (!is_admin()) { |
|
563 | + wpinv_set_error($result->get_error_code(), $error); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | return; |
567 | 567 | } |
568 | 568 | |
569 | - if ( is_admin() ) { |
|
569 | + if (is_admin()) { |
|
570 | 570 | getpaid_admin()->show_success( |
571 | 571 | sprintf( |
572 | 572 | // translators: %s is the subscription ID. |
573 | - __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ), |
|
573 | + __('Successfully cancelled subscription #%s in PayPal.', 'invoicing'), |
|
574 | 574 | $subscription->get_id() |
575 | 575 | ) |
576 | 576 | ); |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | * @return void |
585 | 585 | */ |
586 | 586 | public function verify_ipn() { |
587 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
587 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | public function sandbox_notice() { |
594 | 594 | |
595 | 595 | return sprintf( |
596 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
596 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
597 | 597 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
598 | 598 | '</a>' |
599 | 599 | ); |
@@ -605,41 +605,41 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @param array $admin_settings |
607 | 607 | */ |
608 | - public function admin_settings( $admin_settings ) { |
|
608 | + public function admin_settings($admin_settings) { |
|
609 | 609 | |
610 | 610 | $currencies = sprintf( |
611 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
612 | - implode( ', ', $this->currencies ) |
|
611 | + __('Supported Currencies: %s', 'invoicing'), |
|
612 | + implode(', ', $this->currencies) |
|
613 | 613 | ); |
614 | 614 | |
615 | 615 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
616 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
616 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
617 | 617 | |
618 | 618 | // Access tokens. |
619 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
620 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
619 | + $live_email = wpinv_get_option('paypal_email'); |
|
620 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
621 | 621 | |
622 | 622 | $admin_settings['paypal_connect'] = array( |
623 | 623 | 'type' => 'hook', |
624 | 624 | 'id' => 'paypal_connect', |
625 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
625 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
626 | 626 | ); |
627 | 627 | |
628 | 628 | $admin_settings['paypal_email'] = array( |
629 | 629 | 'type' => 'text', |
630 | 630 | 'class' => 'live-auth-data', |
631 | 631 | 'id' => 'paypal_email', |
632 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
633 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
632 | + 'name' => __('Live Email Address', 'invoicing'), |
|
633 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
634 | 634 | ); |
635 | 635 | |
636 | 636 | $admin_settings['paypal_sandbox_email'] = array( |
637 | 637 | 'type' => 'text', |
638 | 638 | 'class' => 'sandbox-auth-data', |
639 | 639 | 'id' => 'paypal_sandbox_email', |
640 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
641 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
642 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
640 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
641 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
642 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
643 | 643 | ); |
644 | 644 | |
645 | 645 | // Client ID and secret. |
@@ -647,41 +647,41 @@ discard block |
||
647 | 647 | 'type' => 'text', |
648 | 648 | 'class' => 'live-auth-data', |
649 | 649 | 'id' => 'paypal_client_id', |
650 | - 'name' => __( 'Live Client ID', 'invoicing' ), |
|
651 | - 'desc' => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
650 | + 'name' => __('Live Client ID', 'invoicing'), |
|
651 | + 'desc' => __('The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
652 | 652 | ); |
653 | 653 | |
654 | 654 | $admin_settings['paypal_sandbox_client_id'] = array( |
655 | 655 | 'type' => 'text', |
656 | 656 | 'class' => 'sandbox-auth-data', |
657 | 657 | 'id' => 'paypal_sandbox_client_id', |
658 | - 'name' => __( 'Sandbox Client ID', 'invoicing' ), |
|
659 | - 'desc' => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
660 | - 'std' => wpinv_get_option( 'paypal_client_id', '' ), |
|
658 | + 'name' => __('Sandbox Client ID', 'invoicing'), |
|
659 | + 'desc' => __('The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
660 | + 'std' => wpinv_get_option('paypal_client_id', ''), |
|
661 | 661 | ); |
662 | 662 | |
663 | 663 | $admin_settings['paypal_secret'] = array( |
664 | 664 | 'type' => 'text', |
665 | 665 | 'class' => 'live-auth-data', |
666 | 666 | 'id' => 'paypal_secret', |
667 | - 'name' => __( 'Live Secret', 'invoicing' ), |
|
668 | - 'desc' => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
667 | + 'name' => __('Live Secret', 'invoicing'), |
|
668 | + 'desc' => __('The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
669 | 669 | ); |
670 | 670 | |
671 | 671 | $admin_settings['paypal_sandbox_secret'] = array( |
672 | 672 | 'type' => 'text', |
673 | 673 | 'class' => 'sandbox-auth-data', |
674 | 674 | 'id' => 'paypal_sandbox_secret', |
675 | - 'name' => __( 'Sandbox Secret', 'invoicing' ), |
|
676 | - 'desc' => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ), |
|
675 | + 'name' => __('Sandbox Secret', 'invoicing'), |
|
676 | + 'desc' => __('The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'), |
|
677 | 677 | ); |
678 | 678 | |
679 | 679 | $admin_settings['paypal_ipn_url'] = array( |
680 | 680 | 'type' => 'ipn_url', |
681 | 681 | 'id' => 'paypal_ipn_url', |
682 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
682 | + 'name' => __('IPN Url', 'invoicing'), |
|
683 | 683 | 'std' => $this->notify_url, |
684 | - 'desc' => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
684 | + 'desc' => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
685 | 685 | 'readonly' => true, |
686 | 686 | ); |
687 | 687 | |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | * @param string $url |
695 | 695 | * @param WPInv_Subscription $subscription |
696 | 696 | */ |
697 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
697 | + public function filter_cancel_subscription_url($url, $subscription) { |
|
698 | 698 | |
699 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
699 | + if ($this->id !== $subscription->get_gateway()) { |
|
700 | 700 | return $url; |
701 | 701 | } |
702 | 702 | |
@@ -704,16 +704,16 @@ discard block |
||
704 | 704 | $profile_id = $subscription->get_profile_id(); |
705 | 705 | |
706 | 706 | // Bail if no profile ID. |
707 | - if ( empty( $profile_id ) ) { |
|
707 | + if (empty($profile_id)) { |
|
708 | 708 | return $url; |
709 | 709 | } |
710 | 710 | |
711 | 711 | $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
712 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
712 | + if ($this->is_sandbox($subscription->get_parent_payment())) { |
|
713 | 713 | $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
714 | 714 | } |
715 | 715 | |
716 | - return sprintf( $cancel_url, $profile_id ); |
|
716 | + return sprintf($cancel_url, $profile_id); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | /** |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | * @param array $data |
724 | 724 | * @return string |
725 | 725 | */ |
726 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
727 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
726 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
727 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
@@ -735,25 +735,25 @@ discard block |
||
735 | 735 | * @param string $redirect |
736 | 736 | * @return string |
737 | 737 | */ |
738 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
738 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
739 | 739 | |
740 | 740 | $redirect_url = add_query_arg( |
741 | 741 | array( |
742 | 742 | 'getpaid-admin-action' => 'connect_paypal', |
743 | 743 | 'page' => 'wpinv-settings', |
744 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
744 | + 'live_mode' => (int) empty($is_sandbox), |
|
745 | 745 | 'tab' => 'gateways', |
746 | 746 | 'section' => 'paypal', |
747 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
748 | - 'redirect' => urlencode( $redirect ), |
|
747 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
748 | + 'redirect' => urlencode($redirect), |
|
749 | 749 | ), |
750 | - admin_url( 'admin.php' ) |
|
750 | + admin_url('admin.php') |
|
751 | 751 | ); |
752 | 752 | |
753 | 753 | return add_query_arg( |
754 | 754 | array( |
755 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
756 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ), |
|
755 | + 'live_mode' => (int) empty($is_sandbox), |
|
756 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)), |
|
757 | 757 | ), |
758 | 758 | 'https://ayecode.io/oauth/paypal' |
759 | 759 | ); |
@@ -769,10 +769,10 @@ discard block |
||
769 | 769 | |
770 | 770 | ?> |
771 | 771 | <div class="wpinv-paypal-connect-live"> |
772 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a> |
|
772 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a> |
|
773 | 773 | </div> |
774 | 774 | <div class="wpinv-paypal-connect-sandbox"> |
775 | - <a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a> |
|
775 | + <a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a> |
|
776 | 776 | </div> |
777 | 777 | |
778 | 778 | <script> |
@@ -813,26 +813,26 @@ discard block |
||
813 | 813 | * @param array $data Connection data. |
814 | 814 | * @return void |
815 | 815 | */ |
816 | - public function connect_paypal( $data ) { |
|
816 | + public function connect_paypal($data) { |
|
817 | 817 | |
818 | 818 | $sandbox = $this->is_sandbox(); |
819 | - $data = wp_unslash( $data ); |
|
820 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
819 | + $data = wp_unslash($data); |
|
820 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
821 | 821 | |
822 | - if ( isset( $data['live_mode'] ) ) { |
|
823 | - $sandbox = empty( $data['live_mode'] ); |
|
822 | + if (isset($data['live_mode'])) { |
|
823 | + $sandbox = empty($data['live_mode']); |
|
824 | 824 | } |
825 | 825 | |
826 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
827 | - wpinv_update_option( 'paypal_active', 1 ); |
|
826 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
827 | + wpinv_update_option('paypal_active', 1); |
|
828 | 828 | |
829 | - if ( ! empty( $data['error_description'] ) ) { |
|
830 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
829 | + if (!empty($data['error_description'])) { |
|
830 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
831 | 831 | } else { |
832 | 832 | |
833 | 833 | // Retrieve the user info. |
834 | 834 | $user_info = wp_remote_get( |
835 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
835 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
836 | 836 | array( |
837 | 837 | |
838 | 838 | 'headers' => array( |
@@ -843,33 +843,33 @@ discard block |
||
843 | 843 | ) |
844 | 844 | ); |
845 | 845 | |
846 | - if ( is_wp_error( $user_info ) ) { |
|
847 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
846 | + if (is_wp_error($user_info)) { |
|
847 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
848 | 848 | } else { |
849 | 849 | |
850 | 850 | // Create application. |
851 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
851 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
852 | 852 | |
853 | - if ( $sandbox ) { |
|
854 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
855 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
856 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
857 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
853 | + if ($sandbox) { |
|
854 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
855 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
856 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
857 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
858 | 858 | } else { |
859 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
860 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
861 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
862 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
859 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
860 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
861 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
862 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
863 | 863 | } |
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
867 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
868 | 868 | |
869 | - if ( isset( $data['step'] ) ) { |
|
870 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
869 | + if (isset($data['step'])) { |
|
870 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
871 | 871 | } |
872 | - wp_redirect( $redirect ); |
|
872 | + wp_redirect($redirect); |
|
873 | 873 | exit; |
874 | 874 | } |
875 | 875 |
@@ -13,19 +13,19 @@ |
||
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | |
15 | 15 | if ( ! empty( $required ) ) { |
16 | - $label .= "<span class='text-danger'> *</span>"; |
|
16 | + $label .= "<span class='text-danger'> *</span>"; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | - array( |
|
21 | - 'type' => 'checkbox', |
|
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
25 | - 'label' => $label, |
|
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | - 'class' => $label_class |
|
29 | - ), |
|
30 | - true |
|
20 | + array( |
|
21 | + 'type' => 'checkbox', |
|
22 | + 'name' => esc_attr( $id ), |
|
23 | + 'id' => esc_attr( $element_id ), |
|
24 | + 'required' => ! empty( $required ), |
|
25 | + 'label' => $label, |
|
26 | + 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | + 'class' => $label_class |
|
29 | + ), |
|
30 | + true |
|
31 | 31 | ); |
@@ -7,24 +7,24 @@ |
||
7 | 7 | * @version 2.8.24 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | 14 | |
15 | -if ( ! empty( $required ) ) { |
|
15 | +if (!empty($required)) { |
|
16 | 16 | $label .= "<span class='text-danger'> *</span>"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | 20 | array( |
21 | 21 | 'type' => 'checkbox', |
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
22 | + 'name' => esc_attr($id), |
|
23 | + 'id' => esc_attr($element_id), |
|
24 | + 'required' => !empty($required), |
|
25 | 25 | 'label' => $label, |
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
27 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
28 | 28 | 'class' => $label_class |
29 | 29 | ), |
30 | 30 | true |