@@ -7,26 +7,26 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Make sure that the form is active. |
13 | -if ( ! $form->is_active() ) { |
|
13 | +if (!$form->is_active()) { |
|
14 | 14 | echo aui()->alert( |
15 | 15 | array( |
16 | 16 | 'type' => 'warning', |
17 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
17 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
18 | 18 | ) |
19 | 19 | ); |
20 | 20 | return; |
21 | 21 | } |
22 | 22 | |
23 | 23 | // Require login to checkout. |
24 | -if ( wpinv_require_login_to_checkout() && ! get_current_user_id() ) { |
|
24 | +if (wpinv_require_login_to_checkout() && !get_current_user_id()) { |
|
25 | 25 | |
26 | 26 | echo aui()->alert( |
27 | 27 | array( |
28 | 28 | 'type' => 'danger', |
29 | - 'content' => __( 'You must be logged in to checkout.', 'invoicing' ), |
|
29 | + 'content' => __('You must be logged in to checkout.', 'invoicing'), |
|
30 | 30 | ) |
31 | 31 | ); |
32 | 32 | return; |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | // Fires before displaying a payment form. |
37 | -do_action( 'getpaid_before_payment_form', $form ); |
|
37 | +do_action('getpaid_before_payment_form', $form); |
|
38 | 38 | ?> |
39 | 39 | |
40 | -<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint( $form->get_id() ); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr( empty( $form->invoice ) ? wpinv_get_currency() : $form->invoice->get_currency() ); ?>' novalidate> |
|
40 | +<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint($form->get_id()); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr(empty($form->invoice) ? wpinv_get_currency() : $form->invoice->get_currency()); ?>' novalidate> |
|
41 | 41 | |
42 | 42 | <?php |
43 | 43 | |
44 | 44 | // Fires when printing the top of a payment form. |
45 | - do_action( 'getpaid_payment_form_top', $form ); |
|
45 | + do_action('getpaid_payment_form_top', $form); |
|
46 | 46 | |
47 | 47 | // And the optional invoice id. |
48 | - if ( ! empty( $form->invoice ) ) { |
|
49 | - echo getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() ); |
|
48 | + if (!empty($form->invoice)) { |
|
49 | + echo getpaid_hidden_field('invoice_id', $form->invoice->get_id()); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // We also want to include the form id. |
53 | - echo getpaid_hidden_field( 'form_id', $form->get_id() ); |
|
53 | + echo getpaid_hidden_field('form_id', $form->get_id()); |
|
54 | 54 | |
55 | 55 | // And an indication that this is a payment form submission. |
56 | - echo getpaid_hidden_field( 'getpaid_payment_form_submission', '1' ); |
|
56 | + echo getpaid_hidden_field('getpaid_payment_form_submission', '1'); |
|
57 | 57 | |
58 | 58 | // Fires before displaying payment form elements. |
59 | - do_action( 'getpaid_payment_form_before_elements', $form ); |
|
59 | + do_action('getpaid_payment_form_before_elements', $form); |
|
60 | 60 | |
61 | 61 | // Display the elements. |
62 | 62 | ?> |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | <div class="row"> |
65 | 65 | <?php |
66 | 66 | |
67 | - foreach ( $form->get_elements() as $element ) { |
|
67 | + foreach ($form->get_elements() as $element) { |
|
68 | 68 | |
69 | - if ( isset( $element['type'] ) ) { |
|
70 | - $grid_class = esc_attr( getpaid_get_form_element_grid_class( $element ) ); |
|
69 | + if (isset($element['type'])) { |
|
70 | + $grid_class = esc_attr(getpaid_get_form_element_grid_class($element)); |
|
71 | 71 | echo "<div class='$grid_class'>"; |
72 | - do_action( 'getpaid_payment_form_element', $element, $form ); |
|
73 | - do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form ); |
|
72 | + do_action('getpaid_payment_form_element', $element, $form); |
|
73 | + do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form); |
|
74 | 74 | echo "</div>"; |
75 | 75 | } |
76 | 76 | |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | |
83 | 83 | <?php |
84 | 84 | // Fires after displaying payment form elements. |
85 | - do_action( 'getpaid_payment_form_after_elements', $form ); |
|
85 | + do_action('getpaid_payment_form_after_elements', $form); |
|
86 | 86 | |
87 | 87 | echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>"; |
88 | 88 | |
89 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
89 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
90 | 90 | |
91 | 91 | edit_post_link( |
92 | - __( 'Edit this form.', 'invoicing' ), |
|
92 | + __('Edit this form.', 'invoicing'), |
|
93 | 93 | '<small class="form-text text-muted">', |
94 | - ' ' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>', |
|
94 | + ' ' . __('This is only visible to website administators.', 'invoicing') . '</small>', |
|
95 | 95 | $form->get_id(), |
96 | 96 | 'text-danger' |
97 | 97 | ); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | <div class="loading_div overlay overlay-black position-absolute row m-0 rounded overflow-hidden" style="height: 100%;width: 100%;top: 0px;z-index: 2;display:none;"> |
105 | 105 | <div class="spinner-border mx-auto align-self-center text-white" role="status"> |
106 | - <span class="sr-only"><?php _e( 'Loading...', 'invoicing' );?></span> |
|
106 | + <span class="sr-only"><?php _e('Loading...', 'invoicing'); ?></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | 109 | |
@@ -112,4 +112,4 @@ discard block |
||
112 | 112 | <?php |
113 | 113 | |
114 | 114 | // Fires after displaying a payment form. |
115 | -do_action( 'getpaid_after_payment_form', $form ); |
|
115 | +do_action('getpaid_after_payment_form', $form); |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - |
|
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | - |
|
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
50 | - |
|
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
53 | - |
|
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
60 | 21 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
65 | 26 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
68 | 29 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
71 | 32 | |
72 | - // Payment form information. |
|
73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | - } |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
76 | 35 | |
77 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
78 | 39 | |
79 | - } |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
80 | 44 | |
81 | - /** |
|
82 | - * Register core metaboxes. |
|
83 | - */ |
|
84 | - protected static function add_item_meta_boxes( $post_type ) { |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
85 | 47 | |
86 | - if ( $post_type == 'wpi_item' ) { |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
87 | 50 | |
88 | - // Item details. |
|
89 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
90 | 53 | |
91 | - // If taxes are enabled, register the tax metabox. |
|
92 | - if ( wpinv_use_taxes() ) { |
|
93 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
94 | - } |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
95 | 58 | |
96 | - // Item info. |
|
97 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
59 | + } |
|
98 | 60 | |
99 | - } |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
100 | 65 | |
101 | - } |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
102 | 68 | |
103 | - /** |
|
104 | - * Register invoice metaboxes. |
|
105 | - */ |
|
106 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
107 | 71 | |
108 | - // For invoices... |
|
109 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
110 | - $invoice = new WPInv_Invoice( $post ); |
|
72 | + // Payment form information. |
|
73 | + if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
75 | + } |
|
111 | 76 | |
112 | - // Resend invoice. |
|
113 | - if ( ! $invoice->is_draft() ) { |
|
77 | + } |
|
114 | 78 | |
115 | - add_meta_box( |
|
116 | - 'wpinv-mb-resend-invoice', |
|
117 | - sprintf( |
|
118 | - __( 'Resend %s', 'invoicing' ), |
|
119 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
120 | - ), |
|
121 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
122 | - $post_type, |
|
123 | - 'side', |
|
124 | - 'low' |
|
125 | - ); |
|
79 | + } |
|
126 | 80 | |
127 | - } |
|
81 | + /** |
|
82 | + * Register core metaboxes. |
|
83 | + */ |
|
84 | + protected static function add_item_meta_boxes( $post_type ) { |
|
128 | 85 | |
129 | - // Subscriptions. |
|
130 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
131 | - if ( ! empty( $subscriptions ) ) { |
|
86 | + if ( $post_type == 'wpi_item' ) { |
|
132 | 87 | |
133 | - if ( is_array( $subscriptions ) ) { |
|
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
135 | - } else { |
|
136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
137 | - } |
|
88 | + // Item details. |
|
89 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
138 | 90 | |
139 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
140 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
141 | - } |
|
91 | + // If taxes are enabled, register the tax metabox. |
|
92 | + if ( wpinv_use_taxes() ) { |
|
93 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
94 | + } |
|
142 | 95 | |
143 | - } |
|
96 | + // Item info. |
|
97 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
144 | 98 | |
145 | - // Invoice details. |
|
146 | - add_meta_box( |
|
147 | - 'wpinv-details', |
|
148 | - sprintf( |
|
149 | - __( '%s Details', 'invoicing' ), |
|
150 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
151 | - ), |
|
152 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
153 | - $post_type, |
|
154 | - 'side' |
|
155 | - ); |
|
99 | + } |
|
156 | 100 | |
157 | - // Payment details. |
|
158 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
101 | + } |
|
159 | 102 | |
160 | - // Billing details. |
|
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
103 | + /** |
|
104 | + * Register invoice metaboxes. |
|
105 | + */ |
|
106 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
107 | + |
|
108 | + // For invoices... |
|
109 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
110 | + $invoice = new WPInv_Invoice( $post ); |
|
111 | + |
|
112 | + // Resend invoice. |
|
113 | + if ( ! $invoice->is_draft() ) { |
|
114 | + |
|
115 | + add_meta_box( |
|
116 | + 'wpinv-mb-resend-invoice', |
|
117 | + sprintf( |
|
118 | + __( 'Resend %s', 'invoicing' ), |
|
119 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
120 | + ), |
|
121 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
122 | + $post_type, |
|
123 | + 'side', |
|
124 | + 'low' |
|
125 | + ); |
|
126 | + |
|
127 | + } |
|
128 | + |
|
129 | + // Subscriptions. |
|
130 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
131 | + if ( ! empty( $subscriptions ) ) { |
|
132 | + |
|
133 | + if ( is_array( $subscriptions ) ) { |
|
134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
135 | + } else { |
|
136 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
137 | + } |
|
138 | + |
|
139 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
140 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
141 | + } |
|
142 | + |
|
143 | + } |
|
144 | + |
|
145 | + // Invoice details. |
|
146 | + add_meta_box( |
|
147 | + 'wpinv-details', |
|
148 | + sprintf( |
|
149 | + __( '%s Details', 'invoicing' ), |
|
150 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
151 | + ), |
|
152 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
153 | + $post_type, |
|
154 | + 'side' |
|
155 | + ); |
|
156 | + |
|
157 | + // Payment details. |
|
158 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
159 | + |
|
160 | + // Billing details. |
|
161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
162 | 162 | |
163 | - // Invoice items. |
|
164 | - add_meta_box( |
|
165 | - 'wpinv-items', |
|
166 | - sprintf( |
|
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | - ), |
|
170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | - $post_type, |
|
172 | - 'normal', |
|
173 | - 'high' |
|
174 | - ); |
|
163 | + // Invoice items. |
|
164 | + add_meta_box( |
|
165 | + 'wpinv-items', |
|
166 | + sprintf( |
|
167 | + __( '%s Items', 'invoicing' ), |
|
168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | + ), |
|
170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | + $post_type, |
|
172 | + 'normal', |
|
173 | + 'high' |
|
174 | + ); |
|
175 | 175 | |
176 | - // Invoice notes. |
|
177 | - add_meta_box( |
|
178 | - 'wpinv-notes', |
|
179 | - sprintf( |
|
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | - ), |
|
183 | - 'WPInv_Meta_Box_Notes::output', |
|
184 | - $post_type, |
|
185 | - 'side', |
|
186 | - 'low' |
|
187 | - ); |
|
188 | - |
|
189 | - // Shipping Address. |
|
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | - } |
|
193 | - |
|
194 | - // Payment form information. |
|
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | - } |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Remove some metaboxes. |
|
205 | - */ |
|
206 | - public static function remove_meta_boxes() { |
|
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Rename other metaboxes. |
|
212 | - */ |
|
213 | - public static function rename_meta_boxes() { |
|
176 | + // Invoice notes. |
|
177 | + add_meta_box( |
|
178 | + 'wpinv-notes', |
|
179 | + sprintf( |
|
180 | + __( '%s Notes', 'invoicing' ), |
|
181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | + ), |
|
183 | + 'WPInv_Meta_Box_Notes::output', |
|
184 | + $post_type, |
|
185 | + 'side', |
|
186 | + 'low' |
|
187 | + ); |
|
188 | + |
|
189 | + // Shipping Address. |
|
190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | + } |
|
193 | + |
|
194 | + // Payment form information. |
|
195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | + } |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Remove some metaboxes. |
|
205 | + */ |
|
206 | + public static function remove_meta_boxes() { |
|
207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Rename other metaboxes. |
|
212 | + */ |
|
213 | + public static function rename_meta_boxes() { |
|
214 | 214 | |
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if we're saving, then trigger an action based on the post type. |
|
219 | - * |
|
220 | - * @param int $post_id Post ID. |
|
221 | - * @param object $post Post object. |
|
222 | - */ |
|
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | - |
|
227 | - // Do not save for ajax requests. |
|
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | - return; |
|
230 | - } |
|
231 | - |
|
232 | - // $post_id and $post are required |
|
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | - return; |
|
235 | - } |
|
236 | - |
|
237 | - // Dont' save meta boxes for revisions or autosaves. |
|
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | - return; |
|
240 | - } |
|
241 | - |
|
242 | - // Check the nonce. |
|
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - |
|
252 | - // Check user has permission to edit. |
|
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | - |
|
259 | - // We need this save event to run once to avoid potential endless loops. |
|
260 | - self::$saved_meta_boxes = true; |
|
261 | - |
|
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - // Ensure this is our post type. |
|
267 | - $post_types_map = array( |
|
268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | - ); |
|
272 | - |
|
273 | - // Is this our post type? |
|
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // We need this save event to run once to avoid potential endless loops. |
|
279 | - self::$saved_meta_boxes = true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if we're saving, then trigger an action based on the post type. |
|
219 | + * |
|
220 | + * @param int $post_id Post ID. |
|
221 | + * @param object $post Post object. |
|
222 | + */ |
|
223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
224 | + $post_id = absint( $post_id ); |
|
225 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
226 | + |
|
227 | + // Do not save for ajax requests. |
|
228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | + return; |
|
230 | + } |
|
231 | + |
|
232 | + // $post_id and $post are required |
|
233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | + return; |
|
235 | + } |
|
236 | + |
|
237 | + // Dont' save meta boxes for revisions or autosaves. |
|
238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + |
|
242 | + // Check the nonce. |
|
243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + |
|
252 | + // Check user has permission to edit. |
|
253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | + |
|
259 | + // We need this save event to run once to avoid potential endless loops. |
|
260 | + self::$saved_meta_boxes = true; |
|
261 | + |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + // Ensure this is our post type. |
|
267 | + $post_types_map = array( |
|
268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | + ); |
|
272 | + |
|
273 | + // Is this our post type? |
|
274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // We need this save event to run once to avoid potential endless loops. |
|
279 | + self::$saved_meta_boxes = true; |
|
280 | 280 | |
281 | - // Save the post. |
|
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
281 | + // Save the post. |
|
282 | + $class = $post_types_map[ $post->post_type ]; |
|
283 | + $class::save( $post_id, $_POST, $post ); |
|
284 | 284 | |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | } |
@@ -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 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
25 | 25 | public static function init() { |
26 | 26 | |
27 | 27 | // Register metaboxes. |
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
29 | 29 | |
30 | 30 | // Remove metaboxes. |
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
32 | 32 | |
33 | 33 | // Rename metaboxes. |
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
35 | 35 | |
36 | 36 | // Save metaboxes. |
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register core metaboxes. |
42 | 42 | */ |
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
43 | + public static function add_meta_boxes($post_type, $post) { |
|
44 | 44 | |
45 | 45 | // For invoices... |
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
47 | 47 | |
48 | 48 | // For payment forms. |
49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
49 | + self::add_payment_form_meta_boxes($post_type, $post); |
|
50 | 50 | |
51 | 51 | // For invoice items. |
52 | - self::add_item_meta_boxes( $post_type ); |
|
52 | + self::add_item_meta_boxes($post_type); |
|
53 | 53 | |
54 | 54 | // For invoice discounts. |
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
55 | + if ($post_type == 'wpi_discount') { |
|
56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Register core metaboxes. |
63 | 63 | */ |
64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
64 | + protected static function add_payment_form_meta_boxes($post_type, $post) { |
|
65 | 65 | |
66 | 66 | // For payment forms. |
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
67 | + if ($post_type == 'wpi_payment_form') { |
|
68 | 68 | |
69 | 69 | // Design payment form. |
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
71 | 71 | |
72 | 72 | // Payment form information. |
73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
73 | + if ($post->ID != wpinv_get_default_payment_form()) { |
|
74 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | } |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Register core metaboxes. |
83 | 83 | */ |
84 | - protected static function add_item_meta_boxes( $post_type ) { |
|
84 | + protected static function add_item_meta_boxes($post_type) { |
|
85 | 85 | |
86 | - if ( $post_type == 'wpi_item' ) { |
|
86 | + if ($post_type == 'wpi_item') { |
|
87 | 87 | |
88 | 88 | // Item details. |
89 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
89 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
90 | 90 | |
91 | 91 | // If taxes are enabled, register the tax metabox. |
92 | - if ( wpinv_use_taxes() ) { |
|
93 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | + if (wpinv_use_taxes()) { |
|
93 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // Item info. |
97 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
97 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
98 | 98 | |
99 | 99 | } |
100 | 100 | |
@@ -103,20 +103,20 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * Register invoice metaboxes. |
105 | 105 | */ |
106 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
106 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
107 | 107 | |
108 | 108 | // For invoices... |
109 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
110 | - $invoice = new WPInv_Invoice( $post ); |
|
109 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
110 | + $invoice = new WPInv_Invoice($post); |
|
111 | 111 | |
112 | 112 | // Resend invoice. |
113 | - if ( ! $invoice->is_draft() ) { |
|
113 | + if (!$invoice->is_draft()) { |
|
114 | 114 | |
115 | 115 | add_meta_box( |
116 | 116 | 'wpinv-mb-resend-invoice', |
117 | 117 | sprintf( |
118 | - __( 'Resend %s', 'invoicing' ), |
|
119 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | + __('Resend %s', 'invoicing'), |
|
119 | + ucfirst($invoice->get_invoice_quote_type()) |
|
120 | 120 | ), |
121 | 121 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
122 | 122 | $post_type, |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | // Subscriptions. |
130 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
131 | - if ( ! empty( $subscriptions ) ) { |
|
130 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
131 | + if (!empty($subscriptions)) { |
|
132 | 132 | |
133 | - if ( is_array( $subscriptions ) ) { |
|
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
133 | + if (is_array($subscriptions)) { |
|
134 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
135 | 135 | } else { |
136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
136 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
140 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
139 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
140 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | } |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | add_meta_box( |
147 | 147 | 'wpinv-details', |
148 | 148 | sprintf( |
149 | - __( '%s Details', 'invoicing' ), |
|
150 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | + __('%s Details', 'invoicing'), |
|
150 | + ucfirst($invoice->get_invoice_quote_type()) |
|
151 | 151 | ), |
152 | 152 | 'GetPaid_Meta_Box_Invoice_Details::output', |
153 | 153 | $post_type, |
@@ -155,17 +155,17 @@ discard block |
||
155 | 155 | ); |
156 | 156 | |
157 | 157 | // Payment details. |
158 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
158 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
159 | 159 | |
160 | 160 | // Billing details. |
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
162 | 162 | |
163 | 163 | // Invoice items. |
164 | 164 | add_meta_box( |
165 | 165 | 'wpinv-items', |
166 | 166 | sprintf( |
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
167 | + __('%s Items', 'invoicing'), |
|
168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
169 | 169 | ), |
170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | add_meta_box( |
178 | 178 | 'wpinv-notes', |
179 | 179 | sprintf( |
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
180 | + __('%s Notes', 'invoicing'), |
|
181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
182 | 182 | ), |
183 | 183 | 'WPInv_Meta_Box_Notes::output', |
184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | ); |
188 | 188 | |
189 | 189 | // Shipping Address. |
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | // Payment form information. |
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * Remove some metaboxes. |
205 | 205 | */ |
206 | 206 | public static function remove_meta_boxes() { |
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
220 | 220 | * @param int $post_id Post ID. |
221 | 221 | * @param object $post Post object. |
222 | 222 | */ |
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
223 | + public static function save_meta_boxes($post_id, $post) { |
|
224 | + $post_id = absint($post_id); |
|
225 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
226 | 226 | |
227 | 227 | // Do not save for ajax requests. |
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // $post_id and $post are required |
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Check the nonce. |
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Check user has permission to edit. |
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
253 | + if (!current_user_can('edit_post', $post_id)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
258 | 258 | |
259 | 259 | // We need this save event to run once to avoid potential endless loops. |
260 | 260 | self::$saved_meta_boxes = true; |
261 | 261 | |
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | ); |
272 | 272 | |
273 | 273 | // Is this our post type? |
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
274 | + if (!isset($post_types_map[$post->post_type])) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | self::$saved_meta_boxes = true; |
280 | 280 | |
281 | 281 | // Save the post. |
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
282 | + $class = $post_types_map[$post->post_type]; |
|
283 | + $class::save($post_id, $_POST, $post); |
|
284 | 284 | |
285 | 285 | } |
286 | 286 |
@@ -9,41 +9,41 @@ discard block |
||
9 | 9 | * @version 1.0.19 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | 16 | array( |
17 | 17 | 'type' => 'heading', |
18 | - 'name' => __( 'Heading', 'invoicing' ), |
|
18 | + 'name' => __('Heading', 'invoicing'), |
|
19 | 19 | 'defaults' => array( |
20 | 20 | 'level' => 'h2', |
21 | - 'text' => __( 'Heading', 'invoicing' ), |
|
21 | + 'text' => __('Heading', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ), |
24 | 24 | |
25 | 25 | array( |
26 | 26 | 'type' => 'paragraph', |
27 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
27 | + 'name' => __('Paragraph', 'invoicing'), |
|
28 | 28 | 'defaults' => array( |
29 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
29 | + 'text' => __('Paragraph text', 'invoicing'), |
|
30 | 30 | ) |
31 | 31 | ), |
32 | 32 | |
33 | 33 | array( |
34 | 34 | 'type' => 'alert', |
35 | - 'name' => __( 'Alert', 'invoicing' ), |
|
35 | + 'name' => __('Alert', 'invoicing'), |
|
36 | 36 | 'defaults' => array( |
37 | 37 | 'value' => '', |
38 | 38 | 'class' => 'alert-warning', |
39 | - 'text' => __( 'Alert', 'invoicing' ), |
|
39 | + 'text' => __('Alert', 'invoicing'), |
|
40 | 40 | 'dismissible' => false, |
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | |
44 | 44 | array( |
45 | 45 | 'type' => 'separator', |
46 | - 'name' => __( 'Separator', 'invoicing' ), |
|
46 | + 'name' => __('Separator', 'invoicing'), |
|
47 | 47 | 'defaults' => array( |
48 | 48 | 'value' => '', |
49 | 49 | ), |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | |
52 | 52 | array( |
53 | 53 | 'type' => 'text', |
54 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
54 | + 'name' => __('Text Input', 'invoicing'), |
|
55 | 55 | 'defaults' => array( |
56 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
56 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
57 | 57 | 'value' => '', |
58 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
58 | + 'label' => __('Field Label', 'invoicing'), |
|
59 | 59 | 'description' => '', |
60 | 60 | 'required' => false, |
61 | 61 | ) |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | |
64 | 64 | array( |
65 | 65 | 'type' => 'textarea', |
66 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
66 | + 'name' => __('Textarea', 'invoicing'), |
|
67 | 67 | 'defaults' => array( |
68 | - 'placeholder' => __( 'Enter your text here', 'invoicing' ), |
|
68 | + 'placeholder' => __('Enter your text here', 'invoicing'), |
|
69 | 69 | 'value' => '', |
70 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
70 | + 'label' => __('Textarea Label', 'invoicing'), |
|
71 | 71 | 'description' => '', |
72 | 72 | 'required' => false, |
73 | 73 | ) |
@@ -75,27 +75,27 @@ discard block |
||
75 | 75 | |
76 | 76 | array( |
77 | 77 | 'type' => 'select', |
78 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
78 | + 'name' => __('Dropdown', 'invoicing'), |
|
79 | 79 | 'defaults' => array( |
80 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
80 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
81 | 81 | 'value' => '', |
82 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
82 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
83 | 83 | 'description' => '', |
84 | 84 | 'required' => false, |
85 | 85 | 'options' => array( |
86 | - esc_attr__( 'Option One', 'invoicing' ), |
|
87 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
88 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
86 | + esc_attr__('Option One', 'invoicing'), |
|
87 | + esc_attr__('Option Two', 'invoicing'), |
|
88 | + esc_attr__('Option Three', 'invoicing') |
|
89 | 89 | ), |
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | |
93 | 93 | array( |
94 | 94 | 'type' => 'checkbox', |
95 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
95 | + 'name' => __('Checkbox', 'invoicing'), |
|
96 | 96 | 'defaults' => array( |
97 | 97 | 'value' => '', |
98 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
98 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
99 | 99 | 'description' => '', |
100 | 100 | 'required' => false, |
101 | 101 | ) |
@@ -103,23 +103,23 @@ discard block |
||
103 | 103 | |
104 | 104 | array( |
105 | 105 | 'type' => 'radio', |
106 | - 'name' => __( 'Radio', 'invoicing' ), |
|
106 | + 'name' => __('Radio', 'invoicing'), |
|
107 | 107 | 'defaults' => array( |
108 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
108 | + 'label' => __('Select one choice', 'invoicing'), |
|
109 | 109 | 'options' => array( |
110 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
111 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
112 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
110 | + esc_attr__('Choice One', 'invoicing'), |
|
111 | + esc_attr__('Choice Two', 'invoicing'), |
|
112 | + esc_attr__('Choice Three', 'invoicing') |
|
113 | 113 | ), |
114 | 114 | ) |
115 | 115 | ), |
116 | 116 | |
117 | 117 | array( |
118 | 118 | 'type' => 'date', |
119 | - 'name' => __( 'Date', 'invoicing' ), |
|
119 | + 'name' => __('Date', 'invoicing'), |
|
120 | 120 | 'defaults' => array( |
121 | 121 | 'value' => '', |
122 | - 'label' => __( 'Date', 'invoicing' ), |
|
122 | + 'label' => __('Date', 'invoicing'), |
|
123 | 123 | 'description' => '', |
124 | 124 | 'single' => 'single', |
125 | 125 | 'required' => false, |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | |
129 | 129 | array( |
130 | 130 | 'type' => 'time', |
131 | - 'name' => __( 'Time', 'invoicing' ), |
|
131 | + 'name' => __('Time', 'invoicing'), |
|
132 | 132 | 'defaults' => array( |
133 | 133 | 'value' => '', |
134 | - 'label' => __( 'Time', 'invoicing' ), |
|
134 | + 'label' => __('Time', 'invoicing'), |
|
135 | 135 | 'description' => '', |
136 | 136 | 'required' => false, |
137 | 137 | ) |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | |
140 | 140 | array( |
141 | 141 | 'type' => 'number', |
142 | - 'name' => __( 'Number', 'invoicing' ), |
|
142 | + 'name' => __('Number', 'invoicing'), |
|
143 | 143 | 'defaults' => array( |
144 | 144 | 'placeholder' => '', |
145 | 145 | 'value' => '', |
146 | - 'label' => __( 'Number', 'invoicing' ), |
|
146 | + 'label' => __('Number', 'invoicing'), |
|
147 | 147 | 'description' => '', |
148 | 148 | 'required' => false, |
149 | 149 | ) |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | |
152 | 152 | array( |
153 | 153 | 'type' => 'website', |
154 | - 'name' => __( 'Website', 'invoicing' ), |
|
154 | + 'name' => __('Website', 'invoicing'), |
|
155 | 155 | 'defaults' => array( |
156 | 156 | 'placeholder' => 'http://example.com', |
157 | 157 | 'value' => '', |
158 | - 'label' => __( 'Website', 'invoicing' ), |
|
158 | + 'label' => __('Website', 'invoicing'), |
|
159 | 159 | 'description' => '', |
160 | 160 | 'required' => false, |
161 | 161 | ) |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | |
164 | 164 | array( |
165 | 165 | 'type' => 'email', |
166 | - 'name' => __( 'Email', 'invoicing' ), |
|
166 | + 'name' => __('Email', 'invoicing'), |
|
167 | 167 | 'defaults' => array( |
168 | 168 | 'placeholder' => '[email protected]', |
169 | 169 | 'value' => '', |
170 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
170 | + 'label' => __('Email Address', 'invoicing'), |
|
171 | 171 | 'description' => '', |
172 | 172 | 'required' => false, |
173 | 173 | ) |
@@ -175,31 +175,31 @@ discard block |
||
175 | 175 | |
176 | 176 | array( |
177 | 177 | 'type' => 'file_upload', |
178 | - 'name' => __( 'File Upload', 'invoicing' ), |
|
178 | + 'name' => __('File Upload', 'invoicing'), |
|
179 | 179 | 'defaults' => array( |
180 | 180 | 'value' => '', |
181 | - 'label' => __( 'Upload File', 'invoicing' ), |
|
181 | + 'label' => __('Upload File', 'invoicing'), |
|
182 | 182 | 'description' => '', |
183 | 183 | 'required' => false, |
184 | 184 | 'max_file_num' => 1, |
185 | - 'file_types' => array( 'jpg|jpeg|jpe', 'gif', 'png' ), |
|
185 | + 'file_types' => array('jpg|jpeg|jpe', 'gif', 'png'), |
|
186 | 186 | ) |
187 | 187 | ), |
188 | 188 | |
189 | 189 | array( |
190 | 190 | 'type' => 'address', |
191 | - 'name' => __( 'Address', 'invoicing' ), |
|
191 | + 'name' => __('Address', 'invoicing'), |
|
192 | 192 | 'defaults' => array( |
193 | 193 | |
194 | 194 | 'address_type' => 'billing', |
195 | - 'billing_address_title' => __( 'Billing Address', 'invoicing' ), |
|
196 | - 'shipping_address_title' => __( 'Shipping Address', 'invoicing' ), |
|
197 | - 'shipping_address_toggle' => __( 'Same billing & shipping address.', 'invoicing' ), |
|
195 | + 'billing_address_title' => __('Billing Address', 'invoicing'), |
|
196 | + 'shipping_address_title' => __('Shipping Address', 'invoicing'), |
|
197 | + 'shipping_address_toggle' => __('Same billing & shipping address.', 'invoicing'), |
|
198 | 198 | 'fields' => array( |
199 | 199 | array( |
200 | 200 | 'placeholder' => 'Jon', |
201 | 201 | 'value' => '', |
202 | - 'label' => __( 'First Name', 'invoicing' ), |
|
202 | + 'label' => __('First Name', 'invoicing'), |
|
203 | 203 | 'description' => '', |
204 | 204 | 'required' => false, |
205 | 205 | 'visible' => true, |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | array( |
211 | 211 | 'placeholder' => 'Snow', |
212 | 212 | 'value' => '', |
213 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
213 | + 'label' => __('Last Name', 'invoicing'), |
|
214 | 214 | 'description' => '', |
215 | 215 | 'required' => false, |
216 | 216 | 'visible' => true, |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | array( |
222 | 222 | 'placeholder' => '', |
223 | 223 | 'value' => '', |
224 | - 'label' => __( 'Address', 'invoicing' ), |
|
224 | + 'label' => __('Address', 'invoicing'), |
|
225 | 225 | 'description' => '', |
226 | 226 | 'required' => false, |
227 | 227 | 'visible' => true, |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | array( |
233 | 233 | 'placeholder' => '', |
234 | 234 | 'value' => '', |
235 | - 'label' => __( 'City', 'invoicing' ), |
|
235 | + 'label' => __('City', 'invoicing'), |
|
236 | 236 | 'description' => '', |
237 | 237 | 'required' => false, |
238 | 238 | 'visible' => true, |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | ), |
242 | 242 | |
243 | 243 | array( |
244 | - 'placeholder' => __( 'Select your country' ), |
|
244 | + 'placeholder' => __('Select your country'), |
|
245 | 245 | 'value' => '', |
246 | - 'label' => __( 'Country', 'invoicing' ), |
|
246 | + 'label' => __('Country', 'invoicing'), |
|
247 | 247 | 'description' => '', |
248 | 248 | 'required' => false, |
249 | 249 | 'visible' => true, |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | ), |
253 | 253 | |
254 | 254 | array( |
255 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
255 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
256 | 256 | 'value' => '', |
257 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
257 | + 'label' => __('State / Province', 'invoicing'), |
|
258 | 258 | 'description' => '', |
259 | 259 | 'required' => false, |
260 | 260 | 'visible' => true, |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | array( |
266 | 266 | 'placeholder' => '', |
267 | 267 | 'value' => '', |
268 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
268 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
269 | 269 | 'description' => '', |
270 | 270 | 'required' => false, |
271 | 271 | 'visible' => true, |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | array( |
277 | 277 | 'placeholder' => '', |
278 | 278 | 'value' => '', |
279 | - 'label' => __( 'Phone', 'invoicing' ), |
|
279 | + 'label' => __('Phone', 'invoicing'), |
|
280 | 280 | 'description' => '', |
281 | 281 | 'required' => false, |
282 | 282 | 'visible' => true, |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | array( |
288 | 288 | 'placeholder' => '', |
289 | 289 | 'value' => '', |
290 | - 'label' => __( 'Company', 'invoicing' ), |
|
290 | + 'label' => __('Company', 'invoicing'), |
|
291 | 291 | 'description' => '', |
292 | 292 | 'required' => false, |
293 | 293 | 'visible' => false, |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | array( |
299 | 299 | 'placeholder' => '', |
300 | 300 | 'value' => '', |
301 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
301 | + 'label' => __('Company ID', 'invoicing'), |
|
302 | 302 | 'description' => '', |
303 | 303 | 'required' => false, |
304 | 304 | 'visible' => false, |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | array( |
310 | 310 | 'placeholder' => '', |
311 | 311 | 'value' => '', |
312 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
312 | + 'label' => __('VAT Number', 'invoicing'), |
|
313 | 313 | 'description' => '', |
314 | 314 | 'required' => false, |
315 | 315 | 'visible' => false, |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | |
323 | 323 | array( |
324 | 324 | 'type' => 'billing_email', |
325 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
325 | + 'name' => __('Billing Email', 'invoicing'), |
|
326 | 326 | 'defaults' => array( |
327 | 327 | 'placeholder' => '[email protected]', |
328 | 328 | 'value' => '', |
329 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
329 | + 'label' => __('Billing Email', 'invoicing'), |
|
330 | 330 | 'description' => '', |
331 | 331 | 'premade' => true, |
332 | 332 | ) |
@@ -334,18 +334,18 @@ discard block |
||
334 | 334 | |
335 | 335 | array( |
336 | 336 | 'type' => 'discount', |
337 | - 'name' => __( 'Discount Input', 'invoicing' ), |
|
337 | + 'name' => __('Discount Input', 'invoicing'), |
|
338 | 338 | 'defaults' => array( |
339 | 339 | 'value' => '', |
340 | - 'input_label' => __( 'Coupon Code', 'invoicing' ), |
|
341 | - 'button_label' => __( 'Apply Coupon', 'invoicing' ), |
|
342 | - 'description' => __( 'Have a discount code? Enter it above.', 'invoicing' ), |
|
340 | + 'input_label' => __('Coupon Code', 'invoicing'), |
|
341 | + 'button_label' => __('Apply Coupon', 'invoicing'), |
|
342 | + 'description' => __('Have a discount code? Enter it above.', 'invoicing'), |
|
343 | 343 | ) |
344 | 344 | ), |
345 | 345 | |
346 | 346 | array( |
347 | 347 | 'type' => 'items', |
348 | - 'name' => __( 'Items', 'invoicing' ), |
|
348 | + 'name' => __('Items', 'invoicing'), |
|
349 | 349 | 'defaults' => array( |
350 | 350 | 'value' => '', |
351 | 351 | 'items_type' => 'total', |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | |
358 | 358 | array( |
359 | 359 | 'type' => 'price_input', |
360 | - 'name' => __( 'Price Input', 'invoicing' ), |
|
360 | + 'name' => __('Price Input', 'invoicing'), |
|
361 | 361 | 'defaults' => array( |
362 | 362 | 'placeholder' => wpinv_format_amount(0), |
363 | 363 | 'value' => wpinv_format_amount(0), |
364 | 364 | 'minimum' => wpinv_format_amount(0), |
365 | - 'label' => __( 'Enter Amount', 'invoicing' ), |
|
365 | + 'label' => __('Enter Amount', 'invoicing'), |
|
366 | 366 | 'description' => '', |
367 | 367 | ) |
368 | 368 | ), |
369 | 369 | |
370 | 370 | array( |
371 | 371 | 'type' => 'price_select', |
372 | - 'name' => __( 'Price Select', 'invoicing' ), |
|
372 | + 'name' => __('Price Select', 'invoicing'), |
|
373 | 373 | 'defaults' => array( |
374 | 374 | 'description' => '', |
375 | - 'label' => __( 'Select Amount', 'invoicing' ), |
|
375 | + 'label' => __('Select Amount', 'invoicing'), |
|
376 | 376 | 'options' => 'Option 1|10, Option 2|20', |
377 | 377 | 'placeholder' => '', |
378 | 378 | 'select_type' => 'select', |
@@ -381,39 +381,39 @@ discard block |
||
381 | 381 | |
382 | 382 | array( |
383 | 383 | 'type' => 'pay_button', |
384 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
384 | + 'name' => __('Payment Button', 'invoicing'), |
|
385 | 385 | 'defaults' => array( |
386 | 386 | 'value' => '', |
387 | 387 | 'class' => 'btn-primary', |
388 | - 'label' => __( 'Pay %price% »', 'invoicing' ), |
|
389 | - 'free' => __( 'Continue »', 'invoicing' ), |
|
390 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
388 | + 'label' => __('Pay %price% »', 'invoicing'), |
|
389 | + 'free' => __('Continue »', 'invoicing'), |
|
390 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
391 | 391 | 'premade' => true, |
392 | 392 | ) |
393 | 393 | ), |
394 | 394 | |
395 | 395 | array( |
396 | 396 | 'type' => 'gateway_select', |
397 | - 'name' => __( 'Gateway Select', 'invoicing' ), |
|
397 | + 'name' => __('Gateway Select', 'invoicing'), |
|
398 | 398 | 'defaults' => array( |
399 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
399 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
400 | 400 | 'premade' => true, |
401 | 401 | ) |
402 | 402 | ), |
403 | 403 | |
404 | 404 | array( |
405 | 405 | 'type' => 'total_payable', |
406 | - 'name' => __( 'Total Payable', 'invoicing' ), |
|
406 | + 'name' => __('Total Payable', 'invoicing'), |
|
407 | 407 | 'defaults' => array( |
408 | - 'text' => __( 'Total to pay:', 'invoicing' ), |
|
408 | + 'text' => __('Total to pay:', 'invoicing'), |
|
409 | 409 | ) |
410 | 410 | ), |
411 | 411 | |
412 | 412 | array( |
413 | 413 | 'type' => 'ip_address', |
414 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
414 | + 'name' => __('IP Address', 'invoicing'), |
|
415 | 415 | 'defaults' => array( |
416 | - 'text' => __( 'Your IP address is:', 'invoicing' ), |
|
416 | + 'text' => __('Your IP address is:', 'invoicing'), |
|
417 | 417 | ) |
418 | 418 | ) |
419 | 419 | ); |
@@ -12,58 +12,58 @@ |
||
12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | if ( ! empty( $required ) ) { |
15 | - $label .= "<span class='text-danger'> *</span>"; |
|
15 | + $label .= "<span class='text-danger'> *</span>"; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | 20 | if ( ! empty( $disabled_dates ) ) { |
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim( $disabled_date ); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | - $disable_dates[] = $disabled_date; |
|
31 | - continue; |
|
32 | - } |
|
29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | + $disable_dates[] = $disabled_date; |
|
31 | + continue; |
|
32 | + } |
|
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
35 | - $disable_dates[] = array( |
|
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
38 | - ); |
|
34 | + $disabled_date = explode( '|', $disabled_date ); |
|
35 | + $disable_dates[] = array( |
|
36 | + 'from' => trim( $disabled_date[0] ), |
|
37 | + 'to' => trim( $disabled_date[1] ), |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | $options = array( |
45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | - 'data-date-format' => 'Y-m-d', |
|
51 | - 'data-alt-input' => 'true', |
|
52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
45 | + 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | + 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | + 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | + 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
50 | + 'data-date-format' => 'Y-m-d', |
|
51 | + 'data-alt-input' => 'true', |
|
52 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | echo aui()->input( |
57 | - array( |
|
58 | - 'name' => esc_attr( $id ), |
|
59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | - 'required' => ! empty( $required ), |
|
62 | - 'label' => $label, |
|
63 | - 'label_type' => 'vertical', |
|
64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | - 'type' => 'datepicker', |
|
66 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | - ) |
|
57 | + array( |
|
58 | + 'name' => esc_attr( $id ), |
|
59 | + 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | + 'required' => ! empty( $required ), |
|
62 | + 'label' => $label, |
|
63 | + 'label_type' => 'vertical', |
|
64 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
65 | + 'type' => 'datepicker', |
|
66 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
67 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
68 | + ) |
|
69 | 69 | ); |
@@ -7,34 +7,34 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
14 | -if ( ! empty( $required ) ) { |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | -if ( ! empty( $disabled_dates ) ) { |
|
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
20 | +if (!empty($disabled_dates)) { |
|
21 | + $disabled_dates = preg_replace('/\s+/', '', $disabled_dates); |
|
22 | + $disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates); |
|
23 | + $disabled_dates = array_filter(explode(',', $disabled_dates)); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ($disabled_dates as $disabled_date) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim($disabled_date); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
29 | + if (false === strpos($disabled_date, '|')) { |
|
30 | 30 | $disable_dates[] = $disabled_date; |
31 | 31 | continue; |
32 | 32 | } |
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
34 | + $disabled_date = explode('|', $disabled_date); |
|
35 | 35 | $disable_dates[] = array( |
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
36 | + 'from' => trim($disabled_date[0]), |
|
37 | + 'to' => trim($disabled_date[1]), |
|
38 | 38 | ); |
39 | 39 | |
40 | 40 | } |
@@ -42,28 +42,28 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | $options = array( |
45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
45 | + 'data-default-date' => empty('default_date') ? false : $default_date, |
|
46 | + 'data-min-date' => empty('min_date') ? false : $min_date, |
|
47 | + 'data-max-date' => empty('max_date') ? false : $max_date, |
|
48 | + 'data-mode' => empty('mode') ? 'single' : $mode, |
|
49 | + 'data-alt-format' => get_option('date_format', 'F j, Y'), |
|
50 | 50 | 'data-date-format' => 'Y-m-d', |
51 | 51 | 'data-alt-input' => 'true', |
52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
52 | + 'data-disable_alt' => empty($disabled_dates) ? false : wp_json_encode($disable_dates), |
|
53 | + 'data-disable_days_alt' => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)), |
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | echo aui()->input( |
57 | 57 | array( |
58 | - 'name' => esc_attr( $id ), |
|
59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
61 | - 'required' => ! empty( $required ), |
|
58 | + 'name' => esc_attr($id), |
|
59 | + 'id' => esc_attr($id) . uniqid('_'), |
|
60 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
61 | + 'required' => !empty($required), |
|
62 | 62 | 'label' => $label, |
63 | 63 | 'label_type' => 'vertical', |
64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
64 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
65 | 65 | 'type' => 'datepicker', |
66 | 66 | 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
67 | + 'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)), |
|
68 | 68 | ) |
69 | 69 | ); |
@@ -7,104 +7,104 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Default Date', 'invoicing' ); ?></span> |
|
24 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
25 | - <input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
23 | + <span><?php esc_html_e('Default Date', 'invoicing'); ?></span> |
|
24 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
25 | + <input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
26 | 26 | </label> |
27 | 27 | </div> |
28 | 28 | |
29 | 29 | <div class='form-group'> |
30 | 30 | <label class="d-block"> |
31 | - <span><?php esc_html_e( 'Minimum Date', 'invoicing' ); ?></span> |
|
32 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
33 | - <input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
34 | - <small class="form-text text-muted"><?php _e( 'Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing' ); ?></small> |
|
31 | + <span><?php esc_html_e('Minimum Date', 'invoicing'); ?></span> |
|
32 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
33 | + <input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
34 | + <small class="form-text text-muted"><?php _e('Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing'); ?></small> |
|
35 | 35 | </label> |
36 | 36 | </div> |
37 | 37 | |
38 | 38 | <div class='form-group'> |
39 | 39 | <label class="d-block"> |
40 | - <span><?php esc_html_e( 'Maximum Date', 'invoicing' ); ?></span> |
|
41 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
42 | - <input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
43 | - <small class="form-text text-muted"><?php _e( 'Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing' ); ?></small> |
|
40 | + <span><?php esc_html_e('Maximum Date', 'invoicing'); ?></span> |
|
41 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
42 | + <input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
43 | + <small class="form-text text-muted"><?php _e('Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing'); ?></small> |
|
44 | 44 | </label> |
45 | 45 | </div> |
46 | 46 | |
47 | 47 | <div class='form-group'> |
48 | 48 | <label class="d-block"> |
49 | - <span><?php esc_html_e( 'Disabled Dates', 'invoicing' ); ?></span> |
|
50 | - <?php echo wpi_help_tip( sprintf( __( 'You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
51 | - <input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr( sprintf( __( 'For example, %s', 'invoicing' ), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01' ) ); ?>" class='form-control' type="text"/> |
|
52 | - <small class="form-text text-muted"><?php _e( 'Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing' ); ?></small> |
|
49 | + <span><?php esc_html_e('Disabled Dates', 'invoicing'); ?></span> |
|
50 | + <?php echo wpi_help_tip(sprintf(__('You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
51 | + <input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr(sprintf(__('For example, %s', 'invoicing'), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01')); ?>" class='form-control' type="text"/> |
|
52 | + <small class="form-text text-muted"><?php _e('Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing'); ?></small> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 | |
56 | 56 | <div class='form-group'> |
57 | 57 | <label class="d-block"> |
58 | - <span><?php esc_html_e( 'Disable Days', 'invoicing' ) ?></span> |
|
58 | + <span><?php esc_html_e('Disable Days', 'invoicing') ?></span> |
|
59 | 59 | <gpselect2 class='form-control custom-select' v-model='active_form_element.disable_days' multiple> |
60 | - <option value='0'><?php esc_html_e( 'Sundays', 'invoicing' ); ?></option> |
|
61 | - <option value='1'><?php esc_html_e( 'Mondays', 'invoicing' ); ?></option> |
|
62 | - <option value='2'><?php esc_html_e( 'Tuesdays', 'invoicing' ); ?></option> |
|
63 | - <option value='3'><?php esc_html_e( 'Wednesdays', 'invoicing' ); ?></option> |
|
64 | - <option value='4'><?php esc_html_e( 'Thursdays', 'invoicing' ); ?></option> |
|
65 | - <option value='5'><?php esc_html_e( 'Fridays', 'invoicing' ); ?></option> |
|
66 | - <option value='6'><?php esc_html_e( 'Saturdays', 'invoicing' ); ?></option> |
|
60 | + <option value='0'><?php esc_html_e('Sundays', 'invoicing'); ?></option> |
|
61 | + <option value='1'><?php esc_html_e('Mondays', 'invoicing'); ?></option> |
|
62 | + <option value='2'><?php esc_html_e('Tuesdays', 'invoicing'); ?></option> |
|
63 | + <option value='3'><?php esc_html_e('Wednesdays', 'invoicing'); ?></option> |
|
64 | + <option value='4'><?php esc_html_e('Thursdays', 'invoicing'); ?></option> |
|
65 | + <option value='5'><?php esc_html_e('Fridays', 'invoicing'); ?></option> |
|
66 | + <option value='6'><?php esc_html_e('Saturdays', 'invoicing'); ?></option> |
|
67 | 67 | </gpselect2> |
68 | - <small class="form-text text-muted"><?php _e( 'Optionally specify the days of the week to disable.', 'invoicing' ); ?></small> |
|
68 | + <small class="form-text text-muted"><?php _e('Optionally specify the days of the week to disable.', 'invoicing'); ?></small> |
|
69 | 69 | </label> |
70 | 70 | </div> |
71 | 71 | |
72 | 72 | <div class='form-group'> |
73 | 73 | <label class="d-block"> |
74 | - <span><?php esc_html_e( 'Mode', 'invoicing' ) ?></span> |
|
74 | + <span><?php esc_html_e('Mode', 'invoicing') ?></span> |
|
75 | 75 | <select class='form-control custom-select' v-model='active_form_element.mode'> |
76 | - <option value='single'><?php esc_html_e( 'Users can only select a single date', 'invoicing' ); ?></option> |
|
77 | - <option value='range'><?php esc_html_e( 'Users can select a date range', 'invoicing' ); ?></option> |
|
78 | - <option value='multiple'><?php esc_html_e( 'Users can select multiple dates', 'invoicing' ); ?></option> |
|
76 | + <option value='single'><?php esc_html_e('Users can only select a single date', 'invoicing'); ?></option> |
|
77 | + <option value='range'><?php esc_html_e('Users can select a date range', 'invoicing'); ?></option> |
|
78 | + <option value='multiple'><?php esc_html_e('Users can select multiple dates', 'invoicing'); ?></option> |
|
79 | 79 | </select> |
80 | 80 | </label> |
81 | 81 | </div> |
82 | 82 | |
83 | 83 | <div class='form-group'> |
84 | 84 | <label class="d-block"> |
85 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
86 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
87 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
85 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
86 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
87 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
88 | 88 | </label> |
89 | 89 | </div> |
90 | 90 | |
91 | 91 | <div class='form-group form-check'> |
92 | 92 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
93 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
93 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
94 | 94 | </div> |
95 | 95 | |
96 | 96 | <div class='form-group form-check'> |
97 | 97 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
98 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
98 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
99 | 99 | </div> |
100 | 100 | |
101 | 101 | <hr class='featurette-divider mt-4'> |
102 | 102 | |
103 | 103 | <div class='form-group'> |
104 | 104 | <label class="d-block"> |
105 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
105 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
106 | 106 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
107 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
107 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
108 | 108 | </label> |
109 | 109 | </div> |
110 | 110 |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' == $key ) { |
|
40 | - echo wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' == $key) { |
|
40 | + echo wpinv_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)','This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | |
@@ -53,32 +53,32 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | // Total Fee. |
56 | - if ( 'fee' == $key ) { |
|
57 | - echo wpinv_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | + if ('fee' == $key) { |
|
57 | + echo wpinv_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Total discount. |
61 | - if ( 'discount' == $key ) { |
|
62 | - echo wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | + if ('discount' == $key) { |
|
62 | + echo wpinv_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // Shipping. |
66 | - if ( 'shipping' == $key ) { |
|
67 | - echo wpinv_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
66 | + if ('shipping' == $key) { |
|
67 | + echo wpinv_price($invoice->get_shipping(), $invoice->get_currency()); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Sub total. |
71 | - if ( 'subtotal' == $key ) { |
|
72 | - echo wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
71 | + if ('subtotal' == $key) { |
|
72 | + echo wpinv_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Total. |
76 | - if ( 'total' == $key ) { |
|
77 | - echo wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
76 | + if ('total' == $key) { |
|
77 | + echo wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Fires when printing a cart total. |
81 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
81 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
82 | 82 | |
83 | 83 | ?> |
84 | 84 | |
@@ -92,4 +92,4 @@ discard block |
||
92 | 92 | </div> |
93 | 93 | </div> <!-- end .getpaid-invoice-line-totals --> |
94 | 94 | |
95 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
95 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
@@ -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,203 +10,203 @@ 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( $_POST ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Loads submission data. |
|
157 | - * |
|
158 | - * @param array $data |
|
159 | - */ |
|
160 | - public function load_data( $data ) { |
|
161 | - |
|
162 | - // Remove slashes from the submitted data... |
|
163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | - |
|
165 | - // Allow plugins to filter the data. |
|
166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | - |
|
168 | - // Cache it... |
|
169 | - $this->data = $data; |
|
170 | - |
|
171 | - // Then generate a unique id from the data. |
|
172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
173 | - |
|
174 | - // Finally, process the submission. |
|
175 | - try { |
|
176 | - |
|
177 | - // Each process is passed an instance of the class (with reference) |
|
178 | - // and should throw an Exception whenever it encounters one. |
|
179 | - $processors = apply_filters( |
|
180 | - 'getpaid_payment_form_submission_processors', |
|
181 | - array( |
|
182 | - array( $this, 'process_payment_form' ), |
|
183 | - array( $this, 'process_invoice' ), |
|
184 | - array( $this, 'process_fees' ), |
|
185 | - array( $this, 'process_items' ), |
|
186 | - array( $this, 'process_discount' ), |
|
187 | - array( $this, 'process_taxes' ), |
|
188 | - ), |
|
189 | - $this |
|
190 | - ); |
|
191 | - |
|
192 | - foreach ( $processors as $processor ) { |
|
193 | - call_user_func_array( $processor, array( &$this ) ); |
|
194 | - } |
|
195 | - |
|
196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
197 | - $this->last_error = $e->getMessage(); |
|
198 | - $this->last_error_code = $e->getErrorCode(); |
|
199 | - } catch ( Exception $e ) { |
|
200 | - $this->last_error = $e->getMessage(); |
|
201 | - $this->last_error_code = $e->getCode(); |
|
202 | - } |
|
203 | - |
|
204 | - // Fired when we are done processing a submission. |
|
205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | - |
|
207 | - } |
|
208 | - |
|
209 | - /* |
|
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( $_POST ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Loads submission data. |
|
157 | + * |
|
158 | + * @param array $data |
|
159 | + */ |
|
160 | + public function load_data( $data ) { |
|
161 | + |
|
162 | + // Remove slashes from the submitted data... |
|
163 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
164 | + |
|
165 | + // Allow plugins to filter the data. |
|
166 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
167 | + |
|
168 | + // Cache it... |
|
169 | + $this->data = $data; |
|
170 | + |
|
171 | + // Then generate a unique id from the data. |
|
172 | + $this->id = md5( wp_json_encode( $data ) ); |
|
173 | + |
|
174 | + // Finally, process the submission. |
|
175 | + try { |
|
176 | + |
|
177 | + // Each process is passed an instance of the class (with reference) |
|
178 | + // and should throw an Exception whenever it encounters one. |
|
179 | + $processors = apply_filters( |
|
180 | + 'getpaid_payment_form_submission_processors', |
|
181 | + array( |
|
182 | + array( $this, 'process_payment_form' ), |
|
183 | + array( $this, 'process_invoice' ), |
|
184 | + array( $this, 'process_fees' ), |
|
185 | + array( $this, 'process_items' ), |
|
186 | + array( $this, 'process_discount' ), |
|
187 | + array( $this, 'process_taxes' ), |
|
188 | + ), |
|
189 | + $this |
|
190 | + ); |
|
191 | + |
|
192 | + foreach ( $processors as $processor ) { |
|
193 | + call_user_func_array( $processor, array( &$this ) ); |
|
194 | + } |
|
195 | + |
|
196 | + } catch( GetPaid_Payment_Exception $e ) { |
|
197 | + $this->last_error = $e->getMessage(); |
|
198 | + $this->last_error_code = $e->getErrorCode(); |
|
199 | + } catch ( Exception $e ) { |
|
200 | + $this->last_error = $e->getMessage(); |
|
201 | + $this->last_error_code = $e->getCode(); |
|
202 | + } |
|
203 | + |
|
204 | + // Fired when we are done processing a submission. |
|
205 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
206 | + |
|
207 | + } |
|
208 | + |
|
209 | + /* |
|
210 | 210 | |-------------------------------------------------------------------------- |
211 | 211 | | Payment Forms. |
212 | 212 | |-------------------------------------------------------------------------- |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | | submission has an active payment form etc. |
216 | 216 | */ |
217 | 217 | |
218 | - /** |
|
219 | - * Prepares the submission's payment form. |
|
220 | - * |
|
221 | - * @since 1.0.19 |
|
222 | - */ |
|
223 | - public function process_payment_form() { |
|
218 | + /** |
|
219 | + * Prepares the submission's payment form. |
|
220 | + * |
|
221 | + * @since 1.0.19 |
|
222 | + */ |
|
223 | + public function process_payment_form() { |
|
224 | 224 | |
225 | - // Every submission needs an active payment form. |
|
226 | - if ( empty( $this->data['form_id'] ) ) { |
|
227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | - } |
|
225 | + // Every submission needs an active payment form. |
|
226 | + if ( empty( $this->data['form_id'] ) ) { |
|
227 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
228 | + } |
|
229 | 229 | |
230 | - // Fetch the payment form. |
|
231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
230 | + // Fetch the payment form. |
|
231 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
232 | 232 | |
233 | - if ( ! $this->payment_form->is_active() ) { |
|
234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | - } |
|
233 | + if ( ! $this->payment_form->is_active() ) { |
|
234 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
235 | + } |
|
236 | 236 | |
237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | - } |
|
237 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
238 | + } |
|
239 | 239 | |
240 | 240 | /** |
241 | - * Returns the payment form. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @return GetPaid_Payment_Form |
|
245 | - */ |
|
246 | - public function get_payment_form() { |
|
247 | - return $this->payment_form; |
|
248 | - } |
|
241 | + * Returns the payment form. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @return GetPaid_Payment_Form |
|
245 | + */ |
|
246 | + public function get_payment_form() { |
|
247 | + return $this->payment_form; |
|
248 | + } |
|
249 | 249 | |
250 | - /* |
|
250 | + /* |
|
251 | 251 | |-------------------------------------------------------------------------- |
252 | 252 | | Invoices. |
253 | 253 | |-------------------------------------------------------------------------- |
@@ -256,84 +256,84 @@ discard block |
||
256 | 256 | | might be for an existing invoice. |
257 | 257 | */ |
258 | 258 | |
259 | - /** |
|
260 | - * Prepares the submission's invoice. |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - */ |
|
264 | - public function process_invoice() { |
|
259 | + /** |
|
260 | + * Prepares the submission's invoice. |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + */ |
|
264 | + public function process_invoice() { |
|
265 | 265 | |
266 | - // Abort if there is no invoice. |
|
267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | - return; |
|
269 | - } |
|
266 | + // Abort if there is no invoice. |
|
267 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | 270 | |
271 | - // If the submission is for an existing invoice, ensure that it exists |
|
272 | - // and that it is not paid for. |
|
273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
271 | + // If the submission is for an existing invoice, ensure that it exists |
|
272 | + // and that it is not paid for. |
|
273 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
274 | 274 | |
275 | 275 | if ( empty( $invoice ) ) { |
276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | - } |
|
276 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
277 | + } |
|
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | - } |
|
279 | + if ( $invoice->is_paid() ) { |
|
280 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
281 | + } |
|
282 | 282 | |
283 | - $this->payment_form->invoice = $invoice; |
|
284 | - if ( ! $this->payment_form->is_default() ) { |
|
283 | + $this->payment_form->invoice = $invoice; |
|
284 | + if ( ! $this->payment_form->is_default() ) { |
|
285 | 285 | |
286 | - $items = array(); |
|
287 | - $item_ids = array(); |
|
286 | + $items = array(); |
|
287 | + $item_ids = array(); |
|
288 | 288 | |
289 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | - $item_ids[] = $item->get_id(); |
|
292 | - $items[] = $item; |
|
293 | - } |
|
294 | - } |
|
289 | + foreach ( $invoice->get_items() as $item ) { |
|
290 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
291 | + $item_ids[] = $item->get_id(); |
|
292 | + $items[] = $item; |
|
293 | + } |
|
294 | + } |
|
295 | 295 | |
296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | - $item_ids[] = $item->get_id(); |
|
299 | - $items[] = $item; |
|
300 | - } |
|
301 | - } |
|
296 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
298 | + $item_ids[] = $item->get_id(); |
|
299 | + $items[] = $item; |
|
300 | + } |
|
301 | + } |
|
302 | 302 | |
303 | - $this->payment_form->set_items( $items ); |
|
303 | + $this->payment_form->set_items( $items ); |
|
304 | 304 | |
305 | - } else { |
|
306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | - } |
|
308 | - |
|
309 | - $this->country = $invoice->get_country(); |
|
310 | - $this->state = $invoice->get_state(); |
|
311 | - $this->invoice = $invoice; |
|
312 | - |
|
313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the associated invoice. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @return WPInv_Invoice |
|
321 | - */ |
|
322 | - public function get_invoice() { |
|
323 | - return $this->invoice; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Checks whether there is an invoice associated with this submission. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @return bool |
|
331 | - */ |
|
332 | - public function has_invoice() { |
|
333 | - return ! empty( $this->invoice ); |
|
334 | - } |
|
335 | - |
|
336 | - /* |
|
305 | + } else { |
|
306 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
307 | + } |
|
308 | + |
|
309 | + $this->country = $invoice->get_country(); |
|
310 | + $this->state = $invoice->get_state(); |
|
311 | + $this->invoice = $invoice; |
|
312 | + |
|
313 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the associated invoice. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @return WPInv_Invoice |
|
321 | + */ |
|
322 | + public function get_invoice() { |
|
323 | + return $this->invoice; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Checks whether there is an invoice associated with this submission. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @return bool |
|
331 | + */ |
|
332 | + public function has_invoice() { |
|
333 | + return ! empty( $this->invoice ); |
|
334 | + } |
|
335 | + |
|
336 | + /* |
|
337 | 337 | |-------------------------------------------------------------------------- |
338 | 338 | | Items. |
339 | 339 | |-------------------------------------------------------------------------- |
@@ -342,129 +342,129 @@ discard block |
||
342 | 342 | | recurring item. But can have an unlimited number of non-recurring items. |
343 | 343 | */ |
344 | 344 | |
345 | - /** |
|
346 | - * Prepares the submission's items. |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
349 | - */ |
|
350 | - public function process_items() { |
|
351 | - |
|
352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | - |
|
354 | - foreach ( $processor->items as $item ) { |
|
355 | - $this->add_item( $item ); |
|
356 | - } |
|
357 | - |
|
358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Adds an item to the submission. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param GetPaid_Form_Item $item |
|
366 | - */ |
|
367 | - public function add_item( $item ) { |
|
368 | - |
|
369 | - // Make sure that it is available for purchase. |
|
370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | - return; |
|
372 | - } |
|
373 | - |
|
374 | - // Each submission can only contain one recurring item. |
|
375 | - if ( $item->is_recurring() ) { |
|
376 | - $this->has_recurring = $item->get_id(); |
|
377 | - } |
|
378 | - |
|
379 | - // Update the items and totals. |
|
380 | - $this->items[ $item->get_id() ] = $item; |
|
381 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Removes a specific item. |
|
388 | - * |
|
389 | - * You should not call this method after the discounts and taxes |
|
390 | - * have been calculated. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function remove_item( $item_id ) { |
|
395 | - |
|
396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | - |
|
400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | - $this->has_recurring = 0; |
|
402 | - } |
|
403 | - |
|
404 | - unset( $this->items[ $item_id ] ); |
|
405 | - } |
|
406 | - |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Returns the subtotal. |
|
411 | - * |
|
412 | - * @since 1.0.19 |
|
413 | - */ |
|
414 | - public function get_subtotal() { |
|
415 | - |
|
416 | - if ( wpinv_prices_include_tax() ) { |
|
417 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | - } |
|
419 | - |
|
420 | - return $this->totals['subtotal']['initial']; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Returns the recurring subtotal. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function get_recurring_subtotal() { |
|
429 | - |
|
430 | - if ( wpinv_prices_include_tax() ) { |
|
431 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | - } |
|
433 | - |
|
434 | - return $this->totals['subtotal']['recurring']; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Returns all items. |
|
439 | - * |
|
440 | - * @since 1.0.19 |
|
441 | - * @return GetPaid_Form_Item[] |
|
442 | - */ |
|
443 | - public function get_items() { |
|
444 | - return $this->items; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Checks if there's a single subscription group in the submission. |
|
449 | - * |
|
450 | - * @since 2.3.0 |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - public function has_subscription_group() { |
|
454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Checks if there are multipe subscription groups in the submission. |
|
459 | - * |
|
460 | - * @since 2.3.0 |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function has_multiple_subscription_groups() { |
|
464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | - } |
|
466 | - |
|
467 | - /* |
|
345 | + /** |
|
346 | + * Prepares the submission's items. |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | + */ |
|
350 | + public function process_items() { |
|
351 | + |
|
352 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
353 | + |
|
354 | + foreach ( $processor->items as $item ) { |
|
355 | + $this->add_item( $item ); |
|
356 | + } |
|
357 | + |
|
358 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Adds an item to the submission. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param GetPaid_Form_Item $item |
|
366 | + */ |
|
367 | + public function add_item( $item ) { |
|
368 | + |
|
369 | + // Make sure that it is available for purchase. |
|
370 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
371 | + return; |
|
372 | + } |
|
373 | + |
|
374 | + // Each submission can only contain one recurring item. |
|
375 | + if ( $item->is_recurring() ) { |
|
376 | + $this->has_recurring = $item->get_id(); |
|
377 | + } |
|
378 | + |
|
379 | + // Update the items and totals. |
|
380 | + $this->items[ $item->get_id() ] = $item; |
|
381 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
382 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Removes a specific item. |
|
388 | + * |
|
389 | + * You should not call this method after the discounts and taxes |
|
390 | + * have been calculated. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function remove_item( $item_id ) { |
|
395 | + |
|
396 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
399 | + |
|
400 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
401 | + $this->has_recurring = 0; |
|
402 | + } |
|
403 | + |
|
404 | + unset( $this->items[ $item_id ] ); |
|
405 | + } |
|
406 | + |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Returns the subtotal. |
|
411 | + * |
|
412 | + * @since 1.0.19 |
|
413 | + */ |
|
414 | + public function get_subtotal() { |
|
415 | + |
|
416 | + if ( wpinv_prices_include_tax() ) { |
|
417 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
418 | + } |
|
419 | + |
|
420 | + return $this->totals['subtotal']['initial']; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Returns the recurring subtotal. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function get_recurring_subtotal() { |
|
429 | + |
|
430 | + if ( wpinv_prices_include_tax() ) { |
|
431 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
432 | + } |
|
433 | + |
|
434 | + return $this->totals['subtotal']['recurring']; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Returns all items. |
|
439 | + * |
|
440 | + * @since 1.0.19 |
|
441 | + * @return GetPaid_Form_Item[] |
|
442 | + */ |
|
443 | + public function get_items() { |
|
444 | + return $this->items; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Checks if there's a single subscription group in the submission. |
|
449 | + * |
|
450 | + * @since 2.3.0 |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + public function has_subscription_group() { |
|
454 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Checks if there are multipe subscription groups in the submission. |
|
459 | + * |
|
460 | + * @since 2.3.0 |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function has_multiple_subscription_groups() { |
|
464 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
465 | + } |
|
466 | + |
|
467 | + /* |
|
468 | 468 | |-------------------------------------------------------------------------- |
469 | 469 | | Taxes |
470 | 470 | |-------------------------------------------------------------------------- |
@@ -473,128 +473,128 @@ discard block |
||
473 | 473 | | or only one-time. |
474 | 474 | */ |
475 | 475 | |
476 | - /** |
|
477 | - * Prepares the submission's taxes. |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - */ |
|
481 | - public function process_taxes() { |
|
482 | - |
|
483 | - // Abort if we're not using taxes. |
|
484 | - if ( ! $this->use_taxes() ) { |
|
485 | - return; |
|
486 | - } |
|
487 | - |
|
488 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | - if ( ! empty( $country ) ) { |
|
491 | - $this->country = $country; |
|
492 | - } |
|
493 | - |
|
494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | - if ( ! empty( $state ) ) { |
|
496 | - $this->state = $state; |
|
497 | - } |
|
498 | - |
|
499 | - // Confirm if the provided country and the ip country are similar. |
|
500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | - 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' ) ); |
|
503 | - } |
|
504 | - |
|
505 | - // Abort if the country is not taxable. |
|
506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | - return; |
|
508 | - } |
|
509 | - |
|
510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | - |
|
512 | - foreach ( $processor->taxes as $tax ) { |
|
513 | - $this->add_tax( $tax ); |
|
514 | - } |
|
515 | - |
|
516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Adds a tax to the submission. |
|
521 | - * |
|
522 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | - * @since 1.0.19 |
|
524 | - */ |
|
525 | - public function add_tax( $tax ) { |
|
526 | - |
|
527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | - } |
|
531 | - |
|
532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | - |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Removes a specific tax. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - */ |
|
543 | - public function remove_tax( $tax_name ) { |
|
544 | - |
|
545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | - unset( $this->taxes[ $tax_name ] ); |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Whether or not we'll use taxes for the submission. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function use_taxes() { |
|
559 | - |
|
560 | - $use_taxes = wpinv_use_taxes(); |
|
561 | - |
|
562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | - $use_taxes = false; |
|
564 | - } |
|
565 | - |
|
566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | - |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Returns the tax. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - */ |
|
575 | - public function get_tax() { |
|
576 | - return $this->totals['taxes']['initial']; |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Returns the recurring tax. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - */ |
|
584 | - public function get_recurring_tax() { |
|
585 | - return $this->totals['taxes']['recurring']; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Returns all taxes. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - */ |
|
593 | - public function get_taxes() { |
|
594 | - return $this->taxes; |
|
595 | - } |
|
596 | - |
|
597 | - /* |
|
476 | + /** |
|
477 | + * Prepares the submission's taxes. |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + */ |
|
481 | + public function process_taxes() { |
|
482 | + |
|
483 | + // Abort if we're not using taxes. |
|
484 | + if ( ! $this->use_taxes() ) { |
|
485 | + return; |
|
486 | + } |
|
487 | + |
|
488 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
489 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | + if ( ! empty( $country ) ) { |
|
491 | + $this->country = $country; |
|
492 | + } |
|
493 | + |
|
494 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | + if ( ! empty( $state ) ) { |
|
496 | + $this->state = $state; |
|
497 | + } |
|
498 | + |
|
499 | + // Confirm if the provided country and the ip country are similar. |
|
500 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | + 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' ) ); |
|
503 | + } |
|
504 | + |
|
505 | + // Abort if the country is not taxable. |
|
506 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
507 | + return; |
|
508 | + } |
|
509 | + |
|
510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
511 | + |
|
512 | + foreach ( $processor->taxes as $tax ) { |
|
513 | + $this->add_tax( $tax ); |
|
514 | + } |
|
515 | + |
|
516 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Adds a tax to the submission. |
|
521 | + * |
|
522 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
523 | + * @since 1.0.19 |
|
524 | + */ |
|
525 | + public function add_tax( $tax ) { |
|
526 | + |
|
527 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
530 | + } |
|
531 | + |
|
532 | + $this->taxes[ $tax['name'] ] = $tax; |
|
533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
535 | + |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Removes a specific tax. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + */ |
|
543 | + public function remove_tax( $tax_name ) { |
|
544 | + |
|
545 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | + unset( $this->taxes[ $tax_name ] ); |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Whether or not we'll use taxes for the submission. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function use_taxes() { |
|
559 | + |
|
560 | + $use_taxes = wpinv_use_taxes(); |
|
561 | + |
|
562 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
563 | + $use_taxes = false; |
|
564 | + } |
|
565 | + |
|
566 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
567 | + |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Returns the tax. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + */ |
|
575 | + public function get_tax() { |
|
576 | + return $this->totals['taxes']['initial']; |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Returns the recurring tax. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + */ |
|
584 | + public function get_recurring_tax() { |
|
585 | + return $this->totals['taxes']['recurring']; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Returns all taxes. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + */ |
|
593 | + public function get_taxes() { |
|
594 | + return $this->taxes; |
|
595 | + } |
|
596 | + |
|
597 | + /* |
|
598 | 598 | |-------------------------------------------------------------------------- |
599 | 599 | | Discounts |
600 | 600 | |-------------------------------------------------------------------------- |
@@ -603,99 +603,99 @@ discard block |
||
603 | 603 | | or only one-time. They also do not have to come from a discount code. |
604 | 604 | */ |
605 | 605 | |
606 | - /** |
|
607 | - * Prepares the submission's discount. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - */ |
|
611 | - public function process_discount() { |
|
612 | - |
|
613 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | - |
|
617 | - foreach ( $processor->discounts as $discount ) { |
|
618 | - $this->add_discount( $discount ); |
|
619 | - } |
|
620 | - |
|
621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Adds a discount to the submission. |
|
626 | - * |
|
627 | - * @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. |
|
628 | - * @since 1.0.19 |
|
629 | - */ |
|
630 | - public function add_discount( $discount ) { |
|
631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Removes a discount from the submission. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function remove_discount( $name ) { |
|
642 | - |
|
643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | - unset( $this->discounts[ $name ] ); |
|
647 | - } |
|
648 | - |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Checks whether there is a discount code associated with this submission. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - * @return bool |
|
656 | - */ |
|
657 | - public function has_discount_code() { |
|
658 | - return ! empty( $this->discounts['discount_code'] ); |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Returns the discount code. |
|
663 | - * |
|
664 | - * @since 1.0.19 |
|
665 | - * @return string |
|
666 | - */ |
|
667 | - public function get_discount_code() { |
|
668 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Returns the discount. |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - */ |
|
676 | - public function get_discount() { |
|
677 | - return $this->totals['discount']['initial']; |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Returns the recurring discount. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - */ |
|
685 | - public function get_recurring_discount() { |
|
686 | - return $this->totals['discount']['recurring']; |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Returns all discounts. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - */ |
|
694 | - public function get_discounts() { |
|
695 | - return $this->discounts; |
|
696 | - } |
|
697 | - |
|
698 | - /* |
|
606 | + /** |
|
607 | + * Prepares the submission's discount. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + */ |
|
611 | + public function process_discount() { |
|
612 | + |
|
613 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
614 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
615 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
616 | + |
|
617 | + foreach ( $processor->discounts as $discount ) { |
|
618 | + $this->add_discount( $discount ); |
|
619 | + } |
|
620 | + |
|
621 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Adds a discount to the submission. |
|
626 | + * |
|
627 | + * @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. |
|
628 | + * @since 1.0.19 |
|
629 | + */ |
|
630 | + public function add_discount( $discount ) { |
|
631 | + $this->discounts[ $discount['name'] ] = $discount; |
|
632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Removes a discount from the submission. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function remove_discount( $name ) { |
|
642 | + |
|
643 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | + unset( $this->discounts[ $name ] ); |
|
647 | + } |
|
648 | + |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Checks whether there is a discount code associated with this submission. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + * @return bool |
|
656 | + */ |
|
657 | + public function has_discount_code() { |
|
658 | + return ! empty( $this->discounts['discount_code'] ); |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Returns the discount code. |
|
663 | + * |
|
664 | + * @since 1.0.19 |
|
665 | + * @return string |
|
666 | + */ |
|
667 | + public function get_discount_code() { |
|
668 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Returns the discount. |
|
673 | + * |
|
674 | + * @since 1.0.19 |
|
675 | + */ |
|
676 | + public function get_discount() { |
|
677 | + return $this->totals['discount']['initial']; |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Returns the recurring discount. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + */ |
|
685 | + public function get_recurring_discount() { |
|
686 | + return $this->totals['discount']['recurring']; |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Returns all discounts. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + */ |
|
694 | + public function get_discounts() { |
|
695 | + return $this->discounts; |
|
696 | + } |
|
697 | + |
|
698 | + /* |
|
699 | 699 | |-------------------------------------------------------------------------- |
700 | 700 | | Fees |
701 | 701 | |-------------------------------------------------------------------------- |
@@ -705,100 +705,100 @@ discard block |
||
705 | 705 | | fees. |
706 | 706 | */ |
707 | 707 | |
708 | - /** |
|
709 | - * Prepares the submission's fees. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - */ |
|
713 | - public function process_fees() { |
|
714 | - |
|
715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | - |
|
717 | - foreach ( $fees_processor->fees as $fee ) { |
|
718 | - $this->add_fee( $fee ); |
|
719 | - } |
|
720 | - |
|
721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Adds a fee to the submission. |
|
726 | - * |
|
727 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | - * @since 1.0.19 |
|
729 | - */ |
|
730 | - public function add_fee( $fee ) { |
|
731 | - |
|
732 | - if ( $fee['name'] == 'shipping' ) { |
|
733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | - return; |
|
736 | - } |
|
737 | - |
|
738 | - $this->fees[ $fee['name'] ] = $fee; |
|
739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | - |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Removes a fee from the submission. |
|
746 | - * |
|
747 | - * @since 1.0.19 |
|
748 | - */ |
|
749 | - public function remove_fee( $name ) { |
|
750 | - |
|
751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | - unset( $this->fees[ $name ] ); |
|
755 | - } |
|
756 | - |
|
757 | - if ( 'shipping' == $name ) { |
|
758 | - $this->totals['shipping']['initial'] = 0; |
|
759 | - $this->totals['shipping']['recurring'] = 0; |
|
760 | - } |
|
761 | - |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Returns the fees. |
|
766 | - * |
|
767 | - * @since 1.0.19 |
|
768 | - */ |
|
769 | - public function get_fee() { |
|
770 | - return $this->totals['fees']['initial']; |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Returns the recurring fees. |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - */ |
|
778 | - public function get_recurring_fee() { |
|
779 | - return $this->totals['fees']['recurring']; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
783 | - * Returns all fees. |
|
784 | - * |
|
785 | - * @since 1.0.19 |
|
786 | - */ |
|
787 | - public function get_fees() { |
|
788 | - return $this->fees; |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * Checks if there are any fees for the form. |
|
793 | - * |
|
794 | - * @return bool |
|
795 | - * @since 1.0.19 |
|
796 | - */ |
|
797 | - public function has_fees() { |
|
798 | - return count( $this->fees ) !== 0; |
|
799 | - } |
|
800 | - |
|
801 | - /* |
|
708 | + /** |
|
709 | + * Prepares the submission's fees. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + */ |
|
713 | + public function process_fees() { |
|
714 | + |
|
715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
716 | + |
|
717 | + foreach ( $fees_processor->fees as $fee ) { |
|
718 | + $this->add_fee( $fee ); |
|
719 | + } |
|
720 | + |
|
721 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Adds a fee to the submission. |
|
726 | + * |
|
727 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
728 | + * @since 1.0.19 |
|
729 | + */ |
|
730 | + public function add_fee( $fee ) { |
|
731 | + |
|
732 | + if ( $fee['name'] == 'shipping' ) { |
|
733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
735 | + return; |
|
736 | + } |
|
737 | + |
|
738 | + $this->fees[ $fee['name'] ] = $fee; |
|
739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
741 | + |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Removes a fee from the submission. |
|
746 | + * |
|
747 | + * @since 1.0.19 |
|
748 | + */ |
|
749 | + public function remove_fee( $name ) { |
|
750 | + |
|
751 | + if ( isset( $this->fees[ $name ] ) ) { |
|
752 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | + unset( $this->fees[ $name ] ); |
|
755 | + } |
|
756 | + |
|
757 | + if ( 'shipping' == $name ) { |
|
758 | + $this->totals['shipping']['initial'] = 0; |
|
759 | + $this->totals['shipping']['recurring'] = 0; |
|
760 | + } |
|
761 | + |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Returns the fees. |
|
766 | + * |
|
767 | + * @since 1.0.19 |
|
768 | + */ |
|
769 | + public function get_fee() { |
|
770 | + return $this->totals['fees']['initial']; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Returns the recurring fees. |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + */ |
|
778 | + public function get_recurring_fee() { |
|
779 | + return $this->totals['fees']['recurring']; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | + * Returns all fees. |
|
784 | + * |
|
785 | + * @since 1.0.19 |
|
786 | + */ |
|
787 | + public function get_fees() { |
|
788 | + return $this->fees; |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * Checks if there are any fees for the form. |
|
793 | + * |
|
794 | + * @return bool |
|
795 | + * @since 1.0.19 |
|
796 | + */ |
|
797 | + public function has_fees() { |
|
798 | + return count( $this->fees ) !== 0; |
|
799 | + } |
|
800 | + |
|
801 | + /* |
|
802 | 802 | |-------------------------------------------------------------------------- |
803 | 803 | | MISC |
804 | 804 | |-------------------------------------------------------------------------- |
@@ -806,147 +806,147 @@ discard block |
||
806 | 806 | | Extra submission functions. |
807 | 807 | */ |
808 | 808 | |
809 | - /** |
|
810 | - * Returns the shipping amount. |
|
811 | - * |
|
812 | - * @since 1.0.19 |
|
813 | - */ |
|
814 | - public function get_shipping() { |
|
815 | - return $this->totals['shipping']['initial']; |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Returns the recurring shipping. |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - */ |
|
823 | - public function get_recurring_shipping() { |
|
824 | - return $this->totals['shipping']['recurring']; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * Checks if there are any shipping fees for the form. |
|
829 | - * |
|
830 | - * @return bool |
|
831 | - * @since 1.0.19 |
|
832 | - */ |
|
833 | - public function has_shipping() { |
|
834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Checks if this is the initial fetch. |
|
839 | - * |
|
840 | - * @return bool |
|
841 | - * @since 1.0.19 |
|
842 | - */ |
|
843 | - public function is_initial_fetch() { |
|
844 | - return empty( $this->data['initial_state'] ); |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Returns the total amount to collect for this submission. |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - */ |
|
852 | - public function get_total() { |
|
853 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | - return max( $total, 0 ); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the recurring total amount to collect for this submission. |
|
859 | - * |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function get_recurring_total() { |
|
863 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | - return max( $total, 0 ); |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * Whether payment details should be collected for this submission. |
|
869 | - * |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function should_collect_payment_details() { |
|
873 | - $initial = $this->get_total(); |
|
874 | - $recurring = $this->get_recurring_total(); |
|
875 | - |
|
876 | - if ( $this->has_recurring == 0 ) { |
|
877 | - $recurring = 0; |
|
878 | - } |
|
879 | - |
|
880 | - $collect = $initial > 0 || $recurring > 0; |
|
881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Returns the billing email of the user. |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - */ |
|
889 | - public function get_billing_email() { |
|
890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Checks if the submitter has a billing email. |
|
895 | - * |
|
896 | - * @since 1.0.19 |
|
897 | - */ |
|
898 | - public function has_billing_email() { |
|
899 | - $billing_email = $this->get_billing_email(); |
|
900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * Returns the appropriate currency for the submission. |
|
905 | - * |
|
906 | - * @since 1.0.19 |
|
907 | - * @return string |
|
908 | - */ |
|
909 | - public function get_currency() { |
|
910 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * Returns the raw submission data. |
|
915 | - * |
|
916 | - * @since 1.0.19 |
|
917 | - * @return array |
|
918 | - */ |
|
919 | - public function get_data() { |
|
920 | - return $this->data; |
|
921 | - } |
|
922 | - |
|
923 | - /** |
|
924 | - * Returns a field from the submission data |
|
925 | - * |
|
926 | - * @param string $field |
|
927 | - * @since 1.0.19 |
|
928 | - * @return mixed|null |
|
929 | - */ |
|
930 | - public function get_field( $field, $sub_array_key = null ) { |
|
931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | - } |
|
933 | - |
|
934 | - /** |
|
935 | - * Checks if a required field is set. |
|
936 | - * |
|
937 | - * @since 1.0.19 |
|
938 | - */ |
|
939 | - public function is_required_field_set( $field ) { |
|
940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Formats an amount |
|
945 | - * |
|
946 | - * @since 1.0.19 |
|
947 | - */ |
|
948 | - public function format_amount( $amount ) { |
|
949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
950 | - } |
|
809 | + /** |
|
810 | + * Returns the shipping amount. |
|
811 | + * |
|
812 | + * @since 1.0.19 |
|
813 | + */ |
|
814 | + public function get_shipping() { |
|
815 | + return $this->totals['shipping']['initial']; |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * Returns the recurring shipping. |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + */ |
|
823 | + public function get_recurring_shipping() { |
|
824 | + return $this->totals['shipping']['recurring']; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * Checks if there are any shipping fees for the form. |
|
829 | + * |
|
830 | + * @return bool |
|
831 | + * @since 1.0.19 |
|
832 | + */ |
|
833 | + public function has_shipping() { |
|
834 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Checks if this is the initial fetch. |
|
839 | + * |
|
840 | + * @return bool |
|
841 | + * @since 1.0.19 |
|
842 | + */ |
|
843 | + public function is_initial_fetch() { |
|
844 | + return empty( $this->data['initial_state'] ); |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Returns the total amount to collect for this submission. |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + */ |
|
852 | + public function get_total() { |
|
853 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
854 | + return max( $total, 0 ); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the recurring total amount to collect for this submission. |
|
859 | + * |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function get_recurring_total() { |
|
863 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
864 | + return max( $total, 0 ); |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * Whether payment details should be collected for this submission. |
|
869 | + * |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function should_collect_payment_details() { |
|
873 | + $initial = $this->get_total(); |
|
874 | + $recurring = $this->get_recurring_total(); |
|
875 | + |
|
876 | + if ( $this->has_recurring == 0 ) { |
|
877 | + $recurring = 0; |
|
878 | + } |
|
879 | + |
|
880 | + $collect = $initial > 0 || $recurring > 0; |
|
881 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Returns the billing email of the user. |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + */ |
|
889 | + public function get_billing_email() { |
|
890 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Checks if the submitter has a billing email. |
|
895 | + * |
|
896 | + * @since 1.0.19 |
|
897 | + */ |
|
898 | + public function has_billing_email() { |
|
899 | + $billing_email = $this->get_billing_email(); |
|
900 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * Returns the appropriate currency for the submission. |
|
905 | + * |
|
906 | + * @since 1.0.19 |
|
907 | + * @return string |
|
908 | + */ |
|
909 | + public function get_currency() { |
|
910 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * Returns the raw submission data. |
|
915 | + * |
|
916 | + * @since 1.0.19 |
|
917 | + * @return array |
|
918 | + */ |
|
919 | + public function get_data() { |
|
920 | + return $this->data; |
|
921 | + } |
|
922 | + |
|
923 | + /** |
|
924 | + * Returns a field from the submission data |
|
925 | + * |
|
926 | + * @param string $field |
|
927 | + * @since 1.0.19 |
|
928 | + * @return mixed|null |
|
929 | + */ |
|
930 | + public function get_field( $field, $sub_array_key = null ) { |
|
931 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
932 | + } |
|
933 | + |
|
934 | + /** |
|
935 | + * Checks if a required field is set. |
|
936 | + * |
|
937 | + * @since 1.0.19 |
|
938 | + */ |
|
939 | + public function is_required_field_set( $field ) { |
|
940 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Formats an amount |
|
945 | + * |
|
946 | + * @since 1.0.19 |
|
947 | + */ |
|
948 | + public function format_amount( $amount ) { |
|
949 | + return wpinv_price( $amount, $this->get_currency() ); |
|
950 | + } |
|
951 | 951 | |
952 | 952 | } |
@@ -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( $_POST ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data($_POST); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,19 +157,19 @@ 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 | // Remove slashes from the submitted data... |
163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
163 | + $data = wp_kses_post_deep(wp_unslash($data)); |
|
164 | 164 | |
165 | 165 | // Allow plugins to filter the data. |
166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
166 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
167 | 167 | |
168 | 168 | // Cache it... |
169 | 169 | $this->data = $data; |
170 | 170 | |
171 | 171 | // Then generate a unique id from the data. |
172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
172 | + $this->id = md5(wp_json_encode($data)); |
|
173 | 173 | |
174 | 174 | // Finally, process the submission. |
175 | 175 | try { |
@@ -179,30 +179,30 @@ discard block |
||
179 | 179 | $processors = apply_filters( |
180 | 180 | 'getpaid_payment_form_submission_processors', |
181 | 181 | array( |
182 | - array( $this, 'process_payment_form' ), |
|
183 | - array( $this, 'process_invoice' ), |
|
184 | - array( $this, 'process_fees' ), |
|
185 | - array( $this, 'process_items' ), |
|
186 | - array( $this, 'process_discount' ), |
|
187 | - array( $this, 'process_taxes' ), |
|
182 | + array($this, 'process_payment_form'), |
|
183 | + array($this, 'process_invoice'), |
|
184 | + array($this, 'process_fees'), |
|
185 | + array($this, 'process_items'), |
|
186 | + array($this, 'process_discount'), |
|
187 | + array($this, 'process_taxes'), |
|
188 | 188 | ), |
189 | 189 | $this |
190 | 190 | ); |
191 | 191 | |
192 | - foreach ( $processors as $processor ) { |
|
193 | - call_user_func_array( $processor, array( &$this ) ); |
|
192 | + foreach ($processors as $processor) { |
|
193 | + call_user_func_array($processor, array(&$this)); |
|
194 | 194 | } |
195 | 195 | |
196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
196 | + } catch (GetPaid_Payment_Exception $e) { |
|
197 | 197 | $this->last_error = $e->getMessage(); |
198 | 198 | $this->last_error_code = $e->getErrorCode(); |
199 | - } catch ( Exception $e ) { |
|
199 | + } catch (Exception $e) { |
|
200 | 200 | $this->last_error = $e->getMessage(); |
201 | 201 | $this->last_error_code = $e->getCode(); |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Fired when we are done processing a submission. |
205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
205 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | |
@@ -223,18 +223,18 @@ discard block |
||
223 | 223 | public function process_payment_form() { |
224 | 224 | |
225 | 225 | // Every submission needs an active payment form. |
226 | - if ( empty( $this->data['form_id'] ) ) { |
|
227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
226 | + if (empty($this->data['form_id'])) { |
|
227 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Fetch the payment form. |
231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
231 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
232 | 232 | |
233 | - if ( ! $this->payment_form->is_active() ) { |
|
234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
233 | + if (!$this->payment_form->is_active()) { |
|
234 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
235 | 235 | } |
236 | 236 | |
237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
237 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -264,53 +264,53 @@ discard block |
||
264 | 264 | public function process_invoice() { |
265 | 265 | |
266 | 266 | // Abort if there is no invoice. |
267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
267 | + if (empty($this->data['invoice_id'])) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | 271 | // If the submission is for an existing invoice, ensure that it exists |
272 | 272 | // and that it is not paid for. |
273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
273 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
274 | 274 | |
275 | - if ( empty( $invoice ) ) { |
|
276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
275 | + if (empty($invoice)) { |
|
276 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
277 | 277 | } |
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
279 | + if ($invoice->is_paid()) { |
|
280 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $this->payment_form->invoice = $invoice; |
284 | - if ( ! $this->payment_form->is_default() ) { |
|
284 | + if (!$this->payment_form->is_default()) { |
|
285 | 285 | |
286 | 286 | $items = array(); |
287 | 287 | $item_ids = array(); |
288 | 288 | |
289 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
289 | + foreach ($invoice->get_items() as $item) { |
|
290 | + if (!in_array($item->get_id(), $item_ids)) { |
|
291 | 291 | $item_ids[] = $item->get_id(); |
292 | 292 | $items[] = $item; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
296 | + foreach ($this->payment_form->get_items() as $item) { |
|
297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
298 | 298 | $item_ids[] = $item->get_id(); |
299 | 299 | $items[] = $item; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - $this->payment_form->set_items( $items ); |
|
303 | + $this->payment_form->set_items($items); |
|
304 | 304 | |
305 | 305 | } else { |
306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
306 | + $this->payment_form->set_items($invoice->get_items()); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | $this->country = $invoice->get_country(); |
310 | 310 | $this->state = $invoice->get_state(); |
311 | 311 | $this->invoice = $invoice; |
312 | 312 | |
313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
313 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @return bool |
331 | 331 | */ |
332 | 332 | public function has_invoice() { |
333 | - return ! empty( $this->invoice ); |
|
333 | + return !empty($this->invoice); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /* |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | */ |
350 | 350 | public function process_items() { |
351 | 351 | |
352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
352 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
353 | 353 | |
354 | - foreach ( $processor->items as $item ) { |
|
355 | - $this->add_item( $item ); |
|
354 | + foreach ($processor->items as $item) { |
|
355 | + $this->add_item($item); |
|
356 | 356 | } |
357 | 357 | |
358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
358 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -364,20 +364,20 @@ discard block |
||
364 | 364 | * @since 1.0.19 |
365 | 365 | * @param GetPaid_Form_Item $item |
366 | 366 | */ |
367 | - public function add_item( $item ) { |
|
367 | + public function add_item($item) { |
|
368 | 368 | |
369 | 369 | // Make sure that it is available for purchase. |
370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
370 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Each submission can only contain one recurring item. |
375 | - if ( $item->is_recurring() ) { |
|
375 | + if ($item->is_recurring()) { |
|
376 | 376 | $this->has_recurring = $item->get_id(); |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Update the items and totals. |
380 | - $this->items[ $item->get_id() ] = $item; |
|
380 | + $this->items[$item->get_id()] = $item; |
|
381 | 381 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
382 | 382 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
383 | 383 | |
@@ -391,17 +391,17 @@ discard block |
||
391 | 391 | * |
392 | 392 | * @since 1.0.19 |
393 | 393 | */ |
394 | - public function remove_item( $item_id ) { |
|
394 | + public function remove_item($item_id) { |
|
395 | 395 | |
396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
396 | + if (isset($this->items[$item_id])) { |
|
397 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
398 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
399 | 399 | |
400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
400 | + if ($this->items[$item_id]->is_recurring()) { |
|
401 | 401 | $this->has_recurring = 0; |
402 | 402 | } |
403 | 403 | |
404 | - unset( $this->items[ $item_id ] ); |
|
404 | + unset($this->items[$item_id]); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function get_subtotal() { |
415 | 415 | |
416 | - if ( wpinv_prices_include_tax() ) { |
|
416 | + if (wpinv_prices_include_tax()) { |
|
417 | 417 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
418 | 418 | } |
419 | 419 | |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | */ |
428 | 428 | public function get_recurring_subtotal() { |
429 | 429 | |
430 | - if ( wpinv_prices_include_tax() ) { |
|
430 | + if (wpinv_prices_include_tax()) { |
|
431 | 431 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
432 | 432 | } |
433 | 433 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * @return bool |
452 | 452 | */ |
453 | 453 | public function has_subscription_group() { |
454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
454 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * @return bool |
462 | 462 | */ |
463 | 463 | public function has_multiple_subscription_groups() { |
464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
464 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /* |
@@ -481,39 +481,39 @@ discard block |
||
481 | 481 | public function process_taxes() { |
482 | 482 | |
483 | 483 | // Abort if we're not using taxes. |
484 | - if ( ! $this->use_taxes() ) { |
|
484 | + if (!$this->use_taxes()) { |
|
485 | 485 | return; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // If a custom country && state has been passed in, use it to calculate taxes. |
489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | - if ( ! empty( $country ) ) { |
|
489 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
490 | + if (!empty($country)) { |
|
491 | 491 | $this->country = $country; |
492 | 492 | } |
493 | 493 | |
494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | - if ( ! empty( $state ) ) { |
|
494 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
495 | + if (!empty($state)) { |
|
496 | 496 | $this->state = $state; |
497 | 497 | } |
498 | 498 | |
499 | 499 | // Confirm if the provided country and the ip country are similar. |
500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | - 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' ) ); |
|
500 | + $address_confirmed = $this->get_field('confirm-address'); |
|
501 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
502 | + 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')); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | // Abort if the country is not taxable. |
506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
506 | + if (!wpinv_is_country_taxable($this->country)) { |
|
507 | 507 | return; |
508 | 508 | } |
509 | 509 | |
510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
511 | 511 | |
512 | - foreach ( $processor->taxes as $tax ) { |
|
513 | - $this->add_tax( $tax ); |
|
512 | + foreach ($processor->taxes as $tax) { |
|
513 | + $this->add_tax($tax); |
|
514 | 514 | } |
515 | 515 | |
516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
516 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -522,16 +522,16 @@ discard block |
||
522 | 522 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
523 | 523 | * @since 1.0.19 |
524 | 524 | */ |
525 | - public function add_tax( $tax ) { |
|
525 | + public function add_tax($tax) { |
|
526 | 526 | |
527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
527 | + if (wpinv_round_tax_per_tax_rate()) { |
|
528 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
529 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
530 | 530 | } |
531 | 531 | |
532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
532 | + $this->taxes[$tax['name']] = $tax; |
|
533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
535 | 535 | |
536 | 536 | } |
537 | 537 | |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @since 1.0.19 |
542 | 542 | */ |
543 | - public function remove_tax( $tax_name ) { |
|
543 | + public function remove_tax($tax_name) { |
|
544 | 544 | |
545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | - unset( $this->taxes[ $tax_name ] ); |
|
545 | + if (isset($this->taxes[$tax_name])) { |
|
546 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
547 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
548 | + unset($this->taxes[$tax_name]); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | |
560 | 560 | $use_taxes = wpinv_use_taxes(); |
561 | 561 | |
562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
562 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
563 | 563 | $use_taxes = false; |
564 | 564 | } |
565 | 565 | |
566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
566 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
567 | 567 | |
568 | 568 | } |
569 | 569 | |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | |
613 | 613 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
614 | 614 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
615 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
616 | 616 | |
617 | - foreach ( $processor->discounts as $discount ) { |
|
618 | - $this->add_discount( $discount ); |
|
617 | + foreach ($processor->discounts as $discount) { |
|
618 | + $this->add_discount($discount); |
|
619 | 619 | } |
620 | 620 | |
621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
621 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -627,10 +627,10 @@ discard block |
||
627 | 627 | * @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. |
628 | 628 | * @since 1.0.19 |
629 | 629 | */ |
630 | - public function add_discount( $discount ) { |
|
631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
630 | + public function add_discount($discount) { |
|
631 | + $this->discounts[$discount['name']] = $discount; |
|
632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -638,12 +638,12 @@ discard block |
||
638 | 638 | * |
639 | 639 | * @since 1.0.19 |
640 | 640 | */ |
641 | - public function remove_discount( $name ) { |
|
641 | + public function remove_discount($name) { |
|
642 | 642 | |
643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | - unset( $this->discounts[ $name ] ); |
|
643 | + if (isset($this->discounts[$name])) { |
|
644 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
645 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
646 | + unset($this->discounts[$name]); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | * @return bool |
656 | 656 | */ |
657 | 657 | public function has_discount_code() { |
658 | - return ! empty( $this->discounts['discount_code'] ); |
|
658 | + return !empty($this->discounts['discount_code']); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | */ |
713 | 713 | public function process_fees() { |
714 | 714 | |
715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
716 | 716 | |
717 | - foreach ( $fees_processor->fees as $fee ) { |
|
718 | - $this->add_fee( $fee ); |
|
717 | + foreach ($fees_processor->fees as $fee) { |
|
718 | + $this->add_fee($fee); |
|
719 | 719 | } |
720 | 720 | |
721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
721 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
@@ -727,17 +727,17 @@ discard block |
||
727 | 727 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
728 | 728 | * @since 1.0.19 |
729 | 729 | */ |
730 | - public function add_fee( $fee ) { |
|
730 | + public function add_fee($fee) { |
|
731 | 731 | |
732 | - if ( $fee['name'] == 'shipping' ) { |
|
733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
732 | + if ($fee['name'] == 'shipping') { |
|
733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
735 | 735 | return; |
736 | 736 | } |
737 | 737 | |
738 | - $this->fees[ $fee['name'] ] = $fee; |
|
739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
738 | + $this->fees[$fee['name']] = $fee; |
|
739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
741 | 741 | |
742 | 742 | } |
743 | 743 | |
@@ -746,15 +746,15 @@ discard block |
||
746 | 746 | * |
747 | 747 | * @since 1.0.19 |
748 | 748 | */ |
749 | - public function remove_fee( $name ) { |
|
749 | + public function remove_fee($name) { |
|
750 | 750 | |
751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | - unset( $this->fees[ $name ] ); |
|
751 | + if (isset($this->fees[$name])) { |
|
752 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
753 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
754 | + unset($this->fees[$name]); |
|
755 | 755 | } |
756 | 756 | |
757 | - if ( 'shipping' == $name ) { |
|
757 | + if ('shipping' == $name) { |
|
758 | 758 | $this->totals['shipping']['initial'] = 0; |
759 | 759 | $this->totals['shipping']['recurring'] = 0; |
760 | 760 | } |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @since 1.0.19 |
796 | 796 | */ |
797 | 797 | public function has_fees() { |
798 | - return count( $this->fees ) !== 0; |
|
798 | + return count($this->fees) !== 0; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /* |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | * @since 1.0.19 |
832 | 832 | */ |
833 | 833 | public function has_shipping() { |
834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
834 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | * @since 1.0.19 |
842 | 842 | */ |
843 | 843 | public function is_initial_fetch() { |
844 | - return empty( $this->data['initial_state'] ); |
|
844 | + return empty($this->data['initial_state']); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | */ |
852 | 852 | public function get_total() { |
853 | 853 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
854 | - return max( $total, 0 ); |
|
854 | + return max($total, 0); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | */ |
862 | 862 | public function get_recurring_total() { |
863 | 863 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
864 | - return max( $total, 0 ); |
|
864 | + return max($total, 0); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -873,12 +873,12 @@ discard block |
||
873 | 873 | $initial = $this->get_total(); |
874 | 874 | $recurring = $this->get_recurring_total(); |
875 | 875 | |
876 | - if ( $this->has_recurring == 0 ) { |
|
876 | + if ($this->has_recurring == 0) { |
|
877 | 877 | $recurring = 0; |
878 | 878 | } |
879 | 879 | |
880 | 880 | $collect = $initial > 0 || $recurring > 0; |
881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
881 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @since 1.0.19 |
888 | 888 | */ |
889 | 889 | public function get_billing_email() { |
890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
890 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | */ |
898 | 898 | public function has_billing_email() { |
899 | 899 | $billing_email = $this->get_billing_email(); |
900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
900 | + return !empty($billing_email) && is_email($billing_email); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | /** |
@@ -927,8 +927,8 @@ discard block |
||
927 | 927 | * @since 1.0.19 |
928 | 928 | * @return mixed|null |
929 | 929 | */ |
930 | - public function get_field( $field, $sub_array_key = null ) { |
|
931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
930 | + public function get_field($field, $sub_array_key = null) { |
|
931 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -936,8 +936,8 @@ discard block |
||
936 | 936 | * |
937 | 937 | * @since 1.0.19 |
938 | 938 | */ |
939 | - public function is_required_field_set( $field ) { |
|
940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
939 | + public function is_required_field_set($field) { |
|
940 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -945,8 +945,8 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @since 1.0.19 |
947 | 947 | */ |
948 | - public function format_amount( $amount ) { |
|
949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
948 | + public function format_amount($amount) { |
|
949 | + return wpinv_price($amount, $this->get_currency()); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | } |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
125 | + |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
131 | + |
|
132 | + $invoice = $submission->get_invoice(); |
|
133 | 133 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
138 | 138 | |
139 | - return $invoice; |
|
140 | - } |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | 150 | |
151 | - $submission = $this->payment_form_submission; |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | 152 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | if ( empty( $user ) ) { |
200 | 200 | $user = wpinv_create_user( $submission->get_billing_email() ); |
201 | 201 | |
202 | - // (Maybe) send new user notification. |
|
203 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | - wp_send_new_user_notifications( $user, 'user' ); |
|
206 | - } |
|
202 | + // (Maybe) send new user notification. |
|
203 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | + wp_send_new_user_notifications( $user, 'user' ); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -213,49 +213,49 @@ discard block |
||
213 | 213 | |
214 | 214 | if ( is_numeric( $user ) ) { |
215 | 215 | return $user; |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - return $user->ID; |
|
218 | + return $user->ID; |
|
219 | 219 | |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
222 | + /** |
|
223 | 223 | * Prepares submission data for saving to the database. |
224 | 224 | * |
225 | - * @return array |
|
225 | + * @return array |
|
226 | 226 | */ |
227 | 227 | public function prepare_submission_data_for_saving() { |
228 | 228 | |
229 | - $submission = $this->payment_form_submission; |
|
229 | + $submission = $this->payment_form_submission; |
|
230 | 230 | |
231 | - // Prepared submission details. |
|
231 | + // Prepared submission details. |
|
232 | 232 | $prepared = array( |
233 | - 'all' => array(), |
|
234 | - 'meta' => array(), |
|
235 | - ); |
|
233 | + 'all' => array(), |
|
234 | + 'meta' => array(), |
|
235 | + ); |
|
236 | 236 | |
237 | 237 | // Raw submission details. |
238 | - $data = $submission->get_data(); |
|
238 | + $data = $submission->get_data(); |
|
239 | 239 | |
240 | - // Loop through the submitted details. |
|
240 | + // Loop through the submitted details. |
|
241 | 241 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
242 | 242 | |
243 | - // Skip premade fields. |
|
243 | + // Skip premade fields. |
|
244 | 244 | if ( ! empty( $field['premade'] ) ) { |
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | - // Ensure address is provided. |
|
249 | - if ( $field['type'] == 'address' ) { |
|
248 | + // Ensure address is provided. |
|
249 | + if ( $field['type'] == 'address' ) { |
|
250 | 250 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
251 | 251 | |
252 | - foreach ( $field['fields'] as $address_field ) { |
|
252 | + foreach ( $field['fields'] as $address_field ) { |
|
253 | 253 | |
254 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | 260 | } |
261 | 261 | |
@@ -267,31 +267,31 @@ discard block |
||
267 | 267 | // Handle misc fields. |
268 | 268 | if ( isset( $data[ $field['id'] ] ) ) { |
269 | 269 | |
270 | - // Uploads. |
|
271 | - if ( $field['type'] == 'file_upload' ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
270 | + // Uploads. |
|
271 | + if ( $field['type'] == 'file_upload' ) { |
|
272 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | - } |
|
274 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
276 | + } |
|
277 | 277 | |
278 | - $value = array(); |
|
278 | + $value = array(); |
|
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | - $value[] = sprintf( |
|
282 | - '<a href="%s" target="_blank">%s</a>', |
|
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
285 | - ); |
|
286 | - } |
|
280 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
281 | + $value[] = sprintf( |
|
282 | + '<a href="%s" target="_blank">%s</a>', |
|
283 | + esc_url_raw( $url ), |
|
284 | + esc_html( $name ) |
|
285 | + ); |
|
286 | + } |
|
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode( ' | ', $value ); |
|
289 | 289 | |
290 | - } else if ( $field['type'] == 'checkbox' ) { |
|
291 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | - } else { |
|
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | - } |
|
290 | + } else if ( $field['type'] == 'checkbox' ) { |
|
291 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
292 | + } else { |
|
293 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
294 | + } |
|
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
@@ -299,190 +299,190 @@ discard block |
||
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | - } |
|
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if ( ! empty( $field['add_meta'] ) ) { |
|
303 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
304 | + } |
|
305 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - return $prepared; |
|
311 | + return $prepared; |
|
312 | 312 | |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
315 | + /** |
|
316 | 316 | * Retrieves address details. |
317 | 317 | * |
318 | - * @return array |
|
319 | - * @param WPInv_Invoice $invoice |
|
320 | - * @param string $type |
|
318 | + * @return array |
|
319 | + * @param WPInv_Invoice $invoice |
|
320 | + * @param string $type |
|
321 | 321 | */ |
322 | 322 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
323 | 323 | |
324 | - $data = $this->payment_form_submission->get_data(); |
|
325 | - $type = sanitize_key( $type ); |
|
326 | - $address = array(); |
|
327 | - $prepared = array(); |
|
324 | + $data = $this->payment_form_submission->get_data(); |
|
325 | + $type = sanitize_key( $type ); |
|
326 | + $address = array(); |
|
327 | + $prepared = array(); |
|
328 | 328 | |
329 | - if ( ! empty( $data[ $type ] ) ) { |
|
330 | - $address = $data[ $type ]; |
|
331 | - } |
|
329 | + if ( ! empty( $data[ $type ] ) ) { |
|
330 | + $address = $data[ $type ]; |
|
331 | + } |
|
332 | 332 | |
333 | - // Clean address details. |
|
334 | - foreach ( $address as $key => $value ) { |
|
335 | - $key = sanitize_key( $key ); |
|
336 | - $key = str_replace( 'wpinv_', '', $key ); |
|
337 | - $value = wpinv_clean( $value ); |
|
338 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
339 | - } |
|
333 | + // Clean address details. |
|
334 | + foreach ( $address as $key => $value ) { |
|
335 | + $key = sanitize_key( $key ); |
|
336 | + $key = str_replace( 'wpinv_', '', $key ); |
|
337 | + $value = wpinv_clean( $value ); |
|
338 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
339 | + } |
|
340 | 340 | |
341 | - // Filter address details. |
|
342 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | + // Filter address details. |
|
342 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
343 | 343 | |
344 | - // Remove non-whitelisted values. |
|
345 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | + // Remove non-whitelisted values. |
|
345 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
346 | 346 | |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
349 | + /** |
|
350 | 350 | * Prepares the billing details. |
351 | 351 | * |
352 | - * @return array |
|
353 | - * @param WPInv_Invoice $invoice |
|
352 | + * @return array |
|
353 | + * @param WPInv_Invoice $invoice |
|
354 | 354 | */ |
355 | 355 | protected function prepare_billing_info( &$invoice ) { |
356 | 356 | |
357 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
357 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
358 | 358 | |
359 | - // Update the invoice with the billing details. |
|
360 | - $invoice->set_props( $billing_address ); |
|
359 | + // Update the invoice with the billing details. |
|
360 | + $invoice->set_props( $billing_address ); |
|
361 | 361 | |
362 | - } |
|
362 | + } |
|
363 | 363 | |
364 | - /** |
|
364 | + /** |
|
365 | 365 | * Prepares the shipping details. |
366 | 366 | * |
367 | - * @return array |
|
368 | - * @param WPInv_Invoice $invoice |
|
367 | + * @return array |
|
368 | + * @param WPInv_Invoice $invoice |
|
369 | 369 | */ |
370 | 370 | protected function prepare_shipping_info( $invoice ) { |
371 | 371 | |
372 | - $data = $this->payment_form_submission->get_data(); |
|
372 | + $data = $this->payment_form_submission->get_data(); |
|
373 | 373 | |
374 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
376 | - } |
|
374 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
376 | + } |
|
377 | 377 | |
378 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
378 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
379 | 379 | |
380 | - } |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Confirms the submission is valid and send users to the gateway. |
|
384 | - * |
|
385 | - * @param WPInv_Invoice $invoice |
|
386 | - * @param array $prepared_payment_form_data |
|
387 | - * @param array $shipping |
|
388 | - */ |
|
389 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
382 | + /** |
|
383 | + * Confirms the submission is valid and send users to the gateway. |
|
384 | + * |
|
385 | + * @param WPInv_Invoice $invoice |
|
386 | + * @param array $prepared_payment_form_data |
|
387 | + * @param array $shipping |
|
388 | + */ |
|
389 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
390 | 390 | |
391 | - // Ensure the invoice exists. |
|
391 | + // Ensure the invoice exists. |
|
392 | 392 | if ( ! $invoice->exists() ) { |
393 | 393 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
394 | 394 | } |
395 | 395 | |
396 | - // Save payment form data. |
|
397 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | + // Save payment form data. |
|
397 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
398 | 398 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
399 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
401 | 401 | |
402 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
404 | - } |
|
402 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
404 | + } |
|
405 | 405 | |
406 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
408 | - } |
|
406 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
408 | + } |
|
409 | 409 | |
410 | - } |
|
410 | + } |
|
411 | 411 | |
412 | - // Save payment form data. |
|
413 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
412 | + // Save payment form data. |
|
413 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
414 | 414 | if ( ! empty( $shipping ) ) { |
415 | 415 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
416 | - } |
|
416 | + } |
|
417 | 417 | |
418 | - // Backwards compatibility. |
|
418 | + // Backwards compatibility. |
|
419 | 419 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
420 | 420 | |
421 | - $this->process_payment( $invoice ); |
|
421 | + $this->process_payment( $invoice ); |
|
422 | 422 | |
423 | 423 | // If we are here, there was an error. |
424 | - wpinv_send_back_to_checkout( $invoice ); |
|
424 | + wpinv_send_back_to_checkout( $invoice ); |
|
425 | 425 | |
426 | - } |
|
426 | + } |
|
427 | 427 | |
428 | - /** |
|
429 | - * Processes the actual payment. |
|
430 | - * |
|
431 | - * @param WPInv_Invoice $invoice |
|
432 | - */ |
|
433 | - protected function process_payment( $invoice ) { |
|
428 | + /** |
|
429 | + * Processes the actual payment. |
|
430 | + * |
|
431 | + * @param WPInv_Invoice $invoice |
|
432 | + */ |
|
433 | + protected function process_payment( $invoice ) { |
|
434 | 434 | |
435 | - // Clear any checkout errors. |
|
436 | - wpinv_clear_errors(); |
|
435 | + // Clear any checkout errors. |
|
436 | + wpinv_clear_errors(); |
|
437 | 437 | |
438 | - // No need to send free invoices to the gateway. |
|
439 | - if ( $invoice->is_free() ) { |
|
440 | - $this->process_free_payment( $invoice ); |
|
441 | - } |
|
438 | + // No need to send free invoices to the gateway. |
|
439 | + if ( $invoice->is_free() ) { |
|
440 | + $this->process_free_payment( $invoice ); |
|
441 | + } |
|
442 | 442 | |
443 | - $submission = $this->payment_form_submission; |
|
443 | + $submission = $this->payment_form_submission; |
|
444 | 444 | |
445 | - // Fires before sending to the gateway. |
|
446 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
445 | + // Fires before sending to the gateway. |
|
446 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
447 | 447 | |
448 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
449 | - $submission_data = $submission->get_data(); |
|
450 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
448 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
449 | + $submission_data = $submission->get_data(); |
|
450 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
452 | 452 | |
453 | - // Validate the currency. |
|
454 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
456 | - } |
|
453 | + // Validate the currency. |
|
454 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
456 | + } |
|
457 | 457 | |
458 | - // Check to see if we have any errors. |
|
459 | - if ( wpinv_get_errors() ) { |
|
460 | - wpinv_send_back_to_checkout( $invoice ); |
|
461 | - } |
|
458 | + // Check to see if we have any errors. |
|
459 | + if ( wpinv_get_errors() ) { |
|
460 | + wpinv_send_back_to_checkout( $invoice ); |
|
461 | + } |
|
462 | 462 | |
463 | - // Send info to the gateway for payment processing |
|
464 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
463 | + // Send info to the gateway for payment processing |
|
464 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
465 | 465 | |
466 | - // Backwards compatibility. |
|
467 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
466 | + // Backwards compatibility. |
|
467 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
468 | 468 | |
469 | - } |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Marks the invoice as paid in case the checkout is free. |
|
473 | - * |
|
474 | - * @param WPInv_Invoice $invoice |
|
475 | - */ |
|
476 | - protected function process_free_payment( $invoice ) { |
|
471 | + /** |
|
472 | + * Marks the invoice as paid in case the checkout is free. |
|
473 | + * |
|
474 | + * @param WPInv_Invoice $invoice |
|
475 | + */ |
|
476 | + protected function process_free_payment( $invoice ) { |
|
477 | 477 | |
478 | - $invoice->set_gateway( 'none' ); |
|
479 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
480 | - $invoice->mark_paid(); |
|
481 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
478 | + $invoice->set_gateway( 'none' ); |
|
479 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
480 | + $invoice->mark_paid(); |
|
481 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
482 | 482 | |
483 | - } |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
485 | + /** |
|
486 | 486 | * Sends a redrect response to payment details. |
487 | 487 | * |
488 | 488 | */ |
@@ -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 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,33 +185,33 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
199 | + if (empty($user)) { |
|
200 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
201 | 201 | |
202 | 202 | // (Maybe) send new user notification. |
203 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | - wp_send_new_user_notifications( $user, 'user' ); |
|
203 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
204 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
205 | + wp_send_new_user_notifications($user, 'user'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | } |
209 | 209 | |
210 | - if ( is_wp_error( $user ) ) { |
|
211 | - wp_send_json_error( $user->get_error_message() ); |
|
210 | + if (is_wp_error($user)) { |
|
211 | + wp_send_json_error($user->get_error_message()); |
|
212 | 212 | } |
213 | 213 | |
214 | - if ( is_numeric( $user ) ) { |
|
214 | + if (is_numeric($user)) { |
|
215 | 215 | return $user; |
216 | 216 | } |
217 | 217 | |
@@ -235,24 +235,24 @@ discard block |
||
235 | 235 | ); |
236 | 236 | |
237 | 237 | // Raw submission details. |
238 | - $data = $submission->get_data(); |
|
238 | + $data = $submission->get_data(); |
|
239 | 239 | |
240 | 240 | // Loop through the submitted details. |
241 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
241 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
242 | 242 | |
243 | 243 | // Skip premade fields. |
244 | - if ( ! empty( $field['premade'] ) ) { |
|
244 | + if (!empty($field['premade'])) { |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | 248 | // Ensure address is provided. |
249 | - if ( $field['type'] == 'address' ) { |
|
250 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
249 | + if ($field['type'] == 'address') { |
|
250 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
251 | 251 | |
252 | - foreach ( $field['fields'] as $address_field ) { |
|
252 | + foreach ($field['fields'] as $address_field) { |
|
253 | 253 | |
254 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
254 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
255 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -260,49 +260,49 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // If it is required and not set, abort. |
263 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
264 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
263 | + if (!$submission->is_required_field_set($field)) { |
|
264 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle misc fields. |
268 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
268 | + if (isset($data[$field['id']])) { |
|
269 | 269 | |
270 | 270 | // Uploads. |
271 | - if ( $field['type'] == 'file_upload' ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
271 | + if ($field['type'] == 'file_upload') { |
|
272 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
274 | + if (count($data[$field['id']]) > $max_file_num) { |
|
275 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $value = array(); |
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + foreach ($data[$field['id']] as $url => $name) { |
|
281 | 281 | $value[] = sprintf( |
282 | 282 | '<a href="%s" target="_blank">%s</a>', |
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
283 | + esc_url_raw($url), |
|
284 | + esc_html($name) |
|
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode(' | ', $value); |
|
289 | 289 | |
290 | - } else if ( $field['type'] == 'checkbox' ) { |
|
291 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
290 | + } else if ($field['type'] == 'checkbox') { |
|
291 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
292 | 292 | } else { |
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + $value = wp_kses_post($data[$field['id']]); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
298 | - if ( isset( $field['label'] ) ) { |
|
298 | + if (isset($field['label'])) { |
|
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if (!empty($field['add_meta'])) { |
|
303 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
304 | 304 | } |
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
@@ -319,30 +319,30 @@ discard block |
||
319 | 319 | * @param WPInv_Invoice $invoice |
320 | 320 | * @param string $type |
321 | 321 | */ |
322 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
322 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
323 | 323 | |
324 | 324 | $data = $this->payment_form_submission->get_data(); |
325 | - $type = sanitize_key( $type ); |
|
325 | + $type = sanitize_key($type); |
|
326 | 326 | $address = array(); |
327 | 327 | $prepared = array(); |
328 | 328 | |
329 | - if ( ! empty( $data[ $type ] ) ) { |
|
330 | - $address = $data[ $type ]; |
|
329 | + if (!empty($data[$type])) { |
|
330 | + $address = $data[$type]; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Clean address details. |
334 | - foreach ( $address as $key => $value ) { |
|
335 | - $key = sanitize_key( $key ); |
|
336 | - $key = str_replace( 'wpinv_', '', $key ); |
|
337 | - $value = wpinv_clean( $value ); |
|
338 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
334 | + foreach ($address as $key => $value) { |
|
335 | + $key = sanitize_key($key); |
|
336 | + $key = str_replace('wpinv_', '', $key); |
|
337 | + $value = wpinv_clean($value); |
|
338 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | // Filter address details. |
342 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
342 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
343 | 343 | |
344 | 344 | // Remove non-whitelisted values. |
345 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
345 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
346 | 346 | |
347 | 347 | } |
348 | 348 | |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @return array |
353 | 353 | * @param WPInv_Invoice $invoice |
354 | 354 | */ |
355 | - protected function prepare_billing_info( &$invoice ) { |
|
355 | + protected function prepare_billing_info(&$invoice) { |
|
356 | 356 | |
357 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
357 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
358 | 358 | |
359 | 359 | // Update the invoice with the billing details. |
360 | - $invoice->set_props( $billing_address ); |
|
360 | + $invoice->set_props($billing_address); |
|
361 | 361 | |
362 | 362 | } |
363 | 363 | |
@@ -367,15 +367,15 @@ discard block |
||
367 | 367 | * @return array |
368 | 368 | * @param WPInv_Invoice $invoice |
369 | 369 | */ |
370 | - protected function prepare_shipping_info( $invoice ) { |
|
370 | + protected function prepare_shipping_info($invoice) { |
|
371 | 371 | |
372 | 372 | $data = $this->payment_form_submission->get_data(); |
373 | 373 | |
374 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + if (empty($data['same-shipping-address'])) { |
|
375 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
376 | 376 | } |
377 | 377 | |
378 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
378 | + return $this->prepare_address_details($invoice, 'billing'); |
|
379 | 379 | |
380 | 380 | } |
381 | 381 | |
@@ -386,42 +386,42 @@ discard block |
||
386 | 386 | * @param array $prepared_payment_form_data |
387 | 387 | * @param array $shipping |
388 | 388 | */ |
389 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
389 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
390 | 390 | |
391 | 391 | // Ensure the invoice exists. |
392 | - if ( ! $invoice->exists() ) { |
|
393 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
392 | + if (!$invoice->exists()) { |
|
393 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // Save payment form data. |
397 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
398 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
399 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
398 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
399 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
400 | + if (!empty($prepared_payment_form_data)) { |
|
401 | 401 | |
402 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + if (!empty($prepared_payment_form_data['all'])) { |
|
403 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
404 | 404 | } |
405 | 405 | |
406 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
407 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Save payment form data. |
413 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
414 | - if ( ! empty( $shipping ) ) { |
|
415 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
413 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
414 | + if (!empty($shipping)) { |
|
415 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // Backwards compatibility. |
419 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
419 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
420 | 420 | |
421 | - $this->process_payment( $invoice ); |
|
421 | + $this->process_payment($invoice); |
|
422 | 422 | |
423 | 423 | // If we are here, there was an error. |
424 | - wpinv_send_back_to_checkout( $invoice ); |
|
424 | + wpinv_send_back_to_checkout($invoice); |
|
425 | 425 | |
426 | 426 | } |
427 | 427 | |
@@ -430,41 +430,41 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @param WPInv_Invoice $invoice |
432 | 432 | */ |
433 | - protected function process_payment( $invoice ) { |
|
433 | + protected function process_payment($invoice) { |
|
434 | 434 | |
435 | 435 | // Clear any checkout errors. |
436 | 436 | wpinv_clear_errors(); |
437 | 437 | |
438 | 438 | // No need to send free invoices to the gateway. |
439 | - if ( $invoice->is_free() ) { |
|
440 | - $this->process_free_payment( $invoice ); |
|
439 | + if ($invoice->is_free()) { |
|
440 | + $this->process_free_payment($invoice); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | $submission = $this->payment_form_submission; |
444 | 444 | |
445 | 445 | // Fires before sending to the gateway. |
446 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
446 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
447 | 447 | |
448 | 448 | // Allow the sumission data to be modified before it is sent to the gateway. |
449 | 449 | $submission_data = $submission->get_data(); |
450 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
450 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
451 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
452 | 452 | |
453 | 453 | // Validate the currency. |
454 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
454 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
455 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // Check to see if we have any errors. |
459 | - if ( wpinv_get_errors() ) { |
|
460 | - wpinv_send_back_to_checkout( $invoice ); |
|
459 | + if (wpinv_get_errors()) { |
|
460 | + wpinv_send_back_to_checkout($invoice); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | // Send info to the gateway for payment processing |
464 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
464 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
465 | 465 | |
466 | 466 | // Backwards compatibility. |
467 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
467 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
468 | 468 | |
469 | 469 | } |
470 | 470 | |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @param WPInv_Invoice $invoice |
475 | 475 | */ |
476 | - protected function process_free_payment( $invoice ) { |
|
476 | + protected function process_free_payment($invoice) { |
|
477 | 477 | |
478 | - $invoice->set_gateway( 'none' ); |
|
479 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
478 | + $invoice->set_gateway('none'); |
|
479 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
480 | 480 | $invoice->mark_paid(); |
481 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
481 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
482 | 482 | |
483 | 483 | } |
484 | 484 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * Sends a redrect response to payment details. |
487 | 487 | * |
488 | 488 | */ |
489 | - public function send_redirect_response( $url ) { |
|
490 | - $url = urlencode( $url ); |
|
491 | - wp_send_json_success( $url ); |
|
489 | + public function send_redirect_response($url) { |
|
490 | + $url = urlencode($url); |
|
491 | + wp_send_json_success($url); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | } |
@@ -12,474 +12,474 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | 216 | |
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | 223 | |
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
231 | 231 | |
232 | - // Process a refund. |
|
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + // Process a refund. |
|
233 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | - } |
|
237 | + if ( ! $invoice->is_refunded() ) { |
|
238 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | + } |
|
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | - } |
|
241 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | + } |
|
243 | 243 | |
244 | - // Process payments. |
|
245 | - if ( $payment_status == 'completed' ) { |
|
244 | + // Process payments. |
|
245 | + if ( $payment_status == 'completed' ) { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | - } |
|
247 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | + } |
|
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
252 | 252 | |
253 | - $note = ''; |
|
253 | + $note = ''; |
|
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | - } |
|
255 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | + } |
|
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | - } |
|
259 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | + } |
|
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - // Pending payments. |
|
269 | - if ( $payment_status == 'pending' ) { |
|
268 | + // Pending payments. |
|
269 | + if ( $payment_status == 'pending' ) { |
|
270 | 270 | |
271 | - /* translators: %s: pending reason. */ |
|
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + /* translators: %s: pending reason. */ |
|
272 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | - } |
|
274 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | + } |
|
276 | 276 | |
277 | - /* translators: %s: payment status. */ |
|
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + /* translators: %s: payment status. */ |
|
278 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Handles one time payments. |
|
284 | - * |
|
285 | - * @param WPInv_Invoice $invoice Invoice object. |
|
286 | - * @param array $posted Posted data. |
|
287 | - */ |
|
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | - } |
|
282 | + /** |
|
283 | + * Handles one time payments. |
|
284 | + * |
|
285 | + * @param WPInv_Invoice $invoice Invoice object. |
|
286 | + * @param array $posted Posted data. |
|
287 | + */ |
|
288 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Handles subscription sign ups. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice Invoice object. |
|
296 | - * @param array $posted Posted data. |
|
297 | - */ |
|
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
292 | + /** |
|
293 | + * Handles subscription sign ups. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice Invoice object. |
|
296 | + * @param array $posted Posted data. |
|
297 | + */ |
|
298 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
301 | 301 | |
302 | - // Make sure the invoice has a subscription. |
|
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + // Make sure the invoice has a subscription. |
|
303 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | - } |
|
305 | + if ( empty( $subscription ) ) { |
|
306 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | + } |
|
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
310 | 310 | |
311 | - // Validate the IPN. |
|
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + // Validate the IPN. |
|
312 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
315 | 315 | |
316 | - // Activate the subscription. |
|
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | - $subscription->activate(); |
|
316 | + // Activate the subscription. |
|
317 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | + $subscription->activate(); |
|
322 | 322 | |
323 | - // Set the transaction id. |
|
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | - } |
|
323 | + // Set the transaction id. |
|
324 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | + } |
|
328 | 328 | |
329 | - // Update the payment status. |
|
330 | - $invoice->mark_paid(); |
|
329 | + // Update the payment status. |
|
330 | + $invoice->mark_paid(); |
|
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
335 | - } |
|
334 | + wpinv_error_log( 'Subscription started.', false ); |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Handles subscription renewals. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice Invoice object. |
|
341 | - * @param array $posted Posted data. |
|
342 | - */ |
|
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
337 | + /** |
|
338 | + * Handles subscription renewals. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice Invoice object. |
|
341 | + * @param array $posted Posted data. |
|
342 | + */ |
|
343 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
344 | 344 | |
345 | - // Make sure the invoice has a subscription. |
|
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + // Make sure the invoice has a subscription. |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | - } |
|
348 | + if ( empty( $subscription ) ) { |
|
349 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | + } |
|
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
353 | 353 | |
354 | - // PayPal sends a subscr_payment for the first payment too. |
|
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + // PayPal sends a subscr_payment for the first payment too. |
|
355 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach( $dates as $date ) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | - continue; |
|
366 | - } |
|
364 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | + continue; |
|
366 | + } |
|
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | - } |
|
368 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | + } |
|
372 | 372 | |
373 | - return $invoice->mark_paid(); |
|
374 | - |
|
375 | - } |
|
373 | + return $invoice->mark_paid(); |
|
374 | + |
|
375 | + } |
|
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | - |
|
379 | - // Abort if the payment is already recorded. |
|
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | - } |
|
383 | - |
|
384 | - $args = array( |
|
385 | - 'transaction_id' => $posted['txn_id'], |
|
386 | - 'gateway' => $this->id, |
|
387 | - ); |
|
388 | - |
|
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
377 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | + |
|
379 | + // Abort if the payment is already recorded. |
|
380 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | + } |
|
383 | + |
|
384 | + $args = array( |
|
385 | + 'transaction_id' => $posted['txn_id'], |
|
386 | + 'gateway' => $this->id, |
|
387 | + ); |
|
388 | + |
|
389 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
392 | - return; |
|
393 | - } |
|
391 | + if ( empty( $invoice ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
397 | 397 | |
398 | - $subscription->renew(); |
|
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + $subscription->renew(); |
|
399 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
400 | 400 | |
401 | - } |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * Handles subscription cancelations. |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice Invoice object. |
|
407 | - */ |
|
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
403 | + /** |
|
404 | + * Handles subscription cancelations. |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice Invoice object. |
|
407 | + */ |
|
408 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
409 | 409 | |
410 | - // Make sure the invoice has a subscription. |
|
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | - |
|
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | - } |
|
416 | - |
|
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | - $subscription->cancel(); |
|
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
410 | + // Make sure the invoice has a subscription. |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | + |
|
413 | + if ( empty( $subscription ) ) { |
|
414 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | + } |
|
416 | + |
|
417 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | + $subscription->cancel(); |
|
419 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * Handles subscription completions. |
|
425 | - * |
|
426 | - * @param WPInv_Invoice $invoice Invoice object. |
|
427 | - * @param array $posted Posted data. |
|
428 | - */ |
|
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
423 | + /** |
|
424 | + * Handles subscription completions. |
|
425 | + * |
|
426 | + * @param WPInv_Invoice $invoice Invoice object. |
|
427 | + * @param array $posted Posted data. |
|
428 | + */ |
|
429 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
430 | 430 | |
431 | - // Make sure the invoice has a subscription. |
|
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + // Make sure the invoice has a subscription. |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | - } |
|
434 | + if ( empty( $subscription ) ) { |
|
435 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | + } |
|
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | - $subscription->complete(); |
|
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
438 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | + $subscription->complete(); |
|
440 | + wpinv_error_log( 'Subscription completed.', false ); |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * Handles subscription fails. |
|
446 | - * |
|
447 | - * @param WPInv_Invoice $invoice Invoice object. |
|
448 | - * @param array $posted Posted data. |
|
449 | - */ |
|
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
444 | + /** |
|
445 | + * Handles subscription fails. |
|
446 | + * |
|
447 | + * @param WPInv_Invoice $invoice Invoice object. |
|
448 | + * @param array $posted Posted data. |
|
449 | + */ |
|
450 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
451 | 451 | |
452 | - // Make sure the invoice has a subscription. |
|
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + // Make sure the invoice has a subscription. |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | - } |
|
455 | + if ( empty( $subscription ) ) { |
|
456 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | + } |
|
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | - $subscription->failing(); |
|
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
459 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | + $subscription->failing(); |
|
461 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
462 | 462 | |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | - /** |
|
466 | - * Handles subscription suspensions. |
|
467 | - * |
|
468 | - * @param WPInv_Invoice $invoice Invoice object. |
|
469 | - * @param array $posted Posted data. |
|
470 | - */ |
|
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
465 | + /** |
|
466 | + * Handles subscription suspensions. |
|
467 | + * |
|
468 | + * @param WPInv_Invoice $invoice Invoice object. |
|
469 | + * @param array $posted Posted data. |
|
470 | + */ |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
472 | 472 | |
473 | - // Make sure the invoice has a subscription. |
|
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + // Make sure the invoice has a subscription. |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | - } |
|
479 | - |
|
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | - $subscription->cancel(); |
|
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | - } |
|
476 | + if ( empty( $subscription ) ) { |
|
477 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | + } |
|
479 | + |
|
480 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | + $subscription->cancel(); |
|
482 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | + } |
|
484 | 484 | |
485 | 485 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + wpinv_error_log('Validated PayPal Email', false); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,70 +212,70 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
231 | 231 | |
232 | 232 | // Process a refund. |
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + if (!$invoice->is_refunded()) { |
|
238 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
239 | 239 | } |
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + return wpinv_error_log($posted['reason_code'], false); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Process payments. |
245 | - if ( $payment_status == 'completed' ) { |
|
245 | + if ($payment_status == 'completed') { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
247 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
248 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
249 | 249 | } |
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
252 | 252 | |
253 | 253 | $note = ''; |
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + if (!empty($posted['mc_fee'])) { |
|
256 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + if (!empty($posted['payer_status'])) { |
|
260 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
261 | 261 | } |
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
264 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Pending payments. |
269 | - if ( $payment_status == 'pending' ) { |
|
269 | + if ($payment_status == 'pending') { |
|
270 | 270 | |
271 | 271 | /* translators: %s: pending reason. */ |
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /* translators: %s: payment status. */ |
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
279 | 279 | |
280 | 280 | } |
281 | 281 | |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param WPInv_Invoice $invoice Invoice object. |
286 | 286 | * @param array $posted Posted data. |
287 | 287 | */ |
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + protected function ipn_txn_cart($invoice, $posted) { |
|
289 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,43 +295,43 @@ discard block |
||
295 | 295 | * @param WPInv_Invoice $invoice Invoice object. |
296 | 296 | * @param array $posted Posted data. |
297 | 297 | */ |
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log('Processing subscription signup', false); |
|
301 | 301 | |
302 | 302 | // Make sure the invoice has a subscription. |
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
305 | + if (empty($subscription)) { |
|
306 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
307 | 307 | } |
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
310 | 310 | |
311 | 311 | // Validate the IPN. |
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
312 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
313 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
314 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
315 | 315 | |
316 | 316 | // Activate the subscription. |
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
318 | + $subscription->set_date_created(current_time('mysql')); |
|
319 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
320 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
321 | 321 | $subscription->activate(); |
322 | 322 | |
323 | 323 | // Set the transaction id. |
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
324 | + if (!empty($posted['txn_id'])) { |
|
325 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
326 | + $invoice->set_transaction_id($posted['txn_id']); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Update the payment status. |
330 | 330 | $invoice->mark_paid(); |
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | + wpinv_error_log('Subscription started.', false); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -340,45 +340,45 @@ discard block |
||
340 | 340 | * @param WPInv_Invoice $invoice Invoice object. |
341 | 341 | * @param array $posted Posted data. |
342 | 342 | */ |
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
344 | 344 | |
345 | 345 | // Make sure the invoice has a subscription. |
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
348 | + if (empty($subscription)) { |
|
349 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
350 | 350 | } |
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
353 | 353 | |
354 | 354 | // PayPal sends a subscr_payment for the first payment too. |
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
355 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
356 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
357 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
358 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
359 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
360 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach ($dates as $date) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + if ($date !== $today_date && $date !== $payment_date) { |
|
365 | 365 | continue; |
366 | 366 | } |
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
368 | + if (!empty($posted['txn_id'])) { |
|
369 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
370 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | return $invoice->mark_paid(); |
374 | 374 | |
375 | 375 | } |
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
378 | 378 | |
379 | 379 | // Abort if the payment is already recorded. |
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
380 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
381 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $args = array( |
@@ -386,17 +386,17 @@ discard block |
||
386 | 386 | 'gateway' => $this->id, |
387 | 387 | ); |
388 | 388 | |
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
391 | + if (empty($invoice)) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
396 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
397 | 397 | |
398 | 398 | $subscription->renew(); |
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | + wpinv_error_log('Subscription renewed.', false); |
|
400 | 400 | |
401 | 401 | } |
402 | 402 | |
@@ -405,18 +405,18 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @param WPInv_Invoice $invoice Invoice object. |
407 | 407 | */ |
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
409 | 409 | |
410 | 410 | // Make sure the invoice has a subscription. |
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
412 | 412 | |
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | + if (empty($subscription)) { |
|
414 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | 415 | } |
416 | 416 | |
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
418 | 418 | $subscription->cancel(); |
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | + wpinv_error_log('Subscription cancelled.', false); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | |
@@ -426,18 +426,18 @@ discard block |
||
426 | 426 | * @param WPInv_Invoice $invoice Invoice object. |
427 | 427 | * @param array $posted Posted data. |
428 | 428 | */ |
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | + protected function ipn_txn_subscr_eot($invoice) { |
|
430 | 430 | |
431 | 431 | // Make sure the invoice has a subscription. |
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
434 | + if (empty($subscription)) { |
|
435 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
436 | 436 | } |
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
439 | 439 | $subscription->complete(); |
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
440 | + wpinv_error_log('Subscription completed.', false); |
|
441 | 441 | |
442 | 442 | } |
443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
447 | 447 | * @param WPInv_Invoice $invoice Invoice object. |
448 | 448 | * @param array $posted Posted data. |
449 | 449 | */ |
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | + protected function ipn_txn_subscr_failed($invoice) { |
|
451 | 451 | |
452 | 452 | // Make sure the invoice has a subscription. |
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
455 | + if (empty($subscription)) { |
|
456 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
457 | 457 | } |
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
460 | 460 | $subscription->failing(); |
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | + wpinv_error_log('Subscription marked as failing.', false); |
|
462 | 462 | |
463 | 463 | } |
464 | 464 | |
@@ -468,18 +468,18 @@ discard block |
||
468 | 468 | * @param WPInv_Invoice $invoice Invoice object. |
469 | 469 | * @param array $posted Posted data. |
470 | 470 | */ |
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
472 | 472 | |
473 | 473 | // Make sure the invoice has a subscription. |
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
476 | + if (empty($subscription)) { |
|
477 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
478 | 478 | } |
479 | 479 | |
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
481 | 481 | $subscription->cancel(); |
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + wpinv_error_log('Subscription cancelled.', false); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | } |