From a570759e8500fec0be9cc6b8471b20fd4b7da5ed Mon Sep 17 00:00:00 2001 From: Douglas Kesi-Ayeba Kendyson Date: Sun, 18 Sep 2016 13:59:41 +0100 Subject: [PATCH] plan code error fall back. --- public/class-paystack-forms-public.php | 56 +++++++++++++++++++------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/public/class-paystack-forms-public.php b/public/class-paystack-forms-public.php index 47d53c6..b88d454 100755 --- a/public/class-paystack-forms-public.php +++ b/public/class-paystack-forms-public.php @@ -555,7 +555,7 @@ function kkd_pff_paystack_fetch_plan($code){ 'timeout' => 60 ); $request = wp_remote_get( $paystack_url, $args ); - if( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) { + if( ! is_wp_error( $request )) { $paystack_response = json_decode( wp_remote_retrieve_body( $request ) ); } @@ -588,10 +588,24 @@ function kkd_pff_paystack_form_shortcode($atts) { $txncharge = get_post_meta($id,'_txncharge',true); $currency = get_post_meta($id,'_currency',true); $recur = get_post_meta($id,'_recur',true); - $recurplan = get_post_meta($id,'_recurplan',true); + $recurplan = get_post_meta($id,'_recurplan',true); + $showbtn = true; + $planerrorcode = 'Input Correct Recurring Plan Code'; if ($recur == 'plan') { - $plan= kkd_pff_paystack_fetch_plan($recurplan); - $planamount = $plan->data->amount/100; + if ($recurplan == '' || $recurplan == null) { + $showbtn = false; + }else{ + $plan = kkd_pff_paystack_fetch_plan($recurplan); + if (isset($plan->data->amount)) { + $planamount = $plan->data->amount/100; + }else{ + $showbtn = false; + } + + + + } + } // print_r($loggedin); if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') { @@ -631,8 +645,14 @@ function kkd_pff_paystack_form_shortcode($atts) {
'; if ($recur == 'plan') { - echo ''; - }elseif($recur == 'optional'){ + if ($showbtn) { + echo ''; + }else{ + echo '
+ +
'; + } + }elseif($recur == 'optional'){ echo ''; }else{ if ($amount == 0) { @@ -662,10 +682,17 @@ function kkd_pff_paystack_form_shortcode($atts) {
'; }elseif($recur == 'plan'){ - echo ''; - echo '
- -
'; + if ($showbtn) { + echo ''; + echo '
+ +
'; + }else{ + echo '
+ +
'; + } + } @@ -679,10 +706,11 @@ function kkd_pff_paystack_form_shortcode($atts) { * are compulsory
cardlogos - - - '; - echo ''; + '; + if ($showbtn){ + echo ''; + } + echo ''; echo ' ';