Skip to content

Commit be635ba

Browse files
committed
fix fatal error thrown when woocommerce subscription plugin not active
1 parent f6fb63d commit be635ba

4 files changed

Lines changed: 106 additions & 79 deletions

File tree

includes/class-paystack-deprecated.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct() {
6161
*/
6262
public function is_valid_for_use() {
6363

64-
if( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paystack_supported_currencies', array( 'NGN' ) ) ) ) {
64+
if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paystack_supported_currencies', array( 'NGN' ) ) ) ) {
6565

6666
$this->msg = 'Paystack does not support your store currency. Kindly set it to Nigerian Naira &#8358; <a href="' . admin_url( 'admin.php?page=wc-settings&tab=general' ) . '">here</a>';
6767

@@ -141,8 +141,8 @@ public function admin_options() {
141141
echo '</table>';
142142

143143
}
144-
else{ ?>
145-
<div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $this->msg ?></p></div>
144+
else { ?>
145+
<div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $this->msg ?></p></div>
146146

147147
<?php }
148148

@@ -286,7 +286,7 @@ public function verify_paystack_transaction() {
286286

287287
@ob_clean();
288288

289-
if( isset( $_REQUEST['paystack_txnref'] ) ){
289+
if ( isset( $_REQUEST['paystack_txnref'] ) ){
290290

291291
$paystack_url = 'https://api.paystack.co/transaction/verify/' . $_REQUEST['paystack_txnref'];
292292

@@ -301,7 +301,7 @@ public function verify_paystack_transaction() {
301301

302302
$request = wp_remote_get( $paystack_url, $args );
303303

304-
if( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) {
304+
if ( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) {
305305

306306
$paystack_response = json_decode( wp_remote_retrieve_body( $request ) );
307307

@@ -313,7 +313,7 @@ public function verify_paystack_transaction() {
313313

314314
$order = wc_get_order($order_id);
315315

316-
if( in_array( $order->get_status(), array( 'processing', 'completed', 'on-hold' ) ) ) {
316+
if ( in_array( $order->get_status(), array( 'processing', 'completed', 'on-hold' ) ) ) {
317317
wp_redirect( $this->get_return_url( $order ) );
318318
exit;
319319
}
@@ -325,7 +325,7 @@ public function verify_paystack_transaction() {
325325
$paystack_ref = $paystack_response->data->reference;
326326

327327
// check if the amount paid is equal to the order amount.
328-
if( $order_total != $amount_paid ) {
328+
if ( $order_total != $amount_paid ) {
329329

330330
$order->update_status( 'on-hold', '' );
331331

@@ -346,7 +346,7 @@ public function verify_paystack_transaction() {
346346

347347
wc_empty_cart();
348348
}
349-
else{
349+
else {
350350

351351
$order->payment_complete( $paystack_ref );
352352

@@ -393,13 +393,13 @@ public function process_webhooks() {
393393
$json = file_get_contents( "php://input" );
394394

395395
// validate event do all at once to avoid timing attack
396-
if( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $json, $this->secret_key ) ) {
396+
if ( $_SERVER['HTTP_X_PAYSTACK_SIGNATURE'] !== hash_hmac( 'sha512', $json, $this->secret_key ) ) {
397397
exit;
398398
}
399399

400400
$event = json_decode( $json );
401401

402-
if( 'charge.success' == $event->event ) {
402+
if ( 'charge.success' == $event->event ) {
403403

404404
http_response_code(200);
405405

@@ -411,11 +411,11 @@ public function process_webhooks() {
411411

412412
$paystack_txn_ref = get_post_meta( $order_id, '_paystack_txn_ref', true );
413413

414-
if( $event->data->reference != $paystack_txn_ref ) {
414+
if ( $event->data->reference != $paystack_txn_ref ) {
415415
exit;
416416
}
417417

418-
if( in_array( $order->get_status(), array( 'processing', 'completed', 'on-hold' ) ) ) {
418+
if ( in_array( $order->get_status(), array( 'processing', 'completed', 'on-hold' ) ) ) {
419419
exit;
420420
}
421421

@@ -426,7 +426,7 @@ public function process_webhooks() {
426426
$paystack_ref = $event->data->reference;
427427

428428
// check if the amount paid is equal to the order amount.
429-
if( $order_total != $amount_paid ) {
429+
if ( $order_total != $amount_paid ) {
430430

431431
$order->update_status( 'on-hold', '' );
432432

@@ -447,7 +447,7 @@ public function process_webhooks() {
447447

448448
wc_empty_cart();
449449
}
450-
else{
450+
else {
451451

452452
$order->payment_complete( $paystack_ref );
453453

0 commit comments

Comments
 (0)