Skip to content

Commit 14d29ea

Browse files
committed
v2.0.5 - Set minimum payable amount.
1 parent b8b5ef2 commit 14d29ea

5 files changed

Lines changed: 50 additions & 14 deletions

File tree

README.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://paystack.com/demo
44
Tags: paystack, recurrent payments, nigeria, mastercard, visa, target,Naira,payments,verve
55
Requires at least: 3.1
66
Tested up to: 4.7
7-
Stable tag: 2.0.3
7+
Stable tag: 2.0.5
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -84,6 +84,10 @@ You can also follow us on Twitter! **[@paystack](http://twitter.com/paystack)**
8484

8585

8686
== Changelog ==
87+
= 2.0.5 =
88+
* Set minimum payable amount.
89+
= 2.0.4 =
90+
* Fix for no action after clicking the pay button.
8791
= 2.0.3 =
8892
* Send email notification to merchant for every payment.
8993
* Export payment data to CSV.

admin/class-paystack-forms-admin.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,27 @@ function kkd_pff_paystack_editor_add_form_data() {
282282
$currency = get_post_meta($post->ID, '_currency', true);
283283
$filelimit = get_post_meta($post->ID, '_filelimit', true);
284284
$redirect = get_post_meta($post->ID, '_redirect', true);
285+
$minimum = get_post_meta($post->ID, '_minimum', true);
285286

286287
if ($amount == "") {$amount = 0;}
287288
if ($filelimit == "") {$filelimit = 2;}
288289
if ($paybtn == "") {$paybtn = 'Pay';}
289290
if ($successmsg == "") {$successmsg = 'Thank you for paying!';}
290291
if ($currency == "") {$currency = 'NGN';}
291292
if ($txncharge == "") {$txncharge = 'merchant';}
293+
if ($minimum == "") {$minimum = 0;}
292294
// Echo out the field
293295
echo '<p>Currency:</p>';
294296
echo '<input type="text" name="_currency" value="' . $currency . '" class="widefat" />
295297
<small>We currently support only payments in Naira(NGN).</small>';
296298
echo '<p>Amount to be paid(Set 0 for customer input):</p>';
297299
echo '<input type="number" name="_amount" value="' . $amount . '" class="widefat pf-number" />';
298-
echo '<p>Pay button Description:</p>';
300+
if ($minimum == 1) {
301+
echo '<br><label><input name="_minimum" type="checkbox" value="1" checked> Make amount minimum payable </label>';
302+
}else{
303+
echo '<br><label><input name="_minimum" type="checkbox" value="1"> Make amount minimum payable </label>';
304+
}
305+
echo '<p>Pay button Description:</p>';
299306
echo '<input type="text" name="_paybtn" value="' . $paybtn . '" class="widefat" />';
300307
echo '<p>Transaction Charges:</p>';
301308
echo '<select class="form-control" name="_txncharge" id="parent_id" style="width:100%;">
@@ -458,6 +465,7 @@ function kkd_pff_paystack_save_data($post_id, $post) {
458465
}
459466

460467
$form_meta['_amount'] = $_POST['_amount'];
468+
$form_meta['_minimum'] = $_POST['_minimum'];
461469
$form_meta['_paybtn'] = $_POST['_paybtn'];
462470
$form_meta['_currency'] = $_POST['_currency'];
463471
$form_meta['_successmsg'] = $_POST['_successmsg'];

paystack-forms.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Payment forms for Paystack
44
Plugin URI: https://github.com/Kendysond/Wordpress-paystack-forms
55
Description: Payment forms for Paystack allows you create forms that will be used to bill clients for goods and services via Paystack.
6-
Version: 2.0.3
6+
Version: 2.0.5
77
Author: Douglas Kendyson
88
Author URI: http://kendyson.com
99
License: GPL-2.0+

public/class-paystack-forms-public.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ function kkd_pff_paystack_form_shortcode($atts) {
705705
$quantity = get_post_meta($id,'_quantity',true);
706706
$useagreement = get_post_meta($id,'_useagreement',true);
707707
$agreementlink = get_post_meta($id,'_agreementlink',true);
708+
$minimum = get_post_meta($id,'_minimum',true);
709+
if ($minimum == "") {$minimum = 0;}
710+
708711
$showbtn = true;
709712
$planerrorcode = 'Input Correct Recurring Plan Code';
710713
if ($recur == 'plan') {
@@ -758,6 +761,10 @@ function kkd_pff_paystack_form_shortcode($atts) {
758761
echo '<div class="span12 unit">
759762
<label class="label">Amount ('.$currency.') <span>*</span></label>
760763
<div class="input">';
764+
// echo "<pre>".$minimum. "</pre>";
765+
if ($minimum == 1) {
766+
echo '<small> Minimum payable amount <b style="font-size:87% !important;">'.$currency.' '.number_format($amount).'</b></small>';
767+
}
761768
if ($recur == 'plan') {
762769
if ($showbtn) {
763770
echo '<input type="text" name="pf-amount" value="'.$planamount.'" id="pf-amount" readonly required/>';
@@ -771,7 +778,9 @@ function kkd_pff_paystack_form_shortcode($atts) {
771778
}else{
772779
if ($amount == 0) {
773780
echo '<input type="text" name="pf-amount" class="pf-number" value="0" id="pf-amount" required/>';
774-
}else{
781+
}elseif($amount != 0 && $minimum == 1){
782+
echo '<input type="text" name="pf-amount" value="'.$amount.'" id="pf-amount" required/>';
783+
}else{
775784
echo '<input type="text" name="pf-amount" value="'.$amount.'" id="pf-amount" readonly required/>';
776785
}
777786
}
@@ -1080,13 +1089,14 @@ function kkd_pff_paystack_submit_action() {
10801089

10811090
$filelimit = get_post_meta($_POST["pf-id"],'_filelimit',true);
10821091
$currency = get_post_meta($_POST["pf-id"],'_currency',true);
1083-
$formamount = get_post_meta($_POST["pf-id"],'_amount',true);
1092+
$formamount = get_post_meta($_POST["pf-id"],'_amount',true);/// From form
10841093
$recur = get_post_meta($_POST["pf-id"],'_recur',true);
10851094
$subaccount = get_post_meta($_POST["pf-id"],'_subaccount',true);
10861095
$txnbearer = get_post_meta($_POST["pf-id"],'_txnbearer',true);
10871096

10881097
$txncharge = get_post_meta($_POST["pf-id"],'_txncharge',true);
1089-
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);
1098+
$minimum = get_post_meta($_POST["pf-id"],'_minimum',true);
1099+
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);//User input
10901100
$originalamount = $amount;
10911101
$quantity = 1;
10921102
$usequantity = get_post_meta($_POST["pf-id"],'_usequantity',true);
@@ -1105,6 +1115,13 @@ function kkd_pff_paystack_submit_action() {
11051115
$amount = $quantity*$unitamount;
11061116
}
11071117
}
1118+
if ($minimum == 1 && $formamount != 0) {
1119+
if ($originalamount < $formamount) {
1120+
$amount = $formamount;
1121+
}else{
1122+
$amount = $originalamount;
1123+
}
1124+
}
11081125
if ($txncharge == 'customer') {
11091126
$amount = kkd_pff_paystack_add_paystack_charge($amount);
11101127
}
@@ -1337,8 +1354,16 @@ function kkd_pff_paystack_confirm_payment() {
13371354
$currency = get_post_meta($payment_array->post_id,'_currency',true);
13381355
$txncharge = get_post_meta($payment_array->post_id,'_txncharge',true);
13391356
$redirect = get_post_meta($payment_array->post_id,'_redirect',true);
1357+
$minimum = get_post_meta($payment_array->post_id,'_minimum',true);
13401358

1341-
1359+
if ($minimum == 1 && $amount != 0) {
1360+
if ($payment_array->amount < $formamount) {
1361+
$amount = $formamount;
1362+
}else{
1363+
$amount = $payment_array->amount;
1364+
}
1365+
}
1366+
$oamount = $amount;
13421367
$mode = esc_attr( get_option('mode') );
13431368
if ($mode == 'test') {
13441369
$key = esc_attr( get_option('tsk') );
@@ -1383,10 +1408,11 @@ function kkd_pff_paystack_confirm_payment() {
13831408
}
13841409

13851410

1386-
if ($txncharge == 'customer') {
1387-
$amount = kkd_pff_paystack_add_paystack_charge($amount);
1388-
}
1389-
if( $amount != $amount_paid ) {
1411+
// if ($txncharge == 'customer') {
1412+
// $amount = kkd_pff_paystack_add_paystack_charge($amount);
1413+
// }
1414+
if( $oamount != $amount_paid ) {
1415+
echo $amount. ' - '.$amount_paid;
13901416
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
13911417
$result = "failed";
13921418
}else{

public/js/paystack-forms-public.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@
158158
subaccount:data.subaccount,
159159
bearer:data.txnbearer,
160160
ref: data.code,
161-
transaction_charge:'0',
162-
metadata: {'custom_fields': data.custom_fields},
161+
metadata: {'custom_fields': data.custom_fields},
163162
callback: function(response){
164163
$.blockUI({ message: 'Please wait...' });
165164
$.post($form.attr('action'), {'action':'kkd_pff_paystack_confirm_payment','code':response.trxref,'quantity':quantity}, function(newdata) {
@@ -199,7 +198,6 @@
199198
lastname: lastName,
200199
ref: data.code,
201200
subaccount:data.subaccount,
202-
transaction_charge:'0',
203201
bearer:data.txnbearer,
204202
metadata: {'custom_fields': data.custom_fields},
205203
callback: function(response){

0 commit comments

Comments
 (0)