Passed
Pull Request — master (#605)
by Brian
05:22
created
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +161 added lines, -161 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,14 +80,14 @@  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_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_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
91 91
 
92 92
         parent::__construct();
93 93
     }
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
102 102
 	 * @return array
103 103
 	 */
104
-	public function process_payment( $invoice, $submission_data, $submission ) {
104
+	public function process_payment($invoice, $submission_data, $submission) {
105 105
 
106 106
         // Get redirect url.
107
-        $paypal_redirect = $this->get_request_url( $invoice );
107
+        $paypal_redirect = $this->get_request_url($invoice);
108 108
 
109 109
         // Add a note about the request url.
110 110
         $invoice->add_note(
111 111
             sprintf(
112
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
113
-                esc_url( $paypal_redirect )
112
+                __('Redirecting to PayPal: %s', 'invoicing'),
113
+                esc_url($paypal_redirect)
114 114
             ),
115 115
             false,
116 116
             false,
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         );
119 119
 
120 120
         // Redirect to PayPal
121
-        wp_redirect( $paypal_redirect );
121
+        wp_redirect($paypal_redirect);
122 122
         exit;
123 123
 
124 124
     }
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
 	 * @param  WPInv_Invoice $invoice Invoice object.
130 130
 	 * @return string
131 131
 	 */
132
-	public function get_request_url( $invoice ) {
132
+	public function get_request_url($invoice) {
133 133
 
134 134
         // Endpoint for this request
135
-		$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
+		$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 136
 
137 137
         // Retrieve paypal args.
138
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
138
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
139 139
 
140
-        if ( $invoice->is_recurring() ) {
140
+        if ($invoice->is_recurring()) {
141 141
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
142 142
         } else {
143 143
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
144 144
         }
145 145
 
146
-        return add_query_arg( $paypal_args, $this->endpoint );
146
+        return add_query_arg($paypal_args, $this->endpoint);
147 147
 
148 148
 	}
149 149
 
@@ -153,25 +153,25 @@  discard block
 block discarded – undo
153 153
 	 * @param  WPInv_Invoice $invoice Invoice object.
154 154
 	 * @return array
155 155
 	 */
156
-	protected function get_paypal_args( $invoice ) {
156
+	protected function get_paypal_args($invoice) {
157 157
 
158 158
         // Whether or not to send the line items as one item.
159
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
159
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
160 160
 
161
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
162 162
 			$force_one_line_item = true;
163 163
 		}
164 164
 
165 165
 		$paypal_args = apply_filters(
166 166
 			'getpaid_paypal_args',
167 167
 			array_merge(
168
-				$this->get_transaction_args( $invoice ),
169
-				$this->get_line_item_args( $invoice, $force_one_line_item )
168
+				$this->get_transaction_args($invoice),
169
+				$this->get_line_item_args($invoice, $force_one_line_item)
170 170
 			),
171 171
 			$invoice
172 172
 		);
173 173
 
174
-		return $this->fix_request_length( $invoice, $paypal_args );
174
+		return $this->fix_request_length($invoice, $paypal_args);
175 175
     }
176 176
 
177 177
     /**
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 	 * @param WPInv_Invoice $invoice Invoice object.
181 181
 	 * @return array
182 182
 	 */
183
-	protected function get_transaction_args( $invoice ) {
183
+	protected function get_transaction_args($invoice) {
184 184
 
185 185
 		return array(
186 186
             'cmd'           => '_cart',
187
-            'business'      => wpinv_get_option( 'paypal_email', false ),
187
+            'business'      => wpinv_get_option('paypal_email', false),
188 188
             'no_shipping'   => '1',
189 189
             'shipping'      => '0',
190 190
             'no_note'       => '1',
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
             'rm'            => is_ssl() ? 2 : 1,
193 193
             'upload'        => 1,
194 194
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
195
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
196
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
197
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
198
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
195
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
196
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
197
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
198
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
199 199
             'custom'        => $invoice->get_id(),
200
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
201
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
202
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
203
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
204
-            'cbt'           => get_bloginfo( 'name' )
200
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
201
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
202
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
203
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
204
+            'cbt'           => get_bloginfo('name')
205 205
         );
206 206
 
207 207
     }
@@ -213,30 +213,30 @@  discard block
 block discarded – undo
213 213
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
214 214
 	 * @return array
215 215
 	 */
216
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
216
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
217 217
 
218 218
         // Maybe send invoice as a single item.
219
-		if ( $force_one_line_item ) {
220
-            return $this->get_line_item_args_single_item( $invoice );
219
+		if ($force_one_line_item) {
220
+            return $this->get_line_item_args_single_item($invoice);
221 221
         }
222 222
 
223 223
         // Send each line item individually.
224 224
         $line_item_args = array();
225 225
 
226 226
         // Prepare line items.
227
-        $this->prepare_line_items( $invoice );
227
+        $this->prepare_line_items($invoice);
228 228
 
229 229
         // Add taxes to the cart
230
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
231
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
230
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
231
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
232 232
         }
233 233
 
234 234
         // Add discount.
235
-        if ( $invoice->get_total_discount() > 0 ) {
236
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
235
+        if ($invoice->get_total_discount() > 0) {
236
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
237 237
         }
238 238
 
239
-		return array_merge( $line_item_args, $this->get_line_items() );
239
+		return array_merge($line_item_args, $this->get_line_items());
240 240
 
241 241
     }
242 242
 
@@ -246,11 +246,11 @@  discard block
 block discarded – undo
246 246
 	 * @param  WPInv_Invoice $invoice Invoice object.
247 247
 	 * @return array
248 248
 	 */
249
-	protected function get_line_item_args_single_item( $invoice ) {
249
+	protected function get_line_item_args_single_item($invoice) {
250 250
 		$this->delete_line_items();
251 251
 
252
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
253
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
252
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
253
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
254 254
 
255 255
 		return $this->get_line_items();
256 256
     }
@@ -274,19 +274,19 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @param  WPInv_Invoice $invoice Invoice object.
276 276
 	 */
277
-	protected function prepare_line_items( $invoice ) {
277
+	protected function prepare_line_items($invoice) {
278 278
 		$this->delete_line_items();
279 279
 
280 280
 		// Items.
281
-		foreach ( $invoice->get_items() as $item ) {
281
+		foreach ($invoice->get_items() as $item) {
282 282
 			$amount   = $item->get_price();
283 283
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
284
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
284
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
285 285
         }
286 286
 
287 287
         // Fees.
288
-		foreach ( $invoice->get_fees() as $fee => $data ) {
289
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
288
+		foreach ($invoice->get_fees() as $fee => $data) {
289
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
290 290
         }
291 291
 
292 292
     }
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
 	 * @param  float  $amount Amount.
300 300
 	 * @param  string $item_number Item number.
301 301
 	 */
302
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
303
-		$index = ( count( $this->line_items ) / 4 ) + 1;
302
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
303
+		$index = (count($this->line_items) / 4) + 1;
304 304
 
305 305
 		$item = apply_filters(
306 306
 			'getpaid_paypal_line_item',
307 307
 			array(
308
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
308
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
309 309
 				'quantity'    => (float) $quantity,
310
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
311 311
 				'item_number' => $item_number,
312 312
 			),
313 313
 			$item_name,
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 			$item_number
317 317
 		);
318 318
 
319
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
320
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
319
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
320
+        $this->line_items['quantity_' . $index] = $item['quantity'];
321 321
 
322 322
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
323
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
324
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
323
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
324
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
325 325
     }
326 326
 
327 327
     /**
@@ -333,19 +333,19 @@  discard block
 block discarded – undo
333 333
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
334 334
 	 * @return array
335 335
 	 */
336
-	protected function fix_request_length( $invoice, $paypal_args ) {
336
+	protected function fix_request_length($invoice, $paypal_args) {
337 337
 		$max_paypal_length = 2083;
338
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
338
+		$query_candidate   = http_build_query($paypal_args, '', '&');
339 339
 
340
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
341 341
 			return $paypal_args;
342 342
 		}
343 343
 
344 344
 		return apply_filters(
345 345
 			'getpaid_paypal_args',
346 346
 			array_merge(
347
-				$this->get_transaction_args( $invoice ),
348
-				$this->get_line_item_args( $invoice, true )
347
+				$this->get_transaction_args($invoice),
348
+				$this->get_line_item_args($invoice, true)
349 349
 			),
350 350
 			$invoice
351 351
 		);
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
 	 * @param  array $paypal_args PayPal args.
359 359
 	 * @param  WPInv_Invoice    $invoice Invoice object.
360 360
 	 */
361
-	public function process_subscription( $paypal_args, $invoice ) {
361
+	public function process_subscription($paypal_args, $invoice) {
362 362
 
363 363
         // Make sure this is a subscription.
364
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
364
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
365 365
             return $paypal_args;
366 366
         }
367 367
 
@@ -369,17 +369,17 @@  discard block
 block discarded – undo
369 369
         $paypal_args['cmd'] = '_xclick-subscriptions';
370 370
 
371 371
         // Subscription name.
372
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
372
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
373 373
 
374 374
         // Get subscription args.
375
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1) );
375
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
376 376
         $interval               = (int) $subscription->get_frequency();
377 377
         $bill_times             = (int) $subscription->get_bill_times();
378
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
379
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
380
-        $subscription_item      = $invoice->get_recurring( true );
378
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
379
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
380
+        $subscription_item      = $invoice->get_recurring(true);
381 381
 
382
-        if ( $subscription_item->has_free_trial() ) {
382
+        if ($subscription_item->has_free_trial()) {
383 383
 
384 384
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
385 385
 
@@ -389,28 +389,28 @@  discard block
 block discarded – undo
389 389
 			// Trial period.
390 390
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
391 391
 
392
-        } else if ( $initial_amount != $recurring_amount ) {
392
+        } else if ($initial_amount != $recurring_amount) {
393 393
 
394 394
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
395 395
 
396
-            if ( 1 == $bill_times ) {
396
+            if (1 == $bill_times) {
397 397
                 $param_number = 3;
398 398
             } else {
399 399
                 $param_number = 1;
400 400
             }
401 401
 
402
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
402
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
403 403
 
404 404
             // Sign Up interval
405
-            $paypal_args[ 'p' . $param_number ] = $interval;
405
+            $paypal_args['p' . $param_number] = $interval;
406 406
 
407 407
             // Sign Up unit of duration
408
-            $paypal_args[ 't' . $param_number ] = $period;
408
+            $paypal_args['t' . $param_number] = $period;
409 409
 
410 410
         }
411 411
 
412 412
         // We have a recurring payment
413
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
413
+		if (!isset($param_number) || 1 == $param_number) {
414 414
 
415 415
 			// Subscription price
416 416
 			$paypal_args['a3'] = $recurring_amount;
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
         }
425 425
 
426 426
         // Recurring payments
427
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
427
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
428 428
 
429 429
 			// Non-recurring payments
430 430
 			$paypal_args['src'] = 0;
@@ -433,15 +433,15 @@  discard block
 block discarded – undo
433 433
 
434 434
 			$paypal_args['src'] = 1;
435 435
 
436
-			if ( $bill_times > 0 ) {
436
+			if ($bill_times > 0) {
437 437
 
438 438
 				// An initial period is being used to charge a sign-up fee
439
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
440 440
 					$bill_times--;
441 441
 				}
442 442
 
443 443
                 // Make sure it's not over the max of 52
444
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
444
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
445 445
 
446 446
 			}
447 447
         }
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
         $paypal_args['rm'] = 2;
451 451
 
452 452
         // Get rid of redudant items.
453
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
453
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
454 454
 
455
-            if ( isset( $paypal_args[ $arg ] ) ) {
456
-                unset( $paypal_args[ $arg ] );
455
+            if (isset($paypal_args[$arg])) {
456
+                unset($paypal_args[$arg]);
457 457
             }
458 458
 
459 459
         }
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 	 * @return void
473 473
 	 */
474 474
 	public function verify_ipn() {
475
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
475
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
476 476
     }
477 477
 
478 478
     /**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
     public function sandbox_notice() {
482 482
 
483 483
         return sprintf(
484
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
484
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
485 485
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
486 486
 			'</a>'
487 487
 		);
@@ -493,32 +493,32 @@  discard block
 block discarded – undo
493 493
 	 *
494 494
 	 * @param array $admin_settings
495 495
 	 */
496
-	public function admin_settings( $admin_settings ) {
496
+	public function admin_settings($admin_settings) {
497 497
 
498 498
         $currencies = sprintf(
499
-            __( 'Supported Currencies: %s', 'invoicing' ),
500
-            implode( ', ', $this->currencies )
499
+            __('Supported Currencies: %s', 'invoicing'),
500
+            implode(', ', $this->currencies)
501 501
         );
502 502
 
503 503
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
504
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
504
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
505 505
 
506 506
 		// Access tokens.
507
-        $live_account    = wpinv_get_option( 'paypal_live_access_token' );
508
-        $sandbox_account = wpinv_get_option( 'paypal_test_access_token' );
507
+        $live_account    = wpinv_get_option('paypal_live_access_token');
508
+        $sandbox_account = wpinv_get_option('paypal_test_access_token');
509 509
 
510 510
 		$admin_settings['paypal_connect'] = array(
511 511
 			'type'       => 'raw_html',
512 512
 			'id'         => 'paypal_connect',
513
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
513
+			'name'       => __('Connect to PayPal', 'invoicing'),
514 514
 			'desc'       => sprintf(
515 515
 				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a><br><strong style="color: green">%s</strong></div>%s',
516
-				esc_url( self::get_connect_url( false ) ),
517
-				__( 'Connect to PayPal', 'invoicing' ),
518
-				__( 'Connected', 'invoicing' ),
519
-				esc_url( self::get_connect_url( true ) ),
520
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
521
-				__( 'Connected', 'invoicing' ),
516
+				esc_url(self::get_connect_url(false)),
517
+				__('Connect to PayPal', 'invoicing'),
518
+				__('Connected', 'invoicing'),
519
+				esc_url(self::get_connect_url(true)),
520
+				__('Connect to PayPal Sandox', 'invoicing'),
521
+				__('Connected', 'invoicing'),
522 522
 				$this->get_js()
523 523
 			),
524 524
 		);
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 		$admin_settings['disable_paypal_connect'] = array(
527 527
 			'type'       => 'checkbox',
528 528
 			'id'         => 'disable_paypal_connect',
529
-			'name'       => __( 'Manual Mode', 'invoicing' ),
530
-			'desc'       => __( 'Manually enter your credentials', 'invoicing' ),
529
+			'name'       => __('Manual Mode', 'invoicing'),
530
+			'desc'       => __('Manually enter your credentials', 'invoicing'),
531 531
 			'std'        => false,
532 532
 		);
533 533
 
@@ -535,67 +535,67 @@  discard block
 block discarded – undo
535 535
             'type'  => 'text',
536 536
 			'class' => 'live-auth-data',
537 537
             'id'    => 'paypal_email',
538
-            'name'  => __( 'Live Email Address', 'invoicing' ),
539
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
538
+            'name'  => __('Live Email Address', 'invoicing'),
539
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
540 540
         );
541 541
 
542 542
 		$admin_settings['paypal_merchant_id'] = array(
543 543
             'type'  => 'text',
544 544
 			'class' => 'live-auth-data',
545 545
             'id'    => 'paypal_merchant_id',
546
-            'name'  => __( 'Live Merchant ID', 'invoicing' ),
546
+            'name'  => __('Live Merchant ID', 'invoicing'),
547 547
         );
548 548
 
549 549
 		$admin_settings['paypal_client_id'] = array(
550 550
             'type'  => 'text',
551 551
 			'class' => 'live-auth-data',
552 552
             'id'    => 'paypal_client_id',
553
-            'name'  => __( 'Live Client ID', 'invoicing' ),
553
+            'name'  => __('Live Client ID', 'invoicing'),
554 554
         );
555 555
 
556 556
 		$admin_settings['paypal_client_secret'] = array(
557 557
             'type'  => 'text',
558 558
 			'class' => 'live-auth-data',
559 559
             'id'    => 'paypal_client_secret',
560
-            'name'  => __( 'Live Client Secret', 'invoicing' ),
560
+            'name'  => __('Live Client Secret', 'invoicing'),
561 561
         );
562 562
 
563 563
 		$admin_settings['paypal_sandbox_email'] = array(
564 564
             'type'  => 'text',
565 565
 			'class' => 'sandbox-auth-data',
566 566
             'id'    => 'paypal_sandbox_email',
567
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
568
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
569
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
567
+            'name'  => __('Sandbox Email Address', 'invoicing'),
568
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
569
+			'std'   => wpinv_get_option('paypal_email', ''),
570 570
         );
571 571
 
572 572
 		$admin_settings['paypal_sandbox_merchant_id'] = array(
573 573
             'type'  => 'text',
574 574
 			'class' => 'sandbox-auth-data',
575 575
             'id'    => 'paypal_sandbox_merchant_id',
576
-            'name'  => __( 'Sandbox Merchant ID', 'invoicing' ),
576
+            'name'  => __('Sandbox Merchant ID', 'invoicing'),
577 577
         );
578 578
 
579 579
 		$admin_settings['paypal_sandbox_client_id'] = array(
580 580
             'type'  => 'text',
581 581
 			'class' => 'sandbox-auth-data',
582 582
             'id'    => 'paypal_sandbox_client_id',
583
-            'name'  => __( 'Sandbox Client ID', 'invoicing' ),
583
+            'name'  => __('Sandbox Client ID', 'invoicing'),
584 584
         );
585 585
 
586 586
 		$admin_settings['paypal_sandbox_client_secret'] = array(
587 587
             'type'  => 'text',
588 588
 			'class' => 'sandbox-auth-data',
589 589
             'id'    => 'paypal_sandbox_client_secret',
590
-            'name'  => __( 'Sandbox Client Secret', 'invoicing' ),
590
+            'name'  => __('Sandbox Client Secret', 'invoicing'),
591 591
         );
592 592
 
593 593
         $admin_settings['paypal_ipn_url'] = array(
594 594
             'type'     => 'ipn_url',
595 595
             'id'       => 'paypal_ipn_url',
596
-            'name'     => __( 'IPN Url', 'invoicing' ),
596
+            'name'     => __('IPN Url', 'invoicing'),
597 597
             'std'      => $this->notify_url,
598
-            '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>',
598
+            '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>',
599 599
             'readonly' => true,
600 600
         );
601 601
 
@@ -609,24 +609,24 @@  discard block
 block discarded – undo
609 609
      * @param bool $is_sandbox
610 610
      * @return string
611 611
 	 */
612
-	public static function get_connect_url( $is_sandbox ) {
612
+	public static function get_connect_url($is_sandbox) {
613 613
 
614 614
         $redirect_url = add_query_arg(
615 615
             array(
616 616
                 'getpaid-admin-action' => 'connect_paypal',
617 617
                 'page'                 => 'wpinv-settings',
618
-                'live_mode'            => (int) empty( $is_sandbox ),
618
+                'live_mode'            => (int) empty($is_sandbox),
619 619
                 'tab'                  => 'gateways',
620 620
                 'section'              => 'paypal',
621
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
621
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
622 622
             ),
623
-            admin_url( 'admin.php' )
623
+            admin_url('admin.php')
624 624
         );
625 625
 
626 626
         return add_query_arg(
627 627
             array(
628
-                'live_mode'    => (int) empty( $is_sandbox ),
629
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) )
628
+                'live_mode'    => (int) empty($is_sandbox),
629
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url))
630 630
             ),
631 631
             'https://ayecode.io/oauth/paypal'
632 632
         );
@@ -690,26 +690,26 @@  discard block
 block discarded – undo
690 690
 	 * @param array $data Connection data.
691 691
 	 * @return void
692 692
 	 */
693
-	public function connect_paypal( $data ) {
693
+	public function connect_paypal($data) {
694 694
 
695 695
 		$sandbox      = $this->is_sandbox();
696
-		$data         = wp_unslash( $data );
697
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
696
+		$data         = wp_unslash($data);
697
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
698 698
 
699
-		if ( isset( $data['live_mode'] ) ) {
700
-			$sandbox = empty( $data['live_mode'] );
699
+		if (isset($data['live_mode'])) {
700
+			$sandbox = empty($data['live_mode']);
701 701
 		}
702 702
 
703
-		wpinv_update_option( 'stripe_sandbox', (int) $sandbox );
704
-		wpinv_update_option( 'stripe_active', 1 );
703
+		wpinv_update_option('stripe_sandbox', (int) $sandbox);
704
+		wpinv_update_option('stripe_active', 1);
705 705
 
706
-		if ( ! empty( $data['error_description'] ) ) {
707
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
706
+		if (!empty($data['error_description'])) {
707
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
708 708
 		} else {
709 709
 
710 710
 			// Retrieve the user info.
711 711
 			$user_info = wp_remote_get(
712
-				! $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',
712
+				!$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',
713 713
 				array(
714 714
 
715 715
 					'headers' => array(
@@ -720,23 +720,23 @@  discard block
 block discarded – undo
720 720
 				)
721 721
 			);
722 722
 
723
-			if ( is_wp_error( $user_info ) ) {
724
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
723
+			if (is_wp_error($user_info)) {
724
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
725 725
 			} else {
726 726
 
727 727
 				// Create application.
728
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
728
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
729 729
 				$app       = wp_remote_post(
730
-					! $sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
730
+					!$sandbox ? 'https://api-m.paypal.com/v1/identity/applications' : 'https://api-m.sandbox.paypal.com/v1/identity/applications',
731 731
 					array(
732 732
 
733 733
 						'body'    => array(
734 734
 							'application_type' => 'web',
735 735
 							'redirect_uris'    => array(
736
-								add_query_arg( 'getpaid_oauth', 'paypal', home_url() ),
736
+								add_query_arg('getpaid_oauth', 'paypal', home_url()),
737 737
 							),
738 738
 							'client_name'      => 'GetPaid',
739
-							'contacts'         => array( $user_info->emails[0]->value ),
739
+							'contacts'         => array($user_info->emails[0]->value),
740 740
 							'payer_id'         => $user_info->payer_id,
741 741
 							'migrated_app'     => '',
742 742
 						),
@@ -748,29 +748,29 @@  discard block
 block discarded – undo
748 748
 					)
749 749
 				);
750 750
 
751
-				if ( is_wp_error( $app ) ) {
752
-					getpaid_admin()->show_error( wp_kses_post( $app->get_error_message() ) );
751
+				if (is_wp_error($app)) {
752
+					getpaid_admin()->show_error(wp_kses_post($app->get_error_message()));
753 753
 				} else {
754 754
 
755
-					$app = json_decode( $app );
756
-					if ( $sandbox ) {
757
-						wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
758
-						wpinv_update_option( 'paypal_sandbox_merchant_id', '' );
759
-						wpinv_update_option( 'paypal_sandbox_client_id', sanitize_text_field( $app->client_id ) );
760
-						wpinv_update_option( 'paypal_sandbox_client_secret', sanitize_text_field( $app->client_secret ) );
761
-						wpinv_update_option( 'paypal_sandbox_client_secret_expires_at', sanitize_text_field( $app->client_secret_expires_at ) );
762
-						wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
763
-						set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
764
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'wpinv-stripe' ) );
755
+					$app = json_decode($app);
756
+					if ($sandbox) {
757
+						wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
758
+						wpinv_update_option('paypal_sandbox_merchant_id', '');
759
+						wpinv_update_option('paypal_sandbox_client_id', sanitize_text_field($app->client_id));
760
+						wpinv_update_option('paypal_sandbox_client_secret', sanitize_text_field($app->client_secret));
761
+						wpinv_update_option('paypal_sandbox_client_secret_expires_at', sanitize_text_field($app->client_secret_expires_at));
762
+						wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
763
+						set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
764
+						getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'wpinv-stripe'));
765 765
 					} else {
766
-						wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
767
-						wpinv_update_option( 'paypal_merchant_id', '' );
768
-						wpinv_update_option( 'paypal_client_id', sanitize_text_field( $app->client_id ) );
769
-						wpinv_update_option( 'paypal_client_secret', sanitize_text_field( $app->client_secret ) );
770
-						wpinv_update_option( 'paypal_client_secret_expires_at', sanitize_text_field( $app->client_secret_expires_at ) );
771
-						wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
772
-						set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
773
-						getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'wpinv-stripe' ) );
766
+						wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
767
+						wpinv_update_option('paypal_merchant_id', '');
768
+						wpinv_update_option('paypal_client_id', sanitize_text_field($app->client_id));
769
+						wpinv_update_option('paypal_client_secret', sanitize_text_field($app->client_secret));
770
+						wpinv_update_option('paypal_client_secret_expires_at', sanitize_text_field($app->client_secret_expires_at));
771
+						wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
772
+						set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
773
+						getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'wpinv-stripe'));
774 774
 					}
775 775
 
776 776
 				}
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 
780 780
 		}
781 781
 
782
-		wp_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) );
782
+		wp_redirect(admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal'));
783 783
 		exit;
784 784
 	}
785 785
 
Please login to merge, or discard this patch.