Passed
Push — master ( 5114f2...3d08b7 )
by Brian
04:44
created
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  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', 'single_subscription_group' );
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
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93 93
         parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,45 +146,45 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+        return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
190 190
             'no_shipping'   => '1',
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get line item args for paypal request.
213
-	 *
214
-	 * @param  WPInv_Invoice $invoice Invoice object.
215
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216
-	 * @return array
217
-	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
212
+     * Get line item args for paypal request.
213
+     *
214
+     * @param  WPInv_Invoice $invoice Invoice object.
215
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
216
+     * @return array
217
+     */
218
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
221
+        if ( $force_one_line_item ) {
222 222
             return $this->get_line_item_args_single_item( $invoice );
223 223
         }
224 224
 
@@ -238,129 +238,129 @@  discard block
 block discarded – undo
238 238
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+        return array_merge( $line_item_args, $this->get_line_items() );
242 242
 
243 243
     }
244 244
 
245 245
     /**
246
-	 * Get line item args for paypal request as a single line item.
247
-	 *
248
-	 * @param  WPInv_Invoice $invoice Invoice object.
249
-	 * @return array
250
-	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
252
-		$this->delete_line_items();
246
+     * Get line item args for paypal request as a single line item.
247
+     *
248
+     * @param  WPInv_Invoice $invoice Invoice object.
249
+     * @return array
250
+     */
251
+    protected function get_line_item_args_single_item( $invoice ) {
252
+        $this->delete_line_items();
253 253
 
254 254
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256 256
 
257
-		return $this->get_line_items();
257
+        return $this->get_line_items();
258 258
     }
259 259
 
260 260
     /**
261
-	 * Return all line items.
262
-	 */
263
-	protected function get_line_items() {
264
-		return $this->line_items;
265
-	}
261
+     * Return all line items.
262
+     */
263
+    protected function get_line_items() {
264
+        return $this->line_items;
265
+    }
266 266
 
267 267
     /**
268
-	 * Remove all line items.
269
-	 */
270
-	protected function delete_line_items() {
271
-		$this->line_items = array();
268
+     * Remove all line items.
269
+     */
270
+    protected function delete_line_items() {
271
+        $this->line_items = array();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Prepare line items to send to paypal.
276
-	 *
277
-	 * @param  WPInv_Invoice $invoice Invoice object.
278
-	 */
279
-	protected function prepare_line_items( $invoice ) {
280
-		$this->delete_line_items();
281
-
282
-		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
284
-			$amount   = $item->get_price();
285
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
275
+     * Prepare line items to send to paypal.
276
+     *
277
+     * @param  WPInv_Invoice $invoice Invoice object.
278
+     */
279
+    protected function prepare_line_items( $invoice ) {
280
+        $this->delete_line_items();
281
+
282
+        // Items.
283
+        foreach ( $invoice->get_items() as $item ) {
284
+            $amount   = $item->get_price();
285
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
290
+        foreach ( $invoice->get_fees() as $fee => $data ) {
291 291
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
292 292
         }
293 293
 
294 294
     }
295 295
 
296 296
     /**
297
-	 * Add PayPal Line Item.
298
-	 *
299
-	 * @param  string $item_name Item name.
300
-	 * @param  float    $quantity Item quantity.
301
-	 * @param  float  $amount Amount.
302
-	 * @param  string $item_number Item number.
303
-	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
306
-
307
-		$item = apply_filters(
308
-			'getpaid_paypal_line_item',
309
-			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
-				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
-				'item_number' => $item_number,
314
-			),
315
-			$item_name,
316
-			$quantity,
317
-			$amount,
318
-			$item_number
319
-		);
320
-
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
297
+     * Add PayPal Line Item.
298
+     *
299
+     * @param  string $item_name Item name.
300
+     * @param  float    $quantity Item quantity.
301
+     * @param  float  $amount Amount.
302
+     * @param  string $item_number Item number.
303
+     */
304
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
+        $index = ( count( $this->line_items ) / 4 ) + 1;
306
+
307
+        $item = apply_filters(
308
+            'getpaid_paypal_line_item',
309
+            array(
310
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+                'quantity'    => (float) $quantity,
312
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+                'item_number' => $item_number,
314
+            ),
315
+            $item_name,
316
+            $quantity,
317
+            $amount,
318
+            $item_number
319
+        );
320
+
321
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322 322
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
327 327
     }
328 328
 
329 329
     /**
330
-	 * If the default request with line items is too long, generate a new one with only one line item.
331
-	 *
332
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336
-	 * @return array
337
-	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
-		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
-
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
-			return $paypal_args;
344
-		}
345
-
346
-		return apply_filters(
347
-			'getpaid_paypal_args',
348
-			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
351
-			),
352
-			$invoice
353
-		);
330
+     * If the default request with line items is too long, generate a new one with only one line item.
331
+     *
332
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
+     *
334
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
336
+     * @return array
337
+     */
338
+    protected function fix_request_length( $invoice, $paypal_args ) {
339
+        $max_paypal_length = 2083;
340
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+
342
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+            return $paypal_args;
344
+        }
345
+
346
+        return apply_filters(
347
+            'getpaid_paypal_args',
348
+            array_merge(
349
+                $this->get_transaction_args( $invoice ),
350
+                $this->get_line_item_args( $invoice, true )
351
+            ),
352
+            $invoice
353
+        );
354 354
 
355 355
     }
356 356
 
357 357
     /**
358
-	 * Processes recurring invoices.
359
-	 *
360
-	 * @param  array $paypal_args PayPal args.
361
-	 * @param  WPInv_Invoice    $invoice Invoice object.
362
-	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
358
+     * Processes recurring invoices.
359
+     *
360
+     * @param  array $paypal_args PayPal args.
361
+     * @param  WPInv_Invoice    $invoice Invoice object.
362
+     */
363
+    public function process_subscription( $paypal_args, $invoice ) {
364 364
 
365 365
         // Make sure this is a subscription.
366 366
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 
386 386
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
387 387
 
388
-			// Trial period length.
389
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
388
+            // Trial period length.
389
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
390 390
 
391
-			// Trial period.
392
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
391
+            // Trial period.
392
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
393 393
 
394 394
         } else if ( $initial_amount != $recurring_amount ) {
395 395
 
@@ -412,40 +412,40 @@  discard block
 block discarded – undo
412 412
         }
413 413
 
414 414
         // We have a recurring payment
415
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
415
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
416 416
 
417
-			// Subscription price
418
-			$paypal_args['a3'] = $recurring_amount;
417
+            // Subscription price
418
+            $paypal_args['a3'] = $recurring_amount;
419 419
 
420
-			// Subscription duration
421
-			$paypal_args['p3'] = $interval;
420
+            // Subscription duration
421
+            $paypal_args['p3'] = $interval;
422 422
 
423
-			// Subscription period
424
-			$paypal_args['t3'] = $period;
423
+            // Subscription period
424
+            $paypal_args['t3'] = $period;
425 425
 
426 426
         }
427 427
 
428 428
         // Recurring payments
429
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
430 430
 
431
-			// Non-recurring payments
432
-			$paypal_args['src'] = 0;
431
+            // Non-recurring payments
432
+            $paypal_args['src'] = 0;
433 433
 
434
-		} else {
434
+        } else {
435 435
 
436
-			$paypal_args['src'] = 1;
436
+            $paypal_args['src'] = 1;
437 437
 
438
-			if ( $bill_times > 0 ) {
438
+            if ( $bill_times > 0 ) {
439 439
 
440
-				// An initial period is being used to charge a sign-up fee
441
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
-					$bill_times--;
443
-				}
440
+                // An initial period is being used to charge a sign-up fee
441
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
442
+                    $bill_times--;
443
+                }
444 444
 
445 445
                 // Make sure it's not over the max of 52
446 446
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
447 447
 
448
-			}
448
+            }
449 449
         }
450 450
 
451 451
         // Force return URL so that order description & instructions display
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         return apply_filters(
464
-			'getpaid_paypal_subscription_args',
465
-			$paypal_args,
466
-			$invoice
464
+            'getpaid_paypal_subscription_args',
465
+            $paypal_args,
466
+            $invoice
467 467
         );
468 468
 
469 469
     }
470 470
 
471 471
     /**
472
-	 * Processes ipns and marks payments as complete.
473
-	 *
474
-	 * @return void
475
-	 */
476
-	public function verify_ipn() {
472
+     * Processes ipns and marks payments as complete.
473
+     *
474
+     * @return void
475
+     */
476
+    public function verify_ipn() {
477 477
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
478 478
     }
479 479
 
@@ -483,19 +483,19 @@  discard block
 block discarded – undo
483 483
     public function sandbox_notice() {
484 484
 
485 485
         return sprintf(
486
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
-			'</a>'
489
-		);
486
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
487
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488
+            '</a>'
489
+        );
490 490
 
491 491
     }
492 492
 
493
-	/**
494
-	 * Filters the gateway settings.
495
-	 *
496
-	 * @param array $admin_settings
497
-	 */
498
-	public function admin_settings( $admin_settings ) {
493
+    /**
494
+     * Filters the gateway settings.
495
+     *
496
+     * @param array $admin_settings
497
+     */
498
+    public function admin_settings( $admin_settings ) {
499 499
 
500 500
         $currencies = sprintf(
501 501
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -505,39 +505,39 @@  discard block
 block discarded – undo
505 505
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
506 506
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
507 507
 
508
-		// Access tokens.
509
-		$live_email      = wpinv_get_option( 'paypal_email' );
510
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
-
512
-		$admin_settings['paypal_connect'] = array(
513
-			'type'       => 'raw_html',
514
-			'id'         => 'paypal_connect',
515
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
-			'desc'       => sprintf(
517
-				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
-				esc_url( self::get_connect_url( false ) ),
519
-				__( 'Connect to PayPal', 'invoicing' ),
520
-				esc_url( self::get_connect_url( true ) ),
521
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
522
-				$this->get_js()
523
-			),
524
-		);
508
+        // Access tokens.
509
+        $live_email      = wpinv_get_option( 'paypal_email' );
510
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
511
+
512
+        $admin_settings['paypal_connect'] = array(
513
+            'type'       => 'raw_html',
514
+            'id'         => 'paypal_connect',
515
+            'name'       => __( 'Connect to PayPal', 'invoicing' ),
516
+            'desc'       => sprintf(
517
+                '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
+                esc_url( self::get_connect_url( false ) ),
519
+                __( 'Connect to PayPal', 'invoicing' ),
520
+                esc_url( self::get_connect_url( true ) ),
521
+                __( 'Connect to PayPal Sandox', 'invoicing' ),
522
+                $this->get_js()
523
+            ),
524
+        );
525 525
 
526 526
         $admin_settings['paypal_email'] = array(
527 527
             'type'  => 'text',
528
-			'class' => 'live-auth-data',
528
+            'class' => 'live-auth-data',
529 529
             'id'    => 'paypal_email',
530 530
             'name'  => __( 'Live Email Address', 'invoicing' ),
531 531
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
532 532
         );
533 533
 
534
-		$admin_settings['paypal_sandbox_email'] = array(
534
+        $admin_settings['paypal_sandbox_email'] = array(
535 535
             'type'  => 'text',
536
-			'class' => 'sandbox-auth-data',
536
+            'class' => 'sandbox-auth-data',
537 537
             'id'    => 'paypal_sandbox_email',
538 538
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
539 539
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
540
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
540
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
541 541
         );
542 542
 
543 543
         $admin_settings['paypal_ipn_url'] = array(
@@ -549,29 +549,29 @@  discard block
 block discarded – undo
549 549
             'readonly' => true,
550 550
         );
551 551
 
552
-		return $admin_settings;
553
-	}
552
+        return $admin_settings;
553
+    }
554 554
 
555
-	/**
556
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
557
-	 *
558
-	 *
555
+    /**
556
+     * Retrieves the PayPal connect URL when using the setup wizzard.
557
+     *
558
+     *
559 559
      * @param array $data
560 560
      * @return string
561
-	 */
562
-	public static function maybe_get_connect_url( $url = '', $data ) {
563
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
-	}
565
-
566
-	/**
567
-	 * Retrieves the PayPal connect URL.
568
-	 *
569
-	 *
561
+     */
562
+    public static function maybe_get_connect_url( $url = '', $data ) {
563
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
564
+    }
565
+
566
+    /**
567
+     * Retrieves the PayPal connect URL.
568
+     *
569
+     *
570 570
      * @param bool $is_sandbox
571
-	 * @param string $redirect
571
+     * @param string $redirect
572 572
      * @return string
573
-	 */
574
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
573
+     */
574
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
575 575
 
576 576
         $redirect_url = add_query_arg(
577 577
             array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                 'tab'                  => 'gateways',
582 582
                 'section'              => 'paypal',
583 583
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
584
-				'redirect'             => urlencode( $redirect ),
584
+                'redirect'             => urlencode( $redirect ),
585 585
             ),
586 586
             admin_url( 'admin.php' )
587 587
         );
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
 
597 597
     }
598 598
 
599
-	/**
600
-	 * Generates settings page js.
601
-	 *
599
+    /**
600
+     * Generates settings page js.
601
+     *
602 602
      * @return void
603
-	 */
604
-	public static function get_js() {
603
+     */
604
+    public static function get_js() {
605 605
         ob_start();
606 606
         ?>
607 607
             <script>
@@ -637,72 +637,72 @@  discard block
 block discarded – undo
637 637
         return ob_get_clean();
638 638
     }
639 639
 
640
-	/**
641
-	 * Connects to PayPal.
642
-	 *
643
-	 * @param array $data Connection data.
644
-	 * @return void
645
-	 */
646
-	public function connect_paypal( $data ) {
647
-
648
-		$sandbox      = $this->is_sandbox();
649
-		$data         = wp_unslash( $data );
650
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
-
652
-		if ( isset( $data['live_mode'] ) ) {
653
-			$sandbox = empty( $data['live_mode'] );
654
-		}
655
-
656
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
-		wpinv_update_option( 'paypal_active', 1 );
658
-
659
-		if ( ! empty( $data['error_description'] ) ) {
660
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
-		} else {
662
-
663
-			// Retrieve the user info.
664
-			$user_info = wp_remote_get(
665
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
-				array(
667
-
668
-					'headers' => array(
669
-						'Authorization' => 'Bearer ' . $access_token,
670
-						'Content-type'  => 'application/json',
671
-					)
672
-
673
-				)
674
-			);
675
-
676
-			if ( is_wp_error( $user_info ) ) {
677
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
-			} else {
679
-
680
-				// Create application.
681
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
-
683
-				if ( $sandbox ) {
684
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
-				} else {
689
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
-				}
694
-
695
-			}
696
-
697
-		}
698
-
699
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
-
701
-		if ( isset( $data['step'] ) ) {
702
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
703
-		}
704
-		wp_redirect( $redirect );
705
-		exit;
706
-	}
640
+    /**
641
+     * Connects to PayPal.
642
+     *
643
+     * @param array $data Connection data.
644
+     * @return void
645
+     */
646
+    public function connect_paypal( $data ) {
647
+
648
+        $sandbox      = $this->is_sandbox();
649
+        $data         = wp_unslash( $data );
650
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
651
+
652
+        if ( isset( $data['live_mode'] ) ) {
653
+            $sandbox = empty( $data['live_mode'] );
654
+        }
655
+
656
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
+        wpinv_update_option( 'paypal_active', 1 );
658
+
659
+        if ( ! empty( $data['error_description'] ) ) {
660
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
661
+        } else {
662
+
663
+            // Retrieve the user info.
664
+            $user_info = wp_remote_get(
665
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666
+                array(
667
+
668
+                    'headers' => array(
669
+                        'Authorization' => 'Bearer ' . $access_token,
670
+                        'Content-type'  => 'application/json',
671
+                    )
672
+
673
+                )
674
+            );
675
+
676
+            if ( is_wp_error( $user_info ) ) {
677
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
678
+            } else {
679
+
680
+                // Create application.
681
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
682
+
683
+                if ( $sandbox ) {
684
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
688
+                } else {
689
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
693
+                }
694
+
695
+            }
696
+
697
+        }
698
+
699
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+
701
+        if ( isset( $data['step'] ) ) {
702
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
703
+        }
704
+        wp_redirect( $redirect );
705
+        exit;
706
+    }
707 707
 
708 708
 }
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 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' );
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 65
 	 * URL to view a transaction.
@@ -80,15 +80,15 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
88
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
89
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
90
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
91
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
92 92
 
93 93
         parent::__construct();
94 94
     }
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103 103
 	 * @return array
104 104
 	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
105
+	public function process_payment($invoice, $submission_data, $submission) {
106 106
 
107 107
         // Get redirect url.
108
-        $paypal_redirect = $this->get_request_url( $invoice );
108
+        $paypal_redirect = $this->get_request_url($invoice);
109 109
 
110 110
         // Add a note about the request url.
111 111
         $invoice->add_note(
112 112
             sprintf(
113
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
114
-                esc_url( $paypal_redirect )
113
+                __('Redirecting to PayPal: %s', 'invoicing'),
114
+                esc_url($paypal_redirect)
115 115
             ),
116 116
             false,
117 117
             false,
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         );
120 120
 
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
 
125 125
     }
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
 	 * @param  WPInv_Invoice $invoice Invoice object.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_request_url( $invoice ) {
133
+	public function get_request_url($invoice) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
139
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
140 140
 
141
-        if ( $invoice->is_recurring() ) {
141
+        if ($invoice->is_recurring()) {
142 142
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
143 143
         } else {
144 144
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
145 145
         }
146 146
 
147
-        return add_query_arg( $paypal_args, $this->endpoint );
147
+        return add_query_arg($paypal_args, $this->endpoint);
148 148
 
149 149
 	}
150 150
 
@@ -154,25 +154,25 @@  discard block
 block discarded – undo
154 154
 	 * @param  WPInv_Invoice $invoice Invoice object.
155 155
 	 * @return array
156 156
 	 */
157
-	protected function get_paypal_args( $invoice ) {
157
+	protected function get_paypal_args($invoice) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
160
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
161 161
 
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
162
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
163 163
 			$force_one_line_item = true;
164 164
 		}
165 165
 
166 166
 		$paypal_args = apply_filters(
167 167
 			'getpaid_paypal_args',
168 168
 			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
+				$this->get_transaction_args($invoice),
170
+				$this->get_line_item_args($invoice, $force_one_line_item)
171 171
 			),
172 172
 			$invoice
173 173
 		);
174 174
 
175
-		return $this->fix_request_length( $invoice, $paypal_args );
175
+		return $this->fix_request_length($invoice, $paypal_args);
176 176
     }
177 177
 
178 178
     /**
@@ -181,9 +181,9 @@  discard block
 block discarded – undo
181 181
 	 * @param WPInv_Invoice $invoice Invoice object.
182 182
 	 * @return array
183 183
 	 */
184
-	protected function get_transaction_args( $invoice ) {
184
+	protected function get_transaction_args($invoice) {
185 185
 
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
186
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
187 187
 		return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
             'rm'            => is_ssl() ? 2 : 1,
195 195
             'upload'        => 1,
196 196
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
197
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
198
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
199
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
200
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
197
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
198
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
199
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
200
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
201 201
             'custom'        => $invoice->get_id(),
202
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
203
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
204
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
205
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
206
-            'cbt'           => get_bloginfo( 'name' )
202
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
203
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
204
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
205
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
206
+            'cbt'           => get_bloginfo('name')
207 207
         );
208 208
 
209 209
     }
@@ -215,30 +215,30 @@  discard block
 block discarded – undo
215 215
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216 216
 	 * @return array
217 217
 	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
218
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
222
-            return $this->get_line_item_args_single_item( $invoice );
221
+		if ($force_one_line_item) {
222
+            return $this->get_line_item_args_single_item($invoice);
223 223
         }
224 224
 
225 225
         // Send each line item individually.
226 226
         $line_item_args = array();
227 227
 
228 228
         // Prepare line items.
229
-        $this->prepare_line_items( $invoice );
229
+        $this->prepare_line_items($invoice);
230 230
 
231 231
         // Add taxes to the cart
232
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
233
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
232
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
233
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
234 234
         }
235 235
 
236 236
         // Add discount.
237
-        if ( $invoice->get_total_discount() > 0 ) {
238
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
237
+        if ($invoice->get_total_discount() > 0) {
238
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+		return array_merge($line_item_args, $this->get_line_items());
242 242
 
243 243
     }
244 244
 
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 	 * @param  WPInv_Invoice $invoice Invoice object.
249 249
 	 * @return array
250 250
 	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
251
+	protected function get_line_item_args_single_item($invoice) {
252 252
 		$this->delete_line_items();
253 253
 
254
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
254
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
255
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
256 256
 
257 257
 		return $this->get_line_items();
258 258
     }
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param  WPInv_Invoice $invoice Invoice object.
278 278
 	 */
279
-	protected function prepare_line_items( $invoice ) {
279
+	protected function prepare_line_items($invoice) {
280 280
 		$this->delete_line_items();
281 281
 
282 282
 		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
283
+		foreach ($invoice->get_items() as $item) {
284 284
 			$amount   = $item->get_price();
285 285
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
286
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
291
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
290
+		foreach ($invoice->get_fees() as $fee => $data) {
291
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
292 292
         }
293 293
 
294 294
     }
@@ -301,15 +301,15 @@  discard block
 block discarded – undo
301 301
 	 * @param  float  $amount Amount.
302 302
 	 * @param  string $item_number Item number.
303 303
 	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
304
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
305
+		$index = (count($this->line_items) / 4) + 1;
306 306
 
307 307
 		$item = apply_filters(
308 308
 			'getpaid_paypal_line_item',
309 309
 			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
311 311
 				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
313 313
 				'item_number' => $item_number,
314 314
 			),
315 315
 			$item_name,
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 			$item_number
319 319
 		);
320 320
 
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
321
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
322
+        $this->line_items['quantity_' . $index] = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
326
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
327 327
     }
328 328
 
329 329
     /**
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336 336
 	 * @return array
337 337
 	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
338
+	protected function fix_request_length($invoice, $paypal_args) {
339 339
 		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
340
+		$query_candidate   = http_build_query($paypal_args, '', '&');
341 341
 
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
343 343
 			return $paypal_args;
344 344
 		}
345 345
 
346 346
 		return apply_filters(
347 347
 			'getpaid_paypal_args',
348 348
 			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
349
+				$this->get_transaction_args($invoice),
350
+				$this->get_line_item_args($invoice, true)
351 351
 			),
352 352
 			$invoice
353 353
 		);
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 	 * @param  array $paypal_args PayPal args.
361 361
 	 * @param  WPInv_Invoice    $invoice Invoice object.
362 362
 	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
363
+	public function process_subscription($paypal_args, $invoice) {
364 364
 
365 365
         // Make sure this is a subscription.
366
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
366
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
367 367
             return $paypal_args;
368 368
         }
369 369
 
@@ -371,17 +371,17 @@  discard block
 block discarded – undo
371 371
         $paypal_args['cmd'] = '_xclick-subscriptions';
372 372
 
373 373
         // Subscription name.
374
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
374
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
375 375
 
376 376
         // Get subscription args.
377
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1) );
377
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
378 378
         $interval               = (int) $subscription->get_frequency();
379 379
         $bill_times             = (int) $subscription->get_bill_times();
380
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
381
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
382
-        $subscription_item      = $invoice->get_recurring( true );
380
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
381
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
382
+        $subscription_item      = $invoice->get_recurring(true);
383 383
 
384
-        if ( $subscription_item->has_free_trial() ) {
384
+        if ($subscription_item->has_free_trial()) {
385 385
 
386 386
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
387 387
 
@@ -391,28 +391,28 @@  discard block
 block discarded – undo
391 391
 			// Trial period.
392 392
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
393 393
 
394
-        } else if ( $initial_amount != $recurring_amount ) {
394
+        } else if ($initial_amount != $recurring_amount) {
395 395
 
396 396
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
397 397
 
398
-            if ( 1 == $bill_times ) {
398
+            if (1 == $bill_times) {
399 399
                 $param_number = 3;
400 400
             } else {
401 401
                 $param_number = 1;
402 402
             }
403 403
 
404
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
404
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
405 405
 
406 406
             // Sign Up interval
407
-            $paypal_args[ 'p' . $param_number ] = $interval;
407
+            $paypal_args['p' . $param_number] = $interval;
408 408
 
409 409
             // Sign Up unit of duration
410
-            $paypal_args[ 't' . $param_number ] = $period;
410
+            $paypal_args['t' . $param_number] = $period;
411 411
 
412 412
         }
413 413
 
414 414
         // We have a recurring payment
415
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
415
+		if (!isset($param_number) || 1 == $param_number) {
416 416
 
417 417
 			// Subscription price
418 418
 			$paypal_args['a3'] = $recurring_amount;
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
         }
427 427
 
428 428
         // Recurring payments
429
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
429
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
430 430
 
431 431
 			// Non-recurring payments
432 432
 			$paypal_args['src'] = 0;
@@ -435,15 +435,15 @@  discard block
 block discarded – undo
435 435
 
436 436
 			$paypal_args['src'] = 1;
437 437
 
438
-			if ( $bill_times > 0 ) {
438
+			if ($bill_times > 0) {
439 439
 
440 440
 				// An initial period is being used to charge a sign-up fee
441
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
441
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
442 442
 					$bill_times--;
443 443
 				}
444 444
 
445 445
                 // Make sure it's not over the max of 52
446
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
446
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
447 447
 
448 448
 			}
449 449
         }
@@ -452,10 +452,10 @@  discard block
 block discarded – undo
452 452
         $paypal_args['rm'] = 2;
453 453
 
454 454
         // Get rid of redudant items.
455
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
455
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
456 456
 
457
-            if ( isset( $paypal_args[ $arg ] ) ) {
458
-                unset( $paypal_args[ $arg ] );
457
+            if (isset($paypal_args[$arg])) {
458
+                unset($paypal_args[$arg]);
459 459
             }
460 460
 
461 461
         }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	 * @return void
475 475
 	 */
476 476
 	public function verify_ipn() {
477
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
477
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
478 478
     }
479 479
 
480 480
     /**
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
     public function sandbox_notice() {
484 484
 
485 485
         return sprintf(
486
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
486
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
487 487
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
488 488
 			'</a>'
489 489
 		);
@@ -495,30 +495,30 @@  discard block
 block discarded – undo
495 495
 	 *
496 496
 	 * @param array $admin_settings
497 497
 	 */
498
-	public function admin_settings( $admin_settings ) {
498
+	public function admin_settings($admin_settings) {
499 499
 
500 500
         $currencies = sprintf(
501
-            __( 'Supported Currencies: %s', 'invoicing' ),
502
-            implode( ', ', $this->currencies )
501
+            __('Supported Currencies: %s', 'invoicing'),
502
+            implode(', ', $this->currencies)
503 503
         );
504 504
 
505 505
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
506
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
506
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
507 507
 
508 508
 		// Access tokens.
509
-		$live_email      = wpinv_get_option( 'paypal_email' );
510
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
509
+		$live_email      = wpinv_get_option('paypal_email');
510
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
511 511
 
512 512
 		$admin_settings['paypal_connect'] = array(
513 513
 			'type'       => 'raw_html',
514 514
 			'id'         => 'paypal_connect',
515
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
515
+			'name'       => __('Connect to PayPal', 'invoicing'),
516 516
 			'desc'       => sprintf(
517 517
 				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
518
-				esc_url( self::get_connect_url( false ) ),
519
-				__( 'Connect to PayPal', 'invoicing' ),
520
-				esc_url( self::get_connect_url( true ) ),
521
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
518
+				esc_url(self::get_connect_url(false)),
519
+				__('Connect to PayPal', 'invoicing'),
520
+				esc_url(self::get_connect_url(true)),
521
+				__('Connect to PayPal Sandox', 'invoicing'),
522 522
 				$this->get_js()
523 523
 			),
524 524
 		);
@@ -527,25 +527,25 @@  discard block
 block discarded – undo
527 527
             'type'  => 'text',
528 528
 			'class' => 'live-auth-data',
529 529
             'id'    => 'paypal_email',
530
-            'name'  => __( 'Live Email Address', 'invoicing' ),
531
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
530
+            'name'  => __('Live Email Address', 'invoicing'),
531
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
532 532
         );
533 533
 
534 534
 		$admin_settings['paypal_sandbox_email'] = array(
535 535
             'type'  => 'text',
536 536
 			'class' => 'sandbox-auth-data',
537 537
             'id'    => 'paypal_sandbox_email',
538
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
539
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
540
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
538
+            'name'  => __('Sandbox Email Address', 'invoicing'),
539
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
540
+			'std'   => wpinv_get_option('paypal_email', ''),
541 541
         );
542 542
 
543 543
         $admin_settings['paypal_ipn_url'] = array(
544 544
             'type'     => 'ipn_url',
545 545
             'id'       => 'paypal_ipn_url',
546
-            'name'     => __( 'IPN Url', 'invoicing' ),
546
+            'name'     => __('IPN Url', 'invoicing'),
547 547
             'std'      => $this->notify_url,
548
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
548
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
549 549
             'readonly' => true,
550 550
         );
551 551
 
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
      * @param array $data
560 560
      * @return string
561 561
 	 */
562
-	public static function maybe_get_connect_url( $url = '', $data ) {
563
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
562
+	public static function maybe_get_connect_url($url = '', $data) {
563
+		return self::get_connect_url(false, urldecode($data['redirect']));
564 564
 	}
565 565
 
566 566
 	/**
@@ -571,25 +571,25 @@  discard block
 block discarded – undo
571 571
 	 * @param string $redirect
572 572
      * @return string
573 573
 	 */
574
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
574
+	public static function get_connect_url($is_sandbox, $redirect = '') {
575 575
 
576 576
         $redirect_url = add_query_arg(
577 577
             array(
578 578
                 'getpaid-admin-action' => 'connect_paypal',
579 579
                 'page'                 => 'wpinv-settings',
580
-                'live_mode'            => (int) empty( $is_sandbox ),
580
+                'live_mode'            => (int) empty($is_sandbox),
581 581
                 'tab'                  => 'gateways',
582 582
                 'section'              => 'paypal',
583
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
584
-				'redirect'             => urlencode( $redirect ),
583
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
584
+				'redirect'             => urlencode($redirect),
585 585
             ),
586
-            admin_url( 'admin.php' )
586
+            admin_url('admin.php')
587 587
         );
588 588
 
589 589
         return add_query_arg(
590 590
             array(
591
-                'live_mode'    => (int) empty( $is_sandbox ),
592
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) )
591
+                'live_mode'    => (int) empty($is_sandbox),
592
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url))
593 593
             ),
594 594
             'https://ayecode.io/oauth/paypal'
595 595
         );
@@ -643,26 +643,26 @@  discard block
 block discarded – undo
643 643
 	 * @param array $data Connection data.
644 644
 	 * @return void
645 645
 	 */
646
-	public function connect_paypal( $data ) {
646
+	public function connect_paypal($data) {
647 647
 
648 648
 		$sandbox      = $this->is_sandbox();
649
-		$data         = wp_unslash( $data );
650
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
649
+		$data         = wp_unslash($data);
650
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
651 651
 
652
-		if ( isset( $data['live_mode'] ) ) {
653
-			$sandbox = empty( $data['live_mode'] );
652
+		if (isset($data['live_mode'])) {
653
+			$sandbox = empty($data['live_mode']);
654 654
 		}
655 655
 
656
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
657
-		wpinv_update_option( 'paypal_active', 1 );
656
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
657
+		wpinv_update_option('paypal_active', 1);
658 658
 
659
-		if ( ! empty( $data['error_description'] ) ) {
660
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
659
+		if (!empty($data['error_description'])) {
660
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
661 661
 		} else {
662 662
 
663 663
 			// Retrieve the user info.
664 664
 			$user_info = wp_remote_get(
665
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
665
+				!$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
666 666
 				array(
667 667
 
668 668
 					'headers' => array(
@@ -673,35 +673,35 @@  discard block
 block discarded – undo
673 673
 				)
674 674
 			);
675 675
 
676
-			if ( is_wp_error( $user_info ) ) {
677
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
676
+			if (is_wp_error($user_info)) {
677
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
678 678
 			} else {
679 679
 
680 680
 				// Create application.
681
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
681
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
682 682
 
683
-				if ( $sandbox ) {
684
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
685
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
686
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
687
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
683
+				if ($sandbox) {
684
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
685
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
686
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
687
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
688 688
 				} else {
689
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
690
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
691
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
692
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
689
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
690
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
691
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
692
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
693 693
 				}
694 694
 
695 695
 			}
696 696
 
697 697
 		}
698 698
 
699
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
699
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
700 700
 
701
-		if ( isset( $data['step'] ) ) {
702
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
701
+		if (isset($data['step'])) {
702
+			$redirect = add_query_arg('step', $data['step'], $redirect);
703 703
 		}
704
-		wp_redirect( $redirect );
704
+		wp_redirect($redirect);
705 705
 		exit;
706 706
 	}
707 707
 
Please login to merge, or discard this patch.
invoicing.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@  discard block
 block discarded – undo
19 19
 
20 20
 // Define constants.
21 21
 if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
22
+    define( 'WPINV_PLUGIN_FILE', __FILE__ );
23 23
 }
24 24
 
25 25
 if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.4.3' );
26
+    define( 'WPINV_VERSION', '2.4.3' );
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30 30
 if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
31
+    require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
46
-	return $GLOBALS['invoicing'];
46
+    return $GLOBALS['invoicing'];
47 47
 }
48 48
 
49 49
 /**
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,20 +15,20 @@  discard block
 block discarded – undo
15 15
  * @package GetPaid
16 16
  */
17 17
 
18
-defined( 'ABSPATH' ) || exit;
18
+defined('ABSPATH') || exit;
19 19
 
20 20
 // Define constants.
21
-if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-	define( 'WPINV_PLUGIN_FILE', __FILE__ );
21
+if (!defined('WPINV_PLUGIN_FILE')) {
22
+	define('WPINV_PLUGIN_FILE', __FILE__);
23 23
 }
24 24
 
25
-if ( ! defined( 'WPINV_VERSION' ) ) {
26
-	define( 'WPINV_VERSION', '2.4.3' );
25
+if (!defined('WPINV_VERSION')) {
26
+	define('WPINV_VERSION', '2.4.3');
27 27
 }
28 28
 
29 29
 // Include the main Invoicing class.
30
-if ( ! class_exists( 'WPInv_Plugin', false ) ) {
31
-	require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php';
30
+if (!class_exists('WPInv_Plugin', false)) {
31
+	require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php';
32 32
 }
33 33
 
34 34
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  */
40 40
 function getpaid() {
41 41
 
42
-    if ( empty( $GLOBALS['invoicing'] ) ) {
42
+    if (empty($GLOBALS['invoicing'])) {
43 43
         $GLOBALS['invoicing'] = new WPInv_Plugin();
44 44
     }
45 45
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  * @since  2.0.8
53 53
  */
54 54
 function getpaid_deactivation_hook() {
55
-    update_option( 'wpinv_flush_permalinks', 1 );
55
+    update_option('wpinv_flush_permalinks', 1);
56 56
 }
57
-register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' );
57
+register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook');
58 58
 
59 59
 /**
60 60
  * @deprecated
@@ -64,4 +64,4 @@  discard block
 block discarded – undo
64 64
 }
65 65
 
66 66
 // Kickstart the plugin.
67
-add_action( 'plugins_loaded', 'getpaid', -100 );
67
+add_action('plugins_loaded', 'getpaid', -100);
Please login to merge, or discard this patch.