Skip to content

Commit 58a8f30

Browse files
authored
Merge pull request #6 from ibrahimlawal/master
Ensure public key is set before displaying payment form
2 parents 5eae87a + 7c1f3ec commit 58a8f30

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

public/class-paystack-forms-public.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@ public function enqueue_styles() {
2323

2424
}
2525

26-
public function enqueue_scripts() {
27-
26+
public static function fetchPublicKey(){
2827
$mode = esc_attr( get_option('mode') );
2928
if ($mode == 'test') {
3029
$key = esc_attr( get_option('tpk') );
3130
}else{
3231
$key = esc_attr( get_option('lpk') );
3332
}
33+
return $key;
34+
}
35+
36+
public function enqueue_scripts() {
37+
3438
wp_enqueue_script( 'blockUI', plugin_dir_url( __FILE__ ) . 'js/jquery.blockUI.min.js', array( 'jquery' ), $this->version, false );
3539
wp_register_script('Paystack', 'https://js.paystack.co/v1/inline.js', false, '1');
3640
wp_enqueue_script('Paystack');
3741
wp_enqueue_script( 'paystack_frontend', plugin_dir_url( __FILE__ ) . 'js/paystack-forms-public.js', array( 'jquery' ), $this->version, false );
38-
wp_localize_script( 'paystack_frontend', 'settings', array('key'=> $key));
42+
wp_localize_script( 'paystack_frontend', 'settings', array('key'=> Kkd_Pff_Paystack_Public::fetchPublicKey()));
3943

4044
}
4145

@@ -690,7 +694,11 @@ function kkd_pff_paystack_form_shortcode($atts) {
690694
extract(shortcode_atts(array(
691695
'id' => 0,
692696
), $atts));
693-
if ($id != 0) {
697+
$pk = Kkd_Pff_Paystack_Public::fetchPublicKey();
698+
if(!$pk){
699+
echo "<h5>You must set your Paystack API keys to receive payments</h5>";
700+
}
701+
else if ($id != 0) {
694702
$obj = get_post($id);
695703
if ($obj->post_type == 'paystack_form') {
696704
$amount = get_post_meta($id,'_amount',true);

0 commit comments

Comments
 (0)