Skip to content

Commit b92c2fa

Browse files
committed
Check to see if ssl and saved cards is enabled
1 parent 7102999 commit b92c2fa

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

includes/class-paystack-deprecated.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Tbz_WC_Paystack_Gateway extends WC_Payment_Gateway {
88

9+
910
/**
1011
* Constructor
1112
*/
@@ -49,6 +50,7 @@ public function __construct() {
4950
if ( ! $this->is_valid_for_use() ) {
5051
$this->enabled = false;
5152
}
53+
5254
}
5355

5456

@@ -66,6 +68,7 @@ public function is_valid_for_use() {
6668
}
6769

6870
return true;
71+
6972
}
7073

7174
/**
@@ -76,6 +79,7 @@ public function get_icon() {
7679
$icon = '<img src="' . WC_HTTPS::force_https_url( plugins_url( '../assets/images/paystack-woocommerce.png' , __FILE__ ) ) . '" alt="cards" />';
7780

7881
return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
82+
7983
}
8084

8185

@@ -111,6 +115,7 @@ public function is_available() {
111115
}
112116

113117
return false;
118+
114119
}
115120

116121

@@ -132,6 +137,7 @@ public function admin_options() {
132137
<div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $this->msg ?></p></div>
133138

134139
<?php }
140+
135141
}
136142

137143

@@ -259,6 +265,7 @@ public function receipt_page( $order_id ) {
259265

260266
echo '<div id="paystack_form"><form id="order_review" method="post" action="'. WC()->api_request_url( 'Tbz_WC_Paystack_Gateway' ) .'"></form><button class="button alt" id="paystack-payment-button">Pay Now</button> <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">Cancel order &amp; restore cart</a></div>
261267
';
268+
262269
}
263270

264271

includes/class-paystack.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Tbz_WC_Paystack_Gateway extends WC_Payment_Gateway_CC {
88

9+
910
/**
1011
* Constructor
1112
*/
@@ -37,7 +38,7 @@ public function __construct() {
3738
$this->live_public_key = $this->get_option( 'live_public_key' );
3839
$this->live_secret_key = $this->get_option( 'live_secret_key' );
3940

40-
$this->saved_cards = $this->get_option( 'saved_cards' );
41+
$this->saved_cards = $this->get_option( 'saved_cards' ) === 'yes' ? true : false;;
4142

4243
$this->public_key = $this->testmode ? $this->test_public_key : $this->live_public_key;
4344
$this->secret_key = $this->testmode ? $this->test_secret_key : $this->live_secret_key;
@@ -56,6 +57,7 @@ public function __construct() {
5657
if ( ! $this->is_valid_for_use() ) {
5758
$this->enabled = false;
5859
}
60+
5961
}
6062

6163

@@ -73,6 +75,7 @@ public function is_valid_for_use() {
7375
}
7476

7577
return true;
78+
7679
}
7780

7881
/**
@@ -83,6 +86,7 @@ public function get_icon() {
8386
$icon = '<img src="' . WC_HTTPS::force_https_url( plugins_url( 'assets/images/paystack-woocommerce.png' , WC_PAYSTACK_MAIN_FILE ) ) . '" alt="cards" />';
8487

8588
return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
89+
8690
}
8791

8892

@@ -118,6 +122,7 @@ public function is_available() {
118122
}
119123

120124
return false;
125+
121126
}
122127

123128

@@ -139,6 +144,7 @@ public function admin_options() {
139144
<div class="inline error"><p><strong>Paystack Payment Gateway Disabled</strong>: <?php echo $this->msg ?></p></div>
140145

141146
<?php }
147+
142148
}
143149

144150

@@ -190,7 +196,7 @@ public function init_form_fields() {
190196
'title' => 'Saved Cards',
191197
'label' => 'Enable Payment via Saved Cards',
192198
'type' => 'checkbox',
193-
'description' => 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Paystack servers, not on your store.<br>This will only be enabled if you have a valid SSL certificate installed',
199+
'description' => 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Paystack servers, not on your store.<br>Note that you need to have a valid SSL certificate installed.',
194200
'default' => 'no',
195201
'desc_tip' => true,
196202
),
@@ -204,26 +210,19 @@ public function init_form_fields() {
204210
*/
205211
public function payment_fields() {
206212

207-
if( is_ssl() ){
213+
if( ! is_ssl() ){
208214
wp_enqueue_style( 'paystack', plugins_url( 'assets/css/paystack.css', WC_PAYSTACK_MAIN_FILE ) );
209215
return;
210216
}
211217

212-
$user = wp_get_current_user();
213-
$display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards && $user->ID;
214-
215-
echo '<div>';
216-
217-
if ( $display_tokenization ) {
218+
if ( $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards && is_user_logged_in() ) {
218219

219220
$this->tokenization_script();
220-
221221
$this->saved_payment_methods();
222-
223222
$this->save_payment_method_checkbox();
223+
224224
}
225225

226-
echo '</div>';
227226
}
228227

229228

@@ -315,6 +314,7 @@ public function process_payment( $order_id ) {
315314
);
316315

317316
}
317+
318318
}
319319

320320

@@ -418,6 +418,7 @@ public function process_token_payment( $token, $order_id ) {
418418
public function add_payment_method() {
419419
wc_add_notice( 'You can only add a new card when placing an order.', 'error' );
420420
return;
421+
421422
}
422423

423424

@@ -432,6 +433,7 @@ public function receipt_page( $order_id ) {
432433

433434
echo '<div id="paystack_form"><form id="order_review" method="post" action="'. WC()->api_request_url( 'Tbz_WC_Paystack_Gateway' ) .'"></form><button class="button alt" id="paystack-payment-button">Pay Now</button> <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">Cancel order &amp; restore cart</a></div>
434435
';
436+
435437
}
436438

437439

0 commit comments

Comments
 (0)