@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $message = wpinv_email_style_body( $message ); |
| 190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
| 191 | 191 | |
| 192 | - return $mailer->send( |
|
| 192 | + return $mailer->send( |
|
| 193 | 193 | $to, |
| 194 | 194 | $subject, |
| 195 | 195 | $message, |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * Please use GetPaid_Notification_Email_Sender |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /* |
| 12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Generates the email header. |
| 19 | 19 | */ |
| 20 | -function wpinv_email_header( $email_heading ) { |
|
| 21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
| 20 | +function wpinv_email_header($email_heading) { |
|
| 21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
| 22 | 22 | } |
| 23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
| 23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Generates the email footer. |
| 28 | 28 | */ |
| 29 | 29 | function wpinv_email_footer() { |
| 30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
| 30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
| 31 | 31 | } |
| 32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
| 32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | * @param string $email_type |
| 40 | 40 | * @param bool $sent_to_admin |
| 41 | 41 | */ |
| 42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
| 43 | 43 | |
| 44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
| 44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
| 48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Display line items in emails. |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @param string $email_type |
| 55 | 55 | * @param bool $sent_to_admin |
| 56 | 56 | */ |
| 57 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
| 57 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
| 58 | 58 | |
| 59 | 59 | // Prepare line items. |
| 60 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
| 61 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
| 60 | + $columns = getpaid_invoice_item_columns($invoice); |
|
| 61 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
| 62 | 62 | |
| 63 | 63 | // Load the template. |
| 64 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
| 64 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
| 67 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @param string $email_type |
| 75 | 75 | * @param bool $sent_to_admin |
| 76 | 76 | */ |
| 77 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 77 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
| 78 | 78 | |
| 79 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 80 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
| 79 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 80 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
| 83 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Returns email css. |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function getpaid_get_email_css() { |
| 90 | 90 | |
| 91 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
| 92 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
| 91 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
| 92 | + return apply_filters('wpinv_email_styles', $css); |
|
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | |
@@ -100,26 +100,26 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | -function wpinv_email_style_body( $content ) { |
|
| 103 | +function wpinv_email_style_body($content) { |
|
| 104 | 104 | |
| 105 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
| 105 | + if (!class_exists('DOMDocument')) { |
|
| 106 | 106 | return $content; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 112 | + if (!class_exists('Emogrifier')) { |
|
| 113 | 113 | include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
| 117 | 117 | try { |
| 118 | - $emogrifier = new Emogrifier( $content, $css ); |
|
| 118 | + $emogrifier = new Emogrifier($content, $css); |
|
| 119 | 119 | $_content = $emogrifier->emogrify(); |
| 120 | 120 | $content = $_content; |
| 121 | - } catch ( Exception $e ) { |
|
| 122 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
| 121 | + } catch (Exception $e) { |
|
| 122 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return $content; |
@@ -128,37 +128,37 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Backwards compatibility. |
| 130 | 130 | function wpinv_init_transactional_emails() { |
| 131 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
| 132 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
| 131 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
| 132 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
| 135 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
| 136 | 136 | |
| 137 | 137 | function wpinv_send_transactional_email() { |
| 138 | 138 | $args = func_get_args(); |
| 139 | 139 | $function = current_filter() . '_notification'; |
| 140 | - do_action_ref_array( $function, $args ); |
|
| 140 | + do_action_ref_array($function, $args); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | function wpinv_mail_get_from_address() { |
| 144 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) ); |
|
| 145 | - return sanitize_email( $from_address ); |
|
| 144 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email'))); |
|
| 145 | + return sanitize_email($from_address); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | function wpinv_mail_get_from_name() { |
| 149 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) ); |
|
| 150 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
| 149 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display'))); |
|
| 150 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
| 154 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
| 155 | - return ( $active ? true : false ); |
|
| 153 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
| 154 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
| 155 | + return ($active ? true : false); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
| 159 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
| 158 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
| 159 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
| 160 | 160 | |
| 161 | - switch ( $email_type ) { |
|
| 161 | + switch ($email_type) { |
|
| 162 | 162 | case 'html': |
| 163 | 163 | $content_type = 'text/html'; |
| 164 | 164 | break; |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @param array $attachments Any files to attach to the email. |
| 184 | 184 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
| 185 | 185 | */ |
| 186 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
| 186 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
| 187 | 187 | |
| 188 | 188 | $mailer = new GetPaid_Notification_Email_Sender(); |
| 189 | - $message = wpinv_email_style_body( $message ); |
|
| 190 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
| 189 | + $message = wpinv_email_style_body($message); |
|
| 190 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
| 191 | 191 | |
| 192 | 192 | return $mailer->send( |
| 193 | 193 | $to, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | function wpinv_get_emails() { |
| 207 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
| 207 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -213,172 +213,172 @@ discard block |
||
| 213 | 213 | * @param array $settings |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | -function wpinv_settings_emails( $settings = array() ) { |
|
| 217 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
| 218 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
| 216 | +function wpinv_settings_emails($settings = array()) { |
|
| 217 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
| 218 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
| 219 | 219 | } |
| 220 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
| 220 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Filter email section names. |
| 224 | 224 | * |
| 225 | 225 | */ |
| 226 | -function wpinv_settings_sections_emails( $settings ) { |
|
| 227 | - foreach ( wpinv_get_emails() as $key => $email ) { |
|
| 228 | - $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key ); |
|
| 226 | +function wpinv_settings_sections_emails($settings) { |
|
| 227 | + foreach (wpinv_get_emails() as $key => $email) { |
|
| 228 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $settings; |
| 232 | 232 | } |
| 233 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
| 233 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
| 234 | 234 | |
| 235 | -function wpinv_email_is_enabled( $email_type ) { |
|
| 235 | +function wpinv_email_is_enabled($email_type) { |
|
| 236 | 236 | $emails = wpinv_get_emails(); |
| 237 | - $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false; |
|
| 237 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
| 238 | 238 | |
| 239 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
| 239 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 243 | - switch ( $email_type ) { |
|
| 242 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 243 | + switch ($email_type) { |
|
| 244 | 244 | case 'new_invoice': |
| 245 | 245 | case 'cancelled_invoice': |
| 246 | 246 | case 'failed_invoice': |
| 247 | 247 | $recipient = wpinv_get_admin_email(); |
| 248 | 248 | break; |
| 249 | 249 | default: |
| 250 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 251 | - $recipient = ! empty( $invoice ) ? $invoice->get_email() : ''; |
|
| 250 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 251 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
| 252 | 252 | break; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
| 255 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | 259 | * Returns invoice CC recipients |
| 260 | 260 | */ |
| 261 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 262 | - switch ( $email_type ) { |
|
| 261 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 262 | + switch ($email_type) { |
|
| 263 | 263 | case 'new_invoice': |
| 264 | 264 | case 'cancelled_invoice': |
| 265 | 265 | case 'failed_invoice': |
| 266 | 266 | return array(); |
| 267 | 267 | break; |
| 268 | 268 | default: |
| 269 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 270 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
| 271 | - if ( empty( $recipient ) ) { |
|
| 269 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 270 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
| 271 | + if (empty($recipient)) { |
|
| 272 | 272 | return array(); |
| 273 | 273 | } |
| 274 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
| 274 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 281 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
| 282 | - $subject = __( $subject, 'invoicing' ); |
|
| 280 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 281 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
| 282 | + $subject = __($subject, 'invoicing'); |
|
| 283 | 283 | |
| 284 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
| 284 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
| 285 | 285 | |
| 286 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
| 286 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 290 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
| 291 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
| 289 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 290 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
| 291 | + $email_heading = __($email_heading, 'invoicing'); |
|
| 292 | 292 | |
| 293 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
| 293 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
| 294 | 294 | |
| 295 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
| 295 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 299 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
| 300 | - $content = __( $content, 'invoicing' ); |
|
| 298 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 299 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
| 300 | + $content = __($content, 'invoicing'); |
|
| 301 | 301 | |
| 302 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
| 302 | + $content = wpinv_email_format_text($content, $invoice); |
|
| 303 | 303 | |
| 304 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
| 304 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 307 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 308 | 308 | $from_name = wpinv_mail_get_from_address(); |
| 309 | 309 | $from_email = wpinv_mail_get_from_address(); |
| 310 | 310 | |
| 311 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 311 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 312 | 312 | |
| 313 | - $headers = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
| 313 | + $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
| 314 | 314 | $headers .= 'Reply-To: ' . $from_email . "\r\n"; |
| 315 | 315 | $headers .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n"; |
| 316 | 316 | |
| 317 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
| 317 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 320 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 321 | 321 | $attachments = array(); |
| 322 | 322 | |
| 323 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
| 323 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | 327 | * Searches for and replaces certain placeholders in an email. |
| 328 | 328 | */ |
| 329 | -function wpinv_email_format_text( $content, $invoice ) { |
|
| 329 | +function wpinv_email_format_text($content, $invoice) { |
|
| 330 | 330 | |
| 331 | 331 | $replace_array = array( |
| 332 | 332 | '{site_title}' => wpinv_get_blogname(), |
| 333 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
| 333 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 336 | + $invoice = new WPInv_Invoice($invoice); |
|
| 337 | 337 | |
| 338 | - if ( $invoice->get_id() ) { |
|
| 338 | + if ($invoice->get_id()) { |
|
| 339 | 339 | |
| 340 | 340 | $replace_array = array_merge( |
| 341 | 341 | $replace_array, |
| 342 | 342 | array( |
| 343 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 344 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 345 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
| 346 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
| 347 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
| 348 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
| 349 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ), |
|
| 350 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
| 351 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
| 352 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
| 353 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
| 354 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_invoice_quote_type() ), |
|
| 355 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ), |
|
| 356 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
| 343 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 344 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 345 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
| 346 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
| 347 | + '{email}' => sanitize_email($invoice->get_email()), |
|
| 348 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
| 349 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())), |
|
| 350 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
| 351 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
| 352 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
| 353 | + '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
| 354 | + '{invoice_quote}' => sanitize_text_field($invoice->get_invoice_quote_type()), |
|
| 355 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())), |
|
| 356 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
| 357 | 357 | ) |
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Let third party plugins filter the arra. |
| 363 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
| 363 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
| 364 | 364 | |
| 365 | - foreach ( $replace_array as $key => $value ) { |
|
| 366 | - $content = str_replace( $key, $value, $content ); |
|
| 365 | + foreach ($replace_array as $key => $value) { |
|
| 366 | + $content = str_replace($key, $value, $content); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
| 369 | + return apply_filters('wpinv_email_content_replace', $content); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
| 373 | -function wpinv_email_wrap_message( $message ) { |
|
| 373 | +function wpinv_email_wrap_message($message) { |
|
| 374 | 374 | // Buffer |
| 375 | 375 | ob_start(); |
| 376 | 376 | |
| 377 | - do_action( 'wpinv_email_header' ); |
|
| 377 | + do_action('wpinv_email_header'); |
|
| 378 | 378 | |
| 379 | - echo wp_kses_post( wpautop( wptexturize( $message ) ) ); |
|
| 379 | + echo wp_kses_post(wpautop(wptexturize($message))); |
|
| 380 | 380 | |
| 381 | - do_action( 'wpinv_email_footer' ); |
|
| 381 | + do_action('wpinv_email_footer'); |
|
| 382 | 382 | |
| 383 | 383 | // Get contents |
| 384 | 384 | $message = ob_get_clean(); |
@@ -386,21 +386,21 @@ discard block |
||
| 386 | 386 | return $message; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
| 390 | - if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) { |
|
| 391 | - $date_format = get_option( 'date_format' ); |
|
| 392 | - $time_format = get_option( 'time_format' ); |
|
| 389 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
| 390 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) { |
|
| 391 | + $date_format = get_option('date_format'); |
|
| 392 | + $time_format = get_option('time_format'); |
|
| 393 | 393 | ?> |
| 394 | 394 | <div id="wpinv-email-notes"> |
| 395 | - <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3> |
|
| 395 | + <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3> |
|
| 396 | 396 | <ol class="wpinv-notes-lists"> |
| 397 | 397 | <?php |
| 398 | - foreach ( $invoice_notes as $note ) { |
|
| 399 | - $note_time = strtotime( $note->comment_date ); |
|
| 398 | + foreach ($invoice_notes as $note) { |
|
| 399 | + $note_time = strtotime($note->comment_date); |
|
| 400 | 400 | ?> |
| 401 | 401 | <li class="comment wpinv-note"> |
| 402 | - <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p> |
|
| 403 | - <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div> |
|
| 402 | + <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p> |
|
| 403 | + <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div> |
|
| 404 | 404 | </li> |
| 405 | 405 | <?php |
| 406 | 406 | } |
@@ -410,4 +410,4 @@ discard block |
||
| 410 | 410 | <?php |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
| 413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
@@ -12,207 +12,207 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Notes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Filter inovice notes. |
|
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | - |
|
| 24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | - |
|
| 28 | - // Count comments. |
|
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | - |
|
| 31 | - // Fires after notes are loaded. |
|
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Filters invoice notes query to only include our notes. |
|
| 37 | - * |
|
| 38 | - * @param WP_Comment_Query $query |
|
| 39 | - */ |
|
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | - |
|
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | - } else { |
|
| 46 | - |
|
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | - $query->query_vars['type__not_in'] = array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $query; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Exclude notes from the comments feed. |
|
| 60 | - */ |
|
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Delete comments count cache whenever there is |
|
| 67 | - * new comment or the status of a comment changes. Cache |
|
| 68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | - * is called. |
|
| 70 | - */ |
|
| 71 | - public function delete_comments_count_cache() { |
|
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove invoice notes from wp_count_comments(). |
|
| 77 | - * |
|
| 78 | - * @since 2.2 |
|
| 79 | - * @param object $stats Comment stats. |
|
| 80 | - * @param int $post_id Post ID. |
|
| 81 | - * @return object |
|
| 82 | - */ |
|
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | - global $wpdb; |
|
| 85 | - |
|
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | - |
|
| 89 | - if ( ! $stats ) { |
|
| 90 | - $stats = array( |
|
| 91 | - 'total_comments' => 0, |
|
| 92 | - 'all' => 0, |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $count = $wpdb->get_results( |
|
| 96 | - " |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Filter inovice notes. |
|
| 21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | + |
|
| 24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | + |
|
| 28 | + // Count comments. |
|
| 29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | + |
|
| 31 | + // Fires after notes are loaded. |
|
| 32 | + do_action( 'wpinv_notes_init', $this ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Filters invoice notes query to only include our notes. |
|
| 37 | + * |
|
| 38 | + * @param WP_Comment_Query $query |
|
| 39 | + */ |
|
| 40 | + public function set_invoice_note_type( $query ) { |
|
| 41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | + |
|
| 43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | + } else { |
|
| 46 | + |
|
| 47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | + $query->query_vars['type__not_in'] = array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $query; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Exclude notes from the comments feed. |
|
| 60 | + */ |
|
| 61 | + function wpinv_comment_feed_where( $where ) { |
|
| 62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Delete comments count cache whenever there is |
|
| 67 | + * new comment or the status of a comment changes. Cache |
|
| 68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | + * is called. |
|
| 70 | + */ |
|
| 71 | + public function delete_comments_count_cache() { |
|
| 72 | + delete_transient( 'getpaid_count_comments' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove invoice notes from wp_count_comments(). |
|
| 77 | + * |
|
| 78 | + * @since 2.2 |
|
| 79 | + * @param object $stats Comment stats. |
|
| 80 | + * @param int $post_id Post ID. |
|
| 81 | + * @return object |
|
| 82 | + */ |
|
| 83 | + public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | + global $wpdb; |
|
| 85 | + |
|
| 86 | + if ( empty( $post_id ) ) { |
|
| 87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | + |
|
| 89 | + if ( ! $stats ) { |
|
| 90 | + $stats = array( |
|
| 91 | + 'total_comments' => 0, |
|
| 92 | + 'all' => 0, |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $count = $wpdb->get_results( |
|
| 96 | + " |
|
| 97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
| 98 | 98 | FROM {$wpdb->comments} |
| 99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
| 100 | 100 | GROUP BY comment_approved |
| 101 | 101 | ", |
| 102 | - ARRAY_A |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $approved = array( |
|
| 106 | - '0' => 'moderated', |
|
| 107 | - '1' => 'approved', |
|
| 108 | - 'spam' => 'spam', |
|
| 109 | - 'trash' => 'trash', |
|
| 110 | - 'post-trashed' => 'post-trashed', |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - foreach ( (array) $count as $row ) { |
|
| 114 | - // Don't count post-trashed toward totals. |
|
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | - $stats['all'] += $row['num_comments']; |
|
| 117 | - $stats['total_comments'] += $row['num_comments']; |
|
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | - $stats['total_comments'] += $row['num_comments']; |
|
| 120 | - } |
|
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $stats = (object) $stats; |
|
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | - } |
|
| 102 | + ARRAY_A |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $approved = array( |
|
| 106 | + '0' => 'moderated', |
|
| 107 | + '1' => 'approved', |
|
| 108 | + 'spam' => 'spam', |
|
| 109 | + 'trash' => 'trash', |
|
| 110 | + 'post-trashed' => 'post-trashed', |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + foreach ( (array) $count as $row ) { |
|
| 114 | + // Don't count post-trashed toward totals. |
|
| 115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | + $stats['all'] += $row['num_comments']; |
|
| 117 | + $stats['total_comments'] += $row['num_comments']; |
|
| 118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | + $stats['total_comments'] += $row['num_comments']; |
|
| 120 | + } |
|
| 121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ( $approved as $key ) { |
|
| 127 | + if ( empty( $stats[ $key ] ) ) { |
|
| 128 | + $stats[ $key ] = 0; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $stats = (object) $stats; |
|
| 133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $stats; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of invoice notes. |
|
| 142 | - * |
|
| 143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | - * @return WP_Comment[] |
|
| 146 | - */ |
|
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | - |
|
| 149 | - // Default comment args. |
|
| 150 | - $args = array( |
|
| 151 | - 'post_id' => $invoice_id, |
|
| 152 | - 'orderby' => 'comment_ID', |
|
| 153 | - 'order' => 'ASC', |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - // Maybe only show customer comments. |
|
| 157 | - if ( $type == 'customer' ) { |
|
| 158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | - $args['meta_value'] = 1; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | - |
|
| 164 | - return get_comments( $args ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves an invoice comment. |
|
| 169 | - * |
|
| 170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | - * @param string $note The note content. |
|
| 172 | - * @param string $note_author The name of the author of the note. |
|
| 173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | - * @return int|false The new note's ID on success, false on failure. |
|
| 175 | - */ |
|
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | - |
|
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Insert the comment. |
|
| 182 | - */ |
|
| 183 | - $note_id = wp_insert_comment( |
|
| 184 | - wp_filter_comment( |
|
| 185 | - array( |
|
| 186 | - 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | - 'comment_content' => $note, |
|
| 188 | - 'comment_agent' => 'Invoicing', |
|
| 189 | - 'user_id' => get_current_user_id(), |
|
| 190 | - 'comment_author' => $note_author, |
|
| 191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | - 'comment_author_email' => $author_email, |
|
| 193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | - 'comment_type' => 'wpinv_note', |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | - |
|
| 201 | - // Are we notifying the customer? |
|
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | - return $note_id; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | - do_action( |
|
| 137 | + return $stats; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of invoice notes. |
|
| 142 | + * |
|
| 143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | + * @return WP_Comment[] |
|
| 146 | + */ |
|
| 147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | + |
|
| 149 | + // Default comment args. |
|
| 150 | + $args = array( |
|
| 151 | + 'post_id' => $invoice_id, |
|
| 152 | + 'orderby' => 'comment_ID', |
|
| 153 | + 'order' => 'ASC', |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + // Maybe only show customer comments. |
|
| 157 | + if ( $type == 'customer' ) { |
|
| 158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | + $args['meta_value'] = 1; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | + |
|
| 164 | + return get_comments( $args ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves an invoice comment. |
|
| 169 | + * |
|
| 170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | + * @param string $note The note content. |
|
| 172 | + * @param string $note_author The name of the author of the note. |
|
| 173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | + * @return int|false The new note's ID on success, false on failure. |
|
| 175 | + */ |
|
| 176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | + |
|
| 178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Insert the comment. |
|
| 182 | + */ |
|
| 183 | + $note_id = wp_insert_comment( |
|
| 184 | + wp_filter_comment( |
|
| 185 | + array( |
|
| 186 | + 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | + 'comment_content' => $note, |
|
| 188 | + 'comment_agent' => 'Invoicing', |
|
| 189 | + 'user_id' => get_current_user_id(), |
|
| 190 | + 'comment_author' => $note_author, |
|
| 191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | + 'comment_author_email' => $author_email, |
|
| 193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | + 'comment_type' => 'wpinv_note', |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | + |
|
| 201 | + // Are we notifying the customer? |
|
| 202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | + return $note_id; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | + do_action( |
|
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
| 210 | - 'invoice_id' => $invoice->get_id(), |
|
| 211 | - 'user_note' => $note, |
|
| 210 | + 'invoice_id' => $invoice->get_id(), |
|
| 211 | + 'user_note' => $note, |
|
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | - return $note_id; |
|
| 216 | - } |
|
| 214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | + return $note_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | } |
@@ -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 | * Handles invoice notes. |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | public function __construct() { |
| 19 | 19 | |
| 20 | 20 | // Filter inovice notes. |
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 21 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
| 22 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
| 23 | 23 | |
| 24 | 24 | // Delete comments count cache whenever there is a new comment or a comment status changes. |
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 25 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
| 26 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
| 27 | 27 | |
| 28 | 28 | // Count comments. |
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2); |
|
| 30 | 30 | |
| 31 | 31 | // Fires after notes are loaded. |
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 32 | + do_action('wpinv_notes_init', $this); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param WP_Comment_Query $query |
| 39 | 39 | */ |
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 40 | + public function set_invoice_note_type($query) { |
|
| 41 | + $post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | 42 | |
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 43 | + if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) { |
|
| 44 | 44 | $query->query_vars['type'] = 'wpinv_note'; |
| 45 | 45 | } else { |
| 46 | 46 | |
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 47 | + if (empty($query->query_vars['type__not_in'])) { |
|
| 48 | 48 | $query->query_vars['type__not_in'] = array(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $query; |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * Exclude notes from the comments feed. |
| 60 | 60 | */ |
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 61 | + function wpinv_comment_feed_where($where) { |
|
| 62 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * is called. |
| 70 | 70 | */ |
| 71 | 71 | public function delete_comments_count_cache() { |
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 72 | + delete_transient('getpaid_count_comments'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | * @param int $post_id Post ID. |
| 81 | 81 | * @return object |
| 82 | 82 | */ |
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 83 | + public function wp_count_comments($stats, $post_id) { |
|
| 84 | 84 | global $wpdb; |
| 85 | 85 | |
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 86 | + if (empty($post_id)) { |
|
| 87 | + $stats = get_transient('getpaid_count_comments'); |
|
| 88 | 88 | |
| 89 | - if ( ! $stats ) { |
|
| 89 | + if (!$stats) { |
|
| 90 | 90 | $stats = array( |
| 91 | 91 | 'total_comments' => 0, |
| 92 | 92 | 'all' => 0, |
@@ -110,27 +110,27 @@ discard block |
||
| 110 | 110 | 'post-trashed' => 'post-trashed', |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - foreach ( (array) $count as $row ) { |
|
| 113 | + foreach ((array) $count as $row) { |
|
| 114 | 114 | // Don't count post-trashed toward totals. |
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 115 | + if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) { |
|
| 116 | 116 | $stats['all'] += $row['num_comments']; |
| 117 | 117 | $stats['total_comments'] += $row['num_comments']; |
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 118 | + } elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) { |
|
| 119 | 119 | $stats['total_comments'] += $row['num_comments']; |
| 120 | 120 | } |
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 121 | + if (isset($approved[$row['comment_approved']])) { |
|
| 122 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 126 | + foreach ($approved as $key) { |
|
| 127 | + if (empty($stats[$key])) { |
|
| 128 | + $stats[$key] = 0; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $stats = (object) $stats; |
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 133 | + set_transient('getpaid_count_comments', $stats); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $type Optional. Pass in customer to only return customer notes. |
| 145 | 145 | * @return WP_Comment[] |
| 146 | 146 | */ |
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 147 | + public function get_invoice_notes($invoice_id = 0, $type = 'all') { |
|
| 148 | 148 | |
| 149 | 149 | // Default comment args. |
| 150 | 150 | $args = array( |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | 156 | // Maybe only show customer comments. |
| 157 | - if ( $type == 'customer' ) { |
|
| 157 | + if ($type == 'customer') { |
|
| 158 | 158 | $args['meta_key'] = '_wpi_customer_note'; |
| 159 | 159 | $args['meta_value'] = 1; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 162 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
| 163 | 163 | |
| 164 | - return get_comments( $args ); |
|
| 164 | + return get_comments($args); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
| 174 | 174 | * @return int|false The new note's ID on success, false on failure. |
| 175 | 175 | */ |
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 176 | + function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) { |
|
| 177 | 177 | |
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 178 | + do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer); |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Insert the comment. |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | ) |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 199 | + do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer); |
|
| 200 | 200 | |
| 201 | 201 | // Are we notifying the customer? |
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 202 | + if (empty($note_id) || empty($for_customer)) { |
|
| 203 | 203 | return $note_id; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 206 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 207 | 207 | do_action( |
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | 'user_note' => $note, |
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 214 | + do_action('getpaid_new_customer_note', $invoice, $note); |
|
| 215 | 215 | return $note_id; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -15,31 +15,31 @@ discard block |
||
| 15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Class constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() { |
|
| 18 | + * Class constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | parent::__construct(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * Returns the API URL. |
|
| 26 | - * |
|
| 27 | - * |
|
| 28 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function get_api_url( $invoice ) { |
|
| 25 | + * Returns the API URL. |
|
| 26 | + * |
|
| 27 | + * |
|
| 28 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function get_api_url( $invoice ) { |
|
| 32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Communicates with authorize.net |
|
| 37 | - * |
|
| 38 | - * |
|
| 39 | - * @param array $post Data to post. |
|
| 36 | + * Communicates with authorize.net |
|
| 37 | + * |
|
| 38 | + * |
|
| 39 | + * @param array $post Data to post. |
|
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | - * @return stdClass|WP_Error |
|
| 42 | - */ |
|
| 41 | + * @return stdClass|WP_Error |
|
| 42 | + */ |
|
| 43 | 43 | public function post( $post, $invoice ) { |
| 44 | 44 | |
| 45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Returns the API authentication params. |
|
| 93 | - * |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function get_auth_params() { |
|
| 92 | + * Returns the API authentication params. |
|
| 93 | + * |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function get_auth_params() { |
|
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Cancels a subscription remotely |
|
| 108 | - * |
|
| 109 | - * |
|
| 110 | - * @param WPInv_Subscription $subscription Subscription. |
|
| 107 | + * Cancels a subscription remotely |
|
| 108 | + * |
|
| 109 | + * |
|
| 110 | + * @param WPInv_Subscription $subscription Subscription. |
|
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | - */ |
|
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 112 | + */ |
|
| 113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * Processes ipns. |
|
| 130 | - * |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function verify_ipn() { |
|
| 129 | + * Processes ipns. |
|
| 130 | + * |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function verify_ipn() { |
|
| 134 | 134 | |
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Validates IPN invoices. |
|
| 179 | - * |
|
| 178 | + * Validates IPN invoices. |
|
| 179 | + * |
|
| 180 | 180 | * @param WPInv_Invoice $invoice |
| 181 | 181 | * @param object $payload |
| 182 | - * @return void |
|
| 183 | - */ |
|
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 182 | + * @return void |
|
| 183 | + */ |
|
| 184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * Process subscriptio IPNS. |
|
| 192 | - * |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function maybe_process_old_ipn() { |
|
| 191 | + * Process subscriptio IPNS. |
|
| 192 | + * |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function maybe_process_old_ipn() { |
|
| 196 | 196 | |
| 197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
| 198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Validates the old IPN signature. |
|
| 237 | + * Validates the old IPN signature. |
|
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | - */ |
|
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 240 | + */ |
|
| 241 | + public function validate_old_ipn_signature( $posted ) { |
|
| 242 | 242 | |
| 243 | 243 | $signature = $this->get_option( 'signature_key' ); |
| 244 | 244 | if ( ! empty( $signature ) ) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Check Authorize.NET IPN validity. |
|
| 260 | - */ |
|
| 261 | - public function validate_ipn() { |
|
| 259 | + * Check Authorize.NET IPN validity. |
|
| 260 | + */ |
|
| 261 | + public function validate_ipn() { |
|
| 262 | 262 | |
| 263 | 263 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
| 264 | 264 | |
@@ -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 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function get_api_url( $invoice ) { |
|
| 32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 31 | + public function get_api_url($invoice) { |
|
| 32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | 41 | * @return stdClass|WP_Error |
| 42 | 42 | */ |
| 43 | - public function post( $post, $invoice ) { |
|
| 43 | + public function post($post, $invoice) { |
|
| 44 | 44 | |
| 45 | - $url = $this->get_api_url( $invoice ); |
|
| 45 | + $url = $this->get_api_url($invoice); |
|
| 46 | 46 | $response = wp_remote_post( |
| 47 | 47 | $url, |
| 48 | 48 | array( |
| 49 | 49 | 'headers' => array( |
| 50 | 50 | 'Content-Type' => 'application/json; charset=utf-8', |
| 51 | 51 | ), |
| 52 | - 'body' => json_encode( $post ), |
|
| 52 | + 'body' => json_encode($post), |
|
| 53 | 53 | 'method' => 'POST', |
| 54 | 54 | ) |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - if ( is_wp_error( $response ) ) { |
|
| 57 | + if (is_wp_error($response)) { |
|
| 58 | 58 | return $response; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
| 62 | - $response = preg_replace( '/\xEF\xBB\xBF/', '', $response ); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
| 63 | - $response = json_decode( $response ); |
|
| 61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
| 62 | + $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
| 63 | + $response = json_decode($response); |
|
| 64 | 64 | |
| 65 | - if ( empty( $response ) ) { |
|
| 66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
| 65 | + if (empty($response)) { |
|
| 66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
| 69 | + if ($response->messages->resultCode == 'Error') { |
|
| 70 | 70 | |
| 71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
| 72 | - wpinv_error_log( $response ); |
|
| 71 | + if ($this->is_sandbox($invoice)) { |
|
| 72 | + wpinv_error_log($response); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
| 76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
| 75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
| 76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
| 79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
| 80 | 80 | $error = $response->transactionResponse->errors[0]; |
| 81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
| 81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
| 84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | public function get_auth_params() { |
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | - 'name' => $this->get_option( 'login_id' ), |
|
| 101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
| 100 | + 'name' => $this->get_option('login_id'), |
|
| 101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | 112 | */ |
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 113 | + public function cancel_subscription($subscription, $invoice) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200)); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
| 143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
| 144 | - if ( empty( $posted ) ) { |
|
| 145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 143 | + $posted = json_decode(file_get_contents('php://input')); |
|
| 144 | + if (empty($posted)) { |
|
| 145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200)); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Process the IPN. |
| 149 | - $posted = (object) wp_unslash( $posted ); |
|
| 149 | + $posted = (object) wp_unslash($posted); |
|
| 150 | 150 | |
| 151 | 151 | // Process refunds. |
| 152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
| 153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
| 154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
| 153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
| 154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 155 | 155 | $invoice->refund(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Held funds approved. |
| 159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
| 160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
| 159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
| 160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Held funds declined. |
| 166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
| 167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
| 166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
| 167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
| 170 | 170 | $invoice->save(); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param object $payload |
| 182 | 182 | * @return void |
| 183 | 183 | */ |
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
| 184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
| 185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | public function maybe_process_old_ipn() { |
| 196 | 196 | |
| 197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 198 | 198 | |
| 199 | 199 | // Only process subscriptions subscriptions. |
| 200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
| 200 | + if (empty($data['x_subscription_id'])) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Check validity. |
| 205 | - $this->validate_old_ipn_signature( $data ); |
|
| 205 | + $this->validate_old_ipn_signature($data); |
|
| 206 | 206 | |
| 207 | 207 | // Fetch the associated subscription. |
| 208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
| 209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
| 208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
| 209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
| 210 | 210 | |
| 211 | 211 | // Abort if it is missing or completed. |
| 212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
| 212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Payment status. |
| 217 | - if ( 1 == $data['x_response_code'] ) { |
|
| 217 | + if (1 == $data['x_response_code']) { |
|
| 218 | 218 | |
| 219 | 219 | // Renew the subscription. |
| 220 | 220 | $subscription->add_payment( |
| 221 | 221 | array( |
| 222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
| 222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
| 223 | 223 | 'gateway' => $this->id, |
| 224 | 224 | ) |
| 225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | 240 | */ |
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 241 | + public function validate_old_ipn_signature($posted) { |
|
| 242 | 242 | |
| 243 | - $signature = $this->get_option( 'signature_key' ); |
|
| 244 | - if ( ! empty( $signature ) ) { |
|
| 245 | - $login_id = $this->get_option( 'login_id' ); |
|
| 246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
| 247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
| 248 | - $hash = hash_hmac( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
| 243 | + $signature = $this->get_option('signature_key'); |
|
| 244 | + if (!empty($signature)) { |
|
| 245 | + $login_id = $this->get_option('login_id'); |
|
| 246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
| 247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
| 248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
| 249 | 249 | |
| 250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
| 251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
| 250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
| 251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
| 252 | 252 | exit; |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -260,28 +260,28 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public function validate_ipn() { |
| 262 | 262 | |
| 263 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
| 263 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
| 264 | 264 | |
| 265 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 265 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 266 | 266 | return false; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $signature = $this->get_option( 'signature_key' ); |
|
| 269 | + $signature = $this->get_option('signature_key'); |
|
| 270 | 270 | |
| 271 | - if ( empty( $signature ) ) { |
|
| 272 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
| 271 | + if (empty($signature)) { |
|
| 272 | + wpinv_error_log('Error: You have not set a signature key'); |
|
| 273 | 273 | return false; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $hash = hash_hmac( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
| 276 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
| 277 | 277 | |
| 278 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 279 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
| 278 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 279 | + wpinv_error_log('Successfully validated the IPN'); |
|
| 280 | 280 | return true; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
| 284 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
| 283 | + wpinv_error_log('IPN hash is not valid'); |
|
| 284 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
| 285 | 285 | return false; |
| 286 | 286 | |
| 287 | 287 | } |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | class GetPaid_Worldpay_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 = 'worldpay'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Payment method order. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 23 | + * Payment method order. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | 27 | public $order = 5; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Endpoint for requests from Worldpay. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $notify_url; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Endpoint for requests to Worldpay. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 30 | + * Endpoint for requests from Worldpay. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $notify_url; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Endpoint for requests to Worldpay. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | protected $endpoint; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * An array of features that this gateway supports. |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 44 | + * An array of features that this gateway supports. |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | 48 | protected $supports = array( 'sandbox' ); |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a subscription. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 65 | + * URL to view a subscription. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Class constructor. |
|
| 73 | - */ |
|
| 74 | - public function __construct() { |
|
| 72 | + * Class constructor. |
|
| 73 | + */ |
|
| 74 | + public function __construct() { |
|
| 75 | 75 | |
| 76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
| 77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Process Payment. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | - * @param array $submission_data Posted checkout fields. |
|
| 93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 88 | + * Process Payment. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | + * @param array $submission_data Posted checkout fields. |
|
| 93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Get the Worldpay request URL for an invoice. |
|
| 132 | - * |
|
| 133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_request_url( $invoice ) { |
|
| 131 | + * Get the Worldpay request URL for an invoice. |
|
| 132 | + * |
|
| 133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_request_url( $invoice ) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get Worldpay Args for passing to Worldpay. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 152 | - |
|
| 153 | - return apply_filters( |
|
| 154 | - 'getpaid_worldpay_args', |
|
| 155 | - array( |
|
| 146 | + * Get Worldpay Args for passing to Worldpay. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function get_worldpay_args( $invoice ) { |
|
| 152 | + |
|
| 153 | + return apply_filters( |
|
| 154 | + 'getpaid_worldpay_args', |
|
| 155 | + array( |
|
| 156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
| 157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
| 158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
| 178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
| 179 | 179 | ), |
| 180 | - $invoice |
|
| 181 | - ); |
|
| 180 | + $invoice |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Secures worldpay args with an md5 hash. |
|
| 187 | - * |
|
| 188 | - * @param array $args Gateway args. |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function hash_args( $args ) { |
|
| 186 | + * Secures worldpay args with an md5 hash. |
|
| 187 | + * |
|
| 188 | + * @param array $args Gateway args. |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function hash_args( $args ) { |
|
| 192 | 192 | |
| 193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
| 194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Processes ipns and marks payments as complete. |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function verify_ipn() { |
|
| 207 | + * Processes ipns and marks payments as complete. |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function verify_ipn() { |
|
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | - } |
|
| 215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - // Update the ip address. |
|
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 232 | + // Update the ip address. |
|
| 233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Check Worldpay IPN validity. |
|
| 261 | - */ |
|
| 262 | - public function validate_ipn() { |
|
| 260 | + * Check Worldpay IPN validity. |
|
| 261 | + */ |
|
| 262 | + public function validate_ipn() { |
|
| 263 | 263 | |
| 264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
| 265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Filters the gateway settings. |
|
| 309 | - * |
|
| 310 | - * @param array $admin_settings |
|
| 311 | - */ |
|
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 308 | + * Filters the gateway settings. |
|
| 309 | + * |
|
| 310 | + * @param array $admin_settings |
|
| 311 | + */ |
|
| 312 | + public function admin_settings( $admin_settings ) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |
| 352 | 352 | |
| 353 | - return $admin_settings; |
|
| 354 | - } |
|
| 353 | + return $admin_settings; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | } |
@@ -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 | * Worldpay Payment Gateway class. |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @var array |
| 47 | 47 | */ |
| 48 | - protected $supports = array( 'sandbox' ); |
|
| 48 | + protected $supports = array('sandbox'); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Currencies this gateway is allowed for. |
| 52 | 52 | * |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 55 | + public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * URL to view a transaction. |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function __construct() { |
| 75 | 75 | |
| 76 | - $this->method_title = __( 'Worldpay', 'invoicing' ); |
|
| 77 | - $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
|
| 78 | - $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' ); |
|
| 79 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 76 | + $this->method_title = __('Worldpay', 'invoicing'); |
|
| 77 | + $this->title = __('Worldpay - Credit Card / Debit Card', 'invoicing'); |
|
| 78 | + $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing'); |
|
| 79 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 80 | 80 | |
| 81 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
| 82 | - add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) ); |
|
| 81 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
| 82 | + add_filter('getpaid_worldpay_args', array($this, 'hash_args')); |
|
| 83 | 83 | |
| 84 | 84 | parent::__construct(); |
| 85 | 85 | } |
@@ -93,24 +93,24 @@ discard block |
||
| 93 | 93 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 96 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | - $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
|
| 99 | + $worldpay_redirect = esc_url($this->get_request_url($invoice)); |
|
| 100 | 100 | |
| 101 | 101 | // Get submission args. |
| 102 | - $worldpay_args = $this->get_worldpay_args( $invoice ); |
|
| 102 | + $worldpay_args = $this->get_worldpay_args($invoice); |
|
| 103 | 103 | |
| 104 | 104 | $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>"; |
| 105 | 105 | |
| 106 | - foreach ( $worldpay_args as $key => $value ) { |
|
| 106 | + foreach ($worldpay_args as $key => $value) { |
|
| 107 | 107 | |
| 108 | - if ( false === $value || '' === trim( $value ) ) { |
|
| 108 | + if (false === $value || '' === trim($value)) { |
|
| 109 | 109 | continue; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $value = esc_attr( $value ); |
|
| 113 | - $key = wpinv_clean( $key ); |
|
| 112 | + $value = esc_attr($value); |
|
| 113 | + $key = wpinv_clean($key); |
|
| 114 | 114 | $form .= "<input type='hidden' name='$key' value='$value'>"; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | * @param WPInv_Invoice $invoice Invoice object. |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function get_request_url( $invoice ) { |
|
| 136 | + public function get_request_url($invoice) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
@@ -148,34 +148,34 @@ discard block |
||
| 148 | 148 | * @param WPInv_Invoice $invoice Invoice object. |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 151 | + protected function get_worldpay_args($invoice) { |
|
| 152 | 152 | |
| 153 | 153 | return apply_filters( |
| 154 | 154 | 'getpaid_worldpay_args', |
| 155 | 155 | array( |
| 156 | - 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
|
| 157 | - 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
|
| 158 | - 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
|
| 159 | - 'instId' => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory |
|
| 160 | - 'testMode' => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory |
|
| 161 | - 'name' => wpinv_clean( $invoice->get_full_name() ), |
|
| 162 | - 'address' => wpinv_clean( $invoice->get_address() ), |
|
| 163 | - 'postcode' => wpinv_clean( $invoice->get_zip() ), |
|
| 164 | - 'tel' => wpinv_clean( $invoice->get_phone() ), |
|
| 165 | - 'email' => sanitize_email( $invoice->get_email() ), |
|
| 166 | - 'country' => wpinv_clean( $invoice->get_country() ), |
|
| 167 | - 'desc' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
| 168 | - 'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
| 169 | - 'MC_callback' => esc_url_raw( $this->notify_url ), |
|
| 170 | - 'resultfile' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 171 | - 'MC_key' => wpinv_clean( $invoice->get_key() ), |
|
| 156 | + 'amount' => wpinv_sanitize_amount($invoice->get_total()), // mandatory |
|
| 157 | + 'cartId' => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased |
|
| 158 | + 'currency' => wpinv_clean($invoice->get_currency()), // mandatory |
|
| 159 | + 'instId' => wpinv_clean($this->get_option('instId', '')), // mandatory |
|
| 160 | + 'testMode' => $this->is_sandbox($invoice) ? 100 : 0, // mandatory |
|
| 161 | + 'name' => wpinv_clean($invoice->get_full_name()), |
|
| 162 | + 'address' => wpinv_clean($invoice->get_address()), |
|
| 163 | + 'postcode' => wpinv_clean($invoice->get_zip()), |
|
| 164 | + 'tel' => wpinv_clean($invoice->get_phone()), |
|
| 165 | + 'email' => sanitize_email($invoice->get_email()), |
|
| 166 | + 'country' => wpinv_clean($invoice->get_country()), |
|
| 167 | + 'desc' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
| 168 | + 'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
| 169 | + 'MC_callback' => esc_url_raw($this->notify_url), |
|
| 170 | + 'resultfile' => esc_url_raw($this->get_return_url($invoice)), |
|
| 171 | + 'MC_key' => wpinv_clean($invoice->get_key()), |
|
| 172 | 172 | 'MC_invoice_id' => $invoice->get_id(), |
| 173 | - 'address1' => wpinv_clean( $invoice->get_address() ), |
|
| 174 | - 'town' => wpinv_clean( $invoice->get_city() ), |
|
| 175 | - 'region' => wpinv_clean( $invoice->get_state() ), |
|
| 176 | - 'amountString' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
| 177 | - 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
|
| 178 | - 'compName' => wpinv_clean( $invoice->get_company() ), |
|
| 173 | + 'address1' => wpinv_clean($invoice->get_address()), |
|
| 174 | + 'town' => wpinv_clean($invoice->get_city()), |
|
| 175 | + 'region' => wpinv_clean($invoice->get_state()), |
|
| 176 | + 'amountString' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
| 177 | + 'countryString' => wpinv_clean(wpinv_country_name($invoice->get_country())), |
|
| 178 | + 'compName' => wpinv_clean($invoice->get_company()), |
|
| 179 | 179 | ), |
| 180 | 180 | $invoice |
| 181 | 181 | ); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | * @param array $args Gateway args. |
| 189 | 189 | * @return array |
| 190 | 190 | */ |
| 191 | - public function hash_args( $args ) { |
|
| 191 | + public function hash_args($args) { |
|
| 192 | 192 | |
| 193 | - $md5_secret = $this->get_option( 'md5_secret' ); |
|
| 193 | + $md5_secret = $this->get_option('md5_secret'); |
|
| 194 | 194 | |
| 195 | 195 | // Abort if there is no secret. |
| 196 | - if ( empty( $md5_secret ) ) { |
|
| 196 | + if (empty($md5_secret)) { |
|
| 197 | 197 | return $args; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Hash the args. |
| 201 | - $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" ); |
|
| 201 | + $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}"); |
|
| 202 | 202 | |
| 203 | 203 | return $args; |
| 204 | 204 | } |
@@ -211,43 +211,43 @@ discard block |
||
| 211 | 211 | public function verify_ipn() { |
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 214 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 215 | + wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500)); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 220 | - $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] ); |
|
| 219 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 220 | + $invoice = wpinv_get_invoice($posted['MC_invoice_id']); |
|
| 221 | 221 | |
| 222 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
| 222 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
| 223 | 223 | |
| 224 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 225 | - wpinv_error_log( 'Payment status:' . $posted['transStatus'] ); |
|
| 224 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
| 225 | + wpinv_error_log('Payment status:' . $posted['transStatus']); |
|
| 226 | 226 | |
| 227 | 227 | // Update the transaction id. |
| 228 | - if ( ! empty( $posted['transId'] ) ) { |
|
| 229 | - $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
|
| 228 | + if (!empty($posted['transId'])) { |
|
| 229 | + $invoice->set_transaction_id(wpinv_clean($posted['transId'])); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Update the ip address. |
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | - $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
|
| 233 | + if (!empty($posted['ipAddress'])) { |
|
| 234 | + $invoice->set_ip(wpinv_clean($posted['ipAddress'])); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( $posted['transStatus'] == 'Y' ) { |
|
| 238 | - $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) ); |
|
| 237 | + if ($posted['transStatus'] == 'Y') { |
|
| 238 | + $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime'])); |
|
| 239 | 239 | $invoice->mark_paid(); |
| 240 | 240 | return; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( $posted['transStatus'] == 'C' ) { |
|
| 244 | - $invoice->set_status( 'wpi-failed' ); |
|
| 245 | - $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true ); |
|
| 243 | + if ($posted['transStatus'] == 'C') { |
|
| 244 | + $invoice->set_status('wpi-failed'); |
|
| 245 | + $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true); |
|
| 246 | 246 | $invoice->save(); |
| 247 | 247 | return; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] ); |
|
| 250 | + wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']); |
|
| 251 | 251 | $invoice->save(); |
| 252 | 252 | |
| 253 | 253 | } |
@@ -261,27 +261,27 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function validate_ipn() { |
| 263 | 263 | |
| 264 | - wpinv_error_log( 'Validating Worldpay IPN response' ); |
|
| 264 | + wpinv_error_log('Validating Worldpay IPN response'); |
|
| 265 | 265 | |
| 266 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 266 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 267 | 267 | |
| 268 | 268 | // Verify installation. |
| 269 | - if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) { |
|
| 270 | - wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' ); |
|
| 269 | + if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) { |
|
| 270 | + wpinv_error_log('Received invalid installation ID from Worldpay IPN'); |
|
| 271 | 271 | return false; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Verify invoice. |
| 275 | - if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) { |
|
| 276 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
| 275 | + if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) { |
|
| 276 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
| 277 | 277 | return false; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // (maybe) verify password. |
| 281 | - $password = $this->get_option( 'callback_password' ); |
|
| 281 | + $password = $this->get_option('callback_password'); |
|
| 282 | 282 | |
| 283 | - if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) { |
|
| 284 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
| 283 | + if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) { |
|
| 284 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
| 285 | 285 | return false; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | /** |
| 293 | 293 | * Displays a notice on the checkout page if sandbox is enabled. |
| 294 | 294 | */ |
| 295 | - public function sandbox_notice( $description, $gateway ) { |
|
| 296 | - if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) { |
|
| 295 | + public function sandbox_notice($description, $gateway) { |
|
| 296 | + if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) { |
|
| 297 | 297 | $description .= '<br>' . sprintf( |
| 298 | - __( 'SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 298 | + __('SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
| 299 | 299 | '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">', |
| 300 | 300 | '</a>' |
| 301 | 301 | ); |
@@ -309,43 +309,43 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @param array $admin_settings |
| 311 | 311 | */ |
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 312 | + public function admin_settings($admin_settings) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 316 | - implode( ', ', $this->currencies ) |
|
| 315 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 316 | + implode(', ', $this->currencies) |
|
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | 319 | $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)"; |
| 320 | - $admin_settings['worldpay_desc']['std'] = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' ); |
|
| 320 | + $admin_settings['worldpay_desc']['std'] = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing'); |
|
| 321 | 321 | |
| 322 | 322 | $admin_settings['worldpay_instId'] = array( |
| 323 | 323 | 'type' => 'text', |
| 324 | 324 | 'id' => 'worldpay_instId', |
| 325 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
| 325 | + 'name' => __('Installation Id', 'invoicing'), |
|
| 326 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
| 327 | 327 | ); |
| 328 | 328 | |
| 329 | 329 | $admin_settings['worldpay_md5_secret'] = array( |
| 330 | 330 | 'type' => 'text', |
| 331 | 331 | 'id' => 'worldpay_md5_secret', |
| 332 | - 'name' => __( 'MD5 secret', 'invoicing' ), |
|
| 333 | - 'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>', |
|
| 332 | + 'name' => __('MD5 secret', 'invoicing'), |
|
| 333 | + 'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>', |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | 336 | $admin_settings['worldpay_callbackPW'] = array( |
| 337 | 337 | 'type' => 'text', |
| 338 | 338 | 'id' => 'worldpay_callbackPW', |
| 339 | - 'name' => __( 'Payment Response password', 'invoicing' ), |
|
| 340 | - 'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ), |
|
| 339 | + 'name' => __('Payment Response password', 'invoicing'), |
|
| 340 | + 'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'), |
|
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | 343 | $admin_settings['worldpay_ipn_url'] = array( |
| 344 | 344 | 'type' => 'ipn_url', |
| 345 | 345 | 'id' => 'worldpay_ipn_url', |
| 346 | - 'name' => __( 'Payment Response URL', 'invoicing' ), |
|
| 346 | + 'name' => __('Payment Response URL', 'invoicing'), |
|
| 347 | 347 | 'std' => $this->notify_url, |
| 348 | - 'desc' => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ), |
|
| 348 | + 'desc' => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'), |
|
| 349 | 349 | 'custom' => 'worldpay', |
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |
@@ -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 | * The Subscriptions DB Class |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | 'transaction_id' => '', |
| 73 | 73 | 'parent_payment_id' => 0, |
| 74 | 74 | 'product_id' => 0, |
| 75 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
| 76 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
| 75 | + 'created' => date('Y-m-d H:i:s'), |
|
| 76 | + 'expiration' => date('Y-m-d H:i:s'), |
|
| 77 | 77 | 'trial_period' => '', |
| 78 | 78 | 'status' => '', |
| 79 | 79 | 'profile_id' => '', |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | * @access public |
| 87 | 87 | * @since 1.0.0 |
| 88 | 88 | */ |
| 89 | - public function get_subscriptions( $args = array() ) { |
|
| 90 | - return getpaid_get_subscriptions( $args ); |
|
| 89 | + public function get_subscriptions($args = array()) { |
|
| 90 | + return getpaid_get_subscriptions($args); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @access public |
| 97 | 97 | * @since 1.0.0 |
| 98 | 98 | */ |
| 99 | - public function count( $args = array() ) { |
|
| 100 | - return getpaid_get_subscriptions( $args, 'count' ); |
|
| 99 | + public function count($args = array()) { |
|
| 100 | + return getpaid_get_subscriptions($args, 'count'); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -133,9 +133,9 @@ discard block |
||
| 133 | 133 | KEY customer_and_status ( customer_id, status) |
| 134 | 134 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
| 135 | 135 | |
| 136 | - dbDelta( $sql ); |
|
| 136 | + dbDelta($sql); |
|
| 137 | 137 | |
| 138 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
| 138 | + update_option($this->table_name . '_db_version', $this->version); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,199 +10,199 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - 'shipping' => array( |
|
| 54 | - 'initial' => 0, |
|
| 55 | - 'recurring' => 0, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets the associated payment form. |
|
| 62 | - * |
|
| 63 | - * @var GetPaid_Payment_Form |
|
| 64 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + 'shipping' => array( |
|
| 54 | + 'initial' => 0, |
|
| 55 | + 'recurring' => 0, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets the associated payment form. |
|
| 62 | + * |
|
| 63 | + * @var GetPaid_Payment_Form |
|
| 64 | + */ |
|
| 65 | 65 | protected $payment_form = null; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * The country for the submission. |
|
| 69 | - * |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - public $country = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * The state for the submission. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 80 | - public $state = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The invoice associated with the submission. |
|
| 84 | - * |
|
| 85 | - * @var WPInv_Invoice |
|
| 86 | - */ |
|
| 87 | - protected $invoice = null; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The recurring item for the submission. |
|
| 91 | - * |
|
| 92 | - * @var int |
|
| 93 | - */ |
|
| 94 | - public $has_recurring = 0; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * An array of fees for the submission. |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - */ |
|
| 101 | - protected $fees = array(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of discounts for the submission. |
|
| 105 | - * |
|
| 106 | - * @var array |
|
| 107 | - */ |
|
| 108 | - protected $discounts = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * An array of taxes for the submission. |
|
| 112 | - * |
|
| 113 | - * @var array |
|
| 114 | - */ |
|
| 115 | - protected $taxes = array(); |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * An array of items for the submission. |
|
| 119 | - * |
|
| 120 | - * @var GetPaid_Form_Item[] |
|
| 121 | - */ |
|
| 122 | - protected $items = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * The last error. |
|
| 126 | - * |
|
| 127 | - * @var string |
|
| 128 | - */ |
|
| 129 | - public $last_error = null; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * The last error code. |
|
| 133 | - * |
|
| 134 | - * @var string |
|
| 135 | - */ |
|
| 136 | - public $last_error_code = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Class constructor. |
|
| 140 | - * |
|
| 141 | - */ |
|
| 142 | - public function __construct() { |
|
| 143 | - |
|
| 144 | - // Set the state and country to the default state and country. |
|
| 145 | - $this->country = wpinv_default_billing_country(); |
|
| 146 | - $this->state = wpinv_get_default_state(); |
|
| 147 | - |
|
| 148 | - // Do we have an actual submission? |
|
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Loads submission data. |
|
| 157 | - * |
|
| 158 | - * @param array $data |
|
| 159 | - */ |
|
| 160 | - public function load_data( $data ) { |
|
| 161 | - |
|
| 162 | - // Allow plugins to filter the data. |
|
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | - |
|
| 165 | - // Cache it... |
|
| 166 | - $this->data = $data; |
|
| 167 | - |
|
| 168 | - // Then generate a unique id from the data. |
|
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | - |
|
| 171 | - // Finally, process the submission. |
|
| 172 | - try { |
|
| 173 | - |
|
| 174 | - // Each process is passed an instance of the class (with reference) |
|
| 175 | - // and should throw an Exception whenever it encounters one. |
|
| 176 | - $processors = apply_filters( |
|
| 177 | - 'getpaid_payment_form_submission_processors', |
|
| 178 | - array( |
|
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 185 | - ), |
|
| 186 | - $this |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | - } |
|
| 68 | + * The country for the submission. |
|
| 69 | + * |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + public $country = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * The state for the submission. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | + public $state = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The invoice associated with the submission. |
|
| 84 | + * |
|
| 85 | + * @var WPInv_Invoice |
|
| 86 | + */ |
|
| 87 | + protected $invoice = null; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The recurring item for the submission. |
|
| 91 | + * |
|
| 92 | + * @var int |
|
| 93 | + */ |
|
| 94 | + public $has_recurring = 0; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * An array of fees for the submission. |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + */ |
|
| 101 | + protected $fees = array(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of discounts for the submission. |
|
| 105 | + * |
|
| 106 | + * @var array |
|
| 107 | + */ |
|
| 108 | + protected $discounts = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * An array of taxes for the submission. |
|
| 112 | + * |
|
| 113 | + * @var array |
|
| 114 | + */ |
|
| 115 | + protected $taxes = array(); |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * An array of items for the submission. |
|
| 119 | + * |
|
| 120 | + * @var GetPaid_Form_Item[] |
|
| 121 | + */ |
|
| 122 | + protected $items = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * The last error. |
|
| 126 | + * |
|
| 127 | + * @var string |
|
| 128 | + */ |
|
| 129 | + public $last_error = null; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * The last error code. |
|
| 133 | + * |
|
| 134 | + * @var string |
|
| 135 | + */ |
|
| 136 | + public $last_error_code = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Class constructor. |
|
| 140 | + * |
|
| 141 | + */ |
|
| 142 | + public function __construct() { |
|
| 143 | + |
|
| 144 | + // Set the state and country to the default state and country. |
|
| 145 | + $this->country = wpinv_default_billing_country(); |
|
| 146 | + $this->state = wpinv_get_default_state(); |
|
| 147 | + |
|
| 148 | + // Do we have an actual submission? |
|
| 149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Loads submission data. |
|
| 157 | + * |
|
| 158 | + * @param array $data |
|
| 159 | + */ |
|
| 160 | + public function load_data( $data ) { |
|
| 161 | + |
|
| 162 | + // Allow plugins to filter the data. |
|
| 163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | + |
|
| 165 | + // Cache it... |
|
| 166 | + $this->data = $data; |
|
| 167 | + |
|
| 168 | + // Then generate a unique id from the data. |
|
| 169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | + |
|
| 171 | + // Finally, process the submission. |
|
| 172 | + try { |
|
| 173 | + |
|
| 174 | + // Each process is passed an instance of the class (with reference) |
|
| 175 | + // and should throw an Exception whenever it encounters one. |
|
| 176 | + $processors = apply_filters( |
|
| 177 | + 'getpaid_payment_form_submission_processors', |
|
| 178 | + array( |
|
| 179 | + array( $this, 'process_payment_form' ), |
|
| 180 | + array( $this, 'process_invoice' ), |
|
| 181 | + array( $this, 'process_fees' ), |
|
| 182 | + array( $this, 'process_items' ), |
|
| 183 | + array( $this, 'process_discount' ), |
|
| 184 | + array( $this, 'process_taxes' ), |
|
| 185 | + ), |
|
| 186 | + $this |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + foreach ( $processors as $processor ) { |
|
| 190 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | + } |
|
| 192 | 192 | } catch ( GetPaid_Payment_Exception $e ) { |
| 193 | - $this->last_error = $e->getMessage(); |
|
| 194 | - $this->last_error_code = $e->getErrorCode(); |
|
| 195 | - } catch ( Exception $e ) { |
|
| 196 | - $this->last_error = $e->getMessage(); |
|
| 197 | - $this->last_error_code = $e->getCode(); |
|
| 198 | - } |
|
| 193 | + $this->last_error = $e->getMessage(); |
|
| 194 | + $this->last_error_code = $e->getErrorCode(); |
|
| 195 | + } catch ( Exception $e ) { |
|
| 196 | + $this->last_error = $e->getMessage(); |
|
| 197 | + $this->last_error_code = $e->getCode(); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // Fired when we are done processing a submission. |
|
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 200 | + // Fired when we are done processing a submission. |
|
| 201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 202 | 202 | |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /* |
|
| 205 | + /* |
|
| 206 | 206 | |-------------------------------------------------------------------------- |
| 207 | 207 | | Payment Forms. |
| 208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
| 211 | 211 | | submission has an active payment form etc. |
| 212 | 212 | */ |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Prepares the submission's payment form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - */ |
|
| 219 | - public function process_payment_form() { |
|
| 214 | + /** |
|
| 215 | + * Prepares the submission's payment form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + */ |
|
| 219 | + public function process_payment_form() { |
|
| 220 | 220 | |
| 221 | - // Every submission needs an active payment form. |
|
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | - } |
|
| 221 | + // Every submission needs an active payment form. |
|
| 222 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - // Fetch the payment form. |
|
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 226 | + // Fetch the payment form. |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | - } |
|
| 229 | + if ( ! $this->payment_form->is_active() ) { |
|
| 230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | - } |
|
| 233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Returns the payment form. |
|
| 238 | - * |
|
| 239 | - * @since 1.0.19 |
|
| 240 | - * @return GetPaid_Payment_Form |
|
| 241 | - */ |
|
| 242 | - public function get_payment_form() { |
|
| 243 | - return $this->payment_form; |
|
| 244 | - } |
|
| 237 | + * Returns the payment form. |
|
| 238 | + * |
|
| 239 | + * @since 1.0.19 |
|
| 240 | + * @return GetPaid_Payment_Form |
|
| 241 | + */ |
|
| 242 | + public function get_payment_form() { |
|
| 243 | + return $this->payment_form; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /* |
|
| 246 | + /* |
|
| 247 | 247 | |-------------------------------------------------------------------------- |
| 248 | 248 | | Invoices. |
| 249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,84 +252,84 @@ discard block |
||
| 252 | 252 | | might be for an existing invoice. |
| 253 | 253 | */ |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Prepares the submission's invoice. |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - */ |
|
| 260 | - public function process_invoice() { |
|
| 255 | + /** |
|
| 256 | + * Prepares the submission's invoice. |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + */ |
|
| 260 | + public function process_invoice() { |
|
| 261 | 261 | |
| 262 | - // Abort if there is no invoice. |
|
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 262 | + // Abort if there is no invoice. |
|
| 263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | - // and that it is not paid for. |
|
| 269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 267 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | + // and that it is not paid for. |
|
| 269 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 270 | 270 | |
| 271 | 271 | if ( empty( $invoice ) ) { |
| 272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ( $invoice->is_paid() ) { |
|
| 276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $this->payment_form->invoice = $invoice; |
|
| 280 | - if ( ! $this->payment_form->is_default() ) { |
|
| 281 | - |
|
| 282 | - $items = array(); |
|
| 283 | - $item_ids = array(); |
|
| 284 | - |
|
| 285 | - foreach ( $invoice->get_items() as $item ) { |
|
| 286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | - $item_ids[] = $item->get_id(); |
|
| 288 | - $items[] = $item; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | - $item_ids[] = $item->get_id(); |
|
| 295 | - $items[] = $item; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->payment_form->set_items( $items ); |
|
| 300 | - |
|
| 301 | - } else { |
|
| 302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $this->country = $invoice->get_country(); |
|
| 306 | - $this->state = $invoice->get_state(); |
|
| 307 | - $this->invoice = $invoice; |
|
| 308 | - |
|
| 309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Returns the associated invoice. |
|
| 314 | - * |
|
| 315 | - * @since 1.0.19 |
|
| 316 | - * @return WPInv_Invoice |
|
| 317 | - */ |
|
| 318 | - public function get_invoice() { |
|
| 319 | - return $this->invoice; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Checks whether there is an invoice associated with this submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @return bool |
|
| 327 | - */ |
|
| 328 | - public function has_invoice() { |
|
| 329 | - return ! empty( $this->invoice ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /* |
|
| 272 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ( $invoice->is_paid() ) { |
|
| 276 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $this->payment_form->invoice = $invoice; |
|
| 280 | + if ( ! $this->payment_form->is_default() ) { |
|
| 281 | + |
|
| 282 | + $items = array(); |
|
| 283 | + $item_ids = array(); |
|
| 284 | + |
|
| 285 | + foreach ( $invoice->get_items() as $item ) { |
|
| 286 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | + $item_ids[] = $item->get_id(); |
|
| 288 | + $items[] = $item; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | + $item_ids[] = $item->get_id(); |
|
| 295 | + $items[] = $item; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->payment_form->set_items( $items ); |
|
| 300 | + |
|
| 301 | + } else { |
|
| 302 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $this->country = $invoice->get_country(); |
|
| 306 | + $this->state = $invoice->get_state(); |
|
| 307 | + $this->invoice = $invoice; |
|
| 308 | + |
|
| 309 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Returns the associated invoice. |
|
| 314 | + * |
|
| 315 | + * @since 1.0.19 |
|
| 316 | + * @return WPInv_Invoice |
|
| 317 | + */ |
|
| 318 | + public function get_invoice() { |
|
| 319 | + return $this->invoice; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Checks whether there is an invoice associated with this submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @return bool |
|
| 327 | + */ |
|
| 328 | + public function has_invoice() { |
|
| 329 | + return ! empty( $this->invoice ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /* |
|
| 333 | 333 | |-------------------------------------------------------------------------- |
| 334 | 334 | | Items. |
| 335 | 335 | |-------------------------------------------------------------------------- |
@@ -338,129 +338,129 @@ discard block |
||
| 338 | 338 | | recurring item. But can have an unlimited number of non-recurring items. |
| 339 | 339 | */ |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Prepares the submission's items. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - */ |
|
| 346 | - public function process_items() { |
|
| 347 | - |
|
| 348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | - |
|
| 350 | - foreach ( $processor->items as $item ) { |
|
| 351 | - $this->add_item( $item ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Adds an item to the submission. |
|
| 359 | - * |
|
| 360 | - * @since 1.0.19 |
|
| 361 | - * @param GetPaid_Form_Item $item |
|
| 362 | - */ |
|
| 363 | - public function add_item( $item ) { |
|
| 364 | - |
|
| 365 | - // Make sure that it is available for purchase. |
|
| 366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | - return; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Each submission can only contain one recurring item. |
|
| 371 | - if ( $item->is_recurring() ) { |
|
| 372 | - $this->has_recurring = $item->get_id(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // Update the items and totals. |
|
| 376 | - $this->items[ $item->get_id() ] = $item; |
|
| 377 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | - |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Removes a specific item. |
|
| 384 | - * |
|
| 385 | - * You should not call this method after the discounts and taxes |
|
| 386 | - * have been calculated. |
|
| 387 | - * |
|
| 388 | - * @since 1.0.19 |
|
| 389 | - */ |
|
| 390 | - public function remove_item( $item_id ) { |
|
| 391 | - |
|
| 392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | - |
|
| 396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | - $this->has_recurring = 0; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - unset( $this->items[ $item_id ] ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Returns the subtotal. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - */ |
|
| 410 | - public function get_subtotal() { |
|
| 411 | - |
|
| 412 | - if ( wpinv_prices_include_tax() ) { |
|
| 413 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - return $this->totals['subtotal']['initial']; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Returns the recurring subtotal. |
|
| 421 | - * |
|
| 422 | - * @since 1.0.19 |
|
| 423 | - */ |
|
| 424 | - public function get_recurring_subtotal() { |
|
| 425 | - |
|
| 426 | - if ( wpinv_prices_include_tax() ) { |
|
| 427 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $this->totals['subtotal']['recurring']; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Returns all items. |
|
| 435 | - * |
|
| 436 | - * @since 1.0.19 |
|
| 437 | - * @return GetPaid_Form_Item[] |
|
| 438 | - */ |
|
| 439 | - public function get_items() { |
|
| 440 | - return $this->items; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Checks if there's a single subscription group in the submission. |
|
| 445 | - * |
|
| 446 | - * @since 2.3.0 |
|
| 447 | - * @return bool |
|
| 448 | - */ |
|
| 449 | - public function has_subscription_group() { |
|
| 450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Checks if there are multipe subscription groups in the submission. |
|
| 455 | - * |
|
| 456 | - * @since 2.3.0 |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 459 | - public function has_multiple_subscription_groups() { |
|
| 460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /* |
|
| 341 | + /** |
|
| 342 | + * Prepares the submission's items. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + */ |
|
| 346 | + public function process_items() { |
|
| 347 | + |
|
| 348 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | + |
|
| 350 | + foreach ( $processor->items as $item ) { |
|
| 351 | + $this->add_item( $item ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Adds an item to the submission. |
|
| 359 | + * |
|
| 360 | + * @since 1.0.19 |
|
| 361 | + * @param GetPaid_Form_Item $item |
|
| 362 | + */ |
|
| 363 | + public function add_item( $item ) { |
|
| 364 | + |
|
| 365 | + // Make sure that it is available for purchase. |
|
| 366 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | + return; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Each submission can only contain one recurring item. |
|
| 371 | + if ( $item->is_recurring() ) { |
|
| 372 | + $this->has_recurring = $item->get_id(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // Update the items and totals. |
|
| 376 | + $this->items[ $item->get_id() ] = $item; |
|
| 377 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | + |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Removes a specific item. |
|
| 384 | + * |
|
| 385 | + * You should not call this method after the discounts and taxes |
|
| 386 | + * have been calculated. |
|
| 387 | + * |
|
| 388 | + * @since 1.0.19 |
|
| 389 | + */ |
|
| 390 | + public function remove_item( $item_id ) { |
|
| 391 | + |
|
| 392 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | + |
|
| 396 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | + $this->has_recurring = 0; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + unset( $this->items[ $item_id ] ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Returns the subtotal. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + */ |
|
| 410 | + public function get_subtotal() { |
|
| 411 | + |
|
| 412 | + if ( wpinv_prices_include_tax() ) { |
|
| 413 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + return $this->totals['subtotal']['initial']; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Returns the recurring subtotal. |
|
| 421 | + * |
|
| 422 | + * @since 1.0.19 |
|
| 423 | + */ |
|
| 424 | + public function get_recurring_subtotal() { |
|
| 425 | + |
|
| 426 | + if ( wpinv_prices_include_tax() ) { |
|
| 427 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $this->totals['subtotal']['recurring']; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Returns all items. |
|
| 435 | + * |
|
| 436 | + * @since 1.0.19 |
|
| 437 | + * @return GetPaid_Form_Item[] |
|
| 438 | + */ |
|
| 439 | + public function get_items() { |
|
| 440 | + return $this->items; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Checks if there's a single subscription group in the submission. |
|
| 445 | + * |
|
| 446 | + * @since 2.3.0 |
|
| 447 | + * @return bool |
|
| 448 | + */ |
|
| 449 | + public function has_subscription_group() { |
|
| 450 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Checks if there are multipe subscription groups in the submission. |
|
| 455 | + * |
|
| 456 | + * @since 2.3.0 |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | + public function has_multiple_subscription_groups() { |
|
| 460 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /* |
|
| 464 | 464 | |-------------------------------------------------------------------------- |
| 465 | 465 | | Taxes |
| 466 | 466 | |-------------------------------------------------------------------------- |
@@ -469,128 +469,128 @@ discard block |
||
| 469 | 469 | | or only one-time. |
| 470 | 470 | */ |
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Prepares the submission's taxes. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - */ |
|
| 477 | - public function process_taxes() { |
|
| 478 | - |
|
| 479 | - // Abort if we're not using taxes. |
|
| 480 | - if ( ! $this->use_taxes() ) { |
|
| 481 | - return; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | - if ( ! empty( $country ) ) { |
|
| 487 | - $this->country = $country; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | - if ( ! empty( $state ) ) { |
|
| 492 | - $this->state = $state; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // Confirm if the provided country and the ip country are similar. |
|
| 496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // Abort if the country is not taxable. |
|
| 502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | - |
|
| 508 | - foreach ( $processor->taxes as $tax ) { |
|
| 509 | - $this->add_tax( $tax ); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Adds a tax to the submission. |
|
| 517 | - * |
|
| 518 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - */ |
|
| 521 | - public function add_tax( $tax ) { |
|
| 522 | - |
|
| 523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | - |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Removes a specific tax. |
|
| 536 | - * |
|
| 537 | - * @since 1.0.19 |
|
| 538 | - */ |
|
| 539 | - public function remove_tax( $tax_name ) { |
|
| 540 | - |
|
| 541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | - unset( $this->taxes[ $tax_name ] ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Whether or not we'll use taxes for the submission. |
|
| 551 | - * |
|
| 552 | - * @since 1.0.19 |
|
| 553 | - */ |
|
| 554 | - public function use_taxes() { |
|
| 555 | - |
|
| 556 | - $use_taxes = wpinv_use_taxes(); |
|
| 557 | - |
|
| 558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | - $use_taxes = false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | - |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Returns the tax. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - */ |
|
| 571 | - public function get_tax() { |
|
| 572 | - return $this->totals['taxes']['initial']; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Returns the recurring tax. |
|
| 577 | - * |
|
| 578 | - * @since 1.0.19 |
|
| 579 | - */ |
|
| 580 | - public function get_recurring_tax() { |
|
| 581 | - return $this->totals['taxes']['recurring']; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Returns all taxes. |
|
| 586 | - * |
|
| 587 | - * @since 1.0.19 |
|
| 588 | - */ |
|
| 589 | - public function get_taxes() { |
|
| 590 | - return $this->taxes; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /* |
|
| 472 | + /** |
|
| 473 | + * Prepares the submission's taxes. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + */ |
|
| 477 | + public function process_taxes() { |
|
| 478 | + |
|
| 479 | + // Abort if we're not using taxes. |
|
| 480 | + if ( ! $this->use_taxes() ) { |
|
| 481 | + return; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | + if ( ! empty( $country ) ) { |
|
| 487 | + $this->country = $country; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | + if ( ! empty( $state ) ) { |
|
| 492 | + $this->state = $state; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // Confirm if the provided country and the ip country are similar. |
|
| 496 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // Abort if the country is not taxable. |
|
| 502 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | + |
|
| 508 | + foreach ( $processor->taxes as $tax ) { |
|
| 509 | + $this->add_tax( $tax ); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Adds a tax to the submission. |
|
| 517 | + * |
|
| 518 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + */ |
|
| 521 | + public function add_tax( $tax ) { |
|
| 522 | + |
|
| 523 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | + |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Removes a specific tax. |
|
| 536 | + * |
|
| 537 | + * @since 1.0.19 |
|
| 538 | + */ |
|
| 539 | + public function remove_tax( $tax_name ) { |
|
| 540 | + |
|
| 541 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | + unset( $this->taxes[ $tax_name ] ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Whether or not we'll use taxes for the submission. |
|
| 551 | + * |
|
| 552 | + * @since 1.0.19 |
|
| 553 | + */ |
|
| 554 | + public function use_taxes() { |
|
| 555 | + |
|
| 556 | + $use_taxes = wpinv_use_taxes(); |
|
| 557 | + |
|
| 558 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | + $use_taxes = false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | + |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Returns the tax. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + */ |
|
| 571 | + public function get_tax() { |
|
| 572 | + return $this->totals['taxes']['initial']; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Returns the recurring tax. |
|
| 577 | + * |
|
| 578 | + * @since 1.0.19 |
|
| 579 | + */ |
|
| 580 | + public function get_recurring_tax() { |
|
| 581 | + return $this->totals['taxes']['recurring']; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Returns all taxes. |
|
| 586 | + * |
|
| 587 | + * @since 1.0.19 |
|
| 588 | + */ |
|
| 589 | + public function get_taxes() { |
|
| 590 | + return $this->taxes; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /* |
|
| 594 | 594 | |-------------------------------------------------------------------------- |
| 595 | 595 | | Discounts |
| 596 | 596 | |-------------------------------------------------------------------------- |
@@ -599,99 +599,99 @@ discard block |
||
| 599 | 599 | | or only one-time. They also do not have to come from a discount code. |
| 600 | 600 | */ |
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Prepares the submission's discount. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function process_discount() { |
|
| 608 | - |
|
| 609 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | - |
|
| 613 | - foreach ( $processor->discounts as $discount ) { |
|
| 614 | - $this->add_discount( $discount ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Adds a discount to the submission. |
|
| 622 | - * |
|
| 623 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | - * @since 1.0.19 |
|
| 625 | - */ |
|
| 626 | - public function add_discount( $discount ) { |
|
| 627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Removes a discount from the submission. |
|
| 634 | - * |
|
| 635 | - * @since 1.0.19 |
|
| 636 | - */ |
|
| 637 | - public function remove_discount( $name ) { |
|
| 638 | - |
|
| 639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | - unset( $this->discounts[ $name ] ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Checks whether there is a discount code associated with this submission. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @return bool |
|
| 652 | - */ |
|
| 653 | - public function has_discount_code() { |
|
| 654 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Returns the discount code. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - * @return string |
|
| 662 | - */ |
|
| 663 | - public function get_discount_code() { |
|
| 664 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Returns the discount. |
|
| 669 | - * |
|
| 670 | - * @since 1.0.19 |
|
| 671 | - */ |
|
| 672 | - public function get_discount() { |
|
| 673 | - return $this->totals['discount']['initial']; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Returns the recurring discount. |
|
| 678 | - * |
|
| 679 | - * @since 1.0.19 |
|
| 680 | - */ |
|
| 681 | - public function get_recurring_discount() { |
|
| 682 | - return $this->totals['discount']['recurring']; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Returns all discounts. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function get_discounts() { |
|
| 691 | - return $this->discounts; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /* |
|
| 602 | + /** |
|
| 603 | + * Prepares the submission's discount. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function process_discount() { |
|
| 608 | + |
|
| 609 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | + |
|
| 613 | + foreach ( $processor->discounts as $discount ) { |
|
| 614 | + $this->add_discount( $discount ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Adds a discount to the submission. |
|
| 622 | + * |
|
| 623 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | + * @since 1.0.19 |
|
| 625 | + */ |
|
| 626 | + public function add_discount( $discount ) { |
|
| 627 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Removes a discount from the submission. |
|
| 634 | + * |
|
| 635 | + * @since 1.0.19 |
|
| 636 | + */ |
|
| 637 | + public function remove_discount( $name ) { |
|
| 638 | + |
|
| 639 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | + unset( $this->discounts[ $name ] ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Checks whether there is a discount code associated with this submission. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @return bool |
|
| 652 | + */ |
|
| 653 | + public function has_discount_code() { |
|
| 654 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Returns the discount code. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + * @return string |
|
| 662 | + */ |
|
| 663 | + public function get_discount_code() { |
|
| 664 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Returns the discount. |
|
| 669 | + * |
|
| 670 | + * @since 1.0.19 |
|
| 671 | + */ |
|
| 672 | + public function get_discount() { |
|
| 673 | + return $this->totals['discount']['initial']; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Returns the recurring discount. |
|
| 678 | + * |
|
| 679 | + * @since 1.0.19 |
|
| 680 | + */ |
|
| 681 | + public function get_recurring_discount() { |
|
| 682 | + return $this->totals['discount']['recurring']; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Returns all discounts. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function get_discounts() { |
|
| 691 | + return $this->discounts; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /* |
|
| 695 | 695 | |-------------------------------------------------------------------------- |
| 696 | 696 | | Fees |
| 697 | 697 | |-------------------------------------------------------------------------- |
@@ -701,100 +701,100 @@ discard block |
||
| 701 | 701 | | fees. |
| 702 | 702 | */ |
| 703 | 703 | |
| 704 | - /** |
|
| 705 | - * Prepares the submission's fees. |
|
| 706 | - * |
|
| 707 | - * @since 1.0.19 |
|
| 708 | - */ |
|
| 709 | - public function process_fees() { |
|
| 710 | - |
|
| 711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | - |
|
| 713 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | - $this->add_fee( $fee ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Adds a fee to the submission. |
|
| 722 | - * |
|
| 723 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - */ |
|
| 726 | - public function add_fee( $fee ) { |
|
| 727 | - |
|
| 728 | - if ( $fee['name'] == 'shipping' ) { |
|
| 729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Removes a fee from the submission. |
|
| 742 | - * |
|
| 743 | - * @since 1.0.19 |
|
| 744 | - */ |
|
| 745 | - public function remove_fee( $name ) { |
|
| 746 | - |
|
| 747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | - unset( $this->fees[ $name ] ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if ( 'shipping' == $name ) { |
|
| 754 | - $this->totals['shipping']['initial'] = 0; |
|
| 755 | - $this->totals['shipping']['recurring'] = 0; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Returns the fees. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - */ |
|
| 765 | - public function get_fee() { |
|
| 766 | - return $this->totals['fees']['initial']; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Returns the recurring fees. |
|
| 771 | - * |
|
| 772 | - * @since 1.0.19 |
|
| 773 | - */ |
|
| 774 | - public function get_recurring_fee() { |
|
| 775 | - return $this->totals['fees']['recurring']; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * Returns all fees. |
|
| 780 | - * |
|
| 781 | - * @since 1.0.19 |
|
| 782 | - */ |
|
| 783 | - public function get_fees() { |
|
| 784 | - return $this->fees; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Checks if there are any fees for the form. |
|
| 789 | - * |
|
| 790 | - * @return bool |
|
| 791 | - * @since 1.0.19 |
|
| 792 | - */ |
|
| 793 | - public function has_fees() { |
|
| 794 | - return count( $this->fees ) !== 0; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /* |
|
| 704 | + /** |
|
| 705 | + * Prepares the submission's fees. |
|
| 706 | + * |
|
| 707 | + * @since 1.0.19 |
|
| 708 | + */ |
|
| 709 | + public function process_fees() { |
|
| 710 | + |
|
| 711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | + |
|
| 713 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | + $this->add_fee( $fee ); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Adds a fee to the submission. |
|
| 722 | + * |
|
| 723 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + */ |
|
| 726 | + public function add_fee( $fee ) { |
|
| 727 | + |
|
| 728 | + if ( $fee['name'] == 'shipping' ) { |
|
| 729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Removes a fee from the submission. |
|
| 742 | + * |
|
| 743 | + * @since 1.0.19 |
|
| 744 | + */ |
|
| 745 | + public function remove_fee( $name ) { |
|
| 746 | + |
|
| 747 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | + unset( $this->fees[ $name ] ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + if ( 'shipping' == $name ) { |
|
| 754 | + $this->totals['shipping']['initial'] = 0; |
|
| 755 | + $this->totals['shipping']['recurring'] = 0; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Returns the fees. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + */ |
|
| 765 | + public function get_fee() { |
|
| 766 | + return $this->totals['fees']['initial']; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Returns the recurring fees. |
|
| 771 | + * |
|
| 772 | + * @since 1.0.19 |
|
| 773 | + */ |
|
| 774 | + public function get_recurring_fee() { |
|
| 775 | + return $this->totals['fees']['recurring']; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * Returns all fees. |
|
| 780 | + * |
|
| 781 | + * @since 1.0.19 |
|
| 782 | + */ |
|
| 783 | + public function get_fees() { |
|
| 784 | + return $this->fees; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Checks if there are any fees for the form. |
|
| 789 | + * |
|
| 790 | + * @return bool |
|
| 791 | + * @since 1.0.19 |
|
| 792 | + */ |
|
| 793 | + public function has_fees() { |
|
| 794 | + return count( $this->fees ) !== 0; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /* |
|
| 798 | 798 | |-------------------------------------------------------------------------- |
| 799 | 799 | | MISC |
| 800 | 800 | |-------------------------------------------------------------------------- |
@@ -802,147 +802,147 @@ discard block |
||
| 802 | 802 | | Extra submission functions. |
| 803 | 803 | */ |
| 804 | 804 | |
| 805 | - /** |
|
| 806 | - * Returns the shipping amount. |
|
| 807 | - * |
|
| 808 | - * @since 1.0.19 |
|
| 809 | - */ |
|
| 810 | - public function get_shipping() { |
|
| 811 | - return $this->totals['shipping']['initial']; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Returns the recurring shipping. |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - */ |
|
| 819 | - public function get_recurring_shipping() { |
|
| 820 | - return $this->totals['shipping']['recurring']; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Checks if there are any shipping fees for the form. |
|
| 825 | - * |
|
| 826 | - * @return bool |
|
| 827 | - * @since 1.0.19 |
|
| 828 | - */ |
|
| 829 | - public function has_shipping() { |
|
| 830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Checks if this is the initial fetch. |
|
| 835 | - * |
|
| 836 | - * @return bool |
|
| 837 | - * @since 1.0.19 |
|
| 838 | - */ |
|
| 839 | - public function is_initial_fetch() { |
|
| 840 | - return empty( $this->data['initial_state'] ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Returns the total amount to collect for this submission. |
|
| 845 | - * |
|
| 846 | - * @since 1.0.19 |
|
| 847 | - */ |
|
| 848 | - public function get_total() { |
|
| 849 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | - return max( $total, 0 ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Returns the recurring total amount to collect for this submission. |
|
| 855 | - * |
|
| 856 | - * @since 1.0.19 |
|
| 857 | - */ |
|
| 858 | - public function get_recurring_total() { |
|
| 859 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | - return max( $total, 0 ); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Whether payment details should be collected for this submission. |
|
| 865 | - * |
|
| 866 | - * @since 1.0.19 |
|
| 867 | - */ |
|
| 868 | - public function should_collect_payment_details() { |
|
| 869 | - $initial = $this->get_total(); |
|
| 870 | - $recurring = $this->get_recurring_total(); |
|
| 871 | - |
|
| 872 | - if ( $this->has_recurring == 0 ) { |
|
| 873 | - $recurring = 0; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - $collect = $initial > 0 || $recurring > 0; |
|
| 877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Returns the billing email of the user. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - */ |
|
| 885 | - public function get_billing_email() { |
|
| 886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Checks if the submitter has a billing email. |
|
| 891 | - * |
|
| 892 | - * @since 1.0.19 |
|
| 893 | - */ |
|
| 894 | - public function has_billing_email() { |
|
| 895 | - $billing_email = $this->get_billing_email(); |
|
| 896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Returns the appropriate currency for the submission. |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - * @return string |
|
| 904 | - */ |
|
| 905 | - public function get_currency() { |
|
| 906 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Returns the raw submission data. |
|
| 911 | - * |
|
| 912 | - * @since 1.0.19 |
|
| 913 | - * @return array |
|
| 914 | - */ |
|
| 915 | - public function get_data() { |
|
| 916 | - return $this->data; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Returns a field from the submission data |
|
| 921 | - * |
|
| 922 | - * @param string $field |
|
| 923 | - * @since 1.0.19 |
|
| 924 | - * @return mixed|null |
|
| 925 | - */ |
|
| 926 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Checks if a required field is set. |
|
| 932 | - * |
|
| 933 | - * @since 1.0.19 |
|
| 934 | - */ |
|
| 935 | - public function is_required_field_set( $field ) { |
|
| 936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * Formats an amount |
|
| 941 | - * |
|
| 942 | - * @since 1.0.19 |
|
| 943 | - */ |
|
| 944 | - public function format_amount( $amount ) { |
|
| 945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | - } |
|
| 805 | + /** |
|
| 806 | + * Returns the shipping amount. |
|
| 807 | + * |
|
| 808 | + * @since 1.0.19 |
|
| 809 | + */ |
|
| 810 | + public function get_shipping() { |
|
| 811 | + return $this->totals['shipping']['initial']; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Returns the recurring shipping. |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + */ |
|
| 819 | + public function get_recurring_shipping() { |
|
| 820 | + return $this->totals['shipping']['recurring']; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Checks if there are any shipping fees for the form. |
|
| 825 | + * |
|
| 826 | + * @return bool |
|
| 827 | + * @since 1.0.19 |
|
| 828 | + */ |
|
| 829 | + public function has_shipping() { |
|
| 830 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Checks if this is the initial fetch. |
|
| 835 | + * |
|
| 836 | + * @return bool |
|
| 837 | + * @since 1.0.19 |
|
| 838 | + */ |
|
| 839 | + public function is_initial_fetch() { |
|
| 840 | + return empty( $this->data['initial_state'] ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Returns the total amount to collect for this submission. |
|
| 845 | + * |
|
| 846 | + * @since 1.0.19 |
|
| 847 | + */ |
|
| 848 | + public function get_total() { |
|
| 849 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | + return max( $total, 0 ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Returns the recurring total amount to collect for this submission. |
|
| 855 | + * |
|
| 856 | + * @since 1.0.19 |
|
| 857 | + */ |
|
| 858 | + public function get_recurring_total() { |
|
| 859 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | + return max( $total, 0 ); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Whether payment details should be collected for this submission. |
|
| 865 | + * |
|
| 866 | + * @since 1.0.19 |
|
| 867 | + */ |
|
| 868 | + public function should_collect_payment_details() { |
|
| 869 | + $initial = $this->get_total(); |
|
| 870 | + $recurring = $this->get_recurring_total(); |
|
| 871 | + |
|
| 872 | + if ( $this->has_recurring == 0 ) { |
|
| 873 | + $recurring = 0; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + $collect = $initial > 0 || $recurring > 0; |
|
| 877 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Returns the billing email of the user. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + */ |
|
| 885 | + public function get_billing_email() { |
|
| 886 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Checks if the submitter has a billing email. |
|
| 891 | + * |
|
| 892 | + * @since 1.0.19 |
|
| 893 | + */ |
|
| 894 | + public function has_billing_email() { |
|
| 895 | + $billing_email = $this->get_billing_email(); |
|
| 896 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Returns the appropriate currency for the submission. |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + * @return string |
|
| 904 | + */ |
|
| 905 | + public function get_currency() { |
|
| 906 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Returns the raw submission data. |
|
| 911 | + * |
|
| 912 | + * @since 1.0.19 |
|
| 913 | + * @return array |
|
| 914 | + */ |
|
| 915 | + public function get_data() { |
|
| 916 | + return $this->data; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Returns a field from the submission data |
|
| 921 | + * |
|
| 922 | + * @param string $field |
|
| 923 | + * @since 1.0.19 |
|
| 924 | + * @return mixed|null |
|
| 925 | + */ |
|
| 926 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Checks if a required field is set. |
|
| 932 | + * |
|
| 933 | + * @since 1.0.19 |
|
| 934 | + */ |
|
| 935 | + public function is_required_field_set( $field ) { |
|
| 936 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * Formats an amount |
|
| 941 | + * |
|
| 942 | + * @since 1.0.19 |
|
| 943 | + */ |
|
| 944 | + public function format_amount( $amount ) { |
|
| 945 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | + } |
|
| 947 | 947 | |
| 948 | 948 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | $this->state = wpinv_get_default_state(); |
| 147 | 147 | |
| 148 | 148 | // Do we have an actual submission? |
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param array $data |
| 159 | 159 | */ |
| 160 | - public function load_data( $data ) { |
|
| 160 | + public function load_data($data) { |
|
| 161 | 161 | |
| 162 | 162 | // Allow plugins to filter the data. |
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 164 | 164 | |
| 165 | 165 | // Cache it... |
| 166 | 166 | $this->data = $data; |
| 167 | 167 | |
| 168 | 168 | // Then generate a unique id from the data. |
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 169 | + $this->id = md5(wp_json_encode($data)); |
|
| 170 | 170 | |
| 171 | 171 | // Finally, process the submission. |
| 172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
| 176 | 176 | $processors = apply_filters( |
| 177 | 177 | 'getpaid_payment_form_submission_processors', |
| 178 | 178 | array( |
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 179 | + array($this, 'process_payment_form'), |
|
| 180 | + array($this, 'process_invoice'), |
|
| 181 | + array($this, 'process_fees'), |
|
| 182 | + array($this, 'process_items'), |
|
| 183 | + array($this, 'process_discount'), |
|
| 184 | + array($this, 'process_taxes'), |
|
| 185 | 185 | ), |
| 186 | 186 | $this |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | + foreach ($processors as $processor) { |
|
| 190 | + call_user_func_array($processor, array(&$this)); |
|
| 191 | 191 | } |
| 192 | -} catch ( GetPaid_Payment_Exception $e ) { |
|
| 192 | +} catch (GetPaid_Payment_Exception $e) { |
|
| 193 | 193 | $this->last_error = $e->getMessage(); |
| 194 | 194 | $this->last_error_code = $e->getErrorCode(); |
| 195 | - } catch ( Exception $e ) { |
|
| 195 | + } catch (Exception $e) { |
|
| 196 | 196 | $this->last_error = $e->getMessage(); |
| 197 | 197 | $this->last_error_code = $e->getCode(); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Fired when we are done processing a submission. |
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | public function process_payment_form() { |
| 220 | 220 | |
| 221 | 221 | // Every submission needs an active payment form. |
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 222 | + if (empty($this->data['form_id'])) { |
|
| 223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Fetch the payment form. |
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 229 | + if (!$this->payment_form->is_active()) { |
|
| 230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -260,53 +260,53 @@ discard block |
||
| 260 | 260 | public function process_invoice() { |
| 261 | 261 | |
| 262 | 262 | // Abort if there is no invoice. |
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | + if (empty($this->data['invoice_id'])) { |
|
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // If the submission is for an existing invoice, ensure that it exists |
| 268 | 268 | // and that it is not paid for. |
| 269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 269 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 270 | 270 | |
| 271 | - if ( empty( $invoice ) ) { |
|
| 272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 271 | + if (empty($invoice)) { |
|
| 272 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( $invoice->is_paid() ) { |
|
| 276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 275 | + if ($invoice->is_paid()) { |
|
| 276 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $this->payment_form->invoice = $invoice; |
| 280 | - if ( ! $this->payment_form->is_default() ) { |
|
| 280 | + if (!$this->payment_form->is_default()) { |
|
| 281 | 281 | |
| 282 | 282 | $items = array(); |
| 283 | 283 | $item_ids = array(); |
| 284 | 284 | |
| 285 | - foreach ( $invoice->get_items() as $item ) { |
|
| 286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 285 | + foreach ($invoice->get_items() as $item) { |
|
| 286 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 287 | 287 | $item_ids[] = $item->get_id(); |
| 288 | 288 | $items[] = $item; |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 292 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 294 | 294 | $item_ids[] = $item->get_id(); |
| 295 | 295 | $items[] = $item; |
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $this->payment_form->set_items( $items ); |
|
| 299 | + $this->payment_form->set_items($items); |
|
| 300 | 300 | |
| 301 | 301 | } else { |
| 302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | $this->country = $invoice->get_country(); |
| 306 | 306 | $this->state = $invoice->get_state(); |
| 307 | 307 | $this->invoice = $invoice; |
| 308 | 308 | |
| 309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @return bool |
| 327 | 327 | */ |
| 328 | 328 | public function has_invoice() { |
| 329 | - return ! empty( $this->invoice ); |
|
| 329 | + return !empty($this->invoice); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /* |
@@ -345,13 +345,13 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function process_items() { |
| 347 | 347 | |
| 348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 349 | 349 | |
| 350 | - foreach ( $processor->items as $item ) { |
|
| 351 | - $this->add_item( $item ); |
|
| 350 | + foreach ($processor->items as $item) { |
|
| 351 | + $this->add_item($item); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -360,20 +360,20 @@ discard block |
||
| 360 | 360 | * @since 1.0.19 |
| 361 | 361 | * @param GetPaid_Form_Item $item |
| 362 | 362 | */ |
| 363 | - public function add_item( $item ) { |
|
| 363 | + public function add_item($item) { |
|
| 364 | 364 | |
| 365 | 365 | // Make sure that it is available for purchase. |
| 366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 367 | 367 | return; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // Each submission can only contain one recurring item. |
| 371 | - if ( $item->is_recurring() ) { |
|
| 371 | + if ($item->is_recurring()) { |
|
| 372 | 372 | $this->has_recurring = $item->get_id(); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // Update the items and totals. |
| 376 | - $this->items[ $item->get_id() ] = $item; |
|
| 376 | + $this->items[$item->get_id()] = $item; |
|
| 377 | 377 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 378 | 378 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 379 | 379 | |
@@ -387,17 +387,17 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @since 1.0.19 |
| 389 | 389 | */ |
| 390 | - public function remove_item( $item_id ) { |
|
| 390 | + public function remove_item($item_id) { |
|
| 391 | 391 | |
| 392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 392 | + if (isset($this->items[$item_id])) { |
|
| 393 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 394 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 395 | 395 | |
| 396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 397 | 397 | $this->has_recurring = 0; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - unset( $this->items[ $item_id ] ); |
|
| 400 | + unset($this->items[$item_id]); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | public function get_subtotal() { |
| 411 | 411 | |
| 412 | - if ( wpinv_prices_include_tax() ) { |
|
| 412 | + if (wpinv_prices_include_tax()) { |
|
| 413 | 413 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | public function get_recurring_subtotal() { |
| 425 | 425 | |
| 426 | - if ( wpinv_prices_include_tax() ) { |
|
| 426 | + if (wpinv_prices_include_tax()) { |
|
| 427 | 427 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @return bool |
| 448 | 448 | */ |
| 449 | 449 | public function has_subscription_group() { |
| 450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @return bool |
| 458 | 458 | */ |
| 459 | 459 | public function has_multiple_subscription_groups() { |
| 460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /* |
@@ -477,39 +477,39 @@ discard block |
||
| 477 | 477 | public function process_taxes() { |
| 478 | 478 | |
| 479 | 479 | // Abort if we're not using taxes. |
| 480 | - if ( ! $this->use_taxes() ) { |
|
| 480 | + if (!$this->use_taxes()) { |
|
| 481 | 481 | return; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | - if ( ! empty( $country ) ) { |
|
| 485 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 486 | + if (!empty($country)) { |
|
| 487 | 487 | $this->country = $country; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | - if ( ! empty( $state ) ) { |
|
| 490 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 491 | + if (!empty($state)) { |
|
| 492 | 492 | $this->state = $state; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Confirm if the provided country and the ip country are similar. |
| 496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 496 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 497 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 498 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Abort if the country is not taxable. |
| 502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 507 | 507 | |
| 508 | - foreach ( $processor->taxes as $tax ) { |
|
| 509 | - $this->add_tax( $tax ); |
|
| 508 | + foreach ($processor->taxes as $tax) { |
|
| 509 | + $this->add_tax($tax); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,16 +518,16 @@ discard block |
||
| 518 | 518 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | */ |
| 521 | - public function add_tax( $tax ) { |
|
| 521 | + public function add_tax($tax) { |
|
| 522 | 522 | |
| 523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 523 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 524 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 525 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 528 | + $this->taxes[$tax['name']] = $tax; |
|
| 529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | |
@@ -536,12 +536,12 @@ discard block |
||
| 536 | 536 | * |
| 537 | 537 | * @since 1.0.19 |
| 538 | 538 | */ |
| 539 | - public function remove_tax( $tax_name ) { |
|
| 539 | + public function remove_tax($tax_name) { |
|
| 540 | 540 | |
| 541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | - unset( $this->taxes[ $tax_name ] ); |
|
| 541 | + if (isset($this->taxes[$tax_name])) { |
|
| 542 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 543 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 544 | + unset($this->taxes[$tax_name]); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | } |
@@ -555,11 +555,11 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | $use_taxes = wpinv_use_taxes(); |
| 557 | 557 | |
| 558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 559 | 559 | $use_taxes = false; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 563 | 563 | |
| 564 | 564 | } |
| 565 | 565 | |
@@ -608,13 +608,13 @@ discard block |
||
| 608 | 608 | |
| 609 | 609 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 610 | 610 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 612 | 612 | |
| 613 | - foreach ( $processor->discounts as $discount ) { |
|
| 614 | - $this->add_discount( $discount ); |
|
| 613 | + foreach ($processor->discounts as $discount) { |
|
| 614 | + $this->add_discount($discount); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -623,10 +623,10 @@ discard block |
||
| 623 | 623 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 624 | 624 | * @since 1.0.19 |
| 625 | 625 | */ |
| 626 | - public function add_discount( $discount ) { |
|
| 627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 626 | + public function add_discount($discount) { |
|
| 627 | + $this->discounts[$discount['name']] = $discount; |
|
| 628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -634,12 +634,12 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @since 1.0.19 |
| 636 | 636 | */ |
| 637 | - public function remove_discount( $name ) { |
|
| 637 | + public function remove_discount($name) { |
|
| 638 | 638 | |
| 639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | - unset( $this->discounts[ $name ] ); |
|
| 639 | + if (isset($this->discounts[$name])) { |
|
| 640 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 641 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 642 | + unset($this->discounts[$name]); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | * @return bool |
| 652 | 652 | */ |
| 653 | 653 | public function has_discount_code() { |
| 654 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | + return !empty($this->discounts['discount_code']); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -708,13 +708,13 @@ discard block |
||
| 708 | 708 | */ |
| 709 | 709 | public function process_fees() { |
| 710 | 710 | |
| 711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 712 | 712 | |
| 713 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | - $this->add_fee( $fee ); |
|
| 713 | + foreach ($fees_processor->fees as $fee) { |
|
| 714 | + $this->add_fee($fee); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -723,17 +723,17 @@ discard block |
||
| 723 | 723 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 724 | 724 | * @since 1.0.19 |
| 725 | 725 | */ |
| 726 | - public function add_fee( $fee ) { |
|
| 726 | + public function add_fee($fee) { |
|
| 727 | 727 | |
| 728 | - if ( $fee['name'] == 'shipping' ) { |
|
| 729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 728 | + if ($fee['name'] == 'shipping') { |
|
| 729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 731 | 731 | return; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 734 | + $this->fees[$fee['name']] = $fee; |
|
| 735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 737 | 737 | |
| 738 | 738 | } |
| 739 | 739 | |
@@ -742,15 +742,15 @@ discard block |
||
| 742 | 742 | * |
| 743 | 743 | * @since 1.0.19 |
| 744 | 744 | */ |
| 745 | - public function remove_fee( $name ) { |
|
| 745 | + public function remove_fee($name) { |
|
| 746 | 746 | |
| 747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | - unset( $this->fees[ $name ] ); |
|
| 747 | + if (isset($this->fees[$name])) { |
|
| 748 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 749 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 750 | + unset($this->fees[$name]); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - if ( 'shipping' == $name ) { |
|
| 753 | + if ('shipping' == $name) { |
|
| 754 | 754 | $this->totals['shipping']['initial'] = 0; |
| 755 | 755 | $this->totals['shipping']['recurring'] = 0; |
| 756 | 756 | } |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | * @since 1.0.19 |
| 792 | 792 | */ |
| 793 | 793 | public function has_fees() { |
| 794 | - return count( $this->fees ) !== 0; |
|
| 794 | + return count($this->fees) !== 0; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | /* |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | * @since 1.0.19 |
| 828 | 828 | */ |
| 829 | 829 | public function has_shipping() { |
| 830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 830 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | * @since 1.0.19 |
| 838 | 838 | */ |
| 839 | 839 | public function is_initial_fetch() { |
| 840 | - return empty( $this->data['initial_state'] ); |
|
| 840 | + return empty($this->data['initial_state']); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | */ |
| 848 | 848 | public function get_total() { |
| 849 | 849 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
| 850 | - return max( $total, 0 ); |
|
| 850 | + return max($total, 0); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | */ |
| 858 | 858 | public function get_recurring_total() { |
| 859 | 859 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
| 860 | - return max( $total, 0 ); |
|
| 860 | + return max($total, 0); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -869,12 +869,12 @@ discard block |
||
| 869 | 869 | $initial = $this->get_total(); |
| 870 | 870 | $recurring = $this->get_recurring_total(); |
| 871 | 871 | |
| 872 | - if ( $this->has_recurring == 0 ) { |
|
| 872 | + if ($this->has_recurring == 0) { |
|
| 873 | 873 | $recurring = 0; |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | $collect = $initial > 0 || $recurring > 0; |
| 877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 877 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | * @since 1.0.19 |
| 884 | 884 | */ |
| 885 | 885 | public function get_billing_email() { |
| 886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 886 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | public function has_billing_email() { |
| 895 | 895 | $billing_email = $this->get_billing_email(); |
| 896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 896 | + return !empty($billing_email) && is_email($billing_email); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -923,8 +923,8 @@ discard block |
||
| 923 | 923 | * @since 1.0.19 |
| 924 | 924 | * @return mixed|null |
| 925 | 925 | */ |
| 926 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 926 | + public function get_field($field, $sub_array_key = null) { |
|
| 927 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
@@ -932,8 +932,8 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | * @since 1.0.19 |
| 934 | 934 | */ |
| 935 | - public function is_required_field_set( $field ) { |
|
| 936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 935 | + public function is_required_field_set($field) { |
|
| 936 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | /** |
@@ -941,8 +941,8 @@ discard block |
||
| 941 | 941 | * |
| 942 | 942 | * @since 1.0.19 |
| 943 | 943 | */ |
| 944 | - public function format_amount( $amount ) { |
|
| 945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 944 | + public function format_amount($amount) { |
|
| 945 | + return wpinv_price($amount, $this->get_currency()); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,67 +10,67 @@ discard block |
||
| 10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Stores a custom description for the item. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $custom_description = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Stores the item quantity. |
|
| 21 | - * |
|
| 22 | - * @var float |
|
| 23 | - */ |
|
| 24 | - protected $quantity = 1; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Stores the item meta. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $meta = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Is this item required? |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $is_required = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Are quantities allowed? |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $allow_quantities = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Associated invoice. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - public $invoice_id = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Item discount. |
|
| 56 | - * |
|
| 57 | - * @var float |
|
| 58 | - */ |
|
| 59 | - public $item_discount = 0; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Recurring item discount. |
|
| 63 | - * |
|
| 64 | - * @var float |
|
| 65 | - */ |
|
| 66 | - public $recurring_item_discount = 0; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Item tax. |
|
| 70 | - * |
|
| 71 | - * @var float |
|
| 72 | - */ |
|
| 73 | - public $item_tax = 0; |
|
| 13 | + * Stores a custom description for the item. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $custom_description = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Stores the item quantity. |
|
| 21 | + * |
|
| 22 | + * @var float |
|
| 23 | + */ |
|
| 24 | + protected $quantity = 1; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Stores the item meta. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $meta = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Is this item required? |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $is_required = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Are quantities allowed? |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $allow_quantities = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Associated invoice. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + public $invoice_id = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Item discount. |
|
| 56 | + * |
|
| 57 | + * @var float |
|
| 58 | + */ |
|
| 59 | + public $item_discount = 0; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Recurring item discount. |
|
| 63 | + * |
|
| 64 | + * @var float |
|
| 65 | + */ |
|
| 66 | + public $recurring_item_discount = 0; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Item tax. |
|
| 70 | + * |
|
| 71 | + * @var float |
|
| 72 | + */ |
|
| 73 | + public $item_tax = 0; |
|
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,230 +88,230 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * Get the item name. |
|
| 92 | - * |
|
| 93 | - * @since 1.0.19 |
|
| 94 | - * @param string $context View or edit context. |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get the item name without a suffix. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @param string $context View or edit context. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the item description. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @param string $context View or edit context. |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function get_description( $context = 'view' ) { |
|
| 121 | - |
|
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 123 | - return $this->custom_description; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return parent::get_description( $context ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Returns the sub total. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @param string $context View or edit context. |
|
| 134 | - * @return float |
|
| 135 | - */ |
|
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns the recurring sub total. |
|
| 142 | - * |
|
| 143 | - * @since 1.0.19 |
|
| 144 | - * @param string $context View or edit context. |
|
| 145 | - * @return float |
|
| 146 | - */ |
|
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | - |
|
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @deprecated |
|
| 158 | - */ |
|
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get the item quantity. |
|
| 165 | - * |
|
| 166 | - * @since 1.0.19 |
|
| 167 | - * @param string $context View or edit context. |
|
| 168 | - * @return float |
|
| 169 | - */ |
|
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 171 | - $quantity = (float) $this->quantity; |
|
| 172 | - |
|
| 173 | - if ( 'view' == $context ) { |
|
| 174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $quantity; |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the item meta data. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return meta |
|
| 187 | - */ |
|
| 188 | - public function get_item_meta( $context = 'view' ) { |
|
| 189 | - $meta = $this->meta; |
|
| 190 | - |
|
| 191 | - if ( 'view' == $context ) { |
|
| 192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $meta; |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Returns whether or not customers can update the item quantity. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @param string $context View or edit context. |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | - $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | - |
|
| 209 | - if ( 'view' == $context ) { |
|
| 210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return $allow_quantities; |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Returns whether or not the item is required. |
|
| 219 | - * |
|
| 220 | - * @since 1.0.19 |
|
| 221 | - * @param string $context View or edit context. |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - public function get_is_required( $context = 'view' ) { |
|
| 225 | - $is_required = (bool) $this->is_required; |
|
| 226 | - |
|
| 227 | - if ( 'view' == $context ) { |
|
| 228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $is_required; |
|
| 232 | - |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Prepares form data for use. |
|
| 237 | - * |
|
| 238 | - * @since 1.0.19 |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function prepare_data_for_use( $required = null ) { |
|
| 242 | - |
|
| 243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | - return array( |
|
| 245 | - 'title' => strip_tags( $this->get_name() ), |
|
| 246 | - 'id' => $this->get_id(), |
|
| 247 | - 'price' => $this->get_price(), |
|
| 248 | - 'recurring' => $this->is_recurring(), |
|
| 249 | - 'description' => $this->get_description(), |
|
| 250 | - 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | - 'required' => $required, |
|
| 252 | - ); |
|
| 253 | - |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Prepares form data for ajax use. |
|
| 258 | - * |
|
| 259 | - * @since 1.0.19 |
|
| 260 | - * @return array |
|
| 261 | - */ |
|
| 262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | - |
|
| 264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | - |
|
| 266 | - if ( $description ) { |
|
| 267 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | - return array( |
|
| 273 | - 'id' => $this->get_id(), |
|
| 274 | - 'texts' => array( |
|
| 275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | - ), |
|
| 281 | - 'inputs' => array( |
|
| 282 | - 'item-id' => $this->get_id(), |
|
| 283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | - 'item-price' => $price, |
|
| 287 | - ), |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Prepares form data for saving (cart_details). |
|
| 294 | - * |
|
| 295 | - * @since 1.0.19 |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - public function prepare_data_for_saving() { |
|
| 299 | - |
|
| 300 | - return array( |
|
| 301 | - 'post_id' => $this->invoice_id, |
|
| 302 | - 'item_id' => $this->get_id(), |
|
| 303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | - 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | - 'tax' => $this->item_tax, |
|
| 306 | - 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | - 'discount' => $this->item_discount, |
|
| 309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - } |
|
| 91 | + * Get the item name. |
|
| 92 | + * |
|
| 93 | + * @since 1.0.19 |
|
| 94 | + * @param string $context View or edit context. |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function get_name( $context = 'view' ) { |
|
| 98 | + $name = parent::get_name( $context ); |
|
| 99 | + return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get the item name without a suffix. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @param string $context View or edit context. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function get_raw_name( $context = 'view' ) { |
|
| 110 | + return parent::get_name( $context ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the item description. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @param string $context View or edit context. |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function get_description( $context = 'view' ) { |
|
| 121 | + |
|
| 122 | + if ( isset( $this->custom_description ) ) { |
|
| 123 | + return $this->custom_description; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return parent::get_description( $context ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Returns the sub total. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @param string $context View or edit context. |
|
| 134 | + * @return float |
|
| 135 | + */ |
|
| 136 | + public function get_sub_total( $context = 'view' ) { |
|
| 137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns the recurring sub total. |
|
| 142 | + * |
|
| 143 | + * @since 1.0.19 |
|
| 144 | + * @param string $context View or edit context. |
|
| 145 | + * @return float |
|
| 146 | + */ |
|
| 147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | + |
|
| 149 | + if ( $this->is_recurring() ) { |
|
| 150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @deprecated |
|
| 158 | + */ |
|
| 159 | + public function get_qantity( $context = 'view' ) { |
|
| 160 | + return $this->get_quantity( $context ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get the item quantity. |
|
| 165 | + * |
|
| 166 | + * @since 1.0.19 |
|
| 167 | + * @param string $context View or edit context. |
|
| 168 | + * @return float |
|
| 169 | + */ |
|
| 170 | + public function get_quantity( $context = 'view' ) { |
|
| 171 | + $quantity = (float) $this->quantity; |
|
| 172 | + |
|
| 173 | + if ( 'view' == $context ) { |
|
| 174 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $quantity; |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the item meta data. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return meta |
|
| 187 | + */ |
|
| 188 | + public function get_item_meta( $context = 'view' ) { |
|
| 189 | + $meta = $this->meta; |
|
| 190 | + |
|
| 191 | + if ( 'view' == $context ) { |
|
| 192 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $meta; |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Returns whether or not customers can update the item quantity. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @param string $context View or edit context. |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | + $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | + |
|
| 209 | + if ( 'view' == $context ) { |
|
| 210 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return $allow_quantities; |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Returns whether or not the item is required. |
|
| 219 | + * |
|
| 220 | + * @since 1.0.19 |
|
| 221 | + * @param string $context View or edit context. |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + public function get_is_required( $context = 'view' ) { |
|
| 225 | + $is_required = (bool) $this->is_required; |
|
| 226 | + |
|
| 227 | + if ( 'view' == $context ) { |
|
| 228 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $is_required; |
|
| 232 | + |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Prepares form data for use. |
|
| 237 | + * |
|
| 238 | + * @since 1.0.19 |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function prepare_data_for_use( $required = null ) { |
|
| 242 | + |
|
| 243 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | + return array( |
|
| 245 | + 'title' => strip_tags( $this->get_name() ), |
|
| 246 | + 'id' => $this->get_id(), |
|
| 247 | + 'price' => $this->get_price(), |
|
| 248 | + 'recurring' => $this->is_recurring(), |
|
| 249 | + 'description' => $this->get_description(), |
|
| 250 | + 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | + 'required' => $required, |
|
| 252 | + ); |
|
| 253 | + |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Prepares form data for ajax use. |
|
| 258 | + * |
|
| 259 | + * @since 1.0.19 |
|
| 260 | + * @return array |
|
| 261 | + */ |
|
| 262 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | + |
|
| 264 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | + |
|
| 266 | + if ( $description ) { |
|
| 267 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | + return array( |
|
| 273 | + 'id' => $this->get_id(), |
|
| 274 | + 'texts' => array( |
|
| 275 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | + 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | + ), |
|
| 281 | + 'inputs' => array( |
|
| 282 | + 'item-id' => $this->get_id(), |
|
| 283 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | + 'item-price' => $price, |
|
| 287 | + ), |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Prepares form data for saving (cart_details). |
|
| 294 | + * |
|
| 295 | + * @since 1.0.19 |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + public function prepare_data_for_saving() { |
|
| 299 | + |
|
| 300 | + return array( |
|
| 301 | + 'post_id' => $this->invoice_id, |
|
| 302 | + 'item_id' => $this->get_id(), |
|
| 303 | + 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | + 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | + 'tax' => $this->item_tax, |
|
| 306 | + 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | + 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | + 'discount' => $this->item_discount, |
|
| 309 | + 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | + 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | + 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | /* |
| 317 | 317 | |-------------------------------------------------------------------------- |
@@ -323,70 +323,70 @@ discard block |
||
| 323 | 323 | | object. |
| 324 | 324 | */ |
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Set the item qantity. |
|
| 328 | - * |
|
| 329 | - * @since 1.0.19 |
|
| 330 | - * @param float $quantity The item quantity. |
|
| 331 | - */ |
|
| 332 | - public function set_quantity( $quantity ) { |
|
| 333 | - |
|
| 334 | - if ( ! is_numeric( $quantity ) ) { |
|
| 335 | - $quantity = 1; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $this->quantity = (float) $quantity; |
|
| 339 | - |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Set the item meta data. |
|
| 344 | - * |
|
| 345 | - * @since 1.0.19 |
|
| 346 | - * @param array $meta The item meta data. |
|
| 347 | - */ |
|
| 348 | - public function set_item_meta( $meta ) { |
|
| 349 | - $this->meta = maybe_unserialize( $meta ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Set whether or not the quantities are allowed. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param bool $allow_quantities |
|
| 357 | - */ |
|
| 358 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | - $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Set whether or not the item is required. |
|
| 364 | - * |
|
| 365 | - * @since 1.0.19 |
|
| 366 | - * @param bool $is_required |
|
| 367 | - */ |
|
| 368 | - public function set_is_required( $is_required ) { |
|
| 369 | - $this->is_required = (bool) $is_required; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Sets the custom item description. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $description |
|
| 377 | - */ |
|
| 378 | - public function set_custom_description( $description ) { |
|
| 379 | - $this->custom_description = $description; |
|
| 380 | - } |
|
| 326 | + /** |
|
| 327 | + * Set the item qantity. |
|
| 328 | + * |
|
| 329 | + * @since 1.0.19 |
|
| 330 | + * @param float $quantity The item quantity. |
|
| 331 | + */ |
|
| 332 | + public function set_quantity( $quantity ) { |
|
| 333 | + |
|
| 334 | + if ( ! is_numeric( $quantity ) ) { |
|
| 335 | + $quantity = 1; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $this->quantity = (float) $quantity; |
|
| 339 | + |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Set the item meta data. |
|
| 344 | + * |
|
| 345 | + * @since 1.0.19 |
|
| 346 | + * @param array $meta The item meta data. |
|
| 347 | + */ |
|
| 348 | + public function set_item_meta( $meta ) { |
|
| 349 | + $this->meta = maybe_unserialize( $meta ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Set whether or not the quantities are allowed. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param bool $allow_quantities |
|
| 357 | + */ |
|
| 358 | + public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | + $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Set whether or not the item is required. |
|
| 364 | + * |
|
| 365 | + * @since 1.0.19 |
|
| 366 | + * @param bool $is_required |
|
| 367 | + */ |
|
| 368 | + public function set_is_required( $is_required ) { |
|
| 369 | + $this->is_required = (bool) $is_required; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Sets the custom item description. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $description |
|
| 377 | + */ |
|
| 378 | + public function set_custom_description( $description ) { |
|
| 379 | + $this->custom_description = $description; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * We do not want to save items to the database. |
| 384 | 384 | * |
| 385 | - * @return int item id |
|
| 385 | + * @return int item id |
|
| 386 | 386 | */ |
| 387 | 387 | public function save( $data = array() ) { |
| 388 | 388 | return $this->get_id(); |
| 389 | - } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | |-------------------------------------------------------------------------- |
@@ -398,23 +398,23 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Checks whether the item has enabled dynamic pricing. |
|
| 402 | - * |
|
| 403 | - * @since 1.0.19 |
|
| 404 | - * @return bool |
|
| 405 | - */ |
|
| 406 | - public function is_required() { |
|
| 401 | + * Checks whether the item has enabled dynamic pricing. |
|
| 402 | + * |
|
| 403 | + * @since 1.0.19 |
|
| 404 | + * @return bool |
|
| 405 | + */ |
|
| 406 | + public function is_required() { |
|
| 407 | 407 | return (bool) $this->get_is_required(); |
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Checks whether users can edit the quantities. |
|
| 412 | - * |
|
| 413 | - * @since 1.0.19 |
|
| 414 | - * @return bool |
|
| 415 | - */ |
|
| 416 | - public function allows_quantities() { |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Checks whether users can edit the quantities. |
|
| 412 | + * |
|
| 413 | + * @since 1.0.19 |
|
| 414 | + * @return bool |
|
| 415 | + */ |
|
| 416 | + public function allows_quantities() { |
|
| 417 | 417 | return (bool) $this->get_allow_quantities(); |
| 418 | - } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @param string $context View or edit context. |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 97 | + public function get_name($context = 'view') { |
|
| 98 | + $name = parent::get_name($context); |
|
| 99 | + return $name . wpinv_get_item_suffix($this); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * @param string $context View or edit context. |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 109 | + public function get_raw_name($context = 'view') { |
|
| 110 | + return parent::get_name($context); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | * @param string $context View or edit context. |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - public function get_description( $context = 'view' ) { |
|
| 120 | + public function get_description($context = 'view') { |
|
| 121 | 121 | |
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 122 | + if (isset($this->custom_description)) { |
|
| 123 | 123 | return $this->custom_description; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return parent::get_description( $context ); |
|
| 126 | + return parent::get_description($context); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | * @param string $context View or edit context. |
| 134 | 134 | * @return float |
| 135 | 135 | */ |
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 136 | + public function get_sub_total($context = 'view') { |
|
| 137 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | * @param string $context View or edit context. |
| 145 | 145 | * @return float |
| 146 | 146 | */ |
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 147 | + public function get_recurring_sub_total($context = 'view') { |
|
| 148 | 148 | |
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 149 | + if ($this->is_recurring()) { |
|
| 150 | + return $this->get_quantity($context) * $this->get_price($context); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return 0; |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | /** |
| 157 | 157 | * @deprecated |
| 158 | 158 | */ |
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 159 | + public function get_qantity($context = 'view') { |
|
| 160 | + return $this->get_quantity($context); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * @param string $context View or edit context. |
| 168 | 168 | * @return float |
| 169 | 169 | */ |
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 170 | + public function get_quantity($context = 'view') { |
|
| 171 | 171 | $quantity = (float) $this->quantity; |
| 172 | 172 | |
| 173 | - if ( 'view' == $context ) { |
|
| 174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 173 | + if ('view' == $context) { |
|
| 174 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $quantity; |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @param string $context View or edit context. |
| 186 | 186 | * @return meta |
| 187 | 187 | */ |
| 188 | - public function get_item_meta( $context = 'view' ) { |
|
| 188 | + public function get_item_meta($context = 'view') { |
|
| 189 | 189 | $meta = $this->meta; |
| 190 | 190 | |
| 191 | - if ( 'view' == $context ) { |
|
| 192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 191 | + if ('view' == $context) { |
|
| 192 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | return $meta; |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @param string $context View or edit context. |
| 204 | 204 | * @return bool |
| 205 | 205 | */ |
| 206 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 206 | + public function get_allow_quantities($context = 'view') { |
|
| 207 | 207 | $allow_quantities = (bool) $this->allow_quantities; |
| 208 | 208 | |
| 209 | - if ( 'view' == $context ) { |
|
| 210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 209 | + if ('view' == $context) { |
|
| 210 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | return $allow_quantities; |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @param string $context View or edit context. |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - public function get_is_required( $context = 'view' ) { |
|
| 224 | + public function get_is_required($context = 'view') { |
|
| 225 | 225 | $is_required = (bool) $this->is_required; |
| 226 | 226 | |
| 227 | - if ( 'view' == $context ) { |
|
| 228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 227 | + if ('view' == $context) { |
|
| 228 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $is_required; |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @since 1.0.19 |
| 239 | 239 | * @return array |
| 240 | 240 | */ |
| 241 | - public function prepare_data_for_use( $required = null ) { |
|
| 241 | + public function prepare_data_for_use($required = null) { |
|
| 242 | 242 | |
| 243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 243 | + $required = is_null($required) ? $this->is_required() : $required; |
|
| 244 | 244 | return array( |
| 245 | - 'title' => strip_tags( $this->get_name() ), |
|
| 245 | + 'title' => strip_tags($this->get_name()), |
|
| 246 | 246 | 'id' => $this->get_id(), |
| 247 | 247 | 'price' => $this->get_price(), |
| 248 | 248 | 'recurring' => $this->is_recurring(), |
@@ -259,30 +259,30 @@ discard block |
||
| 259 | 259 | * @since 1.0.19 |
| 260 | 260 | * @return array |
| 261 | 261 | */ |
| 262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 262 | + public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) { |
|
| 263 | 263 | |
| 264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 264 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
| 265 | 265 | |
| 266 | - if ( $description ) { |
|
| 266 | + if ($description) { |
|
| 267 | 267 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 270 | + $price = !$is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | + $subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | 272 | return array( |
| 273 | 273 | 'id' => $this->get_id(), |
| 274 | 274 | 'texts' => array( |
| 275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 275 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 276 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
| 277 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 278 | + 'item-price' => wpinv_price($price, $currency), |
|
| 279 | + 'item-total' => wpinv_price($subtotal, $currency), |
|
| 280 | 280 | ), |
| 281 | 281 | 'inputs' => array( |
| 282 | 282 | 'item-id' => $this->get_id(), |
| 283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 283 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 284 | + 'item-description' => wp_kses_post($this->get_description()), |
|
| 285 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 286 | 286 | 'item-price' => $price, |
| 287 | 287 | ), |
| 288 | 288 | ); |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | return array( |
| 301 | 301 | 'post_id' => $this->invoice_id, |
| 302 | 302 | 'item_id' => $this->get_id(), |
| 303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | - 'item_description' => $this->get_description( 'edit' ), |
|
| 303 | + 'item_name' => sanitize_text_field($this->get_raw_name('edit')), |
|
| 304 | + 'item_description' => $this->get_description('edit'), |
|
| 305 | 305 | 'tax' => $this->item_tax, |
| 306 | - 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 306 | + 'item_price' => $this->get_price('edit'), |
|
| 307 | + 'quantity' => (float) $this->get_quantity('edit'), |
|
| 308 | 308 | 'discount' => $this->item_discount, |
| 309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
| 309 | + 'subtotal' => $this->get_sub_total('edit'), |
|
| 310 | + 'price' => $this->get_sub_total('edit') + $this->item_tax - $this->item_discount, |
|
| 311 | + 'meta' => $this->get_item_meta('edit'), |
|
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | 314 | } |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * @since 1.0.19 |
| 330 | 330 | * @param float $quantity The item quantity. |
| 331 | 331 | */ |
| 332 | - public function set_quantity( $quantity ) { |
|
| 332 | + public function set_quantity($quantity) { |
|
| 333 | 333 | |
| 334 | - if ( ! is_numeric( $quantity ) ) { |
|
| 334 | + if (!is_numeric($quantity)) { |
|
| 335 | 335 | $quantity = 1; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @since 1.0.19 |
| 346 | 346 | * @param array $meta The item meta data. |
| 347 | 347 | */ |
| 348 | - public function set_item_meta( $meta ) { |
|
| 349 | - $this->meta = maybe_unserialize( $meta ); |
|
| 348 | + public function set_item_meta($meta) { |
|
| 349 | + $this->meta = maybe_unserialize($meta); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | * @since 1.0.19 |
| 356 | 356 | * @param bool $allow_quantities |
| 357 | 357 | */ |
| 358 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 358 | + public function set_allow_quantities($allow_quantities) { |
|
| 359 | 359 | $this->allow_quantities = (bool) $allow_quantities; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @since 1.0.19 |
| 366 | 366 | * @param bool $is_required |
| 367 | 367 | */ |
| 368 | - public function set_is_required( $is_required ) { |
|
| 368 | + public function set_is_required($is_required) { |
|
| 369 | 369 | $this->is_required = (bool) $is_required; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * @since 1.0.19 |
| 376 | 376 | * @param string $description |
| 377 | 377 | */ |
| 378 | - public function set_custom_description( $description ) { |
|
| 378 | + public function set_custom_description($description) { |
|
| 379 | 379 | $this->custom_description = $description; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | * |
| 385 | 385 | * @return int item id |
| 386 | 386 | */ |
| 387 | - public function save( $data = array() ) { |
|
| 387 | + public function save($data = array()) { |
|
| 388 | 388 | return $this->get_id(); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -12,167 +12,167 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission discounts. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $discounts = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission discounts. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $discounts = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + * @param float $initial_total |
|
| 26 | + * @param float $recurring_total |
|
| 27 | + */ |
|
| 28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | + |
|
| 30 | + // Process any existing invoice discounts. |
|
| 31 | + if ( $submission->has_invoice() ) { |
|
| 32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Do we have a discount? |
|
| 36 | + $discount = $submission->get_field( 'discount' ); |
|
| 37 | + |
|
| 38 | + if ( empty( $discount ) ) { |
|
| 39 | + |
|
| 40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | + unset( $this->discounts['discount_code'] ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Processes the discount code. |
|
| 48 | + $amount = max( $initial_total, $recurring_total ); |
|
| 49 | + $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | + |
|
| 51 | + } |
|
| 20 | 52 | |
| 21 | 53 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - * @param float $initial_total |
|
| 26 | - * @param float $recurring_total |
|
| 27 | - */ |
|
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | - |
|
| 30 | - // Process any existing invoice discounts. |
|
| 31 | - if ( $submission->has_invoice() ) { |
|
| 32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Do we have a discount? |
|
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 37 | - |
|
| 38 | - if ( empty( $discount ) ) { |
|
| 39 | - |
|
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Processes the discount code. |
|
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Processes a submission discount. |
|
| 55 | - * |
|
| 56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | - * @param string $discount |
|
| 58 | - * @param float $amount |
|
| 59 | - */ |
|
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | - |
|
| 62 | - // Fetch the discount. |
|
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 64 | - |
|
| 65 | - // Ensure it is active. |
|
| 54 | + * Processes a submission discount. |
|
| 55 | + * |
|
| 56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | + * @param string $discount |
|
| 58 | + * @param float $amount |
|
| 59 | + */ |
|
| 60 | + public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | + |
|
| 62 | + // Fetch the discount. |
|
| 63 | + $discount = new WPInv_Discount( $discount ); |
|
| 64 | + |
|
| 65 | + // Ensure it is active. |
|
| 66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
| 67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Required items. |
|
| 71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Exceeded limit. |
|
| 76 | - if ( $discount->has_exceeded_limit() ) { |
|
| 77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Validate usages. |
|
| 81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 82 | - |
|
| 83 | - // Validate amount. |
|
| 84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 85 | - |
|
| 86 | - // Save the discount. |
|
| 87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Validates a single use discount. |
|
| 92 | - * |
|
| 93 | - * @param WPInv_Discount $discount |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function is_discount_active( $discount ) { |
|
| 97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns a user's id or email. |
|
| 102 | - * |
|
| 103 | - * @param string $email |
|
| 104 | - * @return int|string|false |
|
| 105 | - */ |
|
| 106 | - public function get_user_id_or_email( $email ) { |
|
| 107 | - |
|
| 108 | - if ( is_user_logged_in() ) { |
|
| 109 | - return get_current_user_id(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Validates a single use discount. |
|
| 117 | - * |
|
| 118 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 119 | - * @param WPInv_Discount $discount |
|
| 120 | - */ |
|
| 121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 122 | - |
|
| 123 | - // Abort if it is not a single use discount. |
|
| 124 | - if ( ! $discount->is_single_use() ) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // Ensure there is a valid billing email. |
|
| 129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 130 | - |
|
| 131 | - if ( empty( $user ) ) { |
|
| 132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Has the user used this discount code before? |
|
| 136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Validates the discount's amount. |
|
| 144 | - * |
|
| 145 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | - * @param WPInv_Discount $discount |
|
| 147 | - * @param float $amount |
|
| 148 | - */ |
|
| 149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 150 | - |
|
| 151 | - // Validate minimum amount. |
|
| 152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Validate the maximum amount. |
|
| 158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Calculates the discount code's amount. |
|
| 167 | - * |
|
| 168 | - * Ensure that the discount exists and has been validated before calling this method. |
|
| 169 | - * |
|
| 170 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | - * @param WPInv_Discount $discount |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - public function calculate_discount( $submission, $discount ) { |
|
| 175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 176 | - } |
|
| 67 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Required items. |
|
| 71 | + if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Exceeded limit. |
|
| 76 | + if ( $discount->has_exceeded_limit() ) { |
|
| 77 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Validate usages. |
|
| 81 | + $this->validate_single_use_discount( $submission, $discount ); |
|
| 82 | + |
|
| 83 | + // Validate amount. |
|
| 84 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 85 | + |
|
| 86 | + // Save the discount. |
|
| 87 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Validates a single use discount. |
|
| 92 | + * |
|
| 93 | + * @param WPInv_Discount $discount |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function is_discount_active( $discount ) { |
|
| 97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns a user's id or email. |
|
| 102 | + * |
|
| 103 | + * @param string $email |
|
| 104 | + * @return int|string|false |
|
| 105 | + */ |
|
| 106 | + public function get_user_id_or_email( $email ) { |
|
| 107 | + |
|
| 108 | + if ( is_user_logged_in() ) { |
|
| 109 | + return get_current_user_id(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Validates a single use discount. |
|
| 117 | + * |
|
| 118 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 119 | + * @param WPInv_Discount $discount |
|
| 120 | + */ |
|
| 121 | + public function validate_single_use_discount( $submission, $discount ) { |
|
| 122 | + |
|
| 123 | + // Abort if it is not a single use discount. |
|
| 124 | + if ( ! $discount->is_single_use() ) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // Ensure there is a valid billing email. |
|
| 129 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 130 | + |
|
| 131 | + if ( empty( $user ) ) { |
|
| 132 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Has the user used this discount code before? |
|
| 136 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Validates the discount's amount. |
|
| 144 | + * |
|
| 145 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | + * @param WPInv_Discount $discount |
|
| 147 | + * @param float $amount |
|
| 148 | + */ |
|
| 149 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 150 | + |
|
| 151 | + // Validate minimum amount. |
|
| 152 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Validate the maximum amount. |
|
| 158 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Calculates the discount code's amount. |
|
| 167 | + * |
|
| 168 | + * Ensure that the discount exists and has been validated before calling this method. |
|
| 169 | + * |
|
| 170 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | + * @param WPInv_Discount $discount |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + public function calculate_discount( $submission, $discount ) { |
|
| 175 | + return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | } |
@@ -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 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
| 25 | 25 | * @param float $initial_total |
| 26 | 26 | * @param float $recurring_total |
| 27 | 27 | */ |
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
| 29 | 29 | |
| 30 | 30 | // Process any existing invoice discounts. |
| 31 | - if ( $submission->has_invoice() ) { |
|
| 31 | + if ($submission->has_invoice()) { |
|
| 32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Do we have a discount? |
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 36 | + $discount = $submission->get_field('discount'); |
|
| 37 | 37 | |
| 38 | - if ( empty( $discount ) ) { |
|
| 38 | + if (empty($discount)) { |
|
| 39 | 39 | |
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 40 | + if (isset($this->discounts['discount_code'])) { |
|
| 41 | + unset($this->discounts['discount_code']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Processes the discount code. |
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 48 | + $amount = max($initial_total, $recurring_total); |
|
| 49 | + $this->process_discount($submission, $discount, $amount); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,34 +57,34 @@ discard block |
||
| 57 | 57 | * @param string $discount |
| 58 | 58 | * @param float $amount |
| 59 | 59 | */ |
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 60 | + public function process_discount($submission, $discount, $amount) { |
|
| 61 | 61 | |
| 62 | 62 | // Fetch the discount. |
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 63 | + $discount = new WPInv_Discount($discount); |
|
| 64 | 64 | |
| 65 | 65 | // Ensure it is active. |
| 66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
| 67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 66 | + if (!$this->is_discount_active($discount)) { |
|
| 67 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('Invalid or expired discount code', 'invoicing')); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Required items. |
| 71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 71 | + if (!$discount->is_required_items_met(array_keys($submission->get_items()))) { |
|
| 72 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You are not allowed to use this discount code.', 'invoicing')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Exceeded limit. |
| 76 | - if ( $discount->has_exceeded_limit() ) { |
|
| 77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 76 | + if ($discount->has_exceeded_limit()) { |
|
| 77 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('This discount code has been used up', 'invoicing')); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Validate usages. |
| 81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 81 | + $this->validate_single_use_discount($submission, $discount); |
|
| 82 | 82 | |
| 83 | 83 | // Validate amount. |
| 84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 84 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
| 85 | 85 | |
| 86 | 86 | // Save the discount. |
| 87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 87 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | * @param WPInv_Discount $discount |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public function is_discount_active( $discount ) { |
|
| 97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 96 | + public function is_discount_active($discount) { |
|
| 97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * @param string $email |
| 104 | 104 | * @return int|string|false |
| 105 | 105 | */ |
| 106 | - public function get_user_id_or_email( $email ) { |
|
| 106 | + public function get_user_id_or_email($email) { |
|
| 107 | 107 | |
| 108 | - if ( is_user_logged_in() ) { |
|
| 108 | + if (is_user_logged_in()) { |
|
| 109 | 109 | return get_current_user_id(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 112 | + return empty($email) ? false : sanitize_email($email); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -118,23 +118,23 @@ discard block |
||
| 118 | 118 | * @param GetPaid_Payment_Form_Submission $submission |
| 119 | 119 | * @param WPInv_Discount $discount |
| 120 | 120 | */ |
| 121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 121 | + public function validate_single_use_discount($submission, $discount) { |
|
| 122 | 122 | |
| 123 | 123 | // Abort if it is not a single use discount. |
| 124 | - if ( ! $discount->is_single_use() ) { |
|
| 124 | + if (!$discount->is_single_use()) { |
|
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Ensure there is a valid billing email. |
| 129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 129 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
| 130 | 130 | |
| 131 | - if ( empty( $user ) ) { |
|
| 132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 131 | + if (empty($user)) { |
|
| 132 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You need to either log in or enter your billing email before applying this discount', 'invoicing')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Has the user used this discount code before? |
| 136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 136 | + if (!$discount->is_valid_for_user($user)) { |
|
| 137 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You have already used this discount', 'invoicing')); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | } |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | * @param WPInv_Discount $discount |
| 147 | 147 | * @param float $amount |
| 148 | 148 | */ |
| 149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 149 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
| 150 | 150 | |
| 151 | 151 | // Validate minimum amount. |
| 152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 152 | + if (!$discount->is_minimum_amount_met($amount)) { |
|
| 153 | + $min = wpinv_price($discount->get_minimum_total(), $submission->get_currency()); |
|
| 154 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min)); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Validate the maximum amount. |
| 158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 158 | + if (!$discount->is_maximum_amount_met($amount)) { |
|
| 159 | + $max = wpinv_price($discount->get_maximum_total(), $submission->get_currency()); |
|
| 160 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @param WPInv_Discount $discount |
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | - public function calculate_discount( $submission, $discount ) { |
|
| 175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 174 | + public function calculate_discount($submission, $discount) { |
|
| 175 | + return getpaid_calculate_invoice_discount($submission, $discount); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | } |
@@ -12,113 +12,113 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The fee validation error. |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $fee_error; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Submission fees. |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $fees = array(); |
|
| 15 | + /** |
|
| 16 | + * The fee validation error. |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $fee_error; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Submission fees. |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $fees = array(); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Process any existing invoice fees. |
|
| 35 | - if ( $submission->has_invoice() ) { |
|
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Process price fields. |
|
| 40 | - $data = $submission->get_data(); |
|
| 41 | - $payment_form = $submission->get_payment_form(); |
|
| 42 | - |
|
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | - |
|
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data, $submission ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 51 | - } |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Process any existing invoice fees. |
|
| 35 | + if ( $submission->has_invoice() ) { |
|
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Process price fields. |
|
| 40 | + $data = $submission->get_data(); |
|
| 41 | + $payment_form = $submission->get_payment_form(); |
|
| 42 | + |
|
| 43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | + |
|
| 45 | + if ( 'price_input' == $element['type'] ) { |
|
| 46 | + $this->process_price_input( $element, $data, $submission ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ( 'price_select' == $element['type'] ) { |
|
| 50 | + $this->process_price_select( $element, $data ); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Process a price input field. |
|
| 58 | - * |
|
| 59 | - * @param array $element |
|
| 60 | - * @param array $data |
|
| 61 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 62 | - */ |
|
| 63 | - public function process_price_input( $element, $data, $submission ) { |
|
| 64 | - |
|
| 65 | - // Abort if not passed. |
|
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | - |
|
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 78 | - 'name' => $element['label'], |
|
| 79 | - 'initial_fee' => $amount, |
|
| 80 | - 'recurring_fee' => 0, |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Process a price select field. |
|
| 87 | - * |
|
| 88 | - * @param array $element |
|
| 89 | - * @param array $data |
|
| 90 | - */ |
|
| 91 | - public function process_price_select( $element, $data ) { |
|
| 92 | - |
|
| 93 | - // Abort if not passed. |
|
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 100 | - $total = 0; |
|
| 101 | - $sub_labels = array(); |
|
| 102 | - |
|
| 103 | - foreach ( $selected as $price ) { |
|
| 104 | - |
|
| 105 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $price = explode( '|', $price ); |
|
| 110 | - |
|
| 111 | - $sub_labels[] = $price[0]; |
|
| 112 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->fees[ $element['label'] ] = array( |
|
| 116 | - 'name' => $element['label'], |
|
| 117 | - 'initial_fee' => $total, |
|
| 118 | - 'recurring_fee' => 0, |
|
| 119 | - 'description' => implode( ', ', $sub_labels ), |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Process a price input field. |
|
| 58 | + * |
|
| 59 | + * @param array $element |
|
| 60 | + * @param array $data |
|
| 61 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 62 | + */ |
|
| 63 | + public function process_price_input( $element, $data, $submission ) { |
|
| 64 | + |
|
| 65 | + // Abort if not passed. |
|
| 66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | + |
|
| 73 | + if ( $amount < $minimum ) { |
|
| 74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->fees[ $element['label'] ] = array( |
|
| 78 | + 'name' => $element['label'], |
|
| 79 | + 'initial_fee' => $amount, |
|
| 80 | + 'recurring_fee' => 0, |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Process a price select field. |
|
| 87 | + * |
|
| 88 | + * @param array $element |
|
| 89 | + * @param array $data |
|
| 90 | + */ |
|
| 91 | + public function process_price_select( $element, $data ) { |
|
| 92 | + |
|
| 93 | + // Abort if not passed. |
|
| 94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 100 | + $total = 0; |
|
| 101 | + $sub_labels = array(); |
|
| 102 | + |
|
| 103 | + foreach ( $selected as $price ) { |
|
| 104 | + |
|
| 105 | + if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $price = explode( '|', $price ); |
|
| 110 | + |
|
| 111 | + $sub_labels[] = $price[0]; |
|
| 112 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->fees[ $element['label'] ] = array( |
|
| 116 | + 'name' => $element['label'], |
|
| 117 | + 'initial_fee' => $total, |
|
| 118 | + 'recurring_fee' => 0, |
|
| 119 | + 'description' => implode( ', ', $sub_labels ), |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | } |
@@ -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 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
| 31 | 31 | */ |
| 32 | - public function __construct( $submission ) { |
|
| 32 | + public function __construct($submission) { |
|
| 33 | 33 | |
| 34 | 34 | // Process any existing invoice fees. |
| 35 | - if ( $submission->has_invoice() ) { |
|
| 35 | + if ($submission->has_invoice()) { |
|
| 36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | $data = $submission->get_data(); |
| 41 | 41 | $payment_form = $submission->get_payment_form(); |
| 42 | 42 | |
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 43 | + foreach ($payment_form->get_elements() as $element) { |
|
| 44 | 44 | |
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data, $submission ); |
|
| 45 | + if ('price_input' == $element['type']) { |
|
| 46 | + $this->process_price_input($element, $data, $submission); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 49 | + if ('price_select' == $element['type']) { |
|
| 50 | + $this->process_price_select($element, $data); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | * @param array $data |
| 61 | 61 | * @param GetPaid_Payment_Form_Submission $submission |
| 62 | 62 | */ |
| 63 | - public function process_price_input( $element, $data, $submission ) { |
|
| 63 | + public function process_price_input($element, $data, $submission) { |
|
| 64 | 64 | |
| 65 | 65 | // Abort if not passed. |
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 66 | + if (empty($data[$element['id']])) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
| 71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
| 72 | 72 | |
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 73 | + if ($amount < $minimum) { |
|
| 74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 77 | + $this->fees[$element['label']] = array( |
|
| 78 | 78 | 'name' => $element['label'], |
| 79 | 79 | 'initial_fee' => $amount, |
| 80 | 80 | 'recurring_fee' => 0, |
@@ -88,35 +88,35 @@ discard block |
||
| 88 | 88 | * @param array $element |
| 89 | 89 | * @param array $data |
| 90 | 90 | */ |
| 91 | - public function process_price_select( $element, $data ) { |
|
| 91 | + public function process_price_select($element, $data) { |
|
| 92 | 92 | |
| 93 | 93 | // Abort if not passed. |
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 94 | + if (empty($data[$element['id']])) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
| 99 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
| 100 | 100 | $total = 0; |
| 101 | 101 | $sub_labels = array(); |
| 102 | 102 | |
| 103 | - foreach ( $selected as $price ) { |
|
| 103 | + foreach ($selected as $price) { |
|
| 104 | 104 | |
| 105 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 105 | + if (!isset($options[$price])) { |
|
| 106 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $price = explode( '|', $price ); |
|
| 109 | + $price = explode('|', $price); |
|
| 110 | 110 | |
| 111 | 111 | $sub_labels[] = $price[0]; |
| 112 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 112 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $this->fees[ $element['label'] ] = array( |
|
| 115 | + $this->fees[$element['label']] = array( |
|
| 116 | 116 | 'name' => $element['label'], |
| 117 | 117 | 'initial_fee' => $total, |
| 118 | 118 | 'recurring_fee' => 0, |
| 119 | - 'description' => implode( ', ', $sub_labels ), |
|
| 119 | + 'description' => implode(', ', $sub_labels), |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | } |