Passed
Push — master ( 7ef8cd...457b0a )
by Brian
05:08
created
includes/gateways/class-getpaid-bank-transfer-gateway.php 1 patch
Indentation   +222 added lines, -222 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' ),
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 
161 161
             if ( ! empty( $value ) ) {
162 162
                 $bank_info[ $field ] = array(
163
-					'label' => $label,
164
-					'value' => $value,
165
-				);
163
+                    'label' => $label,
164
+                    'value' => $value,
165
+                );
166 166
             }
167
-		}
167
+        }
168 168
 
169 169
         $bank_info = apply_filters( 'wpinv_bank_info', $bank_info );
170 170
 
@@ -172,139 +172,139 @@  discard block
 block discarded – undo
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' ) ) ) . '</h3>' . PHP_EOL;
175
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) ) . '</h3>' . PHP_EOL;
176
+
177
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
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;
181
+        }
182
+
183
+        echo '</table>';
176 184
 
177
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
185
+    }
178 186
 
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
-		}
187
+    /**
188
+     * Get country locale if localized.
189
+     *
190
+     * @return array
191
+     */
192
+    public function get_country_locale() {
193
+
194
+        if ( empty( $this->locale ) ) {
195
+
196
+            // Locale information to be used - only those that are not 'Sort Code'.
197
+            $this->locale = apply_filters(
198
+                'getpaid_get_bank_transfer_locale',
199
+                array(
200
+                    'AU' => array(
201
+                        'sortcode' => array(
202
+                            'label' => __( 'BSB', 'invoicing' ),
203
+                        ),
204
+                    ),
205
+                    'CA' => array(
206
+                        'sortcode' => array(
207
+                            'label' => __( 'Bank transit number', 'invoicing' ),
208
+                        ),
209
+                    ),
210
+                    'IN' => array(
211
+                        'sortcode' => array(
212
+                            'label' => __( 'IFSC', 'invoicing' ),
213
+                        ),
214
+                    ),
215
+                    'IT' => array(
216
+                        'sortcode' => array(
217
+                            'label' => __( 'Branch sort', 'invoicing' ),
218
+                        ),
219
+                    ),
220
+                    'NZ' => array(
221
+                        'sortcode' => array(
222
+                            'label' => __( 'Bank code', 'invoicing' ),
223
+                        ),
224
+                    ),
225
+                    'SE' => array(
226
+                        'sortcode' => array(
227
+                            'label' => __( 'Bank code', 'invoicing' ),
228
+                        ),
229
+                    ),
230
+                    'US' => array(
231
+                        'sortcode' => array(
232
+                            'label' => __( 'Routing number', 'invoicing' ),
233
+                        ),
234
+                    ),
235
+                    'ZA' => array(
236
+                        'sortcode' => array(
237
+                            'label' => __( 'Branch code', 'invoicing' ),
238
+                        ),
239
+                    ),
240
+                )
241
+            );
182 242
 
183
-		echo '</table>';
243
+        }
244
+
245
+        return $this->locale;
184 246
 
185 247
     }
186 248
 
187 249
     /**
188
-	 * Get country locale if localized.
189
-	 *
190
-	 * @return array
191
-	 */
192
-	public function get_country_locale() {
193
-
194
-		if ( empty( $this->locale ) ) {
195
-
196
-			// Locale information to be used - only those that are not 'Sort Code'.
197
-			$this->locale = apply_filters(
198
-				'getpaid_get_bank_transfer_locale',
199
-				array(
200
-					'AU' => array(
201
-						'sortcode' => array(
202
-							'label' => __( 'BSB', 'invoicing' ),
203
-						),
204
-					),
205
-					'CA' => array(
206
-						'sortcode' => array(
207
-							'label' => __( 'Bank transit number', 'invoicing' ),
208
-						),
209
-					),
210
-					'IN' => array(
211
-						'sortcode' => array(
212
-							'label' => __( 'IFSC', 'invoicing' ),
213
-						),
214
-					),
215
-					'IT' => array(
216
-						'sortcode' => array(
217
-							'label' => __( 'Branch sort', 'invoicing' ),
218
-						),
219
-					),
220
-					'NZ' => array(
221
-						'sortcode' => array(
222
-							'label' => __( 'Bank code', 'invoicing' ),
223
-						),
224
-					),
225
-					'SE' => array(
226
-						'sortcode' => array(
227
-							'label' => __( 'Bank code', 'invoicing' ),
228
-						),
229
-					),
230
-					'US' => array(
231
-						'sortcode' => array(
232
-							'label' => __( 'Routing number', 'invoicing' ),
233
-						),
234
-					),
235
-					'ZA' => array(
236
-						'sortcode' => array(
237
-							'label' => __( 'Branch code', 'invoicing' ),
238
-						),
239
-					),
240
-				)
241
-			);
242
-
243
-		}
244
-
245
-		return $this->locale;
246
-
247
-	}
248
-
249
-	/**
250
-	 * Filters the gateway settings.
251
-	 *
252
-	 * @param array $admin_settings
253
-	 */
254
-	public function admin_settings( $admin_settings ) {
250
+     * Filters the gateway settings.
251
+     *
252
+     * @param array $admin_settings
253
+     */
254
+    public function admin_settings( $admin_settings ) {
255 255
 
256 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' );
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
-		// Get sortcode label in the $locale array and use appropriate one.
262
-		$country  = wpinv_default_billing_country();
263
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
261
+        // Get sortcode label in the $locale array and use appropriate one.
262
+        $country  = wpinv_default_billing_country();
263
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
264 264
 
265
-		$admin_settings['bank_transfer_ac_name'] = array(
265
+        $admin_settings['bank_transfer_ac_name'] = array(
266 266
             'type' => 'text',
267 267
             'id'   => 'bank_transfer_ac_name',
268 268
             'name' => __( 'Account Name', 'invoicing' ),
269
-		);
269
+        );
270 270
 
271
-		$admin_settings['bank_transfer_ac_no'] = array(
271
+        $admin_settings['bank_transfer_ac_no'] = array(
272 272
             'type' => 'text',
273 273
             'id'   => 'bank_transfer_ac_no',
274 274
             'name' => __( 'Account Number', 'invoicing' ),
275
-		);
275
+        );
276 276
 
277
-		$admin_settings['bank_transfer_bank_name'] = array(
277
+        $admin_settings['bank_transfer_bank_name'] = array(
278 278
             'type' => 'text',
279 279
             'id'   => 'bank_transfer_bank_name',
280 280
             'name' => __( 'Bank Name', 'invoicing' ),
281
-		);
281
+        );
282 282
 
283
-		$admin_settings['bank_transfer_ifsc'] = array(
283
+        $admin_settings['bank_transfer_ifsc'] = array(
284 284
             'type' => 'text',
285 285
             'id'   => 'bank_transfer_ifsc',
286 286
             'name' => __( 'IFSC Code', 'invoicing' ),
287
-		);
287
+        );
288 288
 
289
-		$admin_settings['bank_transfer_iban'] = array(
289
+        $admin_settings['bank_transfer_iban'] = array(
290 290
             'type' => 'text',
291 291
             'id'   => 'bank_transfer_iban',
292 292
             'name' => __( 'IBAN', 'invoicing' ),
293
-		);
293
+        );
294 294
 
295
-		$admin_settings['bank_transfer_bic'] = array(
295
+        $admin_settings['bank_transfer_bic'] = array(
296 296
             'type' => 'text',
297 297
             'id'   => 'bank_transfer_bic',
298 298
             'name' => __( 'BIC/Swift Code', 'invoicing' ),
299
-		);
299
+        );
300 300
 
301
-		$admin_settings['bank_transfer_sort_code'] = array(
302
-			'type' => 'text',
303
-			'id'   => 'bank_transfer_sort_code',
304
-			'name' => $sortcode,
305
-		);
301
+        $admin_settings['bank_transfer_sort_code'] = array(
302
+            'type' => 'text',
303
+            'id'   => 'bank_transfer_sort_code',
304
+            'name' => $sortcode,
305
+        );
306 306
 
307
-		$admin_settings['bank_transfer_info'] = array(
307
+        $admin_settings['bank_transfer_info'] = array(
308 308
             'id'   => 'bank_transfer_info',
309 309
             'name' => __( 'Instructions', 'invoicing' ),
310 310
             'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
@@ -314,17 +314,17 @@  discard block
 block discarded – undo
314 314
             'rows' => 5,
315 315
         );
316 316
 
317
-		return $admin_settings;
318
-	}
317
+        return $admin_settings;
318
+    }
319 319
 
320
-	/**
321
-	 * Processes invoice addons.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 * @param GetPaid_Form_Item[] $items
325
-	 * @return WPInv_Invoice
326
-	 */
327
-	public function process_addons( $invoice, $items ) {
320
+    /**
321
+     * Processes invoice addons.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     * @param GetPaid_Form_Item[] $items
325
+     * @return WPInv_Invoice
326
+     */
327
+    public function process_addons( $invoice, $items ) {
328 328
 
329 329
         foreach ( $items as $item ) {
330 330
             $invoice->add_item( $item );
@@ -332,66 +332,66 @@  discard block
 block discarded – undo
332 332
 
333 333
         $invoice->recalculate_total();
334 334
         $invoice->save();
335
-	}
335
+    }
336 336
 
337
-	/**
338
-	 * (Maybe) renews a bank transfer subscription profile.
339
-	 *
340
-	 *
337
+    /**
338
+     * (Maybe) renews a bank transfer subscription profile.
339
+     *
340
+     *
341 341
      * @param WPInv_Subscription $subscription
342
-	 */
343
-	public function maybe_renew_subscription( $subscription ) {
342
+     */
343
+    public function maybe_renew_subscription( $subscription ) {
344 344
 
345 345
         // Ensure its our subscription && it's active.
346 346
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
347
-			$subscription->create_payment();
347
+            $subscription->create_payment();
348 348
         }
349 349
 
350 350
     }
351 351
 
352
-	/**
353
-	 * Process a bank transfer payment.
354
-	 *
355
-	 *
352
+    /**
353
+     * Process a bank transfer payment.
354
+     *
355
+     *
356 356
      * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function invoice_paid( $invoice ) {
359
-
360
-		// Abort if not paid by bank transfer.
361
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
-			return;
363
-		}
364
-
365
-		// Is it a parent payment?
366
-		if ( 0 == $invoice->get_parent_id() ) {
367
-
368
-			// (Maybe) activate subscriptions.
369
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
-
371
-			if ( ! empty( $subscriptions ) ) {
372
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
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 ) );
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() );
382
-						$subscription->activate();
383
-					}
384
-				}
357
+     */
358
+    public function invoice_paid( $invoice ) {
359
+
360
+        // Abort if not paid by bank transfer.
361
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
362
+            return;
363
+        }
364
+
365
+        // Is it a parent payment?
366
+        if ( 0 == $invoice->get_parent_id() ) {
367
+
368
+            // (Maybe) activate subscriptions.
369
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
370
+
371
+            if ( ! empty( $subscriptions ) ) {
372
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
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 ) );
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() );
382
+                        $subscription->activate();
383
+                    }
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
-			// Renew the subscription.
391
-			if ( $subscription && $subscription->exists() ) {
392
-				$subscription->add_payment( array(), $invoice );
393
-				$subscription->renew();
394
-					}
390
+            // Renew the subscription.
391
+            if ( $subscription && $subscription->exists() ) {
392
+                $subscription->add_payment( array(), $invoice );
393
+                $subscription->renew();
394
+                    }
395 395
 }
396 396
 
397 397
     }
Please login to merge, or discard this patch.