Passed
Push — master ( 35ff88...03949c )
by Brian
04:42
created
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +145 added lines, -145 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,23 +371,23 @@  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 384
 		// Convert 365 days to 1 year.
385
-		if ( 'D' == $period && 365 == $interval ) {
385
+		if ('D' == $period && 365 == $interval) {
386 386
 			$period = 'Y';
387 387
 			$interval = 1;
388 388
 		}
389 389
 
390
-        if ( $subscription_item->has_free_trial() ) {
390
+        if ($subscription_item->has_free_trial()) {
391 391
 
392 392
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
393 393
 
@@ -397,28 +397,28 @@  discard block
 block discarded – undo
397 397
 			// Trial period.
398 398
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
399 399
 
400
-        } else if ( $initial_amount != $recurring_amount ) {
400
+        } else if ($initial_amount != $recurring_amount) {
401 401
 
402 402
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
403 403
 
404
-            if ( 1 == $bill_times ) {
404
+            if (1 == $bill_times) {
405 405
                 $param_number = 3;
406 406
             } else {
407 407
                 $param_number = 1;
408 408
             }
409 409
 
410
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
410
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
411 411
 
412 412
             // Sign Up interval
413
-            $paypal_args[ 'p' . $param_number ] = $interval;
413
+            $paypal_args['p' . $param_number] = $interval;
414 414
 
415 415
             // Sign Up unit of duration
416
-            $paypal_args[ 't' . $param_number ] = $period;
416
+            $paypal_args['t' . $param_number] = $period;
417 417
 
418 418
         }
419 419
 
420 420
         // We have a recurring payment
421
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
421
+		if (!isset($param_number) || 1 == $param_number) {
422 422
 
423 423
 			// Subscription price
424 424
 			$paypal_args['a3'] = $recurring_amount;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         }
433 433
 
434 434
         // Recurring payments
435
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
435
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
436 436
 
437 437
 			// Non-recurring payments
438 438
 			$paypal_args['src'] = 0;
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 
442 442
 			$paypal_args['src'] = 1;
443 443
 
444
-			if ( $bill_times > 0 ) {
444
+			if ($bill_times > 0) {
445 445
 
446 446
 				// An initial period is being used to charge a sign-up fee
447
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
447
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
448 448
 					$bill_times--;
449 449
 				}
450 450
 
451 451
                 // Make sure it's not over the max of 52
452
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
452
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
453 453
 
454 454
 			}
455 455
         }
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
         $paypal_args['rm'] = 2;
459 459
 
460 460
         // Get rid of redudant items.
461
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
461
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
462 462
 
463
-            if ( isset( $paypal_args[ $arg ] ) ) {
464
-                unset( $paypal_args[ $arg ] );
463
+            if (isset($paypal_args[$arg])) {
464
+                unset($paypal_args[$arg]);
465 465
             }
466 466
 
467 467
         }
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return void
481 481
 	 */
482 482
 	public function verify_ipn() {
483
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
483
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
484 484
     }
485 485
 
486 486
     /**
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
492
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
493 493
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494 494
 			'</a>'
495 495
 		);
@@ -501,30 +501,30 @@  discard block
 block discarded – undo
501 501
 	 *
502 502
 	 * @param array $admin_settings
503 503
 	 */
504
-	public function admin_settings( $admin_settings ) {
504
+	public function admin_settings($admin_settings) {
505 505
 
506 506
         $currencies = sprintf(
507
-            __( 'Supported Currencies: %s', 'invoicing' ),
508
-            implode( ', ', $this->currencies )
507
+            __('Supported Currencies: %s', 'invoicing'),
508
+            implode(', ', $this->currencies)
509 509
         );
510 510
 
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
512
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
513 513
 
514 514
 		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
515
+		$live_email      = wpinv_get_option('paypal_email');
516
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
517 517
 
518 518
 		$admin_settings['paypal_connect'] = array(
519 519
 			'type'       => 'raw_html',
520 520
 			'id'         => 'paypal_connect',
521
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
521
+			'name'       => __('Connect to PayPal', 'invoicing'),
522 522
 			'desc'       => sprintf(
523 523
 				'<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',
524
-				esc_url( self::get_connect_url( false ) ),
525
-				__( 'Connect to PayPal', 'invoicing' ),
526
-				esc_url( self::get_connect_url( true ) ),
527
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
524
+				esc_url(self::get_connect_url(false)),
525
+				__('Connect to PayPal', 'invoicing'),
526
+				esc_url(self::get_connect_url(true)),
527
+				__('Connect to PayPal Sandox', 'invoicing'),
528 528
 				$this->get_js()
529 529
 			),
530 530
 		);
@@ -533,25 +533,25 @@  discard block
 block discarded – undo
533 533
             'type'  => 'text',
534 534
 			'class' => 'live-auth-data',
535 535
             'id'    => 'paypal_email',
536
-            'name'  => __( 'Live Email Address', 'invoicing' ),
537
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
536
+            'name'  => __('Live Email Address', 'invoicing'),
537
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
538 538
         );
539 539
 
540 540
 		$admin_settings['paypal_sandbox_email'] = array(
541 541
             'type'  => 'text',
542 542
 			'class' => 'sandbox-auth-data',
543 543
             'id'    => 'paypal_sandbox_email',
544
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
545
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
546
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
544
+            'name'  => __('Sandbox Email Address', 'invoicing'),
545
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
546
+			'std'   => wpinv_get_option('paypal_email', ''),
547 547
         );
548 548
 
549 549
         $admin_settings['paypal_ipn_url'] = array(
550 550
             'type'     => 'ipn_url',
551 551
             'id'       => 'paypal_ipn_url',
552
-            'name'     => __( 'IPN Url', 'invoicing' ),
552
+            'name'     => __('IPN Url', 'invoicing'),
553 553
             'std'      => $this->notify_url,
554
-            '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>',
554
+            '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>',
555 555
             'readonly' => true,
556 556
         );
557 557
 
@@ -565,8 +565,8 @@  discard block
 block discarded – undo
565 565
      * @param array $data
566 566
      * @return string
567 567
 	 */
568
-	public static function maybe_get_connect_url( $url = '', $data ) {
569
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
568
+	public static function maybe_get_connect_url($url = '', $data) {
569
+		return self::get_connect_url(false, urldecode($data['redirect']));
570 570
 	}
571 571
 
572 572
 	/**
@@ -577,25 +577,25 @@  discard block
 block discarded – undo
577 577
 	 * @param string $redirect
578 578
      * @return string
579 579
 	 */
580
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
580
+	public static function get_connect_url($is_sandbox, $redirect = '') {
581 581
 
582 582
         $redirect_url = add_query_arg(
583 583
             array(
584 584
                 'getpaid-admin-action' => 'connect_paypal',
585 585
                 'page'                 => 'wpinv-settings',
586
-                'live_mode'            => (int) empty( $is_sandbox ),
586
+                'live_mode'            => (int) empty($is_sandbox),
587 587
                 'tab'                  => 'gateways',
588 588
                 'section'              => 'paypal',
589
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
590
-				'redirect'             => urlencode( $redirect ),
589
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
590
+				'redirect'             => urlencode($redirect),
591 591
             ),
592
-            admin_url( 'admin.php' )
592
+            admin_url('admin.php')
593 593
         );
594 594
 
595 595
         return add_query_arg(
596 596
             array(
597
-                'live_mode'    => (int) empty( $is_sandbox ),
598
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) )
597
+                'live_mode'    => (int) empty($is_sandbox),
598
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url))
599 599
             ),
600 600
             'https://ayecode.io/oauth/paypal'
601 601
         );
@@ -649,26 +649,26 @@  discard block
 block discarded – undo
649 649
 	 * @param array $data Connection data.
650 650
 	 * @return void
651 651
 	 */
652
-	public function connect_paypal( $data ) {
652
+	public function connect_paypal($data) {
653 653
 
654 654
 		$sandbox      = $this->is_sandbox();
655
-		$data         = wp_unslash( $data );
656
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
655
+		$data         = wp_unslash($data);
656
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
657 657
 
658
-		if ( isset( $data['live_mode'] ) ) {
659
-			$sandbox = empty( $data['live_mode'] );
658
+		if (isset($data['live_mode'])) {
659
+			$sandbox = empty($data['live_mode']);
660 660
 		}
661 661
 
662
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
663
-		wpinv_update_option( 'paypal_active', 1 );
662
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
663
+		wpinv_update_option('paypal_active', 1);
664 664
 
665
-		if ( ! empty( $data['error_description'] ) ) {
666
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
665
+		if (!empty($data['error_description'])) {
666
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
667 667
 		} else {
668 668
 
669 669
 			// Retrieve the user info.
670 670
 			$user_info = wp_remote_get(
671
-				! $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',
671
+				!$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',
672 672
 				array(
673 673
 
674 674
 					'headers' => array(
@@ -679,35 +679,35 @@  discard block
 block discarded – undo
679 679
 				)
680 680
 			);
681 681
 
682
-			if ( is_wp_error( $user_info ) ) {
683
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
682
+			if (is_wp_error($user_info)) {
683
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
684 684
 			} else {
685 685
 
686 686
 				// Create application.
687
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
687
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
688 688
 
689
-				if ( $sandbox ) {
690
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
691
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
692
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
693
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
689
+				if ($sandbox) {
690
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
691
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
692
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
693
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
694 694
 				} else {
695
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
696
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
697
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
698
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
695
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
696
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
697
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
698
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
699 699
 				}
700 700
 
701 701
 			}
702 702
 
703 703
 		}
704 704
 
705
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
705
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
706 706
 
707
-		if ( isset( $data['step'] ) ) {
708
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
707
+		if (isset($data['step'])) {
708
+			$redirect = add_query_arg('step', $data['step'], $redirect);
709 709
 		}
710
-		wp_redirect( $redirect );
710
+		wp_redirect($redirect);
711 711
 		exit;
712 712
 	}
713 713
 
Please login to merge, or discard this patch.