Passed
Push — master ( 58ea02...3d9af1 )
by Brian
04:49
created
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 8;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 8;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -44,24 +44,24 @@  discard block
 block discarded – undo
44 44
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
45 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
 
56 56
     /**
57
-	 * Process Payment.
58
-	 *
59
-	 * @param WPInv_Invoice $invoice Invoice.
60
-	 * @param array $submission_data Posted checkout fields.
61
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
-	 * @return array
63
-	 */
64
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+     * Process Payment.
58
+     *
59
+     * @param WPInv_Invoice $invoice Invoice.
60
+     * @param array $submission_data Posted checkout fields.
61
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
62
+     * @return array
63
+     */
64
+    public function process_payment( $invoice, $submission_data, $submission ) {
65 65
 
66 66
         // Add a transaction id.
67 67
         $invoice->set_transaction_id( $invoice->generate_key('bt_') );
@@ -82,66 +82,66 @@  discard block
 block discarded – undo
82 82
     }
83 83
 
84 84
     /**
85
-	 * Output for the order received page.
86
-	 *
87
-	 * @param WPInv_Invoice $invoice Invoice.
88
-	 */
89
-	public function thankyou_page( $invoice ) {
85
+     * Output for the order received page.
86
+     *
87
+     * @param WPInv_Invoice $invoice Invoice.
88
+     */
89
+    public function thankyou_page( $invoice ) {
90 90
 
91 91
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
92 92
 
93
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
93
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
94 94
 
95 95
             if ( ! empty( $this->instructions ) ) {
96 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
-			echo '</div>';
101
+            echo '</div>';
102 102
 
103 103
         }
104 104
 
105
-	}
105
+    }
106 106
 
107 107
     /**
108
-	 * Add content to the WPI emails.
109
-	 *
110
-	 * @param WPInv_Invoice $invoice Invoice.
111
-	 * @param string     $email_type Email format: plain text or HTML.
112
-	 * @param bool     $sent_to_admin Sent to admin.
113
-	 */
114
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
108
+     * Add content to the WPI emails.
109
+     *
110
+     * @param WPInv_Invoice $invoice Invoice.
111
+     * @param string     $email_type Email format: plain text or HTML.
112
+     * @param bool     $sent_to_admin Sent to admin.
113
+     */
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
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
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
-			echo '</div>';
126
+            echo '</div>';
127 127
 
128
-		}
128
+        }
129 129
 
130 130
     }
131 131
 
132 132
     /**
133
-	 * Get bank details and place into a list format.
134
-	 *
135
-	 * @param WPInv_Invoice $invoice Invoice.
136
-	 */
137
-	protected function bank_details( $invoice ) {
133
+     * Get bank details and place into a list format.
134
+     *
135
+     * @param WPInv_Invoice $invoice Invoice.
136
+     */
137
+    protected function bank_details( $invoice ) {
138 138
 
139
-		// Get the invoice country and country $locale.
140
-		$country = $invoice->get_country();
141
-		$locale  = $this->get_country_locale();
139
+        // Get the invoice country and country $locale.
140
+        $country = $invoice->get_country();
141
+        $locale  = $this->get_country_locale();
142 142
 
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' );
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' );
145 145
 
146 146
         $bank_fields = array(
147 147
             'ac_name'     => __( 'Account Name', 'invoicing' ),
@@ -170,144 +170,144 @@  discard block
 block discarded – undo
170 170
             return;
171 171
         }
172 172
 
173
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL;
173
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL;
174
+
175
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
176
+
177
+        foreach ( $bank_info as $key => $data ) {
178
+
179
+            $key   = sanitize_html_class( $key );
180
+            $label = wp_kses_post( $data['label'] );
181
+            $value = wp_kses_post( wptexturize( $data['value'] ) );
182
+
183
+            echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL;
184
+        }
174 185
 
175
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
186
+        echo '</table>';
176 187
 
177
-		foreach ( $bank_info as $key => $data ) {
188
+    }
178 189
 
179
-			$key   = sanitize_html_class( $key );
180
-			$label = wp_kses_post( $data['label'] );
181
-			$value = wp_kses_post( wptexturize( $data['value'] ) );
190
+    /**
191
+     * Get country locale if localized.
192
+     *
193
+     * @return array
194
+     */
195
+    public function get_country_locale() {
196
+
197
+        if ( empty( $this->locale ) ) {
198
+
199
+            // Locale information to be used - only those that are not 'Sort Code'.
200
+            $this->locale = apply_filters(
201
+                'getpaid_get_bank_transfer_locale',
202
+                array(
203
+                    'AU' => array(
204
+                        'sortcode' => array(
205
+                            'label' => __( 'BSB', 'invoicing' ),
206
+                        ),
207
+                    ),
208
+                    'CA' => array(
209
+                        'sortcode' => array(
210
+                            'label' => __( 'Bank transit number', 'invoicing' ),
211
+                        ),
212
+                    ),
213
+                    'IN' => array(
214
+                        'sortcode' => array(
215
+                            'label' => __( 'IFSC', 'invoicing' ),
216
+                        ),
217
+                    ),
218
+                    'IT' => array(
219
+                        'sortcode' => array(
220
+                            'label' => __( 'Branch sort', 'invoicing' ),
221
+                        ),
222
+                    ),
223
+                    'NZ' => array(
224
+                        'sortcode' => array(
225
+                            'label' => __( 'Bank code', 'invoicing' ),
226
+                        ),
227
+                    ),
228
+                    'SE' => array(
229
+                        'sortcode' => array(
230
+                            'label' => __( 'Bank code', 'invoicing' ),
231
+                        ),
232
+                    ),
233
+                    'US' => array(
234
+                        'sortcode' => array(
235
+                            'label' => __( 'Routing number', 'invoicing' ),
236
+                        ),
237
+                    ),
238
+                    'ZA' => array(
239
+                        'sortcode' => array(
240
+                            'label' => __( 'Branch code', 'invoicing' ),
241
+                        ),
242
+                    ),
243
+                )
244
+            );
182 245
 
183
-			echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL;
184
-		}
246
+        }
185 247
 
186
-		echo '</table>';
248
+        return $this->locale;
187 249
 
188 250
     }
189 251
 
190 252
     /**
191
-	 * Get country locale if localized.
192
-	 *
193
-	 * @return array
194
-	 */
195
-	public function get_country_locale() {
196
-
197
-		if ( empty( $this->locale ) ) {
198
-
199
-			// Locale information to be used - only those that are not 'Sort Code'.
200
-			$this->locale = apply_filters(
201
-				'getpaid_get_bank_transfer_locale',
202
-				array(
203
-					'AU' => array(
204
-						'sortcode' => array(
205
-							'label' => __( 'BSB', 'invoicing' ),
206
-						),
207
-					),
208
-					'CA' => array(
209
-						'sortcode' => array(
210
-							'label' => __( 'Bank transit number', 'invoicing' ),
211
-						),
212
-					),
213
-					'IN' => array(
214
-						'sortcode' => array(
215
-							'label' => __( 'IFSC', 'invoicing' ),
216
-						),
217
-					),
218
-					'IT' => array(
219
-						'sortcode' => array(
220
-							'label' => __( 'Branch sort', 'invoicing' ),
221
-						),
222
-					),
223
-					'NZ' => array(
224
-						'sortcode' => array(
225
-							'label' => __( 'Bank code', 'invoicing' ),
226
-						),
227
-					),
228
-					'SE' => array(
229
-						'sortcode' => array(
230
-							'label' => __( 'Bank code', 'invoicing' ),
231
-						),
232
-					),
233
-					'US' => array(
234
-						'sortcode' => array(
235
-							'label' => __( 'Routing number', 'invoicing' ),
236
-						),
237
-					),
238
-					'ZA' => array(
239
-						'sortcode' => array(
240
-							'label' => __( 'Branch code', 'invoicing' ),
241
-						),
242
-					),
243
-				)
244
-			);
245
-
246
-		}
247
-
248
-		return $this->locale;
249
-
250
-	}
251
-
252
-	/**
253
-	 * Filters the gateway settings.
254
-	 *
255
-	 * @param array $admin_settings
256
-	 */
257
-	public function admin_settings( $admin_settings ) {
253
+     * Filters the gateway settings.
254
+     *
255
+     * @param array $admin_settings
256
+     */
257
+    public function admin_settings( $admin_settings ) {
258 258
 
259 259
         $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' );
260
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
260
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
261 261
 
262
-		$locale  = $this->get_country_locale();
262
+        $locale  = $this->get_country_locale();
263 263
 
264
-		// Get sortcode label in the $locale array and use appropriate one.
265
-		$country  = wpinv_default_billing_country();
266
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
264
+        // Get sortcode label in the $locale array and use appropriate one.
265
+        $country  = wpinv_default_billing_country();
266
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
267 267
 
268
-		$admin_settings['bank_transfer_ac_name'] = array(
268
+        $admin_settings['bank_transfer_ac_name'] = array(
269 269
             'type' => 'text',
270 270
             'id'   => 'bank_transfer_ac_name',
271 271
             'name' => __( 'Account Name', 'invoicing' ),
272
-		);
272
+        );
273 273
 
274
-		$admin_settings['bank_transfer_ac_no'] = array(
274
+        $admin_settings['bank_transfer_ac_no'] = array(
275 275
             'type' => 'text',
276 276
             'id'   => 'bank_transfer_ac_no',
277 277
             'name' => __( 'Account Number', 'invoicing' ),
278
-		);
278
+        );
279 279
 
280
-		$admin_settings['bank_transfer_bank_name'] = array(
280
+        $admin_settings['bank_transfer_bank_name'] = array(
281 281
             'type' => 'text',
282 282
             'id'   => 'bank_transfer_bank_name',
283 283
             'name' => __( 'Bank Name', 'invoicing' ),
284
-		);
284
+        );
285 285
 
286
-		$admin_settings['bank_transfer_ifsc'] = array(
286
+        $admin_settings['bank_transfer_ifsc'] = array(
287 287
             'type' => 'text',
288 288
             'id'   => 'bank_transfer_ifsc',
289 289
             'name' => __( 'IFSC Code', 'invoicing' ),
290
-		);
290
+        );
291 291
 
292
-		$admin_settings['bank_transfer_iban'] = array(
292
+        $admin_settings['bank_transfer_iban'] = array(
293 293
             'type' => 'text',
294 294
             'id'   => 'bank_transfer_iban',
295 295
             'name' => __( 'IBAN', 'invoicing' ),
296
-		);
296
+        );
297 297
 
298
-		$admin_settings['bank_transfer_bic'] = array(
298
+        $admin_settings['bank_transfer_bic'] = array(
299 299
             'type' => 'text',
300 300
             'id'   => 'bank_transfer_bic',
301 301
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
302
-		);
302
+        );
303 303
 
304
-		$admin_settings['bank_transfer_sort_code'] = array(
305
-			'type' => 'text',
306
-			'id'   => 'bank_transfer_sort_code',
307
-			'name' => $sortcode,
308
-		);
304
+        $admin_settings['bank_transfer_sort_code'] = array(
305
+            'type' => 'text',
306
+            'id'   => 'bank_transfer_sort_code',
307
+            'name' => $sortcode,
308
+        );
309 309
 
310
-		$admin_settings['bank_transfer_info'] = array(
310
+        $admin_settings['bank_transfer_info'] = array(
311 311
             'id'   => 'bank_transfer_info',
312 312
             'name' => __( 'Instructions', 'invoicing' ),
313 313
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -317,17 +317,17 @@  discard block
 block discarded – undo
317 317
             'rows' => 5
318 318
         );
319 319
 
320
-		return $admin_settings;
321
-	}
320
+        return $admin_settings;
321
+    }
322 322
 
323
-	/**
324
-	 * Processes invoice addons.
325
-	 *
326
-	 * @param WPInv_Invoice $invoice
327
-	 * @param GetPaid_Form_Item[] $items
328
-	 * @return WPInv_Invoice
329
-	 */
330
-	public function process_addons( $invoice, $items ) {
323
+    /**
324
+     * Processes invoice addons.
325
+     *
326
+     * @param WPInv_Invoice $invoice
327
+     * @param GetPaid_Form_Item[] $items
328
+     * @return WPInv_Invoice
329
+     */
330
+    public function process_addons( $invoice, $items ) {
331 331
 
332 332
         foreach ( $items as $item ) {
333 333
             $invoice->add_item( $item );
@@ -335,70 +335,70 @@  discard block
 block discarded – undo
335 335
 
336 336
         $invoice->recalculate_total();
337 337
         $invoice->save();
338
-	}
338
+    }
339 339
 
340
-	/**
341
-	 * (Maybe) renews a bank transfer subscription profile.
342
-	 *
343
-	 *
340
+    /**
341
+     * (Maybe) renews a bank transfer subscription profile.
342
+     *
343
+     *
344 344
      * @param WPInv_Subscription $subscription
345
-	 */
346
-	public function maybe_renew_subscription( $subscription ) {
345
+     */
346
+    public function maybe_renew_subscription( $subscription ) {
347 347
 
348 348
         // Ensure its our subscription && it's active.
349 349
         if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
350
-			$subscription->create_payment();
350
+            $subscription->create_payment();
351 351
         }
352 352
 
353 353
     }
354 354
 
355
-	/**
356
-	 * Process a bank transfer payment.
357
-	 *
358
-	 *
355
+    /**
356
+     * Process a bank transfer payment.
357
+     *
358
+     *
359 359
      * @param WPInv_Invoice $invoice
360
-	 */
361
-	public function invoice_paid( $invoice ) {
360
+     */
361
+    public function invoice_paid( $invoice ) {
362 362
 
363
-		// Abort if not paid by bank transfer.
364
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
365
-			return;
366
-		}
363
+        // Abort if not paid by bank transfer.
364
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
365
+            return;
366
+        }
367 367
 
368
-		// Is it a parent payment?
369
-		if ( 0 == $invoice->get_parent_id() ) {
368
+        // Is it a parent payment?
369
+        if ( 0 == $invoice->get_parent_id() ) {
370 370
 
371
-			// (Maybe) activate subscriptions.
372
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
371
+            // (Maybe) activate subscriptions.
372
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
373 373
 
374
-			if ( ! empty( $subscriptions ) ) {
375
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
374
+            if ( ! empty( $subscriptions ) ) {
375
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
376 376
 
377
-				foreach ( $subscriptions as $subscription ) {
378
-					if ( $subscription->exists() ) {
379
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
380
-						$expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
377
+                foreach ( $subscriptions as $subscription ) {
378
+                    if ( $subscription->exists() ) {
379
+                        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
380
+                        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
381 381
 
382
-						$subscription->set_next_renewal_date( $expiry );
383
-						$subscription->set_date_created( current_time( 'mysql' ) );
384
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
385
-						$subscription->activate();
386
-					}
387
-				}
382
+                        $subscription->set_next_renewal_date( $expiry );
383
+                        $subscription->set_date_created( current_time( 'mysql' ) );
384
+                        $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
385
+                        $subscription->activate();
386
+                    }
387
+                }
388 388
 
389
-			}
389
+            }
390 390
 
391
-		} else {
391
+        } else {
392 392
 
393
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
393
+            $subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
394 394
 
395
-			// Renew the subscription.
396
-			if ( $subscription && $subscription->exists() ) {
397
-				$subscription->add_payment( array(), $invoice );
398
-				$subscription->renew();
399
-			}
395
+            // Renew the subscription.
396
+            if ( $subscription && $subscription->exists() ) {
397
+                $subscription->add_payment( array(), $invoice );
398
+                $subscription->renew();
399
+            }
400 400
 
401
-		}
401
+        }
402 402
 
403 403
     }
404 404
 
Please login to merge, or discard this patch.