@@ -12,180 +12,180 @@ 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 | - wpinv_set_error( 'invalid_gateway', __( '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 | + wpinv_set_error( 'invalid_gateway', __( '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 | + } |
|
133 | 117 | |
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 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
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 ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
152 | - $data = $submission->get_data(); |
|
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 | + } |
|
153 | 138 | |
154 | - // Set-up the invoice details. |
|
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
139 | + return $invoice; |
|
140 | + } |
|
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 ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + $data = $submission->get_data(); |
|
153 | + |
|
154 | + // Set-up the invoice details. |
|
155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | 158 | $invoice->set_items( $items ); |
159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | 163 | |
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | 166 | |
167 | - if ( $submission->has_discount_code() ) { |
|
167 | + if ( $submission->has_discount_code() ) { |
|
168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
169 | - } |
|
170 | - |
|
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
172 | - return $invoice; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Retrieves the submission's customer. |
|
177 | - * |
|
178 | - * @return int The customer id. |
|
179 | - */ |
|
180 | - protected function get_submission_customer() { |
|
181 | - $submission = $this->payment_form_submission; |
|
182 | - |
|
183 | - // If this is an existing invoice... |
|
184 | - if ( $submission->has_invoice() ) { |
|
185 | - return $submission->get_invoice()->get_user_id(); |
|
186 | - } |
|
187 | - |
|
188 | - // (Maybe) create the user. |
|
169 | + } |
|
170 | + |
|
171 | + getpaid_maybe_add_default_address( $invoice ); |
|
172 | + return $invoice; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Retrieves the submission's customer. |
|
177 | + * |
|
178 | + * @return int The customer id. |
|
179 | + */ |
|
180 | + protected function get_submission_customer() { |
|
181 | + $submission = $this->payment_form_submission; |
|
182 | + |
|
183 | + // If this is an existing invoice... |
|
184 | + if ( $submission->has_invoice() ) { |
|
185 | + return $submission->get_invoice()->get_user_id(); |
|
186 | + } |
|
187 | + |
|
188 | + // (Maybe) create the user. |
|
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | 191 | if ( empty( $user ) ) { |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | if ( empty( $user ) ) { |
196 | 196 | $user = wpinv_create_user( $submission->get_billing_email() ); |
197 | 197 | |
198 | - // (Maybe) send new user notification. |
|
199 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
200 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
201 | - wp_send_new_user_notifications( $user, 'user' ); |
|
202 | - } |
|
198 | + // (Maybe) send new user notification. |
|
199 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
200 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
201 | + wp_send_new_user_notifications( $user, 'user' ); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -209,31 +209,31 @@ discard block |
||
209 | 209 | |
210 | 210 | if ( is_numeric( $user ) ) { |
211 | 211 | return $user; |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - return $user->ID; |
|
214 | + return $user->ID; |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
218 | + /** |
|
219 | 219 | * Prepares submission data for saving to the database. |
220 | 220 | * |
221 | - * @return array |
|
221 | + * @return array |
|
222 | 222 | */ |
223 | 223 | public function prepare_submission_data_for_saving() { |
224 | 224 | |
225 | - $submission = $this->payment_form_submission; |
|
225 | + $submission = $this->payment_form_submission; |
|
226 | 226 | |
227 | - // Prepared submission details. |
|
227 | + // Prepared submission details. |
|
228 | 228 | $prepared = array(); |
229 | 229 | |
230 | 230 | // Raw submission details. |
231 | - $data = $submission->get_data(); |
|
231 | + $data = $submission->get_data(); |
|
232 | 232 | |
233 | - // Loop through the submitted details. |
|
233 | + // Loop through the submitted details. |
|
234 | 234 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
235 | 235 | |
236 | - // Skip premade fields. |
|
236 | + // Skip premade fields. |
|
237 | 237 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
238 | 238 | continue; |
239 | 239 | } |
@@ -251,176 +251,176 @@ discard block |
||
251 | 251 | $label = $field['label']; |
252 | 252 | } |
253 | 253 | |
254 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
254 | + $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - return $prepared; |
|
260 | + return $prepared; |
|
261 | 261 | |
262 | - } |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
264 | + /** |
|
265 | 265 | * Retrieves address details. |
266 | 266 | * |
267 | - * @return array |
|
268 | - * @param WPInv_Invoice $invoice |
|
269 | - * @param string $type |
|
267 | + * @return array |
|
268 | + * @param WPInv_Invoice $invoice |
|
269 | + * @param string $type |
|
270 | 270 | */ |
271 | 271 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
272 | 272 | |
273 | - $data = $this->payment_form_submission->get_data(); |
|
274 | - $type = sanitize_key( $type ); |
|
275 | - $address = array(); |
|
276 | - $prepared = array(); |
|
273 | + $data = $this->payment_form_submission->get_data(); |
|
274 | + $type = sanitize_key( $type ); |
|
275 | + $address = array(); |
|
276 | + $prepared = array(); |
|
277 | 277 | |
278 | - if ( ! empty( $data[ $type ] ) ) { |
|
279 | - $address = $data[ $type ]; |
|
280 | - } |
|
278 | + if ( ! empty( $data[ $type ] ) ) { |
|
279 | + $address = $data[ $type ]; |
|
280 | + } |
|
281 | 281 | |
282 | - // Clean address details. |
|
283 | - foreach ( $address as $key => $value ) { |
|
284 | - $key = sanitize_key( $key ); |
|
285 | - $key = str_replace( 'wpinv_', '', $key ); |
|
286 | - $value = wpinv_clean( $value ); |
|
287 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
288 | - } |
|
282 | + // Clean address details. |
|
283 | + foreach ( $address as $key => $value ) { |
|
284 | + $key = sanitize_key( $key ); |
|
285 | + $key = str_replace( 'wpinv_', '', $key ); |
|
286 | + $value = wpinv_clean( $value ); |
|
287 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
288 | + } |
|
289 | 289 | |
290 | - // Filter address details. |
|
291 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
290 | + // Filter address details. |
|
291 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
292 | 292 | |
293 | - // Remove non-whitelisted values. |
|
294 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
293 | + // Remove non-whitelisted values. |
|
294 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - /** |
|
298 | + /** |
|
299 | 299 | * Prepares the billing details. |
300 | 300 | * |
301 | - * @return array |
|
302 | - * @param WPInv_Invoice $invoice |
|
301 | + * @return array |
|
302 | + * @param WPInv_Invoice $invoice |
|
303 | 303 | */ |
304 | 304 | protected function prepare_billing_info( &$invoice ) { |
305 | 305 | |
306 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
306 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
307 | 307 | |
308 | - // Update the invoice with the billing details. |
|
309 | - $invoice->set_props( $billing_address ); |
|
308 | + // Update the invoice with the billing details. |
|
309 | + $invoice->set_props( $billing_address ); |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Prepares the shipping details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | 318 | */ |
319 | 319 | protected function prepare_shipping_info( $invoice ) { |
320 | 320 | |
321 | - $data = $this->payment_form_submission->get_data(); |
|
321 | + $data = $this->payment_form_submission->get_data(); |
|
322 | 322 | |
323 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
324 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
325 | - } |
|
323 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
324 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
325 | + } |
|
326 | 326 | |
327 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
327 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
328 | 328 | |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Confirms the submission is valid and send users to the gateway. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice |
|
335 | - * @param array $prepared_payment_form_data |
|
336 | - * @param array $shipping |
|
337 | - */ |
|
338 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
331 | + /** |
|
332 | + * Confirms the submission is valid and send users to the gateway. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice |
|
335 | + * @param array $prepared_payment_form_data |
|
336 | + * @param array $shipping |
|
337 | + */ |
|
338 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
339 | 339 | |
340 | - // Ensure the invoice exists. |
|
340 | + // Ensure the invoice exists. |
|
341 | 341 | if ( ! $invoice->exists() ) { |
342 | 342 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
343 | 343 | } |
344 | 344 | |
345 | - // Save payment form data. |
|
346 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
345 | + // Save payment form data. |
|
346 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
347 | 347 | if ( ! empty( $prepared_payment_form_data ) ) { |
348 | 348 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
349 | - } |
|
349 | + } |
|
350 | 350 | |
351 | - // Save payment form data. |
|
351 | + // Save payment form data. |
|
352 | 352 | if ( ! empty( $shipping ) ) { |
353 | 353 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
354 | - } |
|
354 | + } |
|
355 | 355 | |
356 | - // Backwards compatibility. |
|
356 | + // Backwards compatibility. |
|
357 | 357 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
358 | 358 | |
359 | - $this->process_payment( $invoice ); |
|
359 | + $this->process_payment( $invoice ); |
|
360 | 360 | |
361 | 361 | // If we are here, there was an error. |
362 | - wpinv_send_back_to_checkout( $invoice ); |
|
362 | + wpinv_send_back_to_checkout( $invoice ); |
|
363 | 363 | |
364 | - } |
|
364 | + } |
|
365 | 365 | |
366 | - /** |
|
367 | - * Processes the actual payment. |
|
368 | - * |
|
369 | - * @param WPInv_Invoice $invoice |
|
370 | - */ |
|
371 | - protected function process_payment( $invoice ) { |
|
366 | + /** |
|
367 | + * Processes the actual payment. |
|
368 | + * |
|
369 | + * @param WPInv_Invoice $invoice |
|
370 | + */ |
|
371 | + protected function process_payment( $invoice ) { |
|
372 | 372 | |
373 | - // Clear any checkout errors. |
|
374 | - wpinv_clear_errors(); |
|
373 | + // Clear any checkout errors. |
|
374 | + wpinv_clear_errors(); |
|
375 | 375 | |
376 | - // No need to send free invoices to the gateway. |
|
377 | - if ( $invoice->is_free() ) { |
|
378 | - $this->process_free_payment( $invoice ); |
|
379 | - } |
|
376 | + // No need to send free invoices to the gateway. |
|
377 | + if ( $invoice->is_free() ) { |
|
378 | + $this->process_free_payment( $invoice ); |
|
379 | + } |
|
380 | 380 | |
381 | - $submission = $this->payment_form_submission; |
|
381 | + $submission = $this->payment_form_submission; |
|
382 | 382 | |
383 | - // Fires before sending to the gateway. |
|
384 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
383 | + // Fires before sending to the gateway. |
|
384 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
385 | 385 | |
386 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
387 | - $submission_data = $submission->get_data(); |
|
388 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
389 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
386 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
387 | + $submission_data = $submission->get_data(); |
|
388 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
389 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
390 | 390 | |
391 | - // Validate the currency. |
|
392 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
393 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
394 | - } |
|
391 | + // Validate the currency. |
|
392 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
393 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
394 | + } |
|
395 | 395 | |
396 | - // Check to see if we have any errors. |
|
397 | - if ( wpinv_get_errors() ) { |
|
398 | - wpinv_send_back_to_checkout( $invoice ); |
|
399 | - } |
|
396 | + // Check to see if we have any errors. |
|
397 | + if ( wpinv_get_errors() ) { |
|
398 | + wpinv_send_back_to_checkout( $invoice ); |
|
399 | + } |
|
400 | 400 | |
401 | - // Send info to the gateway for payment processing |
|
402 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
401 | + // Send info to the gateway for payment processing |
|
402 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
403 | 403 | |
404 | - // Backwards compatibility. |
|
405 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
404 | + // Backwards compatibility. |
|
405 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
406 | 406 | |
407 | - } |
|
407 | + } |
|
408 | 408 | |
409 | - /** |
|
410 | - * Marks the invoice as paid in case the checkout is free. |
|
411 | - * |
|
412 | - * @param WPInv_Invoice $invoice |
|
413 | - */ |
|
414 | - protected function process_free_payment( $invoice ) { |
|
409 | + /** |
|
410 | + * Marks the invoice as paid in case the checkout is free. |
|
411 | + * |
|
412 | + * @param WPInv_Invoice $invoice |
|
413 | + */ |
|
414 | + protected function process_free_payment( $invoice ) { |
|
415 | 415 | |
416 | - $invoice->set_gateway( 'none' ); |
|
417 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
418 | - $invoice->mark_paid(); |
|
419 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
416 | + $invoice->set_gateway( 'none' ); |
|
417 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
418 | + $invoice->mark_paid(); |
|
419 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
423 | + /** |
|
424 | 424 | * Sends a redrect response to payment details. |
425 | 425 | * |
426 | 426 | */ |