|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yabacon\Paystack; |
|
3
|
|
|
|
|
4
|
|
|
class Fee{ |
|
5
|
|
|
const DEFAULT_PERCENTAGE = 0.015; |
|
6
|
|
|
const DEFAULT_ADDITIONAL_CHARGE = 10000; |
|
7
|
|
|
const DEFAULT_THRESHOLD = 250000; |
|
8
|
|
|
const DEFAULT_CAP = 200000; |
|
9
|
|
|
|
|
10
|
|
|
public static $default_percentage = Fee::DEFAULT_PERCENTAGE; |
|
11
|
|
|
public static $default_additional_charge = Fee::DEFAULT_ADDITIONAL_CHARGE; |
|
12
|
|
|
public static $default_threshold = Fee::DEFAULT_THRESHOLD; |
|
13
|
|
|
public static $default_cap = Fee::DEFAULT_CAP; |
|
14
|
|
|
|
|
15
|
|
|
private $percentage; |
|
16
|
|
|
private $additional_charge; |
|
17
|
|
|
private $threshold; |
|
18
|
|
|
private $cap; |
|
19
|
|
|
|
|
20
|
|
|
private $charge_divider; |
|
21
|
|
|
private $crossover; |
|
22
|
|
|
private $flatline_plus_charge; |
|
23
|
|
|
private $flatline; |
|
24
|
|
|
|
|
25
|
4 |
|
public function __construct(){ |
|
26
|
4 |
|
$this->percentage = Fee::$default_percentage; |
|
27
|
4 |
|
$this->additional_charge = Fee::$default_additional_charge; |
|
28
|
4 |
|
$this->threshold = Fee::$default_threshold; |
|
29
|
4 |
|
$this->cap = Fee::$default_cap; |
|
30
|
4 |
|
$this->__setup(); |
|
31
|
4 |
|
} |
|
32
|
|
|
|
|
33
|
2 |
|
public function withPercentage($percentage){ |
|
34
|
2 |
|
$this->percentage = $percentage; |
|
35
|
2 |
|
$this->__setup(); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public static function resetDefaults(){ |
|
39
|
1 |
|
Fee::$default_percentage = Fee::DEFAULT_PERCENTAGE; |
|
40
|
1 |
|
Fee::$default_additional_charge = Fee::DEFAULT_ADDITIONAL_CHARGE; |
|
41
|
1 |
|
Fee::$default_threshold = Fee::DEFAULT_THRESHOLD; |
|
42
|
1 |
|
Fee::$default_cap = Fee::DEFAULT_CAP; |
|
43
|
1 |
|
} |
|
44
|
|
|
|
|
45
|
2 |
|
public function withAdditionalCharge($additional_charge){ |
|
46
|
2 |
|
$this->additional_charge = $additional_charge; |
|
47
|
2 |
|
$this->__setup(); |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
public function withThreshold($threshold){ |
|
51
|
2 |
|
$this->threshold = $threshold; |
|
52
|
2 |
|
$this->__setup(); |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
public function withCap($cap){ |
|
56
|
2 |
|
$this->cap = $cap; |
|
57
|
2 |
|
$this->__setup(); |
|
58
|
2 |
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
private function __setup(){ |
|
61
|
4 |
|
$this->charge_divider = $this->__charge_divider(); |
|
62
|
4 |
|
$this->crossover = $this->__crossover(); |
|
63
|
4 |
|
$this->flatline_plus_charge = $this->__flatline_plus_charge(); |
|
64
|
4 |
|
$this->flatline = $this->__flatline(); |
|
65
|
4 |
|
} |
|
66
|
|
|
|
|
67
|
4 |
|
private function __charge_divider(){ |
|
68
|
4 |
|
return 1 - $this->percentage; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
4 |
|
private function __crossover(){ |
|
72
|
4 |
|
return ($this->threshold * $this->charge_divider) - $this->additional_charge; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
4 |
|
private function __flatline_plus_charge(){ |
|
76
|
4 |
|
return ($this->cap - $this->additional_charge) / $this->percentage; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
4 |
|
private function __flatline(){ |
|
80
|
4 |
|
return $this->flatline_plus_charge - $this->cap; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
3 |
|
public function addFor($amountinkobo){ |
|
84
|
3 |
|
if ($amountinkobo > $this->flatline) |
|
85
|
3 |
|
return intval(ceil($amountinkobo + $this->cap)); |
|
86
|
3 |
|
elseif ($amountinkobo > $this->crossover) |
|
87
|
3 |
|
return intval(ceil(($amountinkobo + $this->additional_charge) / $this->charge_divider)); |
|
88
|
|
|
else |
|
89
|
3 |
|
return intval(ceil($amountinkobo / $this->charge_divider)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
2 |
|
public function calculateFor($amountinkobo){ |
|
93
|
2 |
|
$fee = $this->percentage * $amountinkobo; |
|
94
|
2 |
|
if($amountinkobo >= $this->threshold){ |
|
95
|
2 |
|
$fee += $this->additional_charge; |
|
96
|
2 |
|
} |
|
97
|
2 |
|
if($fee > $this->cap){ |
|
98
|
1 |
|
$fee = $this->cap; |
|
99
|
1 |
|
} |
|
100
|
2 |
|
return intval(ceil($fee)); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|