PaystackFees
A class for managing Paystack fees in your application.
Installation
Peer Dependency (required)
Install Joi which we have employed for validating parameters sent to functions in this library
npm install --save @hapi/joi
Now install the module
npm install --save paystack-fees
Sample Usage
const PaystackFees = ;// The lines below will create a new object that calculates fees based on the fee// schedule for USD payments. The cap is set to an arbitrarily high number since there// is no cap.const paystackFees = ; // you can now calculate fees for an amount by calling the `calculateFor` functionconst feesFor1000USD = paystackFees;// or the amount to be sent when we intend to be settled a target amountconst amountToSendToBeSettled50USD = paystackFees;
Kind: global class
paystackFees.withPercentage(percentage) ⇒
set the percentage
Kind: instance method of PaystackFees
Returns: the current PaystackFees object
Throws:
- if percentage sent is invalid
Param | Type | Description |
---|---|---|
percentage | number |
positive number less than 1 |
paystackFees.withAdditionalCharge(additionalCharge) ⇒
set the additional charge which will be added if the amount is over threshold
Kind: instance method of PaystackFees
Returns: the current PaystackFees object
Throws:
- if additional charge sent is invalid
Param | Type | Description |
---|---|---|
additionalCharge | number |
0 or more |
paystackFees.withThreshold(threshold) ⇒
set the threshold, beyond which additional charge will be added to fees.
Kind: instance method of PaystackFees
Returns: the current PaystackFees object
Throws:
- if threshold sent is invalid
Param | Type | Description |
---|---|---|
threshold | number |
0 or more |
paystackFees.withCap(cap) ⇒
set the cap
Kind: instance method of PaystackFees
Returns: the current PaystackFees object
Throws:
- if cap sent is invalid
Param | Type | Description |
---|---|---|
cap | number |
positive number greater than or equal to 1 |
paystackFees.addTo(amountInLowerDenomination) ⇒
calculate amount to be sent to paystack to be settled the amount provided
Kind: instance method of PaystackFees
Returns: amount you should send in lower denomination
Throws:
- if amountInLowerDenomination sent is invalid
Param | Type | Description |
---|---|---|
amountInLowerDenomination | number |
The amount we want to be settled after paystack deducts fees |
Example
paystackFee // add fees so we can be settled 100 in higher denomination
paystackFees.calculateFor(amountInLowerDenomination) ⇒
Calculates the fee for an amount in lower denomination
Kind: instance method of PaystackFees
Returns: fees in lower denomination
Throws:
- if amountInLowerDenomination sent is invalid
Param | Type | Description |
---|---|---|
amountInLowerDenomination | number |
The amount we want to send to paystack |
Example
// calculate the charge that will be deducted if// a local cards pays 100 nairaconst amountInKobo = 10000; // 10000 kobo is 100 nairapaystackFee;