@@ -62,28 +62,82 @@ public function enqueue_scripts()
6262define ('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE ' , intval ((KKD_PFF_PAYSTACK_LOCAL_CAP -KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE )/KKD_PFF_PAYSTACK_PERCENTAGE ));
6363define ('KKD_PFF_PAYSTACK_FLATLINE_AMOUNT ' , KKD_PFF_PAYSTACK_FLATLINE_AMOUNT_PLUS_CHARGE - KKD_PFF_PAYSTACK_LOCAL_CAP );
6464
65- function kkd_pff_paystack_add_paystack_charge ( $ amount )
65+ class Kkd_Pff_Paystack_PaystackCharge
6666{
67- // $amountinkobo = $amount; // * 100;
68- $ charge = 0 ;
69- $ amount = intval ($ amount );
70- if ($ amount <= 2500 ) {
71- $ charge = floatval ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE );
72- } else {
73- $ charge = floatval ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE )+100 ;
67+ public $ percentage ;
68+ public $ additional_charge ;
69+ public $ crossover_total ;
70+ public $ cap ;
71+
72+ public $ charge_divider ;
73+ public $ crossover ;
74+ public $ flatline_plus_charge ;
75+ public $ flatline ;
76+
77+ public function __construct ($ percentage = 0.015 , $ additional_charge = 10000 , $ crossover_total = 250000 , $ cap = 200000 )
78+ {
79+ $ this ->percentage = $ percentage ;
80+ $ this ->additional_charge = $ additional_charge ;
81+ $ this ->crossover_total = $ crossover_total ;
82+ $ this ->cap = $ cap ;
83+ $ this ->__setup ();
7484 }
75- // echo $charge;
76- if ($ charge > 2000 ) {
77- $ charge = 2000 ;
85+
86+ private function __setup ()
87+ {
88+ $ this ->charge_divider = $ this ->__charge_divider ();
89+ $ this ->crossover = $ this ->__crossover ();
90+ $ this ->flatline_plus_charge = $ this ->__flatline_plus_charge ();
91+ $ this ->flatline = $ this ->__flatline ();
92+ }
93+
94+ private function __charge_divider ()
95+ {
96+ return floatval (1 - $ this ->percentage );
97+ }
98+
99+ private function __crossover ()
100+ {
101+ return ceil (($ this ->crossover_total * $ this ->charge_divider ) - $ this ->additional_charge );
102+ }
103+
104+ private function __flatline_plus_charge ()
105+ {
106+ return floor (($ this ->cap - $ this ->additional_charge ) / $ this ->percentage );
107+ }
108+
109+ private function __flatline ()
110+ {
111+ return $ this ->flatline_plus_charge - $ this ->cap ;
78112 }
79- $ amount += $ charge ;
80- return $ amount ;
81- // if ($amountinkobo > KKD_PFF_PAYSTACK_FLATLINE_AMOUNT)
82- // return ($amountinkobo + KKD_PFF_PAYSTACK_LOCAL_CAP)/100;
83- // elseif ($amountinkobo > KKD_PFF_PAYSTACK_CROSSOVER_AMOUNT)
84- // return (intval(($amountinkobo + KKD_PFF_PAYSTACK_ADDITIONAL_CHARGE) / KKD_PFF_PAYSTACK_CHARGE_DIVIDER))/100;
85- // else
86- // return (intval($amountinkobo / KKD_PFF_PAYSTACK_CHARGE_DIVIDER))/100;
113+
114+ public function add_for_kobo ($ amountinkobo )
115+ {
116+ if ($ amountinkobo > $ this ->flatline ) {
117+ return $ amountinkobo + $ this ->cap ;
118+ } elseif ($ amountinkobo > $ this ->crossover ) {
119+ return ceil (($ amountinkobo + $ this ->additional_charge ) / $ this ->charge_divider );
120+ } else {
121+ return ceil ($ amountinkobo / $ this ->charge_divider );
122+ }
123+ }
124+
125+ public function add_for_ngn ($ amountinngn )
126+ {
127+ return $ this ->add_for_kobo (ceil ($ amountinngn * 100 )) / 100 ;
128+ }
129+ }
130+
131+ function kkd_pff_paystack_add_paystack_charge ($ amount )
132+ {
133+ $ feeSettings = Kkd_Pff_Paystack_Public::fetchFeeSettings ();
134+ $ pc = new Kkd_Pff_Paystack_PaystackCharge (
135+ $ feeSettings ['prc ' ],
136+ $ feeSettings ['adc ' ],
137+ $ feeSettings ['ths ' ],
138+ $ feeSettings ['cap ' ]
139+ );
140+ return $ pc ->add_for_ngn ($ amount );
87141}
88142
89143add_filter ("wp_mail_content_type " , "kkd_pff_paystack_mail_content_type " );
@@ -777,6 +831,14 @@ function kkd_pff_paystack_form_shortcode($atts)
777831 echo '<input type="hidden" name="pf-id" value=" ' . $ id . '" /> ' ;
778832 echo '<input type="hidden" name="pf-user_id" value=" ' . $ user_id . '" /> ' ;
779833 echo '<input type="hidden" name="pf-recur" value=" ' . $ recur . '" /> ' ;
834+ echo '<input type="hidden" name="pf-currency" id="pf-currency" value=" ' . $ currency . '" /> ' ;
835+ $ feeSettings = Kkd_Pff_Paystack_Public::fetchFeeSettings ();
836+ echo '<script>window.KKD_PAYSTACK_CHARGE_SETTINGS={
837+ percentage: ' .$ feeSettings ['prc ' ].',
838+ additional_charge: ' .$ feeSettings ['adc ' ].',
839+ threshold: ' .$ feeSettings ['ths ' ].',
840+ cap: ' .$ feeSettings ['cap ' ].'
841+ }</script> ' ;
780842 echo '<div class="span12 unit">
781843 <label class="label">Full Name <span>*</span></label>
782844 <div class="input">
@@ -794,10 +856,9 @@ function kkd_pff_paystack_form_shortcode($atts)
794856 if ($ loggedin == 'yes ' ) {
795857 echo 'readonly ' ;
796858 }
797-
798859 echo ' required>
799860 </div>
800- </div> ' ;
861+ </div> ' ;
801862 echo '<div class="span12 unit">
802863 <label class="label">Amount ( ' .$ currency ;
803864 if ($ minimum == 0 && $ amount != 0 && $ usequantity == 'yes ' ) {
@@ -850,8 +911,8 @@ function kkd_pff_paystack_form_shortcode($atts)
850911 }
851912 }
852913 }
853- if ($ txncharge != 'merchant ' && $ recur != 'plan ' ) {
854- echo '<small>Transaction Charge: <b class="pf-txncharge"></b>, Total:<b class="pf-txntotal"></b></small> ' ;
914+ if ($ txncharge != 'merchant ' && $ recur != 'plan ' && $ usequantity !== " yes " ) {
915+ echo '<small>Transaction Charge: <b class="pf-txncharge"></b>, Total: <b class="pf-txntotal"></b></small> ' ;
855916 }
856917
857918 echo '<span id="pf-min-val-warn" style="color: red; font-size: 13px;"></span>
@@ -877,11 +938,14 @@ function kkd_pff_paystack_form_shortcode($atts)
877938 <label class="label">Total ( ' .$ currency ;
878939 echo ') <span>*</span></label>
879940 <div class="input">
880- <input type="text" id="pf-total" name="pf-total" placeholder="" value="" disabled>
881- </div>
941+ <input type="text" id="pf-total" name="pf-total" placeholder="" value="" disabled> ' ;
942+ if ($ txncharge != 'merchant ' && $ recur != 'plan ' ) {
943+ echo '<small>Transaction Charge: <b class="pf-txncharge"></b>, Total: <b class="pf-txntotal"></b></small> ' ;
944+ }
945+ echo '</div>
882946 </div> ' ;
883947 }
884-
948+
885949 if ($ recur == 'optional ' ) {
886950 echo '<div class="span12 unit">
887951 <label class="label">Recurring Payment</label>
0 commit comments