@@ -32,6 +32,8 @@ function kkd_pff_paystack_txncheck($name,$txncharge){
3232 function kkd_pff_paystack_setting_page () {
3333 ?>
3434 <h1>Paystack Forms API KEYS Settings!</h1>
35+
36+ <h4>Optional: To avoid situations where bad network makes it impossible to verify transactions, set your webhook URL <a href="https://dashboard.paystack.co/#/settings/developer">here</a> to the URL below<strong style="color: red"><pre><code><?php echo admin_url ("admin-ajax.php " ) . "?action=kkd_paystack_pff " ;?> </code></pre></strong></h4>
3537 <form method="post" action="options.php">
3638 <?php settings_fields ( 'kkd-pff-paystack-settings-group ' ); do_settings_sections ( 'kkd-pff-paystack-settings-group ' ); ?>
3739 <table class="form-table paystack_setting_page">
@@ -47,8 +49,7 @@ function kkd_pff_paystack_setting_page() {
4749 <tr valign="top">
4850 <th scope="row">Test Secret Key</th>
4951 <td>
50-
51- <input type="text" name="tsk" value="<?php echo esc_attr ( get_option ('tsk ' ) ); ?> " /></td>
52+ <input type="text" name="tsk" value="<?php echo esc_attr ( get_option ('tsk ' ) ); ?> " /></td>
5253 </tr>
5354
5455 <tr valign="top">
@@ -169,7 +170,7 @@ function kkd_pff_paystack_edit_dashboard_header_columns( $columns ) {
169170 $ columns = array (
170171 'cb ' => '<input type="checkbox" /> ' ,
171172 'title ' => __ ( 'Name ' ),
172- 'shortcode ' => __ ( 'Shortcode ' ),
173+ 'shortcode ' => __ ( 'Shortcode ' ),
173174 'payments ' => __ ( 'Payments ' ),
174175 'date ' => __ ( 'Date ' )
175176 );
@@ -260,6 +261,7 @@ function kkd_pff_paystack_editor_add_extra_metaboxes() {
260261 add_meta_box ('kkd_pff_paystack_editor_add_email_data ' , 'Email Receipt Settings ' , 'kkd_pff_paystack_editor_add_email_data ' , 'paystack_form ' , 'normal ' , 'default ' );
261262 add_meta_box ('kkd_pff_paystack_editor_add_quantity_data ' , 'Quantity Payment ' , 'kkd_pff_paystack_editor_add_quantity_data ' , 'paystack_form ' , 'side ' , 'default ' );
262263 add_meta_box ('kkd_pff_paystack_editor_add_agreement_data ' , 'Agreement checkbox ' , 'kkd_pff_paystack_editor_add_agreement_data ' , 'paystack_form ' , 'side ' , 'default ' );
264+ add_meta_box ('kkd_pff_paystack_editor_add_subaccount_data ' , 'Sub Account ' , 'kkd_pff_paystack_editor_add_subaccount_data ' , 'paystack_form ' , 'side ' , 'default ' );
263265
264266 }
265267
@@ -279,6 +281,7 @@ function kkd_pff_paystack_editor_add_form_data() {
279281 $ loggedin = get_post_meta ($ post ->ID , '_loggedin ' , true );
280282 $ currency = get_post_meta ($ post ->ID , '_currency ' , true );
281283 $ filelimit = get_post_meta ($ post ->ID , '_filelimit ' , true );
284+ $ redirect = get_post_meta ($ post ->ID , '_redirect ' , true );
282285
283286 if ($ amount == "" ) {$ amount = 0 ;}
284287 if ($ filelimit == "" ) {$ filelimit = 2 ;}
@@ -297,7 +300,7 @@ function kkd_pff_paystack_editor_add_form_data() {
297300 echo '<p>Transaction Charges:</p> ' ;
298301 echo '<select class="form-control" name="_txncharge" id="parent_id" style="width:100%;">
299302 <option value="merchant" ' .kkd_pff_paystack_txncheck ('merchant ' ,$ txncharge ).'>Merchant Pays(Include in fee)</option>
300- <option value="customer" ' .kkd_pff_paystack_txncheck ('customer ' ,$ txncharge ).'>Client Pays(Extra Fee added) - 1.55%+ NGN100 if above NGN2,500 </option>
303+ <option value="customer" ' .kkd_pff_paystack_txncheck ('customer ' ,$ txncharge ).'>Client Pays(Calculated Paystack Local Fee added) </option>
301304 </select> ' ;
302305 echo '<p>User logged In:</p> ' ;
303306 echo '<select class="form-control" name="_loggedin" id="parent_id" style="width:100%;">
@@ -306,8 +309,10 @@ function kkd_pff_paystack_editor_add_form_data() {
306309 </select> ' ;
307310 echo '<p>Success Message after Payment</p> ' ;
308311 echo '<textarea rows="3" name="_successmsg" class="widefat" > ' .$ successmsg .'</textarea> ' ;
309- echo '<p>File Upload Limit(MB):</p> ' ;
312+ echo '<p>File Upload Limit(MB):</p> ' ;
310313 echo '<input ttype="number" name="_filelimit" value=" ' . $ filelimit . '" class="widefat pf-number" /> ' ;
314+ echo '<p>Redirect to page link after payment(keep blank to use normal success message):</p> ' ;
315+ echo '<input ttype="text" name="_redirect" value=" ' . $ redirect . '" class="widefat" /> ' ;
311316
312317 }
313318 function kkd_pff_paystack_editor_add_email_data () {
@@ -413,6 +418,27 @@ function kkd_pff_paystack_editor_add_agreement_data() {
413418 echo '<input type="text" name="_agreementlink" value=" ' . $ agreementlink . '" class="widefat" /> ' ;
414419
415420 }
421+ function kkd_pff_paystack_editor_add_subaccount_data () {
422+ global $ post ;
423+
424+ // Noncename needed to verify where the data originated
425+ echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value=" ' .
426+ wp_create_nonce ( plugin_basename (__FILE__ ) ) . '" /> ' ;
427+
428+ // Get the location data if its already been entered
429+ $ subaccount = get_post_meta ($ post ->ID , '_subaccount ' , true );
430+ $ txnbearer = get_post_meta ($ post ->ID , '_txnbearer ' , true );
431+
432+
433+ if ($ subaccount == "" ) {$ subaccount = '' ;}
434+ echo '<p>Sub Account code:</p> ' ;
435+ echo '<input type="text" name="_subaccount" value=" ' . $ subaccount . '" class="widefat" /> ' ;
436+ echo '<p>Transaction Charge bearer:</p> ' ;
437+ echo '<select class="form-control" name="_txnbearer" id="parent_id" style="width:100%;">
438+ <option value="account" ' .kkd_pff_paystack_txncheck ('account ' ,$ txnbearer ).'>Merchant (default)</option>
439+ <option value="subaccount" ' .kkd_pff_paystack_txncheck ('subaccount ' ,$ txnbearer ).'>Sub Account</option>
440+ </select> ' ;
441+ }
416442 function kkd_pff_paystack_save_data ($ post_id , $ post ) {
417443
418444 if ( !wp_verify_nonce ( @$ _POST ['eventmeta_noncename ' ], plugin_basename (__FILE__ ) )) {
@@ -424,13 +450,14 @@ function kkd_pff_paystack_save_data($post_id, $post) {
424450 return $ post ->ID ;
425451 }
426452
427- $ form_meta ['_amount ' ] = $ _POST ['_amount ' ];
453+ $ form_meta ['_amount ' ] = $ _POST ['_amount ' ];
428454 $ form_meta ['_paybtn ' ] = $ _POST ['_paybtn ' ];
429455 $ form_meta ['_currency ' ] = $ _POST ['_currency ' ];
430456 $ form_meta ['_successmsg ' ] = $ _POST ['_successmsg ' ];
431457 $ form_meta ['_txncharge ' ] = $ _POST ['_txncharge ' ];
432458 $ form_meta ['_loggedin ' ] = $ _POST ['_loggedin ' ];
433459 $ form_meta ['_filelimit ' ] = $ _POST ['_filelimit ' ];
460+ $ form_meta ['_redirect ' ] = $ _POST ['_redirect ' ];
434461 ///
435462 $ form_meta ['_subject ' ] = $ _POST ['_subject ' ];
436463 $ form_meta ['_heading ' ] = $ _POST ['_heading ' ];
@@ -444,6 +471,8 @@ function kkd_pff_paystack_save_data($post_id, $post) {
444471
445472 $ form_meta ['_useagreement ' ] = $ _POST ['_useagreement ' ];
446473 $ form_meta ['_agreementlink ' ] = $ _POST ['_agreementlink ' ];
474+ $ form_meta ['_subaccount ' ] = $ _POST ['_subaccount ' ];
475+ $ form_meta ['_txnbearer ' ] = $ _POST ['_txnbearer ' ];
447476
448477 // Add values of $form_meta as custom fields
449478
@@ -494,11 +523,26 @@ function kkd_pff_paystack_payment_submissions(){
494523 $ loggedin = get_post_meta ($ id ,'_loggedin ' ,true );
495524 $ txncharge = get_post_meta ($ id ,'_txncharge ' ,true );
496525
497- echo "<title> " .$ obj ->post_title ." Payments </title> " ;
498- echo "<h1> " .$ obj ->post_title ." Payments</h1> " ;
499526 $ exampleListTable = new Kkd_Pff_Paystack_Payments_List_Table ();
500- $ exampleListTable ->prepare_items ();
527+ $ data = $ exampleListTable ->prepare_items ();
528+
501529 ?>
530+ <div id="welcome-panel" class="welcome-panel">
531+ <div class="welcome-panel-content">
532+ <h1 style="margin: 0px;"><?php echo $ obj ->post_title ; ?> Payments </h1>
533+ <p class="about-description">All payments made for this form</p>
534+ <?php if ($ data > 0 ) { ?>
535+
536+ <form action="<?php echo admin_url ('admin-post.php ' ); ?> " method="post">
537+ <input type="hidden" name="action" value="kkd_pff_export_excel">
538+ <input type="hidden" name="form_id" value="<?php echo $ id ; ?> ">
539+ <button type="submit" class="button button-primary button-hero load-customize" >Export Data to Excel</button>
540+ </form>
541+ <?php } ?>
542+
543+ <br><br>
544+ </div>
545+ </div>
502546 <div class="wrap">
503547 <div id="icon-users" class="icon32"></div>
504548 <?php $ exampleListTable ->display (); ?>
@@ -507,6 +551,81 @@ function kkd_pff_paystack_payment_submissions(){
507551
508552 }
509553}
554+ add_action ( 'admin_post_kkd_pff_export_excel ' , 'Kkd_pff_export_excel ' );
555+
556+ function Kkd_pff_export_excel () {
557+ global $ wpdb ;
558+
559+ $ post_id = $ _POST ['form_id ' ];
560+ $ obj = get_post ($ post_id );
561+ $ csv_output = "" ;
562+
563+
564+ $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
565+ $ data = array ();
566+ $ alldbdata = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (post_id = ' " .$ post_id ."' AND paid = '1') ORDER BY `id` ASC " );
567+ $ i = 0 ;
568+
569+ if (count ($ alldbdata ) > 0 ) {
570+ $ header = $ alldbdata [0 ];
571+ $ csv_output .= "#, " ;
572+ $ csv_output .= "Email, " ;
573+ $ csv_output .= "Amount, " ;
574+ $ csv_output .= "Reference, " ;
575+ $ new = json_decode ($ header ->metadata );
576+ $ text = '' ;
577+ if (array_key_exists ("0 " , $ new )) {
578+ foreach ($ new as $ key => $ item ) {
579+ $ csv_output .= $ item ->display_name .", " ;
580+ }
581+ }else {
582+ if (count ($ new ) > 0 ) {
583+ foreach ($ new as $ key => $ item ) {
584+ $ csv_output .= $ key .", " ;
585+ }
586+ }
587+ }
588+ $ csv_output .= "\n" ;
589+
590+ foreach ($ alldbdata as $ key => $ dbdata ) {
591+ $ newkey = $ key +1 ;
592+ if ($ dbdata ->txn_code_2 != "" ) {
593+ $ txn_code = $ dbdata ->txn_code_2 ;
594+ }else {
595+ $ txn_code = $ dbdata ->txn_code ;
596+ }
597+ $ csv_output .= $ newkey .", " ;
598+ $ csv_output .= $ dbdata ->email .", " ;
599+ $ csv_output .= $ currency .' ' .$ dbdata ->amount .", " ;
600+ $ csv_output .= $ txn_code .", " ;
601+ $ new = json_decode ($ header ->metadata );
602+ $ text = '' ;
603+ if (array_key_exists ("0 " , $ new )) {
604+ foreach ($ new as $ key => $ item ) {
605+ $ csv_output .= $ item ->value .", " ;
606+ }
607+ }else {
608+ if (count ($ new ) > 0 ) {
609+ foreach ($ new as $ key => $ item ) {
610+ $ csv_output .= $ item .", " ;
611+ }
612+ }
613+ }
614+ $ csv_output .= "\n" ;
615+ }
616+
617+
618+ $ filename = $ obj ->post_title ."_payments_ " .date ("Y-m-d_H-i " ,time ());
619+ header ("Content-type: application/vnd.ms-excel " );
620+ header ("Content-disposition: csv " . date ("Y-m-d " ) . ".csv " );
621+ header ( "Content-disposition: filename= " .$ filename .".csv " );
622+ print $ csv_output ;
623+ exit ;
624+ }
625+
626+
627+ // Handle request then generate response using echo or leaving PHP and using HTML
628+ }
510629class Kkd_Pff_Paystack_Wp_List_Table{
511630 public function __construct (){
512631 add_action ( 'admin_menu ' , array ($ this , 'add_menu_example_list_table_page ' ));
@@ -561,17 +680,22 @@ public function prepare_items(){
561680
562681 global $ wpdb ;
563682
564- $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
683+ $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
565684 $ data = array ();
566685 $ alldbdata = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (post_id = ' " .$ post_id ."' AND paid = '1') " );
567686
568687 foreach ($ alldbdata as $ key => $ dbdata ) {
569688 $ newkey = $ key +1 ;
689+ if ($ dbdata ->txn_code_2 != "" ) {
690+ $ txn_code = $ dbdata ->txn_code_2 ;
691+ }else {
692+ $ txn_code = $ dbdata ->txn_code ;
693+ }
570694 $ data [] = array (
571- 'id ' => $ newkey ,
572- 'email ' => '<a href="mailto: ' .$ dbdata ->email .'"> ' .$ dbdata ->email .'</a> ' ,
695+ 'id ' => $ newkey ,
696+ 'email ' => '<a href="mailto: ' .$ dbdata ->email .'"> ' .$ dbdata ->email .'</a> ' ,
573697 'amount ' => $ currency .'<b> ' .number_format ($ dbdata ->amount ).'</b> ' ,
574- 'txn_code ' => $ dbdata -> txn_code ,
698+ 'txn_code ' => $ txn_code ,
575699 'metadata ' => format_data ($ dbdata ->metadata ),
576700 'date ' => $ dbdata ->created_at
577701 );
@@ -591,6 +715,9 @@ public function prepare_items(){
591715 $ data = array_slice ($ data ,(($ currentPage -1 )*$ perPage ),$ perPage );
592716 $ this ->_column_headers = array ($ columns , $ hidden , $ sortable );
593717 $ this ->items = $ data ;
718+
719+ $ rows = count ($ alldbdata );
720+ return $ rows ;
594721 }
595722 public function get_columns (){
596723 $ columns = array (
0 commit comments