Skip to content

Commit d7cc942

Browse files
authored
Merge pull request #3 from Kendysond/master
match up with kendysond master
2 parents 5f50754 + ed711e7 commit d7cc942

15 files changed

Lines changed: 1119 additions & 369 deletions

.DS_Store

0 Bytes
Binary file not shown.

README.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: kendysond
33
Donate link: https://paystack.com/demo
44
Tags: paystack, recurrent payments, nigeria, mastercard, visa, target,Naira,payments,verve
55
Requires at least: 3.1
6-
Tested up to: 4.6.1
7-
Stable tag: 1.1.0
6+
Tested up to: 4.7
7+
Stable tag: 2.0.3
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -29,6 +29,13 @@ When you set the 'recur' option to 'optional' on the form settings, your donors/
2929

3030
This can come in handy for weekly/monthly offerings & tithes or recurring donor donations.
3131

32+
= For selling items =
33+
34+
To create a form to allow your users buy or pay for value in quantity.
35+
36+
* Set quantified to be 'yes'.
37+
* Set the max quantity a user can buy.
38+
3239
= Plugin Features =
3340

3441
* __Accept payment__ via MasterCard and Visa Cards.
@@ -77,6 +84,21 @@ You can also follow us on Twitter! **[@paystack](http://twitter.com/paystack)**
7784

7885

7986
== Changelog ==
87+
= 2.0.3 =
88+
* Send email notification to merchant for every payment.
89+
* Export payment data to CSV.
90+
= 2.0.2 =
91+
* Price calculation and bug fixes.
92+
= 2.0.1 =
93+
* Bug fixes.
94+
= 2.0.1 =
95+
* Added option to use subaccount on a form.
96+
* General bug fixes.
97+
= 2.0.0 =
98+
* Fixed compatibility for PHP 5.3 and below.
99+
* Added option to redirect to page after payment.
100+
* Add retry payment link to email invoice.
101+
* Fixed pricing calculation.
80102
= 1.1.1 =
81103
* Added country and Nigerian states automatic shortcode, added radio buttons, added form agreement checkbox.
82104
= 1.1.0 =

admin/class-paystack-forms-admin.php

Lines changed: 140 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}
510629
class 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(

banner-772x250.png

-1.71 KB
Loading

icon-256x256.png

-1.1 KB
Loading

icon.png

5.2 KB
Loading

images/logo.png

-1.38 KB
Loading

images/logos@2x.png

24.6 KB
Loading

includes/class-paystack-forms-activator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static function activate() {
1414
paid int(1) NOT NULL DEFAULT '0',
1515
plan varchar(255) DEFAULT '' NOT NULL,
1616
txn_code varchar(255) DEFAULT '' NOT NULL,
17+
txn_code_2 varchar(255) DEFAULT '' NOT NULL,
1718
amount varchar(255) DEFAULT '' NOT NULL,
1819
ip varchar(255) NOT NULL,
1920
deleted_at varchar(255) DEFAULT '' NULL,
@@ -29,6 +30,12 @@ public static function activate() {
2930
if(empty($row)){
3031
$wpdb->query("ALTER TABLE `".$table_name."` ADD `plan` VARCHAR(255) NOT NULL AFTER `paid`;");
3132
}
33+
$row1 = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
34+
WHERE table_name = '".$table_name."' AND column_name = 'txn_code_2'" );
35+
36+
if(empty($row1)){
37+
$wpdb->query("ALTER TABLE `".$table_name."` ADD `txn_code_2` VARCHAR(255) DEFAULT '' NULL AFTER `txn_code`;");
38+
}
3239

3340
}
3441

includes/class-paystack-forms.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Kkd_Pff_Paystack {
4343
public function __construct() {
4444

4545
$this->plugin_name = 'pff-paystack';
46-
$this->version = '1.0.4';
46+
$this->version = '2.0.0';
4747

4848
$this->load_dependencies();
4949
$this->set_locale();
@@ -144,6 +144,7 @@ private function load_dependencies() {
144144
* side of the site.
145145
*/
146146
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-paystack-forms-public.php';
147+
// require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/paystack-webhook.php';
147148

148149
$this->loader = new Kkd_Pff_Paystack_Loader();
149150

0 commit comments

Comments
 (0)