Skip to content

Commit c94ff69

Browse files
committed
v2.0.9- added multiple amounts on a form
1 parent cc96cef commit c94ff69

File tree

4 files changed

+68
-36
lines changed

4 files changed

+68
-36
lines changed

README.txt

Lines changed: 4 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,donation,church,NGO,form,contact form 7, form,
55
Requires at least: 3.1
66
Tested up to: 4.7
7-
Stable tag: 2.0.8
7+
Stable tag: 2.0.9
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

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

8585

8686
== Changelog ==
87+
= 2.0.9 =
88+
* Added multiple payment amounts on a form
89+
* General code improvement
8790
= 2.0.8 =
8891
* Bug fixes for transaction charge.
8992
= 2.0.7 =

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.8
6+
Version: 2.0.9
77
Author: Douglas Kendyson
88
Author URI: http://kendyson.com
99
License: GPL-2.0+

public/class-paystack-forms-public.php

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,10 @@ function kkd_pff_paystack_form_shortcode($atts) {
729729
if ($usevariableamount == "") {$usevariableamount = 0;}
730730

731731
if ($usevariableamount == 1) {
732-
// $variableamount = '3GB Etisalat:10000';
733732
$paymentoptions = explode(',', $variableamount);
734-
echo "<pre>";
735-
print_r($paymentoptions);
736-
echo "</pre>";
733+
// echo "<pre>";
734+
// print_r($paymentoptions);
735+
// echo "</pre>";
737736
// die();
738737
}
739738
$showbtn = true;
@@ -782,7 +781,13 @@ function kkd_pff_paystack_form_shortcode($atts) {
782781
</div>
783782
</div>';
784783
echo '<div class="span12 unit">
785-
<label class="label">Amount ('.$currency.') <span>*</span></label>
784+
<label class="label">Amount ('.$currency;
785+
if ($minimum == 0 && $amount != 0 && $usequantity == 'yes') {
786+
echo ' '.number_format($amount);
787+
}
788+
789+
790+
echo ') <span>*</span></label>
786791
<div class="input">';
787792
if ($usevariableamount == 0) {
788793
if ($minimum == 1) {
@@ -813,7 +818,7 @@ function kkd_pff_paystack_form_shortcode($atts) {
813818
}else{
814819
if (count($paymentoptions) > 0) {
815820
echo '<div class="select">
816-
<input type="hidden" id="pf-vname" />
821+
<input type="hidden" id="pf-vname" name="pf-vname" />
817822
<select class="form-control" id="pf-vamount" name="pf-amount">';
818823
$max = $quantity+1;
819824
foreach ($paymentoptions as $key => $paymentoption) {
@@ -832,7 +837,7 @@ function kkd_pff_paystack_form_shortcode($atts) {
832837

833838
echo '</div>
834839
</div>';
835-
if ($recur == 'no' && $usequantity == 'yes' && $amount != 0) {
840+
if ($minimum == 0 && $recur == 'no' && $usequantity == 'yes' && $amount != 0) {
836841
echo '<div class="span12 unit">
837842
<label class="label">Quantity</label>
838843
<div class="select">
@@ -880,7 +885,7 @@ function kkd_pff_paystack_form_shortcode($atts) {
880885

881886
if ($useagreement == 'yes'){
882887
echo '<div class="span12 unit">
883-
<label class="checkbox">
888+
<label class="checkbox ">
884889
<input type="checkbox" name="agreement" id="pf-agreement" required value="yes">
885890
<i id="pf-agreementicon" ></i>
886891
Accept terms <a target="_blank" href="'.$agreementlink.'">Link </a>
@@ -1142,24 +1147,15 @@ function kkd_pff_paystack_submit_action() {
11421147
$minimum = get_post_meta($_POST["pf-id"],'_minimum',true);
11431148
$variableamount = get_post_meta($_POST["pf-id"],'_variableamount',true);
11441149
$usevariableamount = get_post_meta($_POST["pf-id"],'_usevariableamount',true);
1145-
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);//User input
1150+
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);
1151+
$variablename = $_POST["pf-vname"];
1152+
// pf-vname
11461153
$originalamount = $amount;
11471154
$quantity = 1;
11481155
$usequantity = get_post_meta($_POST["pf-id"],'_usequantity',true);
1156+
11491157
if(($recur == 'no') && ($formamount != 0)){
1150-
if ($usequantity == 'no') {
1151-
$amount = (int)str_replace(' ', '', $formamount);
1152-
}else{
1153-
$fixedmetadata[] = array(
1154-
'display_name' => 'Unit Price',
1155-
'variable_name' => 'Unit_Price',
1156-
'type' => 'text',
1157-
'value' => $currency.number_format($formamount)
1158-
);
1159-
$quantity = $_POST["pf-quantity"];
1160-
$unitamount = (int)str_replace(' ', '', $formamount);
1161-
$amount = $quantity*$unitamount;
1162-
}
1158+
$amount = (int)str_replace(' ', '', $formamount);
11631159
}
11641160
if ($minimum == 1 && $formamount != 0) {
11651161
if ($originalamount < $formamount) {
@@ -1168,9 +1164,33 @@ function kkd_pff_paystack_submit_action() {
11681164
$amount = $originalamount;
11691165
}
11701166
}
1167+
if ($usevariableamount == 1) {
1168+
$paymentoptions = explode(',', $variableamount);
1169+
if (count($paymentoptions) > 0) {
1170+
foreach ($paymentoptions as $key => $paymentoption) {
1171+
list($a,$b) = explode(':', $paymentoption);
1172+
if ($variablename == $a) {
1173+
$amount = $b;
1174+
}
1175+
}
1176+
}
1177+
}
1178+
$fixedmetadata[] = array(
1179+
'display_name' => 'Unit Price',
1180+
'variable_name' => 'Unit_Price',
1181+
'type' => 'text',
1182+
'value' => $currency.number_format($amount)
1183+
);
1184+
if ($usequantity != 'no') {
1185+
$quantity = $_POST["pf-quantity"];
1186+
$unitamount = (int)str_replace(' ', '', $amount);
1187+
$amount = $quantity*$unitamount;
1188+
}
1189+
1190+
1191+
11711192
if ($txncharge == 'customer') {
11721193
$amount = kkd_pff_paystack_add_paystack_charge($amount);
1173-
// print_r($amount);
11741194
}
11751195
$maxFileSize = $filelimit * 1024 * 1024;
11761196

@@ -1358,6 +1378,13 @@ function kkd_pff_paystack_meta_as_custom_fields($metadata){
13581378
'display_name' => 'Plan',
13591379
'variable_name' => 'Plan',
13601380
'type' => 'text',
1381+
'value' => $value
1382+
);
1383+
}elseif ($key == 'pf-vname') {
1384+
$custom_fields[] = array(
1385+
'display_name' => 'Payment Option',
1386+
'variable_name' => 'Payment Option',
1387+
'type' => 'text',
13611388
'value' => $value
13621389
);
13631390
}elseif ($key == 'pf-interval') {
@@ -1410,6 +1437,8 @@ function kkd_pff_paystack_confirm_payment() {
14101437
$txncharge = get_post_meta($payment_array->post_id,'_txncharge',true);
14111438
$redirect = get_post_meta($payment_array->post_id,'_redirect',true);
14121439
$minimum = get_post_meta($payment_array->post_id,'_minimum',true);
1440+
$usevariableamount = get_post_meta($payment_array->post_id,'_usevariableamount',true);
1441+
$variableamount = get_post_meta($payment_array->post_id,'_variableamount',true);
14131442

14141443
if ($minimum == 1 && $amount != 0) {
14151444
if ($payment_array->amount < $formamount) {
@@ -1446,7 +1475,7 @@ function kkd_pff_paystack_confirm_payment() {
14461475
$result = "success";
14471476
}else{
14481477

1449-
if ($amount == 0) {
1478+
if ($amount == 0 || $usevariableamount == 1) {
14501479
$wpdb->update( $table, array( 'paid' => 1,'amount' =>$amount_paid),array('txn_code'=>$paystack_ref));
14511480
$thankyou = get_post_meta($payment_array->post_id,'_successmsg',true);
14521481
$message = $thankyou;
@@ -1460,9 +1489,7 @@ function kkd_pff_paystack_confirm_payment() {
14601489
$quantity = $_POST["quantity"];
14611490
$unitamount = (int)str_replace(' ', '', $amount);
14621491
$oamount = $quantity*$unitamount;
1463-
1464-
1465-
1492+
14661493
}
14671494
if ($txncharge == 'customer') {
14681495
$oamount = kkd_pff_paystack_add_paystack_charge($oamount);

public/js/paystack-forms-public.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,16 @@
130130

131131
stop = true;
132132
});
133-
if($("#pf-agreement").prop('checked') == false){
134-
$("#pf-agreementicon").addClass('rerror');
135-
stop = true;
136-
}
137-
if (stop) {
138-
$('html,body').animate({ scrollTop: $('.rerror').offset().top - 110 }, 500);
139-
return false;
133+
if($('#pf-agreement').length){
134+
if($("#pf-agreement").prop('checked') == false){
135+
$("#pf-agreementicon").addClass('rerror');
136+
stop = true;
137+
}
138+
if (stop) {
139+
$('html,body').animate({ scrollTop: $('.rerror').offset().top - 110 }, 500);
140+
return false;
140141

142+
}
141143
}
142144

143145
var self = $(this);

0 commit comments

Comments
 (0)