Last active
October 10, 2018 20:36
-
-
Save ibrahimlawal/c6a30029be45397ae6de93232118635c to your computer and use it in GitHub Desktop.
Add Paystack fees in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class PaystackFee: | |
"""Work with Paystack's Fees""" | |
DEFAULT_PERCENTAGE = 0.015 | |
DEFAULT_ADDITIONAL_CHARGE = 10000 | |
DEFAULT_THRESHOLD = 250000 | |
DEFAULT_CAP = 200000 | |
percentage = DEFAULT_PERCENTAGE | |
additional_charge = DEFAULT_ADDITIONAL_CHARGE | |
threshold = DEFAULT_THRESHOLD | |
cap = DEFAULT_CAP | |
chargeDivider = 0 | |
crossover = 0 | |
flatlinePlusCharge = 0 | |
flatline = 0 | |
def __init__(self): | |
self.__setup() | |
def withPercentage(self, percentage): | |
self.percentage = percentage | |
self.__setup() | |
def withAdditionalCharge(self, additional_charge): | |
self.additional_charge = additional_charge | |
self.__setup() | |
def withThreshold(self, threshold): | |
self.threshold = threshold | |
self.__setup() | |
def withCap(self, cap): | |
self.cap = cap | |
self.__setup() | |
def __setup(self): | |
self.chargeDivider = self.__chargeDivider() | |
self.crossover = self.__crossover() | |
self.flatlinePlusCharge = self.__flatlinePlusCharge() | |
self.flatline = self.__flatline() | |
def __chargeDivider(self): | |
return 1 - self.percentage | |
def __crossover(self): | |
return (self.threshold * self.chargeDivider) - self.additional_charge | |
def __flatlinePlusCharge(self): | |
return (self.cap - self.additional_charge) / self.percentage | |
def __flatline(self): | |
return self.flatlinePlusCharge - self.cap | |
def addFor(self, amountinkobo): | |
if (amountinkobo > self.flatline): | |
return int(round(amountinkobo + self.cap)) | |
elif (amountinkobo > self.crossover): | |
return int(round((amountinkobo + self.additional_charge) / self.chargeDivider)) | |
else: | |
return int(round(amountinkobo / self.chargeDivider)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PaystackFee import PaystackFee | |
r = PaystackFee() | |
print r.addFor(530000) | |
# to add foreign payment costs... | |
r.withAdditionalCharge(10000) | |
r.withThreshold(250000) | |
r.withCap(10000000000000) | |
r.withPercentage(0.039) | |
print r.addFor(530000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment