Skip to content

Commit f8b0e1b

Browse files
committed
Improved additional charge calculation
1 parent c32dd37 commit f8b0e1b

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-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: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ 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($amountinkobo)
55+
{
56+
if ($amountinkobo > PAYSTACK_FLATLINE_AMOUNT)
57+
return $amountinkobo + PAYSTACK_LOCAL_CAP;
58+
elseif ($amountinkobo > PAYSTACK_CROSSOVER_AMOUNT)
59+
return intval(($amountinkobo + PAYSTACK_ADDITIONAL_CHARGE) / PAYSTACK_CHARGE_DIVIDER);
60+
else
61+
return intval($amountinkobo / PAYSTACK_CHARGE_DIVIDER);
62+
}
63+
4364
add_filter ("wp_mail_content_type", "kkd_pff_paystack_mail_content_type");
4465
function kkd_pff_paystack_mail_content_type() {
4566
return "text/html";
@@ -987,18 +1008,7 @@ function kkd_pff_paystack_submit_action() {
9871008
}
9881009
}
9891010
if ($txncharge == 'customer') {
990-
$percent = (1.55/100)*$amount;
991-
if ($percent > 2000) {
992-
$newamount = $amount + 2000;
993-
}else{
994-
if ($amount > 2500) {
995-
$newamount = $amount + $percent+100;
996-
}else{
997-
$newamount = $amount + $percent;
998-
}
999-
}
1000-
1001-
$amount = $newamount;
1011+
$amount = kkd_pff_paystack_add_paystack_charge($amount);
10021012
}
10031013
$maxFileSize = $filelimit * 1024 * 1024;
10041014

@@ -1270,18 +1280,7 @@ function kkd_pff_paystack_confirm_payment() {
12701280

12711281

12721282
if ($txncharge == 'customer') {
1273-
$percent = (1.55/100)*$amount;
1274-
if ($percent > 2000) {
1275-
$newamount = $amount + 2000;
1276-
}else{
1277-
if ($amount > 2500) {
1278-
$newamount = $amount + $percent+100;
1279-
}else{
1280-
$newamount = $amount + $percent;
1281-
}
1282-
}
1283-
1284-
$amount = $newamount;
1283+
$amount = kkd_pff_paystack_add_paystack_charge($amount);
12851284
}
12861285
if( $amount != $amount_paid ) {
12871286
$message = "Invalid amount Paid. Amount required is ".$currency."<b>".number_format($amount)."</b>";

0 commit comments

Comments
 (0)