Skip to content

Commit 3e6e5ba

Browse files
committed
Bug fixes + Transfer transaction charges to customer.
1 parent 584d3dc commit 3e6e5ba

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ function kkd_pff_paystack_editor_add_form_data() {
283283
if ($paybtn == "") {$paybtn = 'Pay';}
284284
if ($successmsg == "") {$successmsg = 'Thank you for paying!';}
285285
if ($currency == "") {$currency = 'NGN';}
286+
if ($txncharge == "") {$txncharge = 'merchant';}
286287
// Echo out the field
287288
echo '<p>Currency:</p>';
288289
echo '<input type="text" name="_currency" value="' . $currency . '" class="widefat" />
@@ -292,10 +293,10 @@ function kkd_pff_paystack_editor_add_form_data() {
292293
echo '<p>Pay button Description:</p>';
293294
echo '<input type="text" name="_paybtn" value="' . $paybtn . '" class="widefat" />';
294295
echo '<p>Transaction Charges:</p>';
295-
// echo '<select class="form-control" name="_txncharge" id="parent_id" style="width:100%;">
296-
// <option value="merchant"'.kkd_pff_paystack_txncheck('merchant',$txncharge).'>Merchant Pays(Include in fee)</option>
297-
// <option value="customer" '.kkd_pff_paystack_txncheck('customer',$txncharge).'>Client Pays(Extra Fee added)</option>
298-
// </select>';
296+
echo '<select class="form-control" name="_txncharge" id="parent_id" style="width:100%;">
297+
<option value="merchant"'.kkd_pff_paystack_txncheck('merchant',$txncharge).'>Merchant Pays(Include in fee)</option>
298+
<option value="customer" '.kkd_pff_paystack_txncheck('customer',$txncharge).'>Client Pays(Extra Fee added) - 1.55%+ NGN100 if above NGN2,500 </option>
299+
</select>';
299300
echo '<p>User logged In:</p>';
300301
echo '<select class="form-control" name="_loggedin" id="parent_id" style="width:100%;">
301302
<option value="no" '.kkd_pff_paystack_txncheck('no',$loggedin).'>User must not be logged in</option>

public/class-paystack-forms-public.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,29 @@ function kkd_pff_paystack_submit_action() {
868868

869869
$filelimit = get_post_meta($_POST["pf-id"],'_filelimit',true);
870870
$currency = get_post_meta($_POST["pf-id"],'_currency',true);
871+
$formamount = get_post_meta($_POST["pf-id"],'_amount',true);
872+
$recur = get_post_meta($_POST["pf-id"],'_recur',true);
871873

874+
$txncharge = get_post_meta($_POST["pf-id"],'_txncharge',true);
875+
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);
876+
877+
if(($recur == 'no') && ($formamount != 0)){
878+
$amount = (int)str_replace(' ', '', $formamount);
879+
}
880+
if ($txncharge == 'customer') {
881+
$percent = (1.55/100)*$amount;
882+
if ($percent > 2000) {
883+
$newamount = $amount + 2000;
884+
}else{
885+
if ($amount > 2500) {
886+
$newamount = $amount + $percent+100;
887+
}else{
888+
$newamount = $amount + $percent;
889+
}
890+
}
891+
892+
$amount = $newamount;
893+
}
872894
$maxFileSize = $filelimit * 1024 * 1024;
873895

874896
if(!empty($_FILES)){
@@ -917,7 +939,6 @@ function kkd_pff_paystack_submit_action() {
917939
'Content-Type' => 'application/json',
918940
'Authorization' => 'Bearer ' . $key
919941
);
920-
$amount = (int)str_replace(' ', '', $_POST["pf-amount"]);
921942
$koboamount = $amount*100;
922943
$body = array(
923944
'name' => $fullname.'_'.$code,
@@ -958,7 +979,7 @@ function kkd_pff_paystack_submit_action() {
958979
'post_id' => strip_tags($_POST["pf-id"], ""),
959980
'email' => strip_tags($_POST["pf-pemail"], ""),
960981
'user_id' => strip_tags($_POST["pf-user_id"], ""),
961-
'amount' => strip_tags($_POST["pf-amount"], ""),
982+
'amount' => strip_tags($amount, ""),
962983
'plan' => strip_tags($plancode, ""),
963984
'ip' => kkd_pff_paystack_get_the_user_ip(),
964985
'txn_code' => $code,
@@ -1041,6 +1062,7 @@ function kkd_pff_paystack_confirm_payment() {
10411062
$amount = get_post_meta($payment_array->post_id,'_amount',true);
10421063
$recur = get_post_meta($payment_array->post_id,'_recur',true);
10431064
$currency = get_post_meta($payment_array->post_id,'_currency',true);
1065+
$txncharge = get_post_meta($payment_array->post_id,'_txncharge',true);
10441066

10451067

10461068
$mode = esc_attr( get_option('mode') );
@@ -1077,6 +1099,20 @@ function kkd_pff_paystack_confirm_payment() {
10771099
$result = "success";
10781100
// kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
10791101
}else{
1102+
if ($txncharge == 'customer') {
1103+
$percent = (1.55/100)*$amount;
1104+
if ($percent > 2000) {
1105+
$newamount = $amount + 2000;
1106+
}else{
1107+
if ($amount > 2500) {
1108+
$newamount = $amount + $percent+100;
1109+
}else{
1110+
$newamount = $amount + $percent;
1111+
}
1112+
}
1113+
1114+
$amount = $newamount;
1115+
}
10801116
if( $amount != $amount_paid ) {
10811117
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";
10821118
$result = "failed";

0 commit comments

Comments
 (0)