@@ -286,26 +286,26 @@ discard block |
||
286 | 286 | } |
287 | 287 | |
288 | 288 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
289 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
290 | 290 | |
291 | 291 | $chosen = false; |
292 | 292 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
293 | 293 | $chosen = $invoice->get_gateway(); |
294 | 294 | } |
295 | 295 | |
296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
296 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
297 | 297 | |
298 | - if ( false !== $chosen ) { |
|
299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
300 | - } |
|
298 | + if ( false !== $chosen ) { |
|
299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
300 | + } |
|
301 | 301 | |
302 | - if ( ! empty ( $chosen ) ) { |
|
303 | - $enabled_gateway = urldecode( $chosen ); |
|
304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
305 | - $enabled_gateway = 'manual'; |
|
306 | - } else { |
|
307 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
308 | - } |
|
302 | + if ( ! empty ( $chosen ) ) { |
|
303 | + $enabled_gateway = urldecode( $chosen ); |
|
304 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
305 | + $enabled_gateway = 'manual'; |
|
306 | + } else { |
|
307 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
308 | + } |
|
309 | 309 | |
310 | 310 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
311 | 311 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
319 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | } |
325 | 325 | |
326 | 326 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
327 | - $ret = 0; |
|
328 | - $args = array( |
|
329 | - 'meta_key' => '_wpinv_gateway', |
|
330 | - 'meta_value' => $gateway_id, |
|
331 | - 'nopaging' => true, |
|
332 | - 'post_type' => 'wpi_invoice', |
|
333 | - 'post_status' => $status, |
|
334 | - 'fields' => 'ids' |
|
335 | - ); |
|
336 | - |
|
337 | - $payments = new WP_Query( $args ); |
|
338 | - |
|
339 | - if( $payments ) |
|
340 | - $ret = $payments->post_count; |
|
341 | - return $ret; |
|
327 | + $ret = 0; |
|
328 | + $args = array( |
|
329 | + 'meta_key' => '_wpinv_gateway', |
|
330 | + 'meta_value' => $gateway_id, |
|
331 | + 'nopaging' => true, |
|
332 | + 'post_type' => 'wpi_invoice', |
|
333 | + 'post_status' => $status, |
|
334 | + 'fields' => 'ids' |
|
335 | + ); |
|
336 | + |
|
337 | + $payments = new WP_Query( $args ); |
|
338 | + |
|
339 | + if( $payments ) |
|
340 | + $ret = $payments->post_count; |
|
341 | + return $ret; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | function wpinv_settings_update_gateways( $input ) { |
@@ -12,168 +12,168 @@ 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 | - // Get the items and 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( $invoice ); |
|
43 | - |
|
44 | - // Save the invoice. |
|
45 | - $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 | + // Get the items and 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( $invoice ); |
|
43 | + |
|
44 | + // Save the invoice. |
|
45 | + $invoice->recalculate_total(); |
|
46 | 46 | $invoice->save(); |
47 | 47 | |
48 | - // Send to the gateway. |
|
49 | - $this->post_process_submission( $invoice, $prepared ); |
|
50 | - } |
|
48 | + // Send to the gateway. |
|
49 | + $this->post_process_submission( $invoice, $prepared ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Validates the submission. |
|
54 | - * |
|
55 | - */ |
|
56 | - protected function validate_submission() { |
|
52 | + /** |
|
53 | + * Validates the submission. |
|
54 | + * |
|
55 | + */ |
|
56 | + protected function validate_submission() { |
|
57 | 57 | |
58 | - $submission = $this->payment_form_submission; |
|
59 | - $data = $submission->get_data(); |
|
58 | + $submission = $this->payment_form_submission; |
|
59 | + $data = $submission->get_data(); |
|
60 | 60 | |
61 | - // Do we have an error? |
|
61 | + // Do we have an error? |
|
62 | 62 | if ( ! empty( $submission->last_error ) ) { |
63 | - wp_send_json_error( $submission->last_error ); |
|
63 | + wp_send_json_error( $submission->last_error ); |
|
64 | 64 | } |
65 | 65 | |
66 | - // We need a billing email. |
|
66 | + // We need a billing email. |
|
67 | 67 | if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) { |
68 | 68 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | - if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
74 | - } |
|
71 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | + if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
74 | + } |
|
75 | 75 | |
76 | - // Ensure the gateway is active. |
|
77 | - if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | - } |
|
76 | + // Ensure the gateway is active. |
|
77 | + if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | + } |
|
80 | 80 | |
81 | - // Clear any existing errors. |
|
82 | - wpinv_clear_errors(); |
|
81 | + // Clear any existing errors. |
|
82 | + wpinv_clear_errors(); |
|
83 | 83 | |
84 | - // Allow themes and plugins to hook to errors |
|
85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
84 | + // Allow themes and plugins to hook to errors |
|
85 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
86 | 86 | |
87 | - // Do we have any errors? |
|
87 | + // Do we have any errors? |
|
88 | 88 | if ( wpinv_get_errors() ) { |
89 | 89 | wp_send_json_error( getpaid_get_errors_html() ); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves submission items. |
|
96 | - * |
|
97 | - * @return GetPaid_Form_Item[] |
|
98 | - */ |
|
99 | - protected function get_submission_items() { |
|
94 | + /** |
|
95 | + * Retrieves submission items. |
|
96 | + * |
|
97 | + * @return GetPaid_Form_Item[] |
|
98 | + */ |
|
99 | + protected function get_submission_items() { |
|
100 | 100 | |
101 | - $items = $this->payment_form_submission->get_items(); |
|
101 | + $items = $this->payment_form_submission->get_items(); |
|
102 | 102 | |
103 | 103 | // Ensure that we have items. |
104 | 104 | if ( empty( $items ) && 0 == count( $this->payment_form_submission->get_fees() ) ) { |
105 | 105 | wp_send_json_error( __( 'Please select at least one item.', 'invoicing' ) ); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - return $items; |
|
109 | - } |
|
108 | + return $items; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Retrieves submission invoice. |
|
113 | - * |
|
114 | - * @return WPInv_Invoice |
|
115 | - */ |
|
116 | - protected function get_submission_invoice() { |
|
117 | - $submission = $this->payment_form_submission; |
|
111 | + /** |
|
112 | + * Retrieves submission invoice. |
|
113 | + * |
|
114 | + * @return WPInv_Invoice |
|
115 | + */ |
|
116 | + protected function get_submission_invoice() { |
|
117 | + $submission = $this->payment_form_submission; |
|
118 | 118 | |
119 | - if ( ! $submission->has_invoice() ) { |
|
120 | - return new WPInv_Invoice(); |
|
119 | + if ( ! $submission->has_invoice() ) { |
|
120 | + return new WPInv_Invoice(); |
|
121 | 121 | } |
122 | 122 | |
123 | - $invoice = $submission->get_invoice(); |
|
123 | + $invoice = $submission->get_invoice(); |
|
124 | 124 | |
125 | - // Make sure that it is neither paid or refunded. |
|
126 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
127 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
128 | - } |
|
125 | + // Make sure that it is neither paid or refunded. |
|
126 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
127 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
128 | + } |
|
129 | 129 | |
130 | - return $invoice; |
|
131 | - } |
|
130 | + return $invoice; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Processes the submission invoice. |
|
135 | - * |
|
136 | - * @param WPInv_Invoice $invoice |
|
137 | - * @param GetPaid_Form_Item[] $items |
|
138 | - * @return WPInv_Invoice |
|
139 | - */ |
|
140 | - protected function process_submission_invoice( $invoice, $items ) { |
|
133 | + /** |
|
134 | + * Processes the submission invoice. |
|
135 | + * |
|
136 | + * @param WPInv_Invoice $invoice |
|
137 | + * @param GetPaid_Form_Item[] $items |
|
138 | + * @return WPInv_Invoice |
|
139 | + */ |
|
140 | + protected function process_submission_invoice( $invoice, $items ) { |
|
141 | 141 | |
142 | - $submission = $this->payment_form_submission; |
|
143 | - $data = $submission->get_data(); |
|
142 | + $submission = $this->payment_form_submission; |
|
143 | + $data = $submission->get_data(); |
|
144 | 144 | |
145 | - // Set-up the invoice details. |
|
146 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
147 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
148 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
145 | + // Set-up the invoice details. |
|
146 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
147 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
148 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
149 | 149 | $invoice->set_items( $items ); |
150 | 150 | $invoice->set_fees( $submission->get_fees() ); |
151 | 151 | $invoice->set_taxes( $submission->get_taxes() ); |
152 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
153 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
152 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
153 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
154 | 154 | |
155 | - if ( $submission->has_discount_code() ) { |
|
155 | + if ( $submission->has_discount_code() ) { |
|
156 | 156 | $invoice->set_discount_code( $submission->get_discount_code() ); |
157 | - } |
|
158 | - |
|
159 | - getpaid_maybe_add_default_address( $invoice ); |
|
160 | - return $invoice; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Retrieves the submission's customer. |
|
165 | - * |
|
166 | - * @return int The customer id. |
|
167 | - */ |
|
168 | - protected function get_submission_customer() { |
|
169 | - $submission = $this->payment_form_submission; |
|
170 | - |
|
171 | - // If this is an existing invoice... |
|
172 | - if ( $submission->has_invoice() ) { |
|
173 | - return $submission->get_invoice()->get_user_id(); |
|
174 | - } |
|
175 | - |
|
176 | - // (Maybe) create the user. |
|
157 | + } |
|
158 | + |
|
159 | + getpaid_maybe_add_default_address( $invoice ); |
|
160 | + return $invoice; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Retrieves the submission's customer. |
|
165 | + * |
|
166 | + * @return int The customer id. |
|
167 | + */ |
|
168 | + protected function get_submission_customer() { |
|
169 | + $submission = $this->payment_form_submission; |
|
170 | + |
|
171 | + // If this is an existing invoice... |
|
172 | + if ( $submission->has_invoice() ) { |
|
173 | + return $submission->get_invoice()->get_user_id(); |
|
174 | + } |
|
175 | + |
|
176 | + // (Maybe) create the user. |
|
177 | 177 | $user = get_current_user_id(); |
178 | 178 | |
179 | 179 | if ( empty( $user ) ) { |
@@ -190,31 +190,31 @@ discard block |
||
190 | 190 | |
191 | 191 | if ( is_numeric( $user ) ) { |
192 | 192 | return $user; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - return $user->ID; |
|
195 | + return $user->ID; |
|
196 | 196 | |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
199 | + /** |
|
200 | 200 | * Prepares submission data for saving to the database. |
201 | 201 | * |
202 | - * @param WPInv_Invoice $invoice |
|
202 | + * @param WPInv_Invoice $invoice |
|
203 | 203 | */ |
204 | 204 | public function prepare_submission_data_for_saving( &$invoice ) { |
205 | 205 | |
206 | - $submission = $this->payment_form_submission; |
|
206 | + $submission = $this->payment_form_submission; |
|
207 | 207 | |
208 | - // Prepared submission details. |
|
208 | + // Prepared submission details. |
|
209 | 209 | $prepared = array(); |
210 | 210 | |
211 | 211 | // Raw submission details. |
212 | - $data = $submission->get_data(); |
|
212 | + $data = $submission->get_data(); |
|
213 | 213 | |
214 | - // Loop throught the submitted details. |
|
214 | + // Loop throught the submitted details. |
|
215 | 215 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
216 | 216 | |
217 | - // Skip premade fields. |
|
217 | + // Skip premade fields. |
|
218 | 218 | if ( ! empty( $field['premade'] ) ) { |
219 | 219 | continue; |
220 | 220 | } |
@@ -257,26 +257,26 @@ discard block |
||
257 | 257 | $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
258 | 258 | } |
259 | 259 | |
260 | - } |
|
260 | + } |
|
261 | 261 | |
262 | - return $prepared; |
|
262 | + return $prepared; |
|
263 | 263 | |
264 | - } |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Confirms the submission is valid and send users to the gateway. |
|
268 | - * |
|
269 | - * @param WPInv_Invoice $invoice |
|
270 | - * @param array $prepared_payment_form_data |
|
271 | - */ |
|
272 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
266 | + /** |
|
267 | + * Confirms the submission is valid and send users to the gateway. |
|
268 | + * |
|
269 | + * @param WPInv_Invoice $invoice |
|
270 | + * @param array $prepared_payment_form_data |
|
271 | + */ |
|
272 | + protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
273 | 273 | |
274 | - // Ensure the invoice exists. |
|
274 | + // Ensure the invoice exists. |
|
275 | 275 | if ( $invoice->get_id() == 0 ) { |
276 | 276 | wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
277 | 277 | } |
278 | 278 | |
279 | - // Was this invoice created via the payment form? |
|
279 | + // Was this invoice created via the payment form? |
|
280 | 280 | if ( ! $this->payment_form_submission->has_invoice() ) { |
281 | 281 | update_post_meta( $invoice->get_id(), 'wpinv_created_via', 'payment_form' ); |
282 | 282 | } |
@@ -284,66 +284,66 @@ discard block |
||
284 | 284 | // Save payment form data. |
285 | 285 | if ( ! empty( $prepared_payment_form_data ) ) { |
286 | 286 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
287 | - } |
|
287 | + } |
|
288 | 288 | |
289 | - // Backwards compatibility. |
|
289 | + // Backwards compatibility. |
|
290 | 290 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
291 | - add_action( 'wpinv_pre_send_back_to_checkout', array( $this, 'checkout_error' ) ); |
|
291 | + add_action( 'wpinv_pre_send_back_to_checkout', array( $this, 'checkout_error' ) ); |
|
292 | 292 | |
293 | - $this->process_payment( $invoice ); |
|
293 | + $this->process_payment( $invoice ); |
|
294 | 294 | |
295 | 295 | // If we are here, there was an error. |
296 | - $this->checkout_error(); |
|
296 | + $this->checkout_error(); |
|
297 | 297 | |
298 | - } |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Processes the actual payment. |
|
302 | - * |
|
303 | - * @param WPInv_Invoice $invoice |
|
304 | - */ |
|
305 | - protected function process_payment( $invoice ) { |
|
300 | + /** |
|
301 | + * Processes the actual payment. |
|
302 | + * |
|
303 | + * @param WPInv_Invoice $invoice |
|
304 | + */ |
|
305 | + protected function process_payment( $invoice ) { |
|
306 | 306 | |
307 | - $submission = $this->payment_form_submission; |
|
307 | + $submission = $this->payment_form_submission; |
|
308 | 308 | |
309 | - // No need to send free invoices to the gateway. |
|
310 | - if ( $invoice->is_free() ) { |
|
311 | - $invoice->set_gateway( 'none' ); |
|
312 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
313 | - $invoice->mark_paid(); |
|
314 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
315 | - } |
|
309 | + // No need to send free invoices to the gateway. |
|
310 | + if ( $invoice->is_free() ) { |
|
311 | + $invoice->set_gateway( 'none' ); |
|
312 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
313 | + $invoice->mark_paid(); |
|
314 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
315 | + } |
|
316 | 316 | |
317 | - // Clear any checkout errors. |
|
318 | - wpinv_clear_errors(); |
|
317 | + // Clear any checkout errors. |
|
318 | + wpinv_clear_errors(); |
|
319 | 319 | |
320 | - // Fires before sending to the gateway. |
|
321 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
320 | + // Fires before sending to the gateway. |
|
321 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
322 | 322 | |
323 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
324 | - $submission_data = $submission->get_data(); |
|
325 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
326 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
323 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
324 | + $submission_data = $submission->get_data(); |
|
325 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
326 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
327 | 327 | |
328 | - // Validate the currency. |
|
329 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
330 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
331 | - } |
|
328 | + // Validate the currency. |
|
329 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
330 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
331 | + } |
|
332 | 332 | |
333 | - // Check to see if we have any errors. |
|
334 | - if ( wpinv_get_errors() ) { |
|
335 | - wpinv_send_back_to_checkout(); |
|
336 | - } |
|
333 | + // Check to see if we have any errors. |
|
334 | + if ( wpinv_get_errors() ) { |
|
335 | + wpinv_send_back_to_checkout(); |
|
336 | + } |
|
337 | 337 | |
338 | - // Send info to the gateway for payment processing |
|
339 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
338 | + // Send info to the gateway for payment processing |
|
339 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
340 | 340 | |
341 | - // Backwards compatibility. |
|
342 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
341 | + // Backwards compatibility. |
|
342 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
343 | 343 | |
344 | - } |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
346 | + /** |
|
347 | 347 | * Sends a redrect response to payment details. |
348 | 348 | * |
349 | 349 | */ |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | // Do we have any errors? |
362 | 362 | if ( wpinv_get_errors() ) { |
363 | 363 | wp_send_json_error( getpaid_get_errors_html() ); |
364 | - } |
|
364 | + } |
|
365 | 365 | |
366 | 366 | wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) ); |
367 | 367 | |
368 | - } |
|
368 | + } |
|
369 | 369 | |
370 | 370 | } |