Passed
Pull Request — master (#796)
by Kiran
14:40
created
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Spacing   +97 added lines, -97 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
  * Bank transfer Payment Gateway class.
@@ -56,17 +56,17 @@  discard block
 block discarded – undo
56 56
 	public function __construct() {
57 57
         parent::__construct();
58 58
 
59
-        $this->title                = __( 'Direct bank transfer', 'invoicing' );
60
-        $this->method_title         = __( 'Bank transfer', 'invoicing' );
61
-        $this->checkout_button_text = __( 'Proceed', 'invoicing' );
62
-        $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
59
+        $this->title                = __('Direct bank transfer', 'invoicing');
60
+        $this->method_title         = __('Bank transfer', 'invoicing');
61
+        $this->checkout_button_text = __('Proceed', 'invoicing');
62
+        $this->instructions         = apply_filters('wpinv_bank_instructions', $this->get_option('info'));
63 63
 
64
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
69
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
64
+		add_action('wpinv_receipt_end', array($this, 'thankyou_page'));
65
+		add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40);
66
+		add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11);
67
+		add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3);
68
+		add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
69
+		add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20);
70 70
 
71 71
     }
72 72
 
@@ -78,23 +78,23 @@  discard block
 block discarded – undo
78 78
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
79 79
 	 * @return array
80 80
 	 */
81
-	public function process_payment( $invoice, $submission_data, $submission ) {
81
+	public function process_payment($invoice, $submission_data, $submission) {
82 82
 
83 83
         // Add a transaction id.
84
-        $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
84
+        $invoice->set_transaction_id($invoice->generate_key('bt_'));
85 85
 
86 86
         // Set it as pending payment.
87
-        if ( ! $invoice->needs_payment() ) {
87
+        if (!$invoice->needs_payment()) {
88 88
             $invoice->mark_paid();
89
-        } elseif ( ! $invoice->is_paid() ) {
90
-            $invoice->set_status( 'wpi-onhold' );
89
+        } elseif (!$invoice->is_paid()) {
90
+            $invoice->set_status('wpi-onhold');
91 91
         }
92 92
 
93 93
         // Save it.
94 94
         $invoice->save();
95 95
 
96 96
         // Send to the success page.
97
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
97
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
98 98
 
99 99
     }
100 100
 
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @param WPInv_Invoice $invoice Invoice.
105 105
 	 */
106
-	public function thankyou_page( $invoice ) {
106
+	public function thankyou_page($invoice) {
107 107
 
108
-        if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
108
+        if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
109 109
 
110 110
 			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
111 111
 
112
-            if ( ! empty( $this->instructions ) ) {
113
-                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
112
+            if (!empty($this->instructions)) {
113
+                echo wp_kses_post(wpautop(wptexturize($this->instructions)));
114 114
 			}
115 115
 
116
-			$this->bank_details( $invoice );
116
+			$this->bank_details($invoice);
117 117
 
118 118
 			echo '</div>';
119 119
 
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
 	 * @param string     $email_type Email format: plain text or HTML.
129 129
 	 * @param bool     $sent_to_admin Sent to admin.
130 130
 	 */
131
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
131
+	public function email_instructions($invoice, $email_type, $sent_to_admin) {
132 132
 
133
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
133
+		if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
134 134
 
135 135
 			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
136 136
 
137
-			if ( $this->instructions ) {
138
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
137
+			if ($this->instructions) {
138
+				echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL);
139 139
             }
140 140
 
141
-			$this->bank_details( $invoice );
141
+			$this->bank_details($invoice);
142 142
 
143 143
 			echo '</div>';
144 144
 
@@ -151,50 +151,50 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @param WPInv_Invoice $invoice Invoice.
153 153
 	 */
154
-	protected function bank_details( $invoice ) {
154
+	protected function bank_details($invoice) {
155 155
 
156 156
 		// Get the invoice country and country $locale.
157 157
 		$country = $invoice->get_country();
158 158
 		$locale  = $this->get_country_locale();
159 159
 
160 160
 		// Get shortcode label in the $locale array and use appropriate one.
161
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
161
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
162 162
 
163 163
         $bank_fields = array(
164
-            'ac_name'   => __( 'Account Name', 'invoicing' ),
165
-            'ac_no'     => __( 'Account Number', 'invoicing' ),
166
-            'bank_name' => __( 'Bank Name', 'invoicing' ),
167
-            'ifsc'      => __( 'IFSC code', 'invoicing' ),
168
-            'iban'      => __( 'IBAN', 'invoicing' ),
169
-            'bic'       => __( 'BIC/Swift code', 'invoicing' ),
164
+            'ac_name'   => __('Account Name', 'invoicing'),
165
+            'ac_no'     => __('Account Number', 'invoicing'),
166
+            'bank_name' => __('Bank Name', 'invoicing'),
167
+            'ifsc'      => __('IFSC code', 'invoicing'),
168
+            'iban'      => __('IBAN', 'invoicing'),
169
+            'bic'       => __('BIC/Swift code', 'invoicing'),
170 170
             'sort_code' => $sortcode,
171 171
         );
172 172
 
173 173
         $bank_info = array();
174 174
 
175
-        foreach ( $bank_fields as $field => $label ) {
176
-            $value = $this->get_option( $field );
175
+        foreach ($bank_fields as $field => $label) {
176
+            $value = $this->get_option($field);
177 177
 
178
-            if ( ! empty( $value ) ) {
179
-                $bank_info[ $field ] = array(
178
+            if (!empty($value)) {
179
+                $bank_info[$field] = array(
180 180
 					'label' => $label,
181 181
 					'value' => $value,
182 182
 				);
183 183
             }
184 184
 		}
185 185
 
186
-        $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
186
+        $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice);
187 187
 
188
-        if ( empty( $bank_info ) ) {
188
+        if (empty($bank_info)) {
189 189
             return;
190 190
         }
191 191
 
192
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
192
+		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL;
193 193
 
194 194
 		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
195 195
 
196
-		foreach ( $bank_info as $key => $data ) {
197
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
196
+		foreach ($bank_info as $key => $data) {
197
+			echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL;
198 198
 		}
199 199
 
200 200
 		echo '</table>';
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	public function get_country_locale() {
210 210
 
211
-		if ( empty( $this->locale ) ) {
211
+		if (empty($this->locale)) {
212 212
 
213 213
 			// Locale information to be used - only those that are not 'Sort Code'.
214 214
 			$this->locale = apply_filters(
@@ -216,42 +216,42 @@  discard block
 block discarded – undo
216 216
 				array(
217 217
 					'AU' => array(
218 218
 						'sortcode' => array(
219
-							'label' => __( 'BSB', 'invoicing' ),
219
+							'label' => __('BSB', 'invoicing'),
220 220
 						),
221 221
 					),
222 222
 					'CA' => array(
223 223
 						'sortcode' => array(
224
-							'label' => __( 'Bank transit number', 'invoicing' ),
224
+							'label' => __('Bank transit number', 'invoicing'),
225 225
 						),
226 226
 					),
227 227
 					'IN' => array(
228 228
 						'sortcode' => array(
229
-							'label' => __( 'IFSC', 'invoicing' ),
229
+							'label' => __('IFSC', 'invoicing'),
230 230
 						),
231 231
 					),
232 232
 					'IT' => array(
233 233
 						'sortcode' => array(
234
-							'label' => __( 'Branch sort', 'invoicing' ),
234
+							'label' => __('Branch sort', 'invoicing'),
235 235
 						),
236 236
 					),
237 237
 					'NZ' => array(
238 238
 						'sortcode' => array(
239
-							'label' => __( 'Bank code', 'invoicing' ),
239
+							'label' => __('Bank code', 'invoicing'),
240 240
 						),
241 241
 					),
242 242
 					'SE' => array(
243 243
 						'sortcode' => array(
244
-							'label' => __( 'Bank code', 'invoicing' ),
244
+							'label' => __('Bank code', 'invoicing'),
245 245
 						),
246 246
 					),
247 247
 					'US' => array(
248 248
 						'sortcode' => array(
249
-							'label' => __( 'Routing number', 'invoicing' ),
249
+							'label' => __('Routing number', 'invoicing'),
250 250
 						),
251 251
 					),
252 252
 					'ZA' => array(
253 253
 						'sortcode' => array(
254
-							'label' => __( 'Branch code', 'invoicing' ),
254
+							'label' => __('Branch code', 'invoicing'),
255 255
 						),
256 256
 					),
257 257
 				)
@@ -268,51 +268,51 @@  discard block
 block discarded – undo
268 268
 	 *
269 269
 	 * @param array $admin_settings
270 270
 	 */
271
-	public function admin_settings( $admin_settings ) {
271
+	public function admin_settings($admin_settings) {
272 272
 
273
-        $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
274
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
273
+        $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing');
274
+		$admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing');
275 275
 
276
-		$locale  = $this->get_country_locale();
276
+		$locale = $this->get_country_locale();
277 277
 
278 278
 		// Get sortcode label in the $locale array and use appropriate one.
279 279
 		$country  = wpinv_default_billing_country();
280
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
280
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
281 281
 
282 282
 		$admin_settings['bank_transfer_ac_name'] = array(
283 283
             'type' => 'text',
284 284
             'id'   => 'bank_transfer_ac_name',
285
-            'name' => __( 'Account Name', 'invoicing' ),
285
+            'name' => __('Account Name', 'invoicing'),
286 286
 		);
287 287
 
288 288
 		$admin_settings['bank_transfer_ac_no'] = array(
289 289
             'type' => 'text',
290 290
             'id'   => 'bank_transfer_ac_no',
291
-            'name' => __( 'Account Number', 'invoicing' ),
291
+            'name' => __('Account Number', 'invoicing'),
292 292
 		);
293 293
 
294 294
 		$admin_settings['bank_transfer_bank_name'] = array(
295 295
             'type' => 'text',
296 296
             'id'   => 'bank_transfer_bank_name',
297
-            'name' => __( 'Bank Name', 'invoicing' ),
297
+            'name' => __('Bank Name', 'invoicing'),
298 298
 		);
299 299
 
300 300
 		$admin_settings['bank_transfer_ifsc'] = array(
301 301
             'type' => 'text',
302 302
             'id'   => 'bank_transfer_ifsc',
303
-            'name' => __( 'IFSC Code', 'invoicing' ),
303
+            'name' => __('IFSC Code', 'invoicing'),
304 304
 		);
305 305
 
306 306
 		$admin_settings['bank_transfer_iban'] = array(
307 307
             'type' => 'text',
308 308
             'id'   => 'bank_transfer_iban',
309
-            'name' => __( 'IBAN', 'invoicing' ),
309
+            'name' => __('IBAN', 'invoicing'),
310 310
 		);
311 311
 
312 312
 		$admin_settings['bank_transfer_bic'] = array(
313 313
             'type' => 'text',
314 314
             'id'   => 'bank_transfer_bic',
315
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
315
+            'name' => __('BIC/Swift Code', 'invoicing'),
316 316
 		);
317 317
 
318 318
 		$admin_settings['bank_transfer_sort_code'] = array(
@@ -323,10 +323,10 @@  discard block
 block discarded – undo
323 323
 
324 324
 		$admin_settings['bank_transfer_info'] = array(
325 325
             'id'   => 'bank_transfer_info',
326
-            'name' => __( 'Instructions', 'invoicing' ),
327
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
326
+            'name' => __('Instructions', 'invoicing'),
327
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
328 328
             'type' => 'textarea',
329
-            'std'  => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ),
329
+            'std'  => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'),
330 330
             'cols' => 50,
331 331
             'rows' => 5,
332 332
         );
@@ -341,10 +341,10 @@  discard block
 block discarded – undo
341 341
 	 * @param GetPaid_Form_Item[] $items
342 342
 	 * @return WPInv_Invoice
343 343
 	 */
344
-	public function process_addons( $invoice, $items ) {
344
+	public function process_addons($invoice, $items) {
345 345
 
346
-        foreach ( $items as $item ) {
347
-            $invoice->add_item( $item );
346
+        foreach ($items as $item) {
347
+            $invoice->add_item($item);
348 348
         }
349 349
 
350 350
         $invoice->recalculate_total();
@@ -357,25 +357,25 @@  discard block
 block discarded – undo
357 357
 	 *
358 358
 	 * @param WPInv_Subscription $subscription
359 359
 	 */
360
-	public function maybe_renew_subscription( $subscription ) {
360
+	public function maybe_renew_subscription($subscription) {
361 361
 		// Ensure its our subscription && it's active.
362
-		if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
363
-			add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
362
+		if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) {
363
+			add_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2);
364 364
 
365 365
 			$invoice = $subscription->create_payment();
366 366
 
367
-			if ( ! empty( $invoice ) ) {
367
+			if (!empty($invoice)) {
368 368
 				$is_logged_in = is_user_logged_in();
369 369
 
370 370
 				// Cron run.
371
-				if ( ! $is_logged_in ) {
372
-					$note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
371
+				if (!$is_logged_in) {
372
+					$note = wp_sprintf(__('Renewal %1$s created with the status "%2$s".', 'invoicing'), $invoice->get_invoice_quote_type(), wpinv_status_nicename($invoice->get_status(), $invoice));
373 373
 
374
-					$invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
374
+					$invoice->add_note($note, false, $is_logged_in, !$is_logged_in);
375 375
 				}
376 376
 			}
377 377
 
378
-			remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
378
+			remove_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2);
379 379
 		}
380 380
 	}
381 381
 
@@ -385,42 +385,42 @@  discard block
 block discarded – undo
385 385
 	 *
386 386
      * @param WPInv_Invoice $invoice
387 387
 	 */
388
-	public function invoice_paid( $invoice ) {
388
+	public function invoice_paid($invoice) {
389 389
 
390 390
 		// Abort if not paid by bank transfer.
391
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
391
+		if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) {
392 392
 			return;
393 393
 		}
394 394
 
395 395
 		// Is it a parent payment?
396
-		if ( 0 == $invoice->get_parent_id() ) {
396
+		if (0 == $invoice->get_parent_id()) {
397 397
 
398 398
 			// (Maybe) activate subscriptions.
399
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
399
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
400 400
 
401
-			if ( ! empty( $subscriptions ) ) {
402
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
401
+			if (!empty($subscriptions)) {
402
+				$subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
403 403
 
404
-				foreach ( $subscriptions as $subscription ) {
405
-					if ( $subscription->exists() ) {
406
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
407
-						$expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
404
+				foreach ($subscriptions as $subscription) {
405
+					if ($subscription->exists()) {
406
+						$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
407
+						$expiry   = gmdate('Y-m-d H:i:s', (current_time('timestamp') + $duration));
408 408
 
409
-						$subscription->set_next_renewal_date( $expiry );
410
-						$subscription->set_date_created( current_time( 'mysql' ) );
411
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
409
+						$subscription->set_next_renewal_date($expiry);
410
+						$subscription->set_date_created(current_time('mysql'));
411
+						$subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id());
412 412
 						$subscription->activate();
413 413
 					}
414 414
 				}
415 415
 			}
416 416
 		} else {
417 417
 
418
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
418
+			$subscription = getpaid_get_subscription($invoice->get_subscription_id());
419 419
 
420 420
 			// Renew the subscription.
421
-			if ( $subscription && $subscription->exists() ) {
422
-				$subscription->add_payment( array(), $invoice );
423
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
421
+			if ($subscription && $subscription->exists()) {
422
+				$subscription->add_payment(array(), $invoice);
423
+				$subscription->renew(strtotime($invoice->get_date_created()));
424 424
 			}
425 425
 		}
426 426
 
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param int  $invoice Invoice ID.
436 436
 	 * @return bool True when invoice created via payment form else false.
437 437
 	 */
438
-	public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
439
-		if ( $is_payment_form_invoice ) {
438
+	public function force_is_payment_form_invoice($is_payment_form_invoice, $invoice) {
439
+		if ($is_payment_form_invoice) {
440 440
 			$is_payment_form_invoice = false;
441 441
 		}
442 442
 
Please login to merge, or discard this patch.