Skip to content

Commit 510666a

Browse files
authored
Merge pull request #4 from yabacon/fix/addpaystackcharge
Improved additional charge calculation
2 parents e127a9c + ce210b2 commit 510666a

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function kkd_pff_paystack_editor_add_form_data() {
297297
echo '<p>Transaction Charges:</p>';
298298
echo '<select class="form-control" name="_txncharge" id="parent_id" style="width:100%;">
299299
<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>
300+
<option value="customer" '.kkd_pff_paystack_txncheck('customer',$txncharge).'>Client Pays(Calculated Paystack Local Fee added) </option>
301301
</select>';
302302
echo '<p>User logged In:</p>';
303303
echo '<select class="form-control" name="_loggedin" id="parent_id" style="width:100%;">

public/class-paystack-forms-public.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ public function enqueue_scripts() {
4040
}
4141

4242
}
43+
44+
define('KKD_PFF_PAYSTACK_PERCENTAGE', 0.015);
45+
define('KKD_PFF_PAYSTACK_CROSSOVER_TOTAL', 250000);
46+
define('KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE', 10000);
47+
define('KKD_PFF_PAYSTACK_LOCAL_CAP', 200000);
48+
49+
define('KKD_PFF_PAYSTACK_CHARGE_DIVIDER', floatval(1-PAYSTACK_PERCENTAGE));
50+
define('KKD_PFF_PAYSTACK_CROSSOVER_AMOUNT', intval((PAYSTACK_CROSSOVER_TOTAL*PAYSTACK_CHARGE_DIVIDER)-PAYSTACK_ADDITIONAL_CHARGE));
51+
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE', intval((PAYSTACK_LOCAL_CAP-PAYSTACK_ADDITIONAL_CHARGE)/PAYSTACK_PERCENTAGE));
52+
define('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT', PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE - PAYSTACK_LOCAL_CAP);
53+
54+
function kkd_pff_paystack_add_paystack_charge($amount)
55+
{
56+
$amountinkobo = $amount * 100;
57+
if ($amountinkobo > PAYSTACK_FLATLINE_AMOUNT)
58+
return ($amountinkobo + PAYSTACK_LOCAL_CAP)/100;
59+
elseif ($amountinkobo > PAYSTACK_CROSSOVER_AMOUNT)
60+
return (intval(($amountinkobo + PAYSTACK_ADDITIONAL_CHARGE) / PAYSTACK_CHARGE_DIVIDER))/100;
61+
else
62+
return (intval($amountinkobo / PAYSTACK_CHARGE_DIVIDER))/100;
63+
}
64+
4365
add_filter ("wp_mail_content_type", "kkd_pff_paystack_mail_content_type");
4466
function kkd_pff_paystack_mail_content_type() {
4567
return "text/html";
@@ -993,18 +1015,7 @@ function kkd_pff_paystack_submit_action() {
9931015
}
9941016
}
9951017
if ($txncharge == 'customer') {
996-
$percent = (1.55/100)*$amount;
997-
if ($percent > 2000) {
998-
$newamount = $amount + 2000;
999-
}else{
1000-
if ($amount > 2500) {
1001-
$newamount = $amount + $percent+100;
1002-
}else{
1003-
$newamount = $amount + $percent;
1004-
}
1005-
}
1006-
1007-
$amount = $newamount;
1018+
$amount = kkd_pff_paystack_add_paystack_charge($amount);
10081019
}
10091020
$maxFileSize = $filelimit * 1024 * 1024;
10101021

@@ -1276,18 +1287,7 @@ function kkd_pff_paystack_confirm_payment() {
12761287

12771288

12781289
if ($txncharge == 'customer') {
1279-
$percent = (1.55/100)*$amount;
1280-
if ($percent > 2000) {
1281-
$newamount = $amount + 2000;
1282-
}else{
1283-
if ($amount > 2500) {
1284-
$newamount = $amount + $percent+100;
1285-
}else{
1286-
$newamount = $amount + $percent;
1287-
}
1288-
}
1289-
1290-
$amount = $newamount;
1290+
$amount = kkd_pff_paystack_add_paystack_charge($amount);
12911291
}
12921292
if( $amount != $amount_paid ) {
12931293
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";

0 commit comments

Comments
 (0)