Passed
Push — master ( 457b0a...15a985 )
by Brian
04:45
created
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Spacing   +89 added lines, -89 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.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-	protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+	protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,17 +39,17 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title                = __( 'Direct bank transfer', 'invoicing' );
43
-        $this->method_title         = __( 'Bank transfer', 'invoicing' );
44
-        $this->checkout_button_text = __( 'Proceed', 'invoicing' );
45
-        $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
42
+        $this->title                = __('Direct bank transfer', 'invoicing');
43
+        $this->method_title         = __('Bank transfer', 'invoicing');
44
+        $this->checkout_button_text = __('Proceed', 'invoicing');
45
+        $this->instructions         = apply_filters('wpinv_bank_instructions', $this->get_option('info'));
46 46
 
47
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
48
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
49
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
50
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
51
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
52
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
47
+		add_action('wpinv_receipt_end', array($this, 'thankyou_page'));
48
+		add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40);
49
+		add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11);
50
+		add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3);
51
+		add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
52
+		add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20);
53 53
 
54 54
     }
55 55
 
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62 62
 	 * @return array
63 63
 	 */
64
-	public function process_payment( $invoice, $submission_data, $submission ) {
64
+	public function process_payment($invoice, $submission_data, $submission) {
65 65
 
66 66
         // Add a transaction id.
67
-        $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
67
+        $invoice->set_transaction_id($invoice->generate_key('bt_'));
68 68
 
69 69
         // Set it as pending payment.
70
-        if ( ! $invoice->needs_payment() ) {
70
+        if (!$invoice->needs_payment()) {
71 71
             $invoice->mark_paid();
72
-        } elseif ( ! $invoice->is_paid() ) {
73
-            $invoice->set_status( 'wpi-onhold' );
72
+        } elseif (!$invoice->is_paid()) {
73
+            $invoice->set_status('wpi-onhold');
74 74
         }
75 75
 
76 76
         // Save it.
77 77
         $invoice->save();
78 78
 
79 79
         // Send to the success page.
80
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
80
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
81 81
 
82 82
     }
83 83
 
@@ -86,17 +86,17 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @param WPInv_Invoice $invoice Invoice.
88 88
 	 */
89
-	public function thankyou_page( $invoice ) {
89
+	public function thankyou_page($invoice) {
90 90
 
91
-        if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
91
+        if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
92 92
 
93 93
 			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
94 94
 
95
-            if ( ! empty( $this->instructions ) ) {
96
-                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
95
+            if (!empty($this->instructions)) {
96
+                echo wp_kses_post(wpautop(wptexturize($this->instructions)));
97 97
 			}
98 98
 
99
-			$this->bank_details( $invoice );
99
+			$this->bank_details($invoice);
100 100
 
101 101
 			echo '</div>';
102 102
 
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
 	 * @param string     $email_type Email format: plain text or HTML.
112 112
 	 * @param bool     $sent_to_admin Sent to admin.
113 113
 	 */
114
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
114
+	public function email_instructions($invoice, $email_type, $sent_to_admin) {
115 115
 
116
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
116
+		if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
117 117
 
118 118
 			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
119 119
 
120
-			if ( $this->instructions ) {
121
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
120
+			if ($this->instructions) {
121
+				echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL);
122 122
             }
123 123
 
124
-			$this->bank_details( $invoice );
124
+			$this->bank_details($invoice);
125 125
 
126 126
 			echo '</div>';
127 127
 
@@ -134,50 +134,50 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param WPInv_Invoice $invoice Invoice.
136 136
 	 */
137
-	protected function bank_details( $invoice ) {
137
+	protected function bank_details($invoice) {
138 138
 
139 139
 		// Get the invoice country and country $locale.
140 140
 		$country = $invoice->get_country();
141 141
 		$locale  = $this->get_country_locale();
142 142
 
143 143
 		// Get sortcode label in the $locale array and use appropriate one.
144
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
144
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
145 145
 
146 146
         $bank_fields = array(
147
-            'ac_name'   => __( 'Account Name', 'invoicing' ),
148
-            'ac_no'     => __( 'Account Number', 'invoicing' ),
149
-            'bank_name' => __( 'Bank Name', 'invoicing' ),
150
-            'ifsc'      => __( 'IFSC code', 'invoicing' ),
151
-            'iban'      => __( 'IBAN', 'invoicing' ),
152
-            'bic'       => __( 'BIC/Swift code', 'invoicing' ),
147
+            'ac_name'   => __('Account Name', 'invoicing'),
148
+            'ac_no'     => __('Account Number', 'invoicing'),
149
+            'bank_name' => __('Bank Name', 'invoicing'),
150
+            'ifsc'      => __('IFSC code', 'invoicing'),
151
+            'iban'      => __('IBAN', 'invoicing'),
152
+            'bic'       => __('BIC/Swift code', 'invoicing'),
153 153
             'sort_code' => $sortcode,
154 154
         );
155 155
 
156 156
         $bank_info = array();
157 157
 
158
-        foreach ( $bank_fields as $field => $label ) {
159
-            $value = $this->get_option( $field );
158
+        foreach ($bank_fields as $field => $label) {
159
+            $value = $this->get_option($field);
160 160
 
161
-            if ( ! empty( $value ) ) {
162
-                $bank_info[ $field ] = array(
161
+            if (!empty($value)) {
162
+                $bank_info[$field] = array(
163 163
 					'label' => $label,
164 164
 					'value' => $value,
165 165
 				);
166 166
             }
167 167
 		}
168 168
 
169
-        $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
169
+        $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice);
170 170
 
171
-        if ( empty( $bank_info ) ) {
171
+        if (empty($bank_info)) {
172 172
             return;
173 173
         }
174 174
 
175
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
175
+		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL;
176 176
 
177 177
 		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
178 178
 
179
-		foreach ( $bank_info as $key => $data ) {
180
-			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;
179
+		foreach ($bank_info as $key => $data) {
180
+			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;
181 181
 		}
182 182
 
183 183
 		echo '</table>';
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 */
192 192
 	public function get_country_locale() {
193 193
 
194
-		if ( empty( $this->locale ) ) {
194
+		if (empty($this->locale)) {
195 195
 
196 196
 			// Locale information to be used - only those that are not 'Sort Code'.
197 197
 			$this->locale = apply_filters(
@@ -199,42 +199,42 @@  discard block
 block discarded – undo
199 199
 				array(
200 200
 					'AU' => array(
201 201
 						'sortcode' => array(
202
-							'label' => __( 'BSB', 'invoicing' ),
202
+							'label' => __('BSB', 'invoicing'),
203 203
 						),
204 204
 					),
205 205
 					'CA' => array(
206 206
 						'sortcode' => array(
207
-							'label' => __( 'Bank transit number', 'invoicing' ),
207
+							'label' => __('Bank transit number', 'invoicing'),
208 208
 						),
209 209
 					),
210 210
 					'IN' => array(
211 211
 						'sortcode' => array(
212
-							'label' => __( 'IFSC', 'invoicing' ),
212
+							'label' => __('IFSC', 'invoicing'),
213 213
 						),
214 214
 					),
215 215
 					'IT' => array(
216 216
 						'sortcode' => array(
217
-							'label' => __( 'Branch sort', 'invoicing' ),
217
+							'label' => __('Branch sort', 'invoicing'),
218 218
 						),
219 219
 					),
220 220
 					'NZ' => array(
221 221
 						'sortcode' => array(
222
-							'label' => __( 'Bank code', 'invoicing' ),
222
+							'label' => __('Bank code', 'invoicing'),
223 223
 						),
224 224
 					),
225 225
 					'SE' => array(
226 226
 						'sortcode' => array(
227
-							'label' => __( 'Bank code', 'invoicing' ),
227
+							'label' => __('Bank code', 'invoicing'),
228 228
 						),
229 229
 					),
230 230
 					'US' => array(
231 231
 						'sortcode' => array(
232
-							'label' => __( 'Routing number', 'invoicing' ),
232
+							'label' => __('Routing number', 'invoicing'),
233 233
 						),
234 234
 					),
235 235
 					'ZA' => array(
236 236
 						'sortcode' => array(
237
-							'label' => __( 'Branch code', 'invoicing' ),
237
+							'label' => __('Branch code', 'invoicing'),
238 238
 						),
239 239
 					),
240 240
 				)
@@ -251,51 +251,51 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @param array $admin_settings
253 253
 	 */
254
-	public function admin_settings( $admin_settings ) {
254
+	public function admin_settings($admin_settings) {
255 255
 
256
-        $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' );
257
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
256
+        $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');
257
+		$admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing');
258 258
 
259
-		$locale  = $this->get_country_locale();
259
+		$locale = $this->get_country_locale();
260 260
 
261 261
 		// Get sortcode label in the $locale array and use appropriate one.
262 262
 		$country  = wpinv_default_billing_country();
263
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
263
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
264 264
 
265 265
 		$admin_settings['bank_transfer_ac_name'] = array(
266 266
             'type' => 'text',
267 267
             'id'   => 'bank_transfer_ac_name',
268
-            'name' => __( 'Account Name', 'invoicing' ),
268
+            'name' => __('Account Name', 'invoicing'),
269 269
 		);
270 270
 
271 271
 		$admin_settings['bank_transfer_ac_no'] = array(
272 272
             'type' => 'text',
273 273
             'id'   => 'bank_transfer_ac_no',
274
-            'name' => __( 'Account Number', 'invoicing' ),
274
+            'name' => __('Account Number', 'invoicing'),
275 275
 		);
276 276
 
277 277
 		$admin_settings['bank_transfer_bank_name'] = array(
278 278
             'type' => 'text',
279 279
             'id'   => 'bank_transfer_bank_name',
280
-            'name' => __( 'Bank Name', 'invoicing' ),
280
+            'name' => __('Bank Name', 'invoicing'),
281 281
 		);
282 282
 
283 283
 		$admin_settings['bank_transfer_ifsc'] = array(
284 284
             'type' => 'text',
285 285
             'id'   => 'bank_transfer_ifsc',
286
-            'name' => __( 'IFSC Code', 'invoicing' ),
286
+            'name' => __('IFSC Code', 'invoicing'),
287 287
 		);
288 288
 
289 289
 		$admin_settings['bank_transfer_iban'] = array(
290 290
             'type' => 'text',
291 291
             'id'   => 'bank_transfer_iban',
292
-            'name' => __( 'IBAN', 'invoicing' ),
292
+            'name' => __('IBAN', 'invoicing'),
293 293
 		);
294 294
 
295 295
 		$admin_settings['bank_transfer_bic'] = array(
296 296
             'type' => 'text',
297 297
             'id'   => 'bank_transfer_bic',
298
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
298
+            'name' => __('BIC/Swift Code', 'invoicing'),
299 299
 		);
300 300
 
301 301
 		$admin_settings['bank_transfer_sort_code'] = array(
@@ -306,10 +306,10 @@  discard block
 block discarded – undo
306 306
 
307 307
 		$admin_settings['bank_transfer_info'] = array(
308 308
             'id'   => 'bank_transfer_info',
309
-            'name' => __( 'Instructions', 'invoicing' ),
310
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
309
+            'name' => __('Instructions', 'invoicing'),
310
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
311 311
             'type' => 'textarea',
312
-            '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' ),
312
+            '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'),
313 313
             'cols' => 50,
314 314
             'rows' => 5,
315 315
         );
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 	 * @param GetPaid_Form_Item[] $items
325 325
 	 * @return WPInv_Invoice
326 326
 	 */
327
-	public function process_addons( $invoice, $items ) {
327
+	public function process_addons($invoice, $items) {
328 328
 
329
-        foreach ( $items as $item ) {
330
-            $invoice->add_item( $item );
329
+        foreach ($items as $item) {
330
+            $invoice->add_item($item);
331 331
         }
332 332
 
333 333
         $invoice->recalculate_total();
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 	 *
341 341
      * @param WPInv_Subscription $subscription
342 342
 	 */
343
-	public function maybe_renew_subscription( $subscription ) {
343
+	public function maybe_renew_subscription($subscription) {
344 344
 
345 345
         // Ensure its our subscription && it's active.
346
-        if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
346
+        if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) {
347 347
 			$subscription->create_payment();
348 348
         }
349 349
 
@@ -355,41 +355,41 @@  discard block
 block discarded – undo
355 355
 	 *
356 356
      * @param WPInv_Invoice $invoice
357 357
 	 */
358
-	public function invoice_paid( $invoice ) {
358
+	public function invoice_paid($invoice) {
359 359
 
360 360
 		// Abort if not paid by bank transfer.
361
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
361
+		if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) {
362 362
 			return;
363 363
 		}
364 364
 
365 365
 		// Is it a parent payment?
366
-		if ( 0 == $invoice->get_parent_id() ) {
366
+		if (0 == $invoice->get_parent_id()) {
367 367
 
368 368
 			// (Maybe) activate subscriptions.
369
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
369
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
370 370
 
371
-			if ( ! empty( $subscriptions ) ) {
372
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
371
+			if (!empty($subscriptions)) {
372
+				$subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
373 373
 
374
-				foreach ( $subscriptions as $subscription ) {
375
-					if ( $subscription->exists() ) {
376
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
377
-						$expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
374
+				foreach ($subscriptions as $subscription) {
375
+					if ($subscription->exists()) {
376
+						$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
377
+						$expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
378 378
 
379
-						$subscription->set_next_renewal_date( $expiry );
380
-						$subscription->set_date_created( current_time( 'mysql' ) );
381
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
379
+						$subscription->set_next_renewal_date($expiry);
380
+						$subscription->set_date_created(current_time('mysql'));
381
+						$subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id());
382 382
 						$subscription->activate();
383 383
 					}
384 384
 				}
385 385
 }
386 386
 } else {
387 387
 
388
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
388
+			$subscription = getpaid_get_subscription($invoice->get_subscription_id());
389 389
 
390 390
 			// Renew the subscription.
391
-			if ( $subscription && $subscription->exists() ) {
392
-				$subscription->add_payment( array(), $invoice );
391
+			if ($subscription && $subscription->exists()) {
392
+				$subscription->add_payment(array(), $invoice);
393 393
 				$subscription->renew();
394 394
 					}
395 395
 }
Please login to merge, or discard this patch.