@@ -622,6 +622,28 @@ function send_receipt($id,$currency,$amount,$name,$email,$code,$metadata){
622622 wp_mail ($ user_email , $ email_subject , $ message ,$ headers );
623623
624624}
625+ function fetch_plan ($ code ){
626+ $ mode = esc_attr ( get_option ('mode ' ) );
627+ if ($ mode == 'test ' ) {
628+ $ key = esc_attr ( get_option ('tsk ' ) );
629+ }else {
630+ $ key = esc_attr ( get_option ('lsk ' ) );
631+ }
632+ $ paystack_url = 'https://api.paystack.co/plan/ ' . $ code ;
633+ $ headers = array (
634+ 'Authorization ' => 'Bearer ' . $ key
635+ );
636+ $ args = array (
637+ 'headers ' => $ headers ,
638+ 'timeout ' => 60
639+ );
640+ $ request = wp_remote_get ( $ paystack_url , $ args );
641+ if ( ! is_wp_error ( $ request ) && 200 == wp_remote_retrieve_response_code ( $ request ) ) {
642+ $ paystack_response = json_decode ( wp_remote_retrieve_body ( $ request ) );
643+
644+ }
645+ return $ paystack_response ;
646+ }
625647function cf_shortcode ($ atts ) {
626648 ob_start ();
627649 if ( is_user_logged_in () ) {
@@ -642,7 +664,7 @@ function cf_shortcode($atts) {
642664 $ loggedin = get_post_meta ($ id ,'_loggedin ' ,true );
643665 $ txncharge = get_post_meta ($ id ,'_txncharge ' ,true );
644666 $ currency = get_post_meta ($ id ,'_currency ' ,true );
645- $ recur = get_post_meta ($ id ,'_recur ' ,true );
667+ $ recur = get_post_meta ($ id ,'_recur ' ,true );
646668 $ recurplan = get_post_meta ($ id ,'_recurplan ' ,true );
647669 // print_r($loggedin);
648670 if ($ loggedin == 'no ' ) {
@@ -669,7 +691,7 @@ function cf_shortcode($atts) {
669691 echo '</p> ' ;
670692 if ($ recur != 'no ' ) {
671693 if ($ recur == 'optional ' ) {
672- echo '<p>Reccuring Payment<br /> ' ;
694+ echo '<p>Recuring Payment<br /> ' ;
673695 echo '<select class="form-control" name="pf-interval" style="width:100%;">
674696 <option value="no">None</option>
675697 <option value="hourly">Hourly</option>
@@ -681,9 +703,11 @@ function cf_shortcode($atts) {
681703 echo '</p> ' ;
682704
683705 }else {
706+ $ plan = fetch_plan ($ recurplan );
707+ $ planamount = $ plan ->data ->amount /100 ;
684708 echo '<input type="hidden" name="pf-plancode" value=" ' . $ recurplan . '" /> ' ;
685709 // echo '<input type="number" name="pf-amount" class="form-control pf-number" id="pf-amount" required/>';
686- echo '<p> Weekly Recuring Payment </p> ' ;
710+ echo '<p> ' . $ plan -> data -> name . ' ' . $ plan -> data -> interval . ' recuring payment - ' . $ plan -> data -> currency . number_format ( $ planamount ). ' </p> ' ;
687711 }
688712
689713 }
@@ -898,7 +922,7 @@ function paystack_submit_action() {
898922 if ($ recur == 'optional ' ) {
899923 $ interval = $ _POST ['pf-interval ' ];
900924 if ($ interval != 'no ' ) {
901- unset($ metadata ['pf-interval ' ]);
925+ unset($ metadata ['pf-interval ' ]);
902926 $ mode = esc_attr ( get_option ('mode ' ) );
903927 if ($ mode == 'test ' ) {
904928 $ key = esc_attr ( get_option ('tsk ' ) );
@@ -911,9 +935,11 @@ function paystack_submit_action() {
911935 'Content-Type ' => 'application/json ' ,
912936 'Authorization ' => 'Bearer ' . $ key
913937 );
938+ $ amount = (int )str_replace (' ' , '' , $ _POST ["pf-amount " ]);
939+ $ koboamount = $ amount *100 ;
914940 $ body = array (
915941 'name ' => $ fullname .'_ ' .$ code ,
916- 'amount ' => $ _POST [ " pf-amount " ] ,
942+ 'amount ' => $ koboamount ,
917943 'interval ' => $ interval
918944 );
919945
@@ -922,14 +948,18 @@ function paystack_submit_action() {
922948 'headers ' => $ headers ,
923949 'timeout ' => 60
924950 );
951+ // print_r($args);
952+
925953
926954 $ request = wp_remote_post ( $ paystack_url , $ args );
927- if ( ! is_wp_error ( $ request ) && 200 == wp_remote_retrieve_response_code ( $ request ) ) {
928- $ paystack_response = json_decode ( wp_remote_retrieve_body ( $ request ) );
929- if ( 'Plan created ' == $ paystack_response ->message ) {
930- $ plancode = $ paystack_response ->data ->plan_code ;
931- // $paystack_ref = $paystack_response->data->reference;
932- }
955+ // print_r($request);
956+
957+ if ( ! is_wp_error ( $ request )) {
958+ // echo "string";
959+ $ paystack_response = json_decode (wp_remote_retrieve_body ($ request ));
960+ // print_r($paystack_response);
961+ $ plancode = $ paystack_response ->data ->plan_code ;
962+ // echo $plancod;
933963
934964 }
935965 # code...
@@ -952,10 +982,6 @@ function paystack_submit_action() {
952982 'txn_code ' => $ code ,
953983 'metadata ' => json_encode ($ fixedmetadata )
954984 );
955- // print_r($fixedmetadata);
956- // print_r($_FILES);
957- // die();
958-
959985 $ exist = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (post_id = ' " .$ insert ['post_id ' ]."'
960986 AND email = ' " .$ insert ['email ' ]."'
961987 AND user_id = ' " .$ insert ['pf-user_id ' ]."'
@@ -1014,6 +1040,7 @@ function paystack_meta_as_custom_fields($metadata){
10141040
10151041add_action ( 'wp_ajax_paystack_confirm_payment ' , 'paystack_confirm_payment ' );
10161042add_action ( 'wp_ajax_nopriv_paystack_confirm_payment ' , 'paystack_confirm_payment ' );
1043+
10171044function paystack_confirm_payment () {
10181045 if (trim ($ _POST ['code ' ]) == '' ) {
10191046 $ response ['error ' ] = true ;
0 commit comments