Passed
Push — master ( 9d2707...de43a2 )
by Brian
04:26
created
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -13,449 +13,449 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-		$this->enabled = wpinv_is_gateway_active( $this->id );
141
-
142
-		// Register gateway.
143
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
-
145
-		// Enable Subscriptions.
146
-		if ( $this->supports( 'subscription' ) ) {
147
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
-		}
149
-
150
-		// Enable sandbox.
151
-		if ( $this->supports( 'sandbox' ) ) {
152
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
-		}
154
-
155
-		// Gateway settings.
156
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+        $this->enabled = wpinv_is_gateway_active( $this->id );
141
+
142
+        // Register gateway.
143
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
+
145
+        // Enable Subscriptions.
146
+        if ( $this->supports( 'subscription' ) ) {
147
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
+        }
149
+
150
+        // Enable sandbox.
151
+        if ( $this->supports( 'sandbox' ) ) {
152
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
+        }
154
+
155
+        // Gateway settings.
156
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
157 157
 		
158 158
 
159
-		// Gateway checkout fiellds.
160
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
-
162
-		// Process payment.
163
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
159
+        // Gateway checkout fiellds.
160
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
+
162
+        // Process payment.
163
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
164
+
165
+        // Change the checkout button text.
166
+        if ( ! empty( $this->checkout_button_text ) ) {
167
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
+        }
169
+
170
+        // Check if a gateway is valid for a given currency.
171
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
+
173
+        // Generate the transaction url.
174
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
+
176
+        // Generate the subscription url.
177
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
+
179
+        // Confirm payments.
180
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
+
182
+        // Verify IPNs.
183
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
+
185
+    }
186
+
187
+    /**
188
+     * Checks if this gateway is a given gateway.
189
+     *
190
+     * @since 1.0.19
191
+     * @return bool
192
+     */
193
+    public function is( $gateway ) {
194
+        return $gateway == $this->id;
195
+    }
196
+
197
+    /**
198
+     * Returns a users saved tokens for this gateway.
199
+     *
200
+     * @since 1.0.19
201
+     * @return array
202
+     */
203
+    public function get_tokens( $sandbox = null ) {
204
+
205
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
206
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
207
+
208
+            if ( is_array( $tokens ) ) {
209
+                $this->tokens = $tokens;
210
+            }
211
+
212
+        }
213
+
214
+        if ( ! is_bool( $sandbox ) ) {
215
+            return $this->tokens;
216
+        }
217
+
218
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
219
+        return wp_list_filter( $this->tokens, $args );
220
+
221
+    }
222
+
223
+    /**
224
+     * Saves a token for this gateway.
225
+     *
226
+     * @since 1.0.19
227
+     */
228
+    public function save_token( $token ) {
229
+
230
+        $tokens   = $this->get_tokens();
231
+        $tokens[] = $token;
232
+
233
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
234
+
235
+        $this->tokens = $tokens;
236
+
237
+    }
238
+
239
+    /**
240
+     * Return the title for admin screens.
241
+     *
242
+     * @return string
243
+     */
244
+    public function get_method_title() {
245
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
246
+    }
247
+
248
+    /**
249
+     * Return the description for admin screens.
250
+     *
251
+     * @return string
252
+     */
253
+    public function get_method_description() {
254
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
255
+    }
256
+
257
+    /**
258
+     * Get the success url.
259
+     *
260
+     * @param WPInv_Invoice $invoice Invoice object.
261
+     * @return string
262
+     */
263
+    public function get_return_url( $invoice ) {
264
+
265
+        // Payment success url
266
+        $return_url = add_query_arg(
267
+            array(
268
+                'payment-confirm' => $this->id,
269
+                'invoice_key'     => $invoice->get_key(),
270
+                'utm_nooverride'  => 1
271
+            ),
272
+            wpinv_get_success_page_uri()
273
+        );
274
+
275
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
276
+    }
277
+
278
+    /**
279
+     * Confirms payments when rendering the success page.
280
+     *
281
+     * @param string $content Success page content.
282
+     * @return string
283
+     */
284
+    public function confirm_payment( $content ) {
285
+
286
+        // Retrieve the invoice.
287
+        $invoice_id = getpaid_get_current_invoice_id();
288
+        $invoice    = wpinv_get_invoice( $invoice_id );
289
+
290
+        // Ensure that it exists and that it is pending payment.
291
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
292
+            return $content;
293
+        }
294
+
295
+        // Can the user view this invoice??
296
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
297
+            return $content;
298
+        }
299
+
300
+        // Show payment processing indicator.
301
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
302
+    }
303
+
304
+    /**
305
+     * Processes ipns and marks payments as complete.
306
+     *
307
+     * @return void
308
+     */
309
+    public function verify_ipn() {}
310
+
311
+    /**
312
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
313
+     *
314
+     * @param string $transaction_url transaction url.
315
+     * @param WPInv_Invoice $invoice Invoice object.
316
+     * @return string transaction URL, or empty string.
317
+     */
318
+    public function filter_transaction_url( $transaction_url, $invoice ) {
319
+
320
+        $transaction_id  = $invoice->get_transaction_id();
321
+
322
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
323
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
324
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
325
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
326
+        }
327
+
328
+        return $transaction_url;
329
+    }
330
+
331
+    /**
332
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
333
+     *
334
+     * @param string $subscription_url transaction url.
335
+     * @param WPInv_Invoice $invoice Invoice object.
336
+     * @return string subscription URL, or empty string.
337
+     */
338
+    public function filter_subscription_url( $subscription_url, $invoice ) {
339
+
340
+        $profile_id      = $invoice->get_subscription_id();
341
+
342
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
343
+
344
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
345
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
346
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
347
+
348
+        }
349
+
350
+        return $subscription_url;
351
+    }
352
+
353
+    /**
354
+     * Check if the gateway is available for use.
355
+     *
356
+     * @return bool
357
+     */
358
+    public function is_available() {
359
+        return ! empty( $this->enabled );
360
+    }
361
+
362
+    /**
363
+     * Return the gateway's title.
364
+     *
365
+     * @return string
366
+     */
367
+    public function get_title() {
368
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
369
+    }
370
+
371
+    /**
372
+     * Return the gateway's description.
373
+     *
374
+     * @return string
375
+     */
376
+    public function get_description() {
377
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
378
+    }
379
+
380
+    /**
381
+     * Process Payment.
382
+     *
383
+     *
384
+     * @param WPInv_Invoice $invoice Invoice.
385
+     * @param array $submission_data Posted checkout fields.
386
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
387
+     * @return void
388
+     */
389
+    public function process_payment( $invoice, $submission_data, $submission ) {
390
+        // Process the payment then either redirect to the success page or the gateway.
391
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
392
+    }
393
+
394
+    /**
395
+     * Process refund.
396
+     *
397
+     * If the gateway declares 'refunds' support, this will allow it to refund.
398
+     * a passed in amount.
399
+     *
400
+     * @param WPInv_Invoice $invoice Invoice.
401
+     * @param  float  $amount Refund amount.
402
+     * @param  string $reason Refund reason.
403
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
404
+     */
405
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
406
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
407
+    }
408
+
409
+    /**
410
+     * Displays the payment fields, credit cards etc.
411
+     * 
412
+     * @param int $invoice_id 0 or invoice id.
413
+     * @param GetPaid_Payment_Form $form Current payment form.
414
+     */
415
+    public function payment_fields( $invoice_id, $form ) {
416
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
417
+    }
418
+
419
+    /**
420
+     * Filters the gateway settings.
421
+     * 
422
+     * @param array $admin_settings
423
+     */
424
+    public function admin_settings( $admin_settings ) {
425
+        return $admin_settings;
426
+    }
427
+
428
+    /**
429
+     * Retrieves the value of a gateway setting.
430
+     * 
431
+     * @param string $option
432
+     */
433
+    public function get_option( $option, $default = false ) {
434
+        return wpinv_get_option( $this->id . '_' . $option, $default );
435
+    }
436
+
437
+    /**
438
+     * Check if a gateway supports a given feature.
439
+     *
440
+     * Gateways should override this to declare support (or lack of support) for a feature.
441
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
442
+     *
443
+     * @param string $feature string The name of a feature to test support for.
444
+     * @return bool True if the gateway supports the feature, false otherwise.
445
+     * @since 1.0.19
446
+     */
447
+    public function supports( $feature ) {
448
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
449
+    }
164 450
 
165
-		// Change the checkout button text.
166
-		if ( ! empty( $this->checkout_button_text ) ) {
167
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
-		}
169
-
170
-		// Check if a gateway is valid for a given currency.
171
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
-
173
-		// Generate the transaction url.
174
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
-
176
-		// Generate the subscription url.
177
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
-
179
-		// Confirm payments.
180
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
-
182
-		// Verify IPNs.
183
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
-
185
-	}
186
-
187
-	/**
188
-	 * Checks if this gateway is a given gateway.
189
-	 *
190
-	 * @since 1.0.19
191
-	 * @return bool
192
-	 */
193
-	public function is( $gateway ) {
194
-		return $gateway == $this->id;
195
-	}
196
-
197
-	/**
198
-	 * Returns a users saved tokens for this gateway.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @return array
202
-	 */
203
-	public function get_tokens( $sandbox = null ) {
204
-
205
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
206
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
207
-
208
-			if ( is_array( $tokens ) ) {
209
-				$this->tokens = $tokens;
210
-			}
211
-
212
-		}
213
-
214
-		if ( ! is_bool( $sandbox ) ) {
215
-			return $this->tokens;
216
-		}
217
-
218
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
219
-		return wp_list_filter( $this->tokens, $args );
220
-
221
-	}
222
-
223
-	/**
224
-	 * Saves a token for this gateway.
225
-	 *
226
-	 * @since 1.0.19
227
-	 */
228
-	public function save_token( $token ) {
229
-
230
-		$tokens   = $this->get_tokens();
231
-		$tokens[] = $token;
232
-
233
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
234
-
235
-		$this->tokens = $tokens;
236
-
237
-	}
238
-
239
-	/**
240
-	 * Return the title for admin screens.
241
-	 *
242
-	 * @return string
243
-	 */
244
-	public function get_method_title() {
245
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
246
-	}
247
-
248
-	/**
249
-	 * Return the description for admin screens.
250
-	 *
251
-	 * @return string
252
-	 */
253
-	public function get_method_description() {
254
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
255
-	}
256
-
257
-	/**
258
-	 * Get the success url.
259
-	 *
260
-	 * @param WPInv_Invoice $invoice Invoice object.
261
-	 * @return string
262
-	 */
263
-	public function get_return_url( $invoice ) {
264
-
265
-		// Payment success url
266
-		$return_url = add_query_arg(
267
-			array(
268
-				'payment-confirm' => $this->id,
269
-				'invoice_key'     => $invoice->get_key(),
270
-				'utm_nooverride'  => 1
271
-			),
272
-			wpinv_get_success_page_uri()
273
-		);
274
-
275
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
276
-	}
277
-
278
-	/**
279
-	 * Confirms payments when rendering the success page.
280
-	 *
281
-	 * @param string $content Success page content.
282
-	 * @return string
283
-	 */
284
-	public function confirm_payment( $content ) {
285
-
286
-		// Retrieve the invoice.
287
-		$invoice_id = getpaid_get_current_invoice_id();
288
-		$invoice    = wpinv_get_invoice( $invoice_id );
289
-
290
-		// Ensure that it exists and that it is pending payment.
291
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
292
-			return $content;
293
-		}
294
-
295
-		// Can the user view this invoice??
296
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
297
-			return $content;
298
-		}
299
-
300
-		// Show payment processing indicator.
301
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
302
-	}
303
-
304
-	/**
305
-	 * Processes ipns and marks payments as complete.
306
-	 *
307
-	 * @return void
308
-	 */
309
-	public function verify_ipn() {}
310
-
311
-	/**
312
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
313
-	 *
314
-	 * @param string $transaction_url transaction url.
315
-	 * @param WPInv_Invoice $invoice Invoice object.
316
-	 * @return string transaction URL, or empty string.
317
-	 */
318
-	public function filter_transaction_url( $transaction_url, $invoice ) {
319
-
320
-		$transaction_id  = $invoice->get_transaction_id();
321
-
322
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
323
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
324
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
325
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
326
-		}
327
-
328
-		return $transaction_url;
329
-	}
330
-
331
-	/**
332
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
333
-	 *
334
-	 * @param string $subscription_url transaction url.
335
-	 * @param WPInv_Invoice $invoice Invoice object.
336
-	 * @return string subscription URL, or empty string.
337
-	 */
338
-	public function filter_subscription_url( $subscription_url, $invoice ) {
339
-
340
-		$profile_id      = $invoice->get_subscription_id();
341
-
342
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
343
-
344
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
345
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
346
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
347
-
348
-		}
349
-
350
-		return $subscription_url;
351
-	}
352
-
353
-	/**
354
-	 * Check if the gateway is available for use.
355
-	 *
356
-	 * @return bool
357
-	 */
358
-	public function is_available() {
359
-		return ! empty( $this->enabled );
360
-	}
361
-
362
-	/**
363
-	 * Return the gateway's title.
364
-	 *
365
-	 * @return string
366
-	 */
367
-	public function get_title() {
368
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
369
-	}
370
-
371
-	/**
372
-	 * Return the gateway's description.
373
-	 *
374
-	 * @return string
375
-	 */
376
-	public function get_description() {
377
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
378
-	}
379
-
380
-	/**
381
-	 * Process Payment.
382
-	 *
383
-	 *
384
-	 * @param WPInv_Invoice $invoice Invoice.
385
-	 * @param array $submission_data Posted checkout fields.
386
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
387
-	 * @return void
388
-	 */
389
-	public function process_payment( $invoice, $submission_data, $submission ) {
390
-		// Process the payment then either redirect to the success page or the gateway.
391
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
392
-	}
393
-
394
-	/**
395
-	 * Process refund.
396
-	 *
397
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
398
-	 * a passed in amount.
399
-	 *
400
-	 * @param WPInv_Invoice $invoice Invoice.
401
-	 * @param  float  $amount Refund amount.
402
-	 * @param  string $reason Refund reason.
403
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
404
-	 */
405
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
406
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
407
-	}
408
-
409
-	/**
410
-	 * Displays the payment fields, credit cards etc.
411
-	 * 
412
-	 * @param int $invoice_id 0 or invoice id.
413
-	 * @param GetPaid_Payment_Form $form Current payment form.
414
-	 */
415
-	public function payment_fields( $invoice_id, $form ) {
416
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
417
-	}
418
-
419
-	/**
420
-	 * Filters the gateway settings.
421
-	 * 
422
-	 * @param array $admin_settings
423
-	 */
424
-	public function admin_settings( $admin_settings ) {
425
-		return $admin_settings;
426
-	}
427
-
428
-	/**
429
-	 * Retrieves the value of a gateway setting.
430
-	 * 
431
-	 * @param string $option
432
-	 */
433
-	public function get_option( $option, $default = false ) {
434
-		return wpinv_get_option( $this->id . '_' . $option, $default );
435
-	}
436
-
437
-	/**
438
-	 * Check if a gateway supports a given feature.
439
-	 *
440
-	 * Gateways should override this to declare support (or lack of support) for a feature.
441
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
442
-	 *
443
-	 * @param string $feature string The name of a feature to test support for.
444
-	 * @return bool True if the gateway supports the feature, false otherwise.
445
-	 * @since 1.0.19
446
-	 */
447
-	public function supports( $feature ) {
448
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
449
-	}
450
-
451
-	/**
452
-	 * Returns the credit card form html.
453
-	 * 
454
-	 * @param bool $save whether or not to display the save button.
455
-	 */
451
+    /**
452
+     * Returns the credit card form html.
453
+     * 
454
+     * @param bool $save whether or not to display the save button.
455
+     */
456 456
     public function get_cc_form( $save = false ) {
457 457
 
458
-		ob_start();
458
+        ob_start();
459 459
 
460 460
         $id_prefix = esc_attr( uniqid( $this->id ) );
461 461
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
                                         'name'              => $this->id . '[cc_cvv2]',
551 551
                                         'id'                => "$id_prefix-cc-cvv2",
552 552
                                         'label'             => __( 'CCV', 'invoicing' ),
553
-										'label_type'        => 'vertical',
554
-										'class'             => 'form-control-sm',
553
+                                        'label_type'        => 'vertical',
554
+                                        'class'             => 'form-control-sm',
555 555
                                     )
556 556
                                 );
557 557
                             ?>
@@ -561,175 +561,175 @@  discard block
 block discarded – undo
561 561
 					
562 562
 					<?php
563 563
 
564
-						if ( $save ) {
565
-							echo $this->save_payment_method_checkbox();
566
-						}
564
+                        if ( $save ) {
565
+                            echo $this->save_payment_method_checkbox();
566
+                        }
567 567
 
568
-					?>
568
+                    ?>
569 569
                 </div>
570 570
 
571 571
             </div>
572 572
 		<?php
573 573
 		
574
-		return ob_get_clean();
574
+        return ob_get_clean();
575 575
 
576 576
     }
577 577
 
578
-	/**
579
-	 * Displays a new payment method entry form.
580
-	 *
581
-	 * @since 1.0.19
582
-	 */
583
-	public function new_payment_method_entry( $form ) {
584
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
585
-	}
586
-
587
-	/**
588
-	 * Grab and display our saved payment methods.
589
-	 *
590
-	 * @since 1.0.19
591
-	 */
592
-	public function saved_payment_methods() {
593
-		$html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
594
-
595
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
596
-			$html .= $this->get_saved_payment_method_option_html( $token );
597
-		}
598
-
599
-		$html .= $this->get_new_payment_method_option_html();
600
-		$html .= '</ul>';
601
-
602
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
603
-	}
604
-
605
-	/**
606
-	 * Gets saved payment method HTML from a token.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  array $token Payment Token.
610
-	 * @return string Generated payment method HTML
611
-	 */
612
-	public function get_saved_payment_method_option_html( $token ) {
613
-
614
-		return sprintf(
615
-			'<li class="getpaid-payment-method form-group">
578
+    /**
579
+     * Displays a new payment method entry form.
580
+     *
581
+     * @since 1.0.19
582
+     */
583
+    public function new_payment_method_entry( $form ) {
584
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
585
+    }
586
+
587
+    /**
588
+     * Grab and display our saved payment methods.
589
+     *
590
+     * @since 1.0.19
591
+     */
592
+    public function saved_payment_methods() {
593
+        $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
594
+
595
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
596
+            $html .= $this->get_saved_payment_method_option_html( $token );
597
+        }
598
+
599
+        $html .= $this->get_new_payment_method_option_html();
600
+        $html .= '</ul>';
601
+
602
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
603
+    }
604
+
605
+    /**
606
+     * Gets saved payment method HTML from a token.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  array $token Payment Token.
610
+     * @return string Generated payment method HTML
611
+     */
612
+    public function get_saved_payment_method_option_html( $token ) {
613
+
614
+        return sprintf(
615
+            '<li class="getpaid-payment-method form-group">
616 616
 				<label>
617 617
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
618 618
 					<span>%3$s</span>
619 619
 				</label>
620 620
 			</li>',
621
-			esc_attr( $this->id ),
622
-			esc_attr( $token['id'] ),
623
-			esc_html( $token['name'] ),
624
-			checked( empty( $token['default'] ), false, false )
625
-		);
621
+            esc_attr( $this->id ),
622
+            esc_attr( $token['id'] ),
623
+            esc_html( $token['name'] ),
624
+            checked( empty( $token['default'] ), false, false )
625
+        );
626 626
 
627
-	}
627
+    }
628 628
 
629
-	/**
630
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
631
-	 *
632
-	 * @since 1.0.19
633
-	 */
634
-	public function get_new_payment_method_option_html() {
629
+    /**
630
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
631
+     *
632
+     * @since 1.0.19
633
+     */
634
+    public function get_new_payment_method_option_html() {
635 635
 
636
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
636
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
637 637
 
638
-		return sprintf(
639
-			'<li class="getpaid-new-payment-method">
638
+        return sprintf(
639
+            '<li class="getpaid-new-payment-method">
640 640
 				<label>
641 641
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
642 642
 					<span>%2$s</span>
643 643
 				</label>
644 644
 			</li>',
645
-			esc_attr( $this->id ),
646
-			esc_html( $label )
647
-		);
645
+            esc_attr( $this->id ),
646
+            esc_html( $label )
647
+        );
648 648
 
649
-	}
649
+    }
650 650
 
651
-	/**
652
-	 * Outputs a checkbox for saving a new payment method to the database.
653
-	 *
654
-	 * @since 1.0.19
655
-	 */
656
-	public function save_payment_method_checkbox() {
651
+    /**
652
+     * Outputs a checkbox for saving a new payment method to the database.
653
+     *
654
+     * @since 1.0.19
655
+     */
656
+    public function save_payment_method_checkbox() {
657 657
 
658
-		return sprintf(
659
-			'<p class="form-group getpaid-save-payment-method">
658
+        return sprintf(
659
+            '<p class="form-group getpaid-save-payment-method">
660 660
 				<label>
661 661
 					<input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
662 662
 					<span>%2$s</span>
663 663
 				</label>
664 664
 			</p>',
665
-			esc_attr( $this->id ),
666
-			esc_html__( 'Save payment method', 'invoicing' )
667
-		);
665
+            esc_attr( $this->id ),
666
+            esc_html__( 'Save payment method', 'invoicing' )
667
+        );
668 668
 
669
-	}
669
+    }
670 670
 
671
-	/**
672
-	 * Registers the gateway.
673
-	 *
674
-	 * @return array
675
-	 */
676
-	public function register_gateway( $gateways ) {
671
+    /**
672
+     * Registers the gateway.
673
+     *
674
+     * @return array
675
+     */
676
+    public function register_gateway( $gateways ) {
677 677
 
678
-		$gateways[ $this->id ] = array(
678
+        $gateways[ $this->id ] = array(
679 679
 
680
-			'admin_label'    => $this->method_title,
680
+            'admin_label'    => $this->method_title,
681 681
             'checkout_label' => $this->title,
682
-			'ordering'       => $this->order,
683
-
684
-		);
685
-
686
-		return $gateways;
687
-
688
-	}
689
-
690
-	/**
691
-	 * Checks whether or not this is a sandbox request.
692
-	 *
693
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
694
-	 * @return bool
695
-	 */
696
-	public function is_sandbox( $invoice = null ) {
697
-
698
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
699
-			return $invoice->get_mode() == 'test';
700
-		}
701
-
702
-		return wpinv_is_test_mode( $this->id );
703
-
704
-	}
705
-
706
-	/**
707
-	 * Renames the checkout button
708
-	 *
709
-	 * @return string
710
-	 */
711
-	public function rename_checkout_button() {
712
-		return $this->checkout_button_text;
713
-	}
714
-
715
-	/**
716
-	 * Validate gateway currency
717
-	 *
718
-	 * @return bool
719
-	 */
720
-	public function validate_currency( $validation, $currency ) {
721
-
722
-		// Required currencies.
723
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
724
-			return false;
725
-		}
726
-
727
-		// Excluded currencies.
728
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
729
-			return false;
730
-		}
731
-
732
-		return $validation;
733
-	}
682
+            'ordering'       => $this->order,
683
+
684
+        );
685
+
686
+        return $gateways;
687
+
688
+    }
689
+
690
+    /**
691
+     * Checks whether or not this is a sandbox request.
692
+     *
693
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
694
+     * @return bool
695
+     */
696
+    public function is_sandbox( $invoice = null ) {
697
+
698
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
699
+            return $invoice->get_mode() == 'test';
700
+        }
701
+
702
+        return wpinv_is_test_mode( $this->id );
703
+
704
+    }
705
+
706
+    /**
707
+     * Renames the checkout button
708
+     *
709
+     * @return string
710
+     */
711
+    public function rename_checkout_button() {
712
+        return $this->checkout_button_text;
713
+    }
714
+
715
+    /**
716
+     * Validate gateway currency
717
+     *
718
+     * @return bool
719
+     */
720
+    public function validate_currency( $validation, $currency ) {
721
+
722
+        // Required currencies.
723
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
724
+            return false;
725
+        }
726
+
727
+        // Excluded currencies.
728
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
729
+            return false;
730
+        }
731
+
732
+        return $validation;
733
+    }
734 734
 
735 735
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -13,94 +13,94 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
     
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90 90
 
91 91
         parent::__construct();
92 92
     }
93 93
 
94 94
     /**
95
-	 * Process Payment.
96
-	 *
97
-	 *
98
-	 * @param WPInv_Invoice $invoice Invoice.
99
-	 * @param array $submission_data Posted checkout fields.
100
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
-	 * @return array
102
-	 */
103
-	public function process_payment( $invoice, $submission_data, $submission ) {
95
+     * Process Payment.
96
+     *
97
+     *
98
+     * @param WPInv_Invoice $invoice Invoice.
99
+     * @param array $submission_data Posted checkout fields.
100
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
+     * @return array
102
+     */
103
+    public function process_payment( $invoice, $submission_data, $submission ) {
104 104
 
105 105
         // Get redirect url.
106 106
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
     }
124 124
 
125 125
     /**
126
-	 * Get the PayPal request URL for an invoice.
127
-	 *
128
-	 * @param  WPInv_Invoice $invoice Invoice object.
129
-	 * @return string
130
-	 */
131
-	public function get_request_url( $invoice ) {
126
+     * Get the PayPal request URL for an invoice.
127
+     *
128
+     * @param  WPInv_Invoice $invoice Invoice object.
129
+     * @return string
130
+     */
131
+    public function get_request_url( $invoice ) {
132 132
 
133 133
         // Endpoint for this request
134
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
134
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
135 135
 
136 136
         // Retrieve paypal args.
137 137
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -144,44 +144,44 @@  discard block
 block discarded – undo
144 144
 
145 145
         return add_query_arg( $paypal_args, $this->endpoint );
146 146
 
147
-	}
147
+    }
148 148
 
149 149
     /**
150
-	 * Get PayPal Args for passing to PP.
151
-	 *
152
-	 * @param  WPInv_Invoice $invoice Invoice object.
153
-	 * @return array
154
-	 */
155
-	protected function get_paypal_args( $invoice ) {
150
+     * Get PayPal Args for passing to PP.
151
+     *
152
+     * @param  WPInv_Invoice $invoice Invoice object.
153
+     * @return array
154
+     */
155
+    protected function get_paypal_args( $invoice ) {
156 156
 
157 157
         // Whether or not to send the line items as one item.
158
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
159
-
160
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
-			$force_one_line_item = true;
162
-		}
163
-
164
-		$paypal_args = apply_filters(
165
-			'getpaid_paypal_args',
166
-			array_merge(
167
-				$this->get_transaction_args( $invoice ),
168
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
-			),
170
-			$invoice
171
-		);
172
-
173
-		return $this->fix_request_length( $invoice, $paypal_args );
158
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
159
+
160
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
+            $force_one_line_item = true;
162
+        }
163
+
164
+        $paypal_args = apply_filters(
165
+            'getpaid_paypal_args',
166
+            array_merge(
167
+                $this->get_transaction_args( $invoice ),
168
+                $this->get_line_item_args( $invoice, $force_one_line_item )
169
+            ),
170
+            $invoice
171
+        );
172
+
173
+        return $this->fix_request_length( $invoice, $paypal_args );
174 174
     }
175 175
 
176 176
     /**
177
-	 * Get transaction args for paypal request.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 * @return array
181
-	 */
182
-	protected function get_transaction_args( $invoice ) {
183
-
184
-		return array(
177
+     * Get transaction args for paypal request.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     * @return array
181
+     */
182
+    protected function get_transaction_args( $invoice ) {
183
+
184
+        return array(
185 185
             'cmd'           => '_cart',
186 186
             'business'      => wpinv_get_option( 'paypal_email', false ),
187 187
             'no_shipping'   => '1',
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
     }
207 207
 
208 208
     /**
209
-	 * Get line item args for paypal request.
210
-	 *
211
-	 * @param  WPInv_Invoice $invoice Invoice object.
212
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
213
-	 * @return array
214
-	 */
215
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
209
+     * Get line item args for paypal request.
210
+     *
211
+     * @param  WPInv_Invoice $invoice Invoice object.
212
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
213
+     * @return array
214
+     */
215
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
216 216
 
217 217
         // Maybe send invoice as a single item.
218
-		if ( $force_one_line_item ) {
218
+        if ( $force_one_line_item ) {
219 219
             return $this->get_line_item_args_single_item( $invoice );
220 220
         }
221 221
 
@@ -235,129 +235,129 @@  discard block
 block discarded – undo
235 235
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
236 236
         }
237 237
 
238
-		return array_merge( $line_item_args, $this->get_line_items() );
238
+        return array_merge( $line_item_args, $this->get_line_items() );
239 239
 
240 240
     }
241 241
 
242 242
     /**
243
-	 * Get line item args for paypal request as a single line item.
244
-	 *
245
-	 * @param  WPInv_Invoice $invoice Invoice object.
246
-	 * @return array
247
-	 */
248
-	protected function get_line_item_args_single_item( $invoice ) {
249
-		$this->delete_line_items();
243
+     * Get line item args for paypal request as a single line item.
244
+     *
245
+     * @param  WPInv_Invoice $invoice Invoice object.
246
+     * @return array
247
+     */
248
+    protected function get_line_item_args_single_item( $invoice ) {
249
+        $this->delete_line_items();
250 250
 
251 251
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
252
-		$this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
252
+        $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
253 253
 
254
-		return $this->get_line_items();
254
+        return $this->get_line_items();
255 255
     }
256 256
 
257 257
     /**
258
-	 * Return all line items.
259
-	 */
260
-	protected function get_line_items() {
261
-		return $this->line_items;
262
-	}
258
+     * Return all line items.
259
+     */
260
+    protected function get_line_items() {
261
+        return $this->line_items;
262
+    }
263 263
 
264 264
     /**
265
-	 * Remove all line items.
266
-	 */
267
-	protected function delete_line_items() {
268
-		$this->line_items = array();
265
+     * Remove all line items.
266
+     */
267
+    protected function delete_line_items() {
268
+        $this->line_items = array();
269 269
     }
270 270
 
271 271
     /**
272
-	 * Prepare line items to send to paypal.
273
-	 *
274
-	 * @param  WPInv_Invoice $invoice Invoice object.
275
-	 */
276
-	protected function prepare_line_items( $invoice ) {
277
-		$this->delete_line_items();
278
-
279
-		// Items.
280
-		foreach ( $invoice->get_items() as $item ) {
281
-			$amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
272
+     * Prepare line items to send to paypal.
273
+     *
274
+     * @param  WPInv_Invoice $invoice Invoice object.
275
+     */
276
+    protected function prepare_line_items( $invoice ) {
277
+        $this->delete_line_items();
278
+
279
+        // Items.
280
+        foreach ( $invoice->get_items() as $item ) {
281
+            $amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
284 284
         }
285 285
 
286 286
         // Fees.
287
-		foreach ( $invoice->get_fees() as $fee => $data ) {
287
+        foreach ( $invoice->get_fees() as $fee => $data ) {
288 288
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
289 289
         }
290 290
 
291 291
     }
292 292
 
293 293
     /**
294
-	 * Add PayPal Line Item.
295
-	 *
296
-	 * @param  string $item_name Item name.
297
-	 * @param  int    $quantity Item quantity.
298
-	 * @param  float  $amount Amount.
299
-	 * @param  string $item_number Item number.
300
-	 */
301
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
-		$index = ( count( $this->line_items ) / 4 ) + 1;
303
-
304
-		$item = apply_filters(
305
-			'getpaid_paypal_line_item',
306
-			array(
307
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
308
-				'quantity'    => (int) $quantity,
309
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
-				'item_number' => $item_number,
311
-			),
312
-			$item_name,
313
-			$quantity,
314
-			$amount,
315
-			$item_number
316
-		);
317
-
318
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
294
+     * Add PayPal Line Item.
295
+     *
296
+     * @param  string $item_name Item name.
297
+     * @param  int    $quantity Item quantity.
298
+     * @param  float  $amount Amount.
299
+     * @param  string $item_number Item number.
300
+     */
301
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
+        $index = ( count( $this->line_items ) / 4 ) + 1;
303
+
304
+        $item = apply_filters(
305
+            'getpaid_paypal_line_item',
306
+            array(
307
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
308
+                'quantity'    => (int) $quantity,
309
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
+                'item_number' => $item_number,
311
+            ),
312
+            $item_name,
313
+            $quantity,
314
+            $amount,
315
+            $item_number
316
+        );
317
+
318
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
319 319
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
320 320
         
321 321
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
322
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
324 324
     }
325 325
 
326 326
     /**
327
-	 * If the default request with line items is too long, generate a new one with only one line item.
328
-	 *
329
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
-	 *
331
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
333
-	 * @return array
334
-	 */
335
-	protected function fix_request_length( $invoice, $paypal_args ) {
336
-		$max_paypal_length = 2083;
337
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
338
-
339
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
-			return $paypal_args;
341
-		}
342
-
343
-		return apply_filters(
344
-			'getpaid_paypal_args',
345
-			array_merge(
346
-				$this->get_transaction_args( $invoice ),
347
-				$this->get_line_item_args( $invoice, true )
348
-			),
349
-			$invoice
350
-		);
327
+     * If the default request with line items is too long, generate a new one with only one line item.
328
+     *
329
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
+     *
331
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
333
+     * @return array
334
+     */
335
+    protected function fix_request_length( $invoice, $paypal_args ) {
336
+        $max_paypal_length = 2083;
337
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
338
+
339
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
+            return $paypal_args;
341
+        }
342
+
343
+        return apply_filters(
344
+            'getpaid_paypal_args',
345
+            array_merge(
346
+                $this->get_transaction_args( $invoice ),
347
+                $this->get_line_item_args( $invoice, true )
348
+            ),
349
+            $invoice
350
+        );
351 351
 
352 352
     }
353 353
     
354 354
     /**
355
-	 * Processes recurring invoices.
356
-	 *
357
-	 * @param  array $paypal_args PayPal args.
358
-	 * @param  WPInv_Invoice    $invoice Invoice object.
359
-	 */
360
-	public function process_subscription( $paypal_args, $invoice ) {
355
+     * Processes recurring invoices.
356
+     *
357
+     * @param  array $paypal_args PayPal args.
358
+     * @param  WPInv_Invoice    $invoice Invoice object.
359
+     */
360
+    public function process_subscription( $paypal_args, $invoice ) {
361 361
 
362 362
         // Make sure this is a subscription.
363 363
         if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) {
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 
383 383
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
384 384
 
385
-			// Trial period length.
386
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
385
+            // Trial period length.
386
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
387 387
 
388
-			// Trial period.
389
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
388
+            // Trial period.
389
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
390 390
 
391 391
         } else if ( $initial_amount != $recurring_amount ) {
392 392
 
@@ -409,40 +409,40 @@  discard block
 block discarded – undo
409 409
         }
410 410
 
411 411
         // We have a recurring payment
412
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
412
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
413 413
 
414
-			// Subscription price
415
-			$paypal_args['a3'] = $recurring_amount;
414
+            // Subscription price
415
+            $paypal_args['a3'] = $recurring_amount;
416 416
 
417
-			// Subscription duration
418
-			$paypal_args['p3'] = $interval;
417
+            // Subscription duration
418
+            $paypal_args['p3'] = $interval;
419 419
 
420
-			// Subscription period
421
-			$paypal_args['t3'] = $period;
420
+            // Subscription period
421
+            $paypal_args['t3'] = $period;
422 422
 
423 423
         }
424 424
         
425 425
         // Recurring payments
426
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
426
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
427 427
 
428
-			// Non-recurring payments
429
-			$paypal_args['src'] = 0;
428
+            // Non-recurring payments
429
+            $paypal_args['src'] = 0;
430 430
 
431
-		} else {
431
+        } else {
432 432
 
433
-			$paypal_args['src'] = 1;
433
+            $paypal_args['src'] = 1;
434 434
 
435
-			if ( $bill_times > 0 ) {
435
+            if ( $bill_times > 0 ) {
436 436
 
437
-				// An initial period is being used to charge a sign-up fee
438
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
-					$bill_times--;
440
-				}
437
+                // An initial period is being used to charge a sign-up fee
438
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
+                    $bill_times--;
440
+                }
441 441
 
442 442
                 // Make sure it's not over the max of 52
443 443
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
444 444
 
445
-			}
445
+            }
446 446
         }
447 447
         
448 448
         // Force return URL so that order description & instructions display
@@ -458,19 +458,19 @@  discard block
 block discarded – undo
458 458
         }
459 459
 
460 460
         return apply_filters(
461
-			'getpaid_paypal_subscription_args',
462
-			$paypal_args,
463
-			$invoice
461
+            'getpaid_paypal_subscription_args',
462
+            $paypal_args,
463
+            $invoice
464 464
         );
465 465
 
466 466
     }
467 467
 
468 468
     /**
469
-	 * Processes ipns and marks payments as complete.
470
-	 *
471
-	 * @return void
472
-	 */
473
-	public function verify_ipn() {
469
+     * Processes ipns and marks payments as complete.
470
+     *
471
+     * @return void
472
+     */
473
+    public function verify_ipn() {
474 474
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
475 475
     }
476 476
 
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
     public function sandbox_notice() {
481 481
 
482 482
         return sprintf(
483
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
484
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
485
-			'</a>'
486
-		);
483
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
484
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
485
+            '</a>'
486
+        );
487 487
 
488 488
     }
489 489
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -12,216 +12,216 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-
42
-	}
43
-
44
-	/**
45
-	 * Adds totals to a response for submission refresh prices.
46
-	 *
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function add_totals( $submission ) {
50
-
51
-		$this->response = array_merge(
52
-			$this->response,
53
-			array(
54
-
55
-				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
61
-				),
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+
42
+    }
43
+
44
+    /**
45
+     * Adds totals to a response for submission refresh prices.
46
+     *
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function add_totals( $submission ) {
50
+
51
+        $this->response = array_merge(
52
+            $this->response,
53
+            array(
54
+
55
+                'totals'        => array(
56
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
58
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
59
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
60
+                    'total'     => $submission->format_amount( $submission->get_total() ),
61
+                ),
62 62
 	
63
-				'recurring'     => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
69
-				),
63
+                'recurring'     => array(
64
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
65
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
66
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
67
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
68
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
69
+                ),
70 70
 
71
-			)
72
-		);
71
+            )
72
+        );
73 73
 
74
-	}
74
+    }
75 75
 
76
-	/**
77
-	 * Adds texts to a response for submission refresh prices.
78
-	 *
79
-	 * @param GetPaid_Payment_Form_Submission $submission
80
-	 */
81
-	public function add_texts( $submission ) {
76
+    /**
77
+     * Adds texts to a response for submission refresh prices.
78
+     *
79
+     * @param GetPaid_Payment_Form_Submission $submission
80
+     */
81
+    public function add_texts( $submission ) {
82 82
 
83
-		$payable = $submission->format_amount( $submission->get_total() );
83
+        $payable = $submission->format_amount( $submission->get_total() );
84 84
 
85
-		if ( $submission->has_recurring != 0 ) {
85
+        if ( $submission->has_recurring != 0 ) {
86 86
 
87
-			$recurring = new WPInv_Item( $submission->has_recurring );
88
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
87
+            $recurring = new WPInv_Item( $submission->has_recurring );
88
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
89 89
 
90
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
91
-				$payable = "$payable / $period";
92
-			} else {
93
-				$payable = sprintf(
94
-					__( '%1$s (renews at %2$s / %3$s)'),
95
-					$submission->format_amount( $submission->get_total() ),
96
-					$submission->format_amount( $submission->get_recurring_total() ),
97
-					$period
98
-				);
99
-			}
90
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
91
+                $payable = "$payable / $period";
92
+            } else {
93
+                $payable = sprintf(
94
+                    __( '%1$s (renews at %2$s / %3$s)'),
95
+                    $submission->format_amount( $submission->get_total() ),
96
+                    $submission->format_amount( $submission->get_recurring_total() ),
97
+                    $period
98
+                );
99
+            }
100 100
 
101
-		}
101
+        }
102 102
 
103
-		$texts = array(
104
-			'.getpaid-checkout-total-payable' => $payable,
105
-		);
103
+        $texts = array(
104
+            '.getpaid-checkout-total-payable' => $payable,
105
+        );
106 106
 
107
-		foreach ( $submission->get_items() as $item_id => $item ) {
108
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
109
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
110
-		}
107
+        foreach ( $submission->get_items() as $item_id => $item ) {
108
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
109
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
110
+        }
111 111
 
112
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
113 113
 
114
-	}
114
+    }
115 115
 
116
-	/**
117
-	 * Adds items to a response for submission refresh prices.
118
-	 *
119
-	 * @param GetPaid_Payment_Form_Submission $submission
120
-	 */
121
-	public function add_items( $submission ) {
116
+    /**
117
+     * Adds items to a response for submission refresh prices.
118
+     *
119
+     * @param GetPaid_Payment_Form_Submission $submission
120
+     */
121
+    public function add_items( $submission ) {
122 122
 
123
-		// Add items.
124
-		$items = array();
123
+        // Add items.
124
+        $items = array();
125 125
 
126 126
         foreach ( $submission->get_items() as $item_id => $item ) {
127
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
128
-		}
127
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
128
+        }
129 129
 
130
-		$this->response = array_merge(
131
-			$this->response,
132
-			array( 'items' => $items )
133
-		);
130
+        $this->response = array_merge(
131
+            $this->response,
132
+            array( 'items' => $items )
133
+        );
134 134
 
135
-	}
135
+    }
136 136
 
137
-	/**
138
-	 * Adds fees to a response for submission refresh prices.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 */
142
-	public function add_fees( $submission ) {
137
+    /**
138
+     * Adds fees to a response for submission refresh prices.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     */
142
+    public function add_fees( $submission ) {
143 143
 
144
-		$fees = array();
144
+        $fees = array();
145 145
 
146 146
         foreach ( $submission->get_fees() as $name => $data ) {
147
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
148
-		}
147
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
148
+        }
149 149
 
150
-		$this->response = array_merge(
151
-			$this->response,
152
-			array( 'fees' => $fees )
153
-		);
150
+        $this->response = array_merge(
151
+            $this->response,
152
+            array( 'fees' => $fees )
153
+        );
154 154
 
155
-	}
155
+    }
156 156
 
157
-	/**
158
-	 * Adds discounts to a response for submission refresh prices.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 */
162
-	public function add_discounts( $submission ) {
157
+    /**
158
+     * Adds discounts to a response for submission refresh prices.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     */
162
+    public function add_discounts( $submission ) {
163 163
 
164
-		$discounts = array();
164
+        $discounts = array();
165 165
 
166 166
         foreach ( $submission->get_discounts() as $name => $data ) {
167
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
168
-		}
167
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
168
+        }
169 169
 
170
-		$this->response = array_merge(
171
-			$this->response,
172
-			array( 'discounts' => $discounts )
173
-		);
170
+        $this->response = array_merge(
171
+            $this->response,
172
+            array( 'discounts' => $discounts )
173
+        );
174 174
 
175
-	}
175
+    }
176 176
 
177
-	/**
178
-	 * Adds taxes to a response for submission refresh prices.
179
-	 *
180
-	 * @param GetPaid_Payment_Form_Submission $submission
181
-	 */
182
-	public function add_taxes( $submission ) {
177
+    /**
178
+     * Adds taxes to a response for submission refresh prices.
179
+     *
180
+     * @param GetPaid_Payment_Form_Submission $submission
181
+     */
182
+    public function add_taxes( $submission ) {
183 183
 
184
-		$taxes = array();
184
+        $taxes = array();
185 185
 
186 186
         foreach ( $submission->get_taxes() as $name => $data ) {
187
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
188
-		}
187
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
188
+        }
189 189
 
190
-		$this->response = array_merge(
191
-			$this->response,
192
-			array( 'taxes' => $taxes )
193
-		);
190
+        $this->response = array_merge(
191
+            $this->response,
192
+            array( 'taxes' => $taxes )
193
+        );
194 194
 
195
-	}
195
+    }
196 196
 
197
-	/**
198
-	 * Adds gateways to a response for submission refresh prices.
199
-	 *
200
-	 * @param GetPaid_Payment_Form_Submission $submission
201
-	 */
202
-	public function add_gateways( $submission ) {
197
+    /**
198
+     * Adds gateways to a response for submission refresh prices.
199
+     *
200
+     * @param GetPaid_Payment_Form_Submission $submission
201
+     */
202
+    public function add_gateways( $submission ) {
203 203
 
204
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
204
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205 205
 
206
-		if ( $this->response['has_recurring'] ) {
206
+        if ( $this->response['has_recurring'] ) {
207 207
 
208
-			foreach ( $gateways as $i => $gateway ) {
208
+            foreach ( $gateways as $i => $gateway ) {
209 209
 
210
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
211
-					unset( $gateways[ $i ] );
212
-				}
210
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
211
+                    unset( $gateways[ $i ] );
212
+                }
213 213
 
214
-			}
214
+            }
215 215
 
216
-		}
216
+        }
217 217
 
218 218
 
219
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
220
-		$this->response = array_merge(
221
-			$this->response,
222
-			array( 'gateways' => $gateways )
223
-		);
219
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
220
+        $this->response = array_merge(
221
+            $this->response,
222
+            array( 'gateways' => $gateways )
223
+        );
224 224
 
225
-	}
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.