@@ -555,7 +555,7 @@ function kkd_pff_paystack_fetch_plan($code){
555555 'timeout ' => 60
556556 );
557557 $ request = wp_remote_get ( $ paystack_url , $ args );
558- if ( ! is_wp_error ( $ request ) && 200 == wp_remote_retrieve_response_code ( $ request ) ) {
558+ if ( ! is_wp_error ( $ request )) {
559559 $ paystack_response = json_decode ( wp_remote_retrieve_body ( $ request ) );
560560
561561 }
@@ -588,10 +588,24 @@ function kkd_pff_paystack_form_shortcode($atts) {
588588 $ txncharge = get_post_meta ($ id ,'_txncharge ' ,true );
589589 $ currency = get_post_meta ($ id ,'_currency ' ,true );
590590 $ recur = get_post_meta ($ id ,'_recur ' ,true );
591- $ recurplan = get_post_meta ($ id ,'_recurplan ' ,true );
591+ $ recurplan = get_post_meta ($ id ,'_recurplan ' ,true );
592+ $ showbtn = true ;
593+ $ planerrorcode = 'Input Correct Recurring Plan Code ' ;
592594 if ($ recur == 'plan ' ) {
593- $ plan = kkd_pff_paystack_fetch_plan ($ recurplan );
594- $ planamount = $ plan ->data ->amount /100 ;
595+ if ($ recurplan == '' || $ recurplan == null ) {
596+ $ showbtn = false ;
597+ }else {
598+ $ plan = kkd_pff_paystack_fetch_plan ($ recurplan );
599+ if (isset ($ plan ->data ->amount )) {
600+ $ planamount = $ plan ->data ->amount /100 ;
601+ }else {
602+ $ showbtn = false ;
603+ }
604+
605+
606+
607+ }
608+
595609 }
596610 // print_r($loggedin);
597611 if ((($ user_id != 0 ) && ($ loggedin == 'yes ' )) || $ loggedin == 'no ' ) {
@@ -631,8 +645,14 @@ function kkd_pff_paystack_form_shortcode($atts) {
631645 <label class="label">Amount ( ' .$ currency .') <span>*</span></label>
632646 <div class="input"> ' ;
633647 if ($ recur == 'plan ' ) {
634- echo '<input type="text" name="pf-amount" value=" ' .$ planamount .'" id="pf-amount" readonly required/> ' ;
635- }elseif ($ recur == 'optional ' ){
648+ if ($ showbtn ) {
649+ echo '<input type="text" name="pf-amount" value=" ' .$ planamount .'" id="pf-amount" readonly required/> ' ;
650+ }else {
651+ echo '<div class="span12 unit">
652+ <label class="label" style="font-size:18px;font-weight:600;line-height: 20px;"> ' .$ planerrorcode .'</label>
653+ </div> ' ;
654+ }
655+ }elseif ($ recur == 'optional ' ){
636656 echo '<input type="text" name="pf-amount" class="pf-number" id="pf-amount" value="0" required/> ' ;
637657 }else {
638658 if ($ amount == 0 ) {
@@ -662,10 +682,17 @@ function kkd_pff_paystack_form_shortcode($atts) {
662682 </div>
663683 </div> ' ;
664684 }elseif ($ recur == 'plan ' ){
665- echo '<input type="hidden" name="pf-plancode" value=" ' . $ recurplan . '" /> ' ;
666- echo '<div class="span12 unit">
667- <label class="label" style="font-size:18px;font-weight:600;line-height: 20px;"> ' .$ plan ->data ->name .' ' .$ plan ->data ->interval . ' recuring payment - ' .$ plan ->data ->currency .' ' .number_format ($ planamount ).'</label>
668- </div> ' ;
685+ if ($ showbtn ) {
686+ echo '<input type="hidden" name="pf-plancode" value=" ' . $ recurplan . '" /> ' ;
687+ echo '<div class="span12 unit">
688+ <label class="label" style="font-size:18px;font-weight:600;line-height: 20px;"> ' .$ plan ->data ->name .' ' .$ plan ->data ->interval . ' recuring payment - ' .$ plan ->data ->currency .' ' .number_format ($ planamount ).'</label>
689+ </div> ' ;
690+ }else {
691+ echo '<div class="span12 unit">
692+ <label class="label" style="font-size:18px;font-weight:600;line-height: 20px;"> ' .$ planerrorcode .'</label>
693+ </div> ' ;
694+ }
695+
669696 }
670697
671698
@@ -679,10 +706,11 @@ function kkd_pff_paystack_form_shortcode($atts) {
679706 <small><span style="color: red;">*</span> are compulsory</small><br />
680707 <img src=" ' . plugins_url ( '../images/logos@2x.png ' , __FILE__ ) .'" alt="cardlogos" class="paystack-cardlogos size-full wp-image-1096" />
681708
682- <button type="reset" class="secondary-btn">Reset</button>
683- <button type="submit" class="primary-btn"> ' .$ paybtn .'</button>
684- </div> ' ;
685- echo '' ;
709+ <button type="reset" class="secondary-btn">Reset</button> ' ;
710+ if ($ showbtn ){
711+ echo '<button type="submit" class="primary-btn"> ' .$ paybtn .'</button> ' ;
712+ }
713+ echo '</div> ' ;
686714
687715 echo '</div>
688716 </form> ' ;
0 commit comments