Passed
Push — master ( 82fd8c...abf543 )
by Brian
04:42
created
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Spacing   +175 added lines, -175 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' );
27
+    protected $supports = array('subscription', 'sandbox');
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,13 +80,13 @@  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( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
88
+        add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
89
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
90 90
 
91 91
         parent::__construct();
92 92
     }
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101 101
 	 * @return array
102 102
 	 */
103
-	public function process_payment( $invoice, $submission_data, $submission ) {
103
+	public function process_payment($invoice, $submission_data, $submission) {
104 104
 
105 105
         // Get redirect url.
106
-        $paypal_redirect = $this->get_request_url( $invoice );
106
+        $paypal_redirect = $this->get_request_url($invoice);
107 107
 
108 108
         // Add a note about the request url.
109 109
         $invoice->add_note(
110 110
             sprintf(
111
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
112
-                esc_url( $paypal_redirect )
111
+                __('Redirecting to PayPal: %s', 'invoicing'),
112
+                esc_url($paypal_redirect)
113 113
             ),
114 114
             false,
115 115
             false,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         );
118 118
 
119 119
         // Redirect to PayPal
120
-        wp_redirect( $paypal_redirect );
120
+        wp_redirect($paypal_redirect);
121 121
         exit;
122 122
 
123 123
     }
@@ -128,21 +128,21 @@  discard block
 block discarded – undo
128 128
 	 * @param  WPInv_Invoice $invoice Invoice object.
129 129
 	 * @return string
130 130
 	 */
131
-	public function get_request_url( $invoice ) {
131
+	public function get_request_url($invoice) {
132 132
 
133 133
         // Endpoint for this request
134
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
134
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
135 135
 
136 136
         // Retrieve paypal args.
137
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
137
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
138 138
 
139
-        if ( $invoice->is_recurring() ) {
139
+        if ($invoice->is_recurring()) {
140 140
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
141 141
         } else {
142 142
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
143 143
         }
144 144
 
145
-        return add_query_arg( $paypal_args, $this->endpoint );
145
+        return add_query_arg($paypal_args, $this->endpoint);
146 146
 
147 147
 	}
148 148
 
@@ -152,25 +152,25 @@  discard block
 block discarded – undo
152 152
 	 * @param  WPInv_Invoice $invoice Invoice object.
153 153
 	 * @return array
154 154
 	 */
155
-	protected function get_paypal_args( $invoice ) {
155
+	protected function get_paypal_args($invoice) {
156 156
 
157 157
         // Whether or not to send the line items as one item.
158
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
158
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice);
159 159
 
160
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
160
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
161 161
 			$force_one_line_item = true;
162 162
 		}
163 163
 
164 164
 		$paypal_args = apply_filters(
165 165
 			'getpaid_paypal_args',
166 166
 			array_merge(
167
-				$this->get_transaction_args( $invoice ),
168
-				$this->get_line_item_args( $invoice, $force_one_line_item )
167
+				$this->get_transaction_args($invoice),
168
+				$this->get_line_item_args($invoice, $force_one_line_item)
169 169
 			),
170 170
 			$invoice
171 171
 		);
172 172
 
173
-		return $this->fix_request_length( $invoice, $paypal_args );
173
+		return $this->fix_request_length($invoice, $paypal_args);
174 174
     }
175 175
 
176 176
     /**
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 	 * @param WPInv_Invoice $invoice Invoice object.
180 180
 	 * @return array
181 181
 	 */
182
-	protected function get_transaction_args( $invoice ) {
182
+	protected function get_transaction_args($invoice) {
183 183
 
184 184
 		return array(
185 185
             'cmd'           => '_cart',
186
-            'business'      => wpinv_get_option( 'paypal_email', false ),
186
+            'business'      => wpinv_get_option('paypal_email', false),
187 187
             'no_shipping'   => '1',
188 188
             'shipping'      => '0',
189 189
             'no_note'       => '1',
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
             'rm'            => is_ssl() ? 2 : 1,
192 192
             'upload'        => 1,
193 193
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
194
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
195
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
196
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
197
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
194
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
195
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
196
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
197
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
198 198
             'custom'        => $invoice->get_id(),
199
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
200
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
201
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
202
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
203
-            'cbt'           => get_bloginfo( 'name' )
199
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
200
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
201
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
202
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
203
+            'cbt'           => get_bloginfo('name')
204 204
         );
205 205
 
206 206
     }
@@ -212,30 +212,30 @@  discard block
 block discarded – undo
212 212
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
213 213
 	 * @return array
214 214
 	 */
215
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
215
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
216 216
 
217 217
         // Maybe send invoice as a single item.
218
-		if ( $force_one_line_item ) {
219
-            return $this->get_line_item_args_single_item( $invoice );
218
+		if ($force_one_line_item) {
219
+            return $this->get_line_item_args_single_item($invoice);
220 220
         }
221 221
 
222 222
         // Send each line item individually.
223 223
         $line_item_args = array();
224 224
 
225 225
         // Prepare line items.
226
-        $this->prepare_line_items( $invoice );
226
+        $this->prepare_line_items($invoice);
227 227
 
228 228
         // Add taxes to the cart
229
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
230
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
229
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
230
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
231 231
         }
232 232
 
233 233
         // Add discount.
234
-        if ( $invoice->get_total_discount() > 0 ) {
235
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
234
+        if ($invoice->get_total_discount() > 0) {
235
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
236 236
         }
237 237
 
238
-		return array_merge( $line_item_args, $this->get_line_items() );
238
+		return array_merge($line_item_args, $this->get_line_items());
239 239
 
240 240
     }
241 241
 
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 	 * @param  WPInv_Invoice $invoice Invoice object.
246 246
 	 * @return array
247 247
 	 */
248
-	protected function get_line_item_args_single_item( $invoice ) {
248
+	protected function get_line_item_args_single_item($invoice) {
249 249
 		$this->delete_line_items();
250 250
 
251
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
252
-		$this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
251
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
252
+		$this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id());
253 253
 
254 254
 		return $this->get_line_items();
255 255
     }
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @param  WPInv_Invoice $invoice Invoice object.
275 275
 	 */
276
-	protected function prepare_line_items( $invoice ) {
276
+	protected function prepare_line_items($invoice) {
277 277
 		$this->delete_line_items();
278 278
 
279 279
 		// Items.
280
-		foreach ( $invoice->get_items() as $item ) {
280
+		foreach ($invoice->get_items() as $item) {
281 281
 			$amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282 282
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
283
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
284 284
         }
285 285
 
286 286
         // Fees.
287
-		foreach ( $invoice->get_fees() as $fee => $data ) {
288
-            $this->add_line_item( $fee, 1, $data['amount'] );
287
+		foreach ($invoice->get_fees() as $fee => $data) {
288
+            $this->add_line_item($fee, 1, $data['amount']);
289 289
         }
290 290
 
291 291
     }
@@ -298,15 +298,15 @@  discard block
 block discarded – undo
298 298
 	 * @param  float  $amount Amount.
299 299
 	 * @param  string $item_number Item number.
300 300
 	 */
301
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
-		$index = ( count( $this->line_items ) / 4 ) + 1;
301
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
302
+		$index = (count($this->line_items) / 4) + 1;
303 303
 
304 304
 		$item = apply_filters(
305 305
 			'getpaid_paypal_line_item',
306 306
 			array(
307
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
307
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
308 308
 				'quantity'    => (int) $quantity,
309
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
309
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
310 310
 				'item_number' => $item_number,
311 311
 			),
312 312
 			$item_name,
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 			$item_number
316 316
 		);
317 317
 
318
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
319
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
318
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
319
+        $this->line_items['quantity_' . $index] = $item['quantity'];
320 320
         
321 321
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
322
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+		$this->line_items['amount_' . $index]      = $item['amount'];
323
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
324 324
     }
325 325
 
326 326
     /**
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
333 333
 	 * @return array
334 334
 	 */
335
-	protected function fix_request_length( $invoice, $paypal_args ) {
335
+	protected function fix_request_length($invoice, $paypal_args) {
336 336
 		$max_paypal_length = 2083;
337
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
337
+		$query_candidate   = http_build_query($paypal_args, '', '&');
338 338
 
339
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
339
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
340 340
 			return $paypal_args;
341 341
 		}
342 342
 
343 343
 		return apply_filters(
344 344
 			'getpaid_paypal_args',
345 345
 			array_merge(
346
-				$this->get_transaction_args( $invoice ),
347
-				$this->get_line_item_args( $invoice, true )
346
+				$this->get_transaction_args($invoice),
347
+				$this->get_line_item_args($invoice, true)
348 348
 			),
349 349
 			$invoice
350 350
 		);
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	 * @param  array $paypal_args PayPal args.
358 358
 	 * @param  WPInv_Invoice    $invoice Invoice object.
359 359
 	 */
360
-	public function process_subscription( $paypal_args, $invoice ) {
360
+	public function process_subscription($paypal_args, $invoice) {
361 361
 
362 362
         // Make sure this is a subscription.
363
-        if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) {
363
+        if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) {
364 364
             return $paypal_args;
365 365
         }
366 366
 
@@ -368,17 +368,17 @@  discard block
 block discarded – undo
368 368
         $paypal_args['cmd'] = '_xclick-subscriptions';
369 369
 
370 370
         // Subscription name.
371
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
371
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
372 372
 
373 373
         // Get subscription args.
374
-        $period                 = strtoupper( substr( $subscription->period, 0, 1) );
374
+        $period                 = strtoupper(substr($subscription->period, 0, 1));
375 375
         $interval               = (int) $subscription->frequency;
376 376
         $bill_times             = (int) $subscription->bill_times;
377
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
378
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
379
-        $subscription_item      = $invoice->get_recurring( true );
377
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
378
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
379
+        $subscription_item      = $invoice->get_recurring(true);
380 380
 
381
-        if ( $subscription_item->has_free_trial() ) {
381
+        if ($subscription_item->has_free_trial()) {
382 382
 
383 383
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
384 384
 
@@ -388,28 +388,28 @@  discard block
 block discarded – undo
388 388
 			// Trial period.
389 389
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
390 390
 
391
-        } else if ( $initial_amount != $recurring_amount ) {
391
+        } else if ($initial_amount != $recurring_amount) {
392 392
 
393 393
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
394 394
 
395
-            if ( 1 == $bill_times ) {
395
+            if (1 == $bill_times) {
396 396
                 $param_number = 3;
397 397
             } else {
398 398
                 $param_number = 1;
399 399
             }
400 400
 
401
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount;
401
+            $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount;
402 402
 
403 403
             // Sign Up interval
404
-            $paypal_args[ 'p' . $param_number ] = $interval;
404
+            $paypal_args['p' . $param_number] = $interval;
405 405
 
406 406
             // Sign Up unit of duration
407
-            $paypal_args[ 't' . $param_number ] = $period;
407
+            $paypal_args['t' . $param_number] = $period;
408 408
 
409 409
         }
410 410
 
411 411
         // We have a recurring payment
412
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
412
+		if (!isset($param_number) || 1 == $param_number) {
413 413
 
414 414
 			// Subscription price
415 415
 			$paypal_args['a3'] = $recurring_amount;
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         }
424 424
         
425 425
         // Recurring payments
426
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
426
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
427 427
 
428 428
 			// Non-recurring payments
429 429
 			$paypal_args['src'] = 0;
@@ -432,15 +432,15 @@  discard block
 block discarded – undo
432 432
 
433 433
 			$paypal_args['src'] = 1;
434 434
 
435
-			if ( $bill_times > 0 ) {
435
+			if ($bill_times > 0) {
436 436
 
437 437
 				// An initial period is being used to charge a sign-up fee
438
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
438
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
439 439
 					$bill_times--;
440 440
 				}
441 441
 
442 442
                 // Make sure it's not over the max of 52
443
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
443
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
444 444
 
445 445
 			}
446 446
         }
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
         $paypal_args['rm'] = 2;
450 450
         
451 451
         // Get rid of redudant items.
452
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
452
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
453 453
 
454
-            if ( isset( $paypal_args[ $arg ] ) ) {
455
-                unset( $paypal_args[ $arg ] );
454
+            if (isset($paypal_args[$arg])) {
455
+                unset($paypal_args[$arg]);
456 456
             }
457 457
 
458 458
         }
@@ -473,26 +473,26 @@  discard block
 block discarded – undo
473 473
 	public function verify_ipn() {
474 474
 
475 475
         // Validate the IPN.
476
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
477
-		    wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) );
476
+        if (empty($_POST) || !$this->validate_ipn()) {
477
+		    wp_die('PayPal IPN Request Failure', 'PayPal IPN', array('response' => 500));
478 478
 		}
479 479
 
480 480
         // Process the IPN.
481
-        $posted  = wp_unslash( $_POST );
482
-        $invoice = wpinv_get_invoice( $posted['custom'] );
481
+        $posted  = wp_unslash($_POST);
482
+        $invoice = wpinv_get_invoice($posted['custom']);
483 483
 
484
-        if ( $invoice && $this->id == $invoice->get_gateway() ) {
484
+        if ($invoice && $this->id == $invoice->get_gateway()) {
485 485
 
486
-            $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) );
487
-            $posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
486
+            $posted['payment_status'] = sanitize_key(strtolower($posted['payment_status']));
487
+            $posted['txn_type']       = sanitize_key(strtolower($posted['txn_type']));
488 488
 
489
-            wpinv_error_log( 'Found invoice #' . $invoice->get_number() );
490
-            wpinv_error_log( 'Payment status:' . $posted['payment_status'] );
489
+            wpinv_error_log('Found invoice #' . $invoice->get_number());
490
+            wpinv_error_log('Payment status:' . $posted['payment_status']);
491 491
 
492
-			if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
493
-				call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
492
+			if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) {
493
+				call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted);
494 494
             } else {
495
-                wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] );
495
+                wpinv_error_log('Aborting, Invalid type:' . $posted['txn_type']);
496 496
             }
497 497
 
498 498
         }
@@ -506,10 +506,10 @@  discard block
 block discarded – undo
506 506
 	 */
507 507
 	public function validate_ipn() {
508 508
 
509
-		wpinv_error_log( 'Validating PayPal IPN response' );
509
+		wpinv_error_log('Validating PayPal IPN response');
510 510
 
511 511
 		// Get received values from post data.
512
-		$validate_ipn        = wp_unslash( $_POST );
512
+		$validate_ipn        = wp_unslash($_POST);
513 513
 		$validate_ipn['cmd'] = '_notify-validate';
514 514
 
515 515
 		// Send back post vars to paypal.
@@ -523,18 +523,18 @@  discard block
 block discarded – undo
523 523
 		);
524 524
 
525 525
 		// Post back to get a response.
526
-		$response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
526
+		$response = wp_safe_remote_post($this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params);
527 527
 
528 528
         // Check to see if the request was valid.
529
-		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
530
-            wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' );
529
+		if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) {
530
+            wpinv_error_log($response['body'], 'Received valid response from PayPal IPN');
531 531
 			return true;
532 532
         }
533 533
 
534
-        if ( is_wp_error( $response ) ) {
535
-            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
534
+        if (is_wp_error($response)) {
535
+            wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN');
536 536
         } else {
537
-            wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
537
+            wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN');
538 538
         }
539 539
 
540 540
         return false;
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
 	 * @param WPInv_Invoice $invoice          Invoice object.
548 548
 	 * @param string   $currency currency to validate.
549 549
 	 */
550
-	protected function validate_ipn_currency( $invoice, $currency ) {
551
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
552
-            wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" );
550
+	protected function validate_ipn_currency($invoice, $currency) {
551
+		if (strtolower($invoice->get_currency()) !== strtolower($currency)) {
552
+            wpinv_record_gateway_error('IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}");
553 553
 
554 554
 			/* translators: %s: currency code. */
555
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
555
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency));
556 556
 			exit;
557 557
 		}
558 558
 	}
@@ -563,12 +563,12 @@  discard block
 block discarded – undo
563 563
 	 * @param WPInv_Invoice $invoice          Invoice object.
564 564
 	 * @param float   $amount amount to validate.
565 565
 	 */
566
-	protected function validate_ipn_amount( $invoice, $amount ) {
567
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
568
-            wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" );
566
+	protected function validate_ipn_amount($invoice, $amount) {
567
+		if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) {
568
+            wpinv_record_gateway_error('IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}");
569 569
 
570 570
 			/* translators: %s: Amount. */
571
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
571
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount));
572 572
 			exit;
573 573
 		}
574 574
 	}
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
 	 * @param WPInv_Invoice $invoice          Invoice object.
580 580
 	 * @param string   $receiver_email Email to validate.
581 581
 	 */
582
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
583
-        $paypal_email = wpinv_get_option( 'paypal_email' );
582
+	protected function validate_ipn_receiver_email($invoice, $receiver_email) {
583
+        $paypal_email = wpinv_get_option('paypal_email');
584 584
 
585
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
586
-            wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
585
+		if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) {
586
+            wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}");
587 587
 
588 588
 			/* translators: %s: email address . */
589
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
589
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email));
590 590
 			exit;
591 591
         }
592 592
 
@@ -598,57 +598,57 @@  discard block
 block discarded – undo
598 598
 	 * @param WPInv_Invoice $invoice  Invoice object.
599 599
 	 * @param array    $posted Posted data.
600 600
 	 */
601
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
601
+	protected function ipn_txn_web_accept($invoice, $posted) {
602 602
 
603 603
         // Collect payment details
604
-        $payment_status = strtolower( $posted['payment_status'] );
605
-        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
604
+        $payment_status = strtolower($posted['payment_status']);
605
+        $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
606 606
 
607
-        $this->validate_ipn_receiver_email( $invoice, $business_email );
608
-        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
607
+        $this->validate_ipn_receiver_email($invoice, $business_email);
608
+        $this->validate_ipn_currency($invoice, $posted['mc_currency']);
609 609
 
610 610
         // Update the transaction id.
611
-        if ( ! empty( $posted['txn_id'] ) ) {
612
-            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
611
+        if (!empty($posted['txn_id'])) {
612
+            $invoice->set_transaction_id(wpinv_clean($posted['txn_id']));
613 613
             $invoice->save();
614 614
         }
615 615
 
616 616
         // Process a refund.
617
-        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
617
+        if ($payment_status == 'refunded' || $payment_status == 'reversed') {
618 618
 
619
-            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
619
+            update_post_meta($invoice->get_id(), 'refunded_remotely', 1);
620 620
 
621
-            if ( ! $invoice->is_refunded() ) {
622
-                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
621
+            if (!$invoice->is_refunded()) {
622
+                $invoice->update_status('wpi-refunded', $posted['reason_code']);
623 623
             }
624 624
 
625 625
             exit;
626 626
         }
627 627
 
628 628
         // Process payments.
629
-        if ( $payment_status == 'completed' ) {
629
+        if ($payment_status == 'completed') {
630 630
 
631
-            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
632
-                wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already complete.' );
631
+            if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
632
+                wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already complete.');
633 633
                 exit;
634 634
             }
635 635
 
636
-            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
636
+            $this->validate_ipn_amount($invoice, $posted['mc_gross']);
637 637
 
638
-            if ( 'completed' === $payment_status || 'pending' === $payment_status ) {
638
+            if ('completed' === $payment_status || 'pending' === $payment_status) {
639 639
 
640 640
                 $note = '';
641 641
 
642
-                if ( ! empty( $posted['mc_fee'] ) ) {
643
-                    $note = sprintf( __( 'PayPal Transaction Fee %s', 'invoicing' ), wpinv_clean( $posted['mc_fee'] ) );
642
+                if (!empty($posted['mc_fee'])) {
643
+                    $note = sprintf(__('PayPal Transaction Fee %s', 'invoicing'), wpinv_clean($posted['mc_fee']));
644 644
                 }
645 645
 
646
-                $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? wpinv_clean( $posted['txn_id'] ) : '' ), $note );
646
+                $invoice->mark_paid((!empty($posted['txn_id']) ? wpinv_clean($posted['txn_id']) : ''), $note);
647 647
 
648 648
             } else {
649 649
 
650 650
                 /* translators: %s: pending reason. */
651
-                $invoice->update_status( 'wpi_processing', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
651
+                $invoice->update_status('wpi_processing', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason']));
652 652
 
653 653
             }
654 654
 
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
         // Process failures.
660 660
 
661 661
         /* translators: %s: payment status. */
662
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) );
662
+		$invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), wpinv_clean($posted['payment_status'])));
663 663
 
664 664
 	}
665 665
 
@@ -669,8 +669,8 @@  discard block
 block discarded – undo
669 669
 	 * @param WPInv_Invoice $invoice  Invoice object.
670 670
 	 * @param array    $posted Posted data.
671 671
 	 */
672
-	protected function ipn_txn_cart( $invoice, $posted ) {
673
-		$this->ipn_txn_web_accept( $invoice, $posted );
672
+	protected function ipn_txn_cart($invoice, $posted) {
673
+		$this->ipn_txn_web_accept($invoice, $posted);
674 674
     }
675 675
 
676 676
     /**
@@ -679,39 +679,39 @@  discard block
 block discarded – undo
679 679
 	 * @param WPInv_Invoice $invoice  Invoice object.
680 680
 	 * @param array    $posted Posted data.
681 681
 	 */
682
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
682
+	protected function ipn_txn_subscr_signup($invoice, $posted) {
683 683
 
684 684
         // Make sure the invoice has a subscription.
685
-        $subscription = wpinv_get_subscription( $invoice );
685
+        $subscription = wpinv_get_subscription($invoice);
686 686
 
687
-        if ( empty( $subscription ) ) {
688
-            wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' );
687
+        if (empty($subscription)) {
688
+            wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found');
689 689
         }
690 690
 
691 691
         // Update the subscription ids.
692 692
         $subscription->update(
693 693
             array(
694
-                'profile_id' => sanitize_text_field( $posted['subscr_id'] ),
694
+                'profile_id' => sanitize_text_field($posted['subscr_id']),
695 695
             )
696 696
         );
697 697
 
698 698
         // Set the transaction id.
699
-        if ( ! empty( $posted['txn_id'] ) ) {
700
-            $invoice->set_transaction_id( $posted['txn_id'] );
699
+        if (!empty($posted['txn_id'])) {
700
+            $invoice->set_transaction_id($posted['txn_id']);
701 701
         }
702 702
 
703 703
         // Update the payment status.
704 704
         $invoice->mark_paid();
705 705
 
706
-        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
706
+        $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
707 707
 
708 708
         // Update the subscription duration.
709
-        $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created );
709
+        $duration = strtotime($subscription->expiration) - strtotime($subscription->created);
710 710
         $subscription->update( 
711 711
             array(
712 712
                 'status'     => 'trialling' == $subscription->status ? 'trialling' : 'active',
713
-                'created'    => current_time( 'mysql' ),
714
-                'expiration' => date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ),
713
+                'created'    => current_time('mysql'),
714
+                'expiration' => date('Y-m-d H:i:s', (current_time('timestamp') + $duration)),
715 715
             )
716 716
         );
717 717
 
@@ -723,25 +723,25 @@  discard block
 block discarded – undo
723 723
 	 * @param WPInv_Invoice $invoice  Invoice object.
724 724
 	 * @param array    $posted Posted data.
725 725
 	 */
726
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
726
+	protected function ipn_txn_subscr_payment($invoice, $posted) {
727 727
 
728 728
         // Make sure the invoice has a subscription.
729
-        $subscription = wpinv_get_subscription( $invoice );
729
+        $subscription = wpinv_get_subscription($invoice);
730 730
 
731
-        if ( empty( $subscription ) ) {
732
-            wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' );
731
+        if (empty($subscription)) {
732
+            wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found');
733 733
         }
734 734
 
735
-        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
735
+        $this->validate_ipn_currency($invoice, $posted['mc_currency']);
736 736
 
737 737
         // Abort if the payment is already recorded.
738
-        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
738
+        if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
739 739
             return;
740 740
         }
741 741
 
742 742
         // Abort if this is the first payment.
743
-        if ( date( 'Ynd', $subscription->created ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) {
744
-            $invoice->set_transaction_id( $posted['txn_id'] );
743
+        if (date('Ynd', $subscription->created) == date('Ynd', strtotime($posted['payment_date']))) {
744
+            $invoice->set_transaction_id($posted['txn_id']);
745 745
             $invoice->save();
746 746
             return;
747 747
         }
@@ -752,14 +752,14 @@  discard block
 block discarded – undo
752 752
             'gateway'        => $this->id,
753 753
         );
754 754
 
755
-        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
755
+        $invoice = wpinv_get_invoice($subscription->add_payment($args));
756 756
 
757
-        if ( empty( $invoice ) ) {
757
+        if (empty($invoice)) {
758 758
             return;
759 759
         }
760 760
 
761
-        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
762
-        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
761
+        $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
762
+        $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
763 763
 
764 764
         $subscription->renew();
765 765
 
@@ -771,9 +771,9 @@  discard block
 block discarded – undo
771 771
 	 * @param WPInv_Invoice $invoice  Invoice object.
772 772
 	 * @param array    $posted Posted data.
773 773
 	 */
774
-	protected function ipn_txn_subscr_cancel( $invoice, $posted ) {
774
+	protected function ipn_txn_subscr_cancel($invoice, $posted) {
775 775
 
776
-        if ( $subscription = wpinv_get_subscription( $invoice ) ) {
776
+        if ($subscription = wpinv_get_subscription($invoice)) {
777 777
             $subscription->cancel();
778 778
         }
779 779
 
@@ -785,9 +785,9 @@  discard block
 block discarded – undo
785 785
 	 * @param WPInv_Invoice $invoice  Invoice object.
786 786
 	 * @param array    $posted Posted data.
787 787
 	 */
788
-	protected function ipn_txn_subscr_eot( $invoice, $posted ) {
788
+	protected function ipn_txn_subscr_eot($invoice, $posted) {
789 789
 
790
-        if ( $subscription = wpinv_get_subscription( $invoice ) ) {
790
+        if ($subscription = wpinv_get_subscription($invoice)) {
791 791
             $subscription->complete();
792 792
         }
793 793
 
@@ -799,9 +799,9 @@  discard block
 block discarded – undo
799 799
 	 * @param WPInv_Invoice $invoice  Invoice object.
800 800
 	 * @param array    $posted Posted data.
801 801
 	 */
802
-	protected function ipn_txn_subscr_failed( $invoice, $posted ) {
802
+	protected function ipn_txn_subscr_failed($invoice, $posted) {
803 803
 
804
-        if ( $subscription = wpinv_get_subscription( $invoice ) ) {
804
+        if ($subscription = wpinv_get_subscription($invoice)) {
805 805
             $subscription->failing();
806 806
         }
807 807
 
@@ -810,10 +810,10 @@  discard block
 block discarded – undo
810 810
     /**
811 811
      * Displays a notice on the checkout page if sandbox is enabled.
812 812
      */
813
-    public function sandbox_notice( $description, $gateway ) {
814
-        if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) {
813
+    public function sandbox_notice($description, $gateway) {
814
+        if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) {
815 815
             $description .= '<br>&nbsp;<br>' . sprintf(
816
-                __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
816
+                __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
817 817
                 '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
818 818
                 '</a>'
819 819
             );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +147 added lines, -147 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
  * Authorize.net 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', 'tokens' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_last_name(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_last_name(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,24 +311,24 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319 319
                         'name'                 => getpaid_tax()->get_vat_name(),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330 330
 
331
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
331
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
332 332
 
333 333
     }
334 334
 
@@ -338,29 +338,29 @@  discard block
 block discarded – undo
338 338
      * @param stdClass $result Api response.
339 339
 	 * @param WPInv_Invoice $invoice Invoice.
340 340
 	 */
341
-	public function process_charge_response( $result, $invoice ) {
341
+	public function process_charge_response($result, $invoice) {
342 342
 
343 343
         wpinv_clear_errors();
344 344
 		$response_code = (int) $result->transactionResponse->responseCode;
345 345
 
346 346
 		// Succeeded.
347
-		if ( 1 == $response_code || 4 == $response_code ) {
347
+		if (1 == $response_code || 4 == $response_code) {
348 348
 
349 349
 			// Maybe set a transaction id.
350
-			if ( ! empty( $result->transactionResponse->transId ) ) {
351
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
350
+			if (!empty($result->transactionResponse->transId)) {
351
+				$invoice->set_transaction_id($result->transactionResponse->transId);
352 352
 			}
353 353
 
354
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
354
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
355 355
 
356
-			if ( 1 == $response_code ) {
356
+			if (1 == $response_code) {
357 357
 				return $invoice->mark_paid();
358 358
 			}
359 359
 
360
-			$invoice->set_status( 'wpi-onhold' );
360
+			$invoice->set_status('wpi-onhold');
361 361
         	$invoice->add_note(
362 362
                 sprintf(
363
-                    __( 'Held for review: %s', 'invoicing' ),
363
+                    __('Held for review: %s', 'invoicing'),
364 364
                     $result->transactionResponse->messages->message[0]->description
365 365
                 )
366 366
 			);
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
 
370 370
 		}
371 371
 
372
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
372
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
373 373
 
374
-        if ( ! empty( $result->transactionResponse->errors ) ) {
374
+        if (!empty($result->transactionResponse->errors)) {
375 375
             $errors = (object) $result->transactionResponse->errors;
376
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
376
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
377 377
         }
378 378
 
379 379
     }
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 	 * @param array $card Card details.
386 386
 	 * @return array
387 387
 	 */
388
-	public function get_payment_information( $card ) {
388
+	public function get_payment_information($card) {
389 389
         return array(
390 390
 
391
-            'creditCard'         => array (
391
+            'creditCard'         => array(
392 392
                 'cardNumber'     => $card['cc_number'],
393 393
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
394 394
                 'cardCode'       => $card['cc_cvv2'],
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @param WPInv_Invoice $invoice Invoice.
405 405
 	 * @return string
406 406
 	 */
407
-	public function get_customer_profile_meta_name( $invoice ) {
408
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
407
+	public function get_customer_profile_meta_name($invoice) {
408
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
409 409
     }
410 410
 
411 411
     /**
@@ -416,34 +416,34 @@  discard block
 block discarded – undo
416 416
      * @param WPInv_Invoice $invoice
417 417
 	 * @return WP_Error|string The payment profile id
418 418
 	 */
419
-	public function validate_submission_data( $submission_data, $invoice ) {
419
+	public function validate_submission_data($submission_data, $invoice) {
420 420
 
421 421
         // Validate authentication details.
422 422
         $auth = $this->get_auth_params();
423 423
 
424
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
425
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
424
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
425
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
426 426
         }
427 427
 
428 428
         // Validate the payment method.
429
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
430
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
429
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
430
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
431 431
         }
432 432
 
433 433
         // Are we adding a new payment method?
434
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
434
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
435 435
             return $submission_data['getpaid-authorizenet-payment-method'];
436 436
         }
437 437
 
438 438
         // Retrieve the customer profile id.
439
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
439
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
440 440
 
441 441
         // Create payment method.
442
-        if ( empty( $profile_id ) ) {
443
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
442
+        if (empty($profile_id)) {
443
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
444 444
         }
445 445
 
446
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
447 447
 
448 448
     }
449 449
 
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
 	 * @param WPInv_Invoice $invoice Invoice.
455 455
 	 * @return array
456 456
 	 */
457
-	public function get_line_items( $invoice ) {
457
+	public function get_line_items($invoice) {
458 458
         $items = array();
459 459
 
460
-        foreach ( $invoice->get_items() as $item ) {
460
+        foreach ($invoice->get_items() as $item) {
461 461
 
462 462
             $items[] = array(
463
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
464
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
465
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
463
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
464
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
465
+                'description' => getpaid_limit_length($item->get_description(), 255),
466 466
                 'quantity'    => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
467 467
                 'unitPrice'   => (float) $item->get_price(),
468 468
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -482,36 +482,36 @@  discard block
 block discarded – undo
482 482
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
483 483
 	 * @return array
484 484
 	 */
485
-	public function process_payment( $invoice, $submission_data, $submission ) {
485
+	public function process_payment($invoice, $submission_data, $submission) {
486 486
 
487 487
         // Validate the submitted data.
488
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
488
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
489 489
 
490 490
         // Do we have an error?
491
-        if ( is_wp_error( $payment_profile_id ) ) {
492
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
491
+        if (is_wp_error($payment_profile_id)) {
492
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
493 493
             wpinv_send_back_to_checkout();
494 494
         }
495 495
 
496 496
         // Save the payment method to the order.
497
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
497
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
498 498
 
499 499
         // Check if this is a subscription or not.
500
-        $subscription = getpaid_get_invoice_subscription( $invoice );
501
-        if ( ! empty( $subscription ) ) {
502
-            $this->process_subscription( $invoice, $subscription );
500
+        $subscription = getpaid_get_invoice_subscription($invoice);
501
+        if (!empty($subscription)) {
502
+            $this->process_subscription($invoice, $subscription);
503 503
         }
504 504
 
505 505
         // If it is free, send to the success page.
506
-        if ( ! $invoice->needs_payment() ) {
506
+        if (!$invoice->needs_payment()) {
507 507
             $invoice->mark_paid();
508
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
508
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
509 509
         }
510 510
 
511 511
         // Charge the payment profile.
512
-        $this->process_initial_payment( $invoice );
512
+        $this->process_initial_payment($invoice);
513 513
 
514
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
514
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
515 515
 
516 516
         exit;
517 517
 
@@ -522,22 +522,22 @@  discard block
 block discarded – undo
522 522
 	 *
523 523
      * @param WPInv_Invoice $invoice Invoice.
524 524
 	 */
525
-	protected function process_initial_payment( $invoice ) {
525
+	protected function process_initial_payment($invoice) {
526 526
 
527
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
528
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
529
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
527
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
528
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
529
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
530 530
 
531 531
 		// Do we have an error?
532
-		if ( is_wp_error( $result ) ) {
533
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
532
+		if (is_wp_error($result)) {
533
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
534 534
 			wpinv_send_back_to_checkout();
535 535
 		}
536 536
 
537 537
 		// Process the response.
538
-		$this->process_charge_response( $result, $invoice );
538
+		$this->process_charge_response($result, $invoice);
539 539
 
540
-		if ( wpinv_get_errors() ) {
540
+		if (wpinv_get_errors()) {
541 541
 			wpinv_send_back_to_checkout();
542 542
 		}
543 543
 
@@ -549,24 +549,24 @@  discard block
 block discarded – undo
549 549
      * @param WPInv_Invoice $invoice Invoice.
550 550
      * @param WPInv_Subscription $subscription Subscription.
551 551
 	 */
552
-	public function process_subscription( $invoice, $subscription ) {
552
+	public function process_subscription($invoice, $subscription) {
553 553
 
554 554
         // Check if there is an initial amount to charge.
555
-        if ( (float) $invoice->get_total() > 0 ) {
556
-			$this->process_initial_payment( $invoice );
555
+        if ((float) $invoice->get_total() > 0) {
556
+			$this->process_initial_payment($invoice);
557 557
         }
558 558
 
559 559
         // Activate the subscription.
560
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
561
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
560
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
561
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
562 562
 
563
-		$subscription->set_next_renewal_date( $expiry );
564
-		$subscription->set_date_created( current_time( 'mysql' ) );
565
-		$subscription->set_profile_id( $invoice->generate_key() );
563
+		$subscription->set_next_renewal_date($expiry);
564
+		$subscription->set_date_created(current_time('mysql'));
565
+		$subscription->set_profile_id($invoice->generate_key());
566 566
 		$subscription->activate();
567 567
 
568 568
 		// Redirect to the success page.
569
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
569
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
570 570
 
571 571
     }
572 572
 
@@ -577,20 +577,20 @@  discard block
 block discarded – undo
577 577
 	 * @param bool $should_expire
578 578
      * @param WPInv_Subscription $subscription
579 579
 	 */
580
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
580
+	public function maybe_renew_subscription($should_expire, $subscription) {
581 581
 
582 582
         // Ensure its our subscription && it's active.
583
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
583
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
584 584
             return $should_expire;
585 585
         }
586 586
 
587 587
         // If this is the last renewal, complete the subscription.
588
-        if ( $subscription->is_last_renewal() ) {
588
+        if ($subscription->is_last_renewal()) {
589 589
             $subscription->complete();
590 590
             return false;
591 591
         }
592 592
 
593
-        $this->renew_subscription( $subscription );
593
+        $this->renew_subscription($subscription);
594 594
 
595 595
         return false;
596 596
 
@@ -601,28 +601,28 @@  discard block
 block discarded – undo
601 601
 	 *
602 602
      * @param WPInv_Subscription $subscription
603 603
 	 */
604
-	public function renew_subscription( $subscription ) {
604
+	public function renew_subscription($subscription) {
605 605
 
606 606
 		// Generate the renewal invoice.
607 607
 		$new_invoice = $subscription->create_payment();
608 608
 		$old_invoice = $subscription->get_parent_payment();
609 609
 
610
-        if ( empty( $new_invoice ) ) {
611
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
610
+        if (empty($new_invoice)) {
611
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
612 612
             $subscription->failing();
613 613
             return;
614 614
         }
615 615
 
616 616
         // Charge the payment method.
617
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
618
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
619
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
617
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
618
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
619
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
620 620
 
621 621
 		// Do we have an error?
622
-		if ( is_wp_error( $result ) ) {
622
+		if (is_wp_error($result)) {
623 623
 
624 624
 			$old_invoice->add_note(
625
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
625
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
626 626
 				true,
627 627
 				false,
628 628
 				true
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 		}
634 634
 
635 635
 		// Process the response.
636
-		$this->process_charge_response( $result, $new_invoice );
636
+		$this->process_charge_response($result, $new_invoice);
637 637
 
638
-		if ( wpinv_get_errors() ) {
638
+		if (wpinv_get_errors()) {
639 639
 
640 640
 			$old_invoice->add_note(
641
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
641
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
642 642
 				true,
643 643
 				false,
644 644
 				true
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 
649 649
         }
650 650
 
651
-        $subscription->add_payment( array(), $new_invoice );
651
+        $subscription->add_payment(array(), $new_invoice);
652 652
         $subscription->renew();
653 653
 
654 654
     }
@@ -656,11 +656,11 @@  discard block
 block discarded – undo
656 656
     /**
657 657
      * Displays a notice on the checkout page if sandbox is enabled.
658 658
      */
659
-    public function sandbox_notice( $description, $gateway ) {
659
+    public function sandbox_notice($description, $gateway) {
660 660
 
661
-        if ( $this->id == $gateway && wpinv_is_test_mode( $this->id ) ) {
661
+        if ($this->id == $gateway && wpinv_is_test_mode($this->id)) {
662 662
             $description .= '<br>&nbsp;<br>' . sprintf(
663
-                __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
663
+                __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
664 664
                 '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
665 665
                 '</a>'
666 666
             );
@@ -674,42 +674,42 @@  discard block
 block discarded – undo
674 674
 	 *
675 675
 	 * @param array $admin_settings
676 676
 	 */
677
-	public function admin_settings( $admin_settings ) {
677
+	public function admin_settings($admin_settings) {
678 678
 
679 679
         $currencies = sprintf(
680
-            __( 'Supported Currencies: %s', 'invoicing' ),
681
-            implode( ', ', $this->currencies )
680
+            __('Supported Currencies: %s', 'invoicing'),
681
+            implode(', ', $this->currencies)
682 682
         );
683 683
 
684 684
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
685
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
685
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
686 686
 
687 687
         $admin_settings['authorizenet_login_id'] = array(
688 688
             'type' => 'text',
689 689
             'id'   => 'authorizenet_login_id',
690
-            'name' => __( 'API Login ID', 'invoicing' ),
691
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
690
+            'name' => __('API Login ID', 'invoicing'),
691
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
692 692
         );
693 693
 
694 694
         $admin_settings['authorizenet_transaction_key'] = array(
695 695
             'type' => 'text',
696 696
             'id'   => 'authorizenet_transaction_key',
697
-            'name' => __( 'Transaction Key', 'invoicing' ),
697
+            'name' => __('Transaction Key', 'invoicing'),
698 698
         );
699 699
 
700 700
         $admin_settings['authorizenet_signature_key'] = array(
701 701
             'type' => 'text',
702 702
             'id'   => 'authorizenet_signature_key',
703
-            'name' => __( 'Signature Key', 'invoicing' ),
704
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
703
+            'name' => __('Signature Key', 'invoicing'),
704
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
705 705
         );
706 706
 
707 707
         $admin_settings['authorizenet_ipn_url'] = array(
708 708
             'type'     => 'ipn_url',
709 709
             'id'       => 'authorizenet_ipn_url',
710
-            'name'     => __( 'Webhook URL', 'invoicing' ),
710
+            'name'     => __('Webhook URL', 'invoicing'),
711 711
             'std'      => $this->notify_url,
712
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
712
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
713 713
             'custom'   => 'authorizenet',
714 714
             'readonly' => true,
715 715
         );
Please login to merge, or discard this patch.