Skip to content

Pull changes from dev #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/change-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: run unit tests and coverage scan
env:
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
RAVE_SECRET_KEY: ${{ secrets.SECRET_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
pip install coverage
coverage run test.py
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ staging
zero
.coverage
example.py
randomTester.py
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2693,15 +2693,16 @@ This is used to create virtual account for transfers.

### ```.create(accountDetails)```

This allows a customer to create a virtual card. It requires a dict ```vcardDetails``` containing ```email```, ```seckey```, ```is_permanant```, ```frequency```, ```duration``` and ```narration```.
This allows a customer to create a virtual account. It requires a dict ```vaccountDetails``` containing ```email```, ```seckey```, ```is_permanant```, ```frequency```, ```bvn```, ```duration``` and ```narration```.

A sample Create call is:

```py
res = rave.VirtualAccount.create({
"email": "[email protected]",
"seckey": "FLWSECK-****************************-X",
"is_permanent": true
"bvn": "12345678901",
"is_permanent": true,
"narration": "Cornelius A-O"
})
print(res)
```
Expand Down
Binary file removed rave_python/__pycache__/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions rave_python/rave.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from rave_python.rave_account import Account
from rave_python.rave_applepay import ApplePay
from rave_python.rave_bills import Bills
from rave_python.rave_card import Card
from rave_python.rave_ebills import Ebills
from rave_python.rave_fawrypay import FawryPay
from rave_python.rave_francophone import Francophone
from rave_python.rave_ghmobile import GhMobile
from rave_python.rave_googlepay import GooglePay
from rave_python.rave_mpesa import Mpesa
from rave_python.rave_paymentplan import PaymentPlan
from rave_python.rave_preauth import Preauth
Expand All @@ -30,12 +33,15 @@ class Rave:
def __init__(self, publicKey, secretKey, production=False, usingEnv=True):
""" This is main organizing object. It contains the following:\n
rave.Account -- For bank account transactions\n
rave.ApplePay -- For Apple Pay wallet transactions\n
rave.BankTransfer -- For pay with bank transfer transaction\n
rave.Bills -- For Bills payments\n
rave.Card -- For card transactions\n
rave.Enaira -- For enaira wallet payments\n
rave.FawryPay -- For Egyptian collections via Fawry Pay\n
rave.Francophone -- For West African Francophone mobile money transactions\n
rave.GhMobile -- For Ghana mobile money transactions\n
rave.GooglePay -- For Google Pay wallet transactions\n
rave.Mpesa -- For mpesa transactions\n
rave.PaymentPlan -- For payment plan creation and operation\n
rave.Preauth -- For preauthorized transactions\n
Expand All @@ -54,13 +60,16 @@ def __init__(self, publicKey, secretKey, production=False, usingEnv=True):

classes = (
Account,
ApplePay,
BankTransfer,
Bills,
Card,
Ebills,
Enaira,
FawryPay,
Francophone,
GhMobile,
GooglePay,
Mpesa,
PaymentPlan,
Preauth,
Expand Down
80 changes: 80 additions & 0 deletions rave_python/rave_applepay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from rave_python.rave_payment import Payment
from rave_python.rave_exceptions import AccountChargeError
from rave_python.rave_misc import generateTransactionReference

class ApplePay(Payment):
""" This is the rave object for Apple Pay transactions. It contains the following public functions:\n
.charge -- This is for charging a Customer with Apple Pay\n
.verify -- This checks the status of your transaction\n
.refund -- This initiates the refund for the transaction\n
"""

def _handleChargeResponse(self, response, txRef, request=None):
""" This handles account charge responses """
# This checks if we can parse the json successfully
res = self._preliminaryResponseChecks(
response, AccountChargeError, txRef=txRef)

response_json = res['json']
# change - added data before flwRef
response_data = response_json['data']
flw_ref = response_data['flwRef']
auth_url = response_data['authurl']

# If all preliminary checks are passed
data = {
'error': False,
'validationRequired': True,
'authurl': auth_url,
'txRef': txRef,
'flwRef': flw_ref,
'message': "Kindly redirect your user to the authurl. This url is only supported by Safari browsers and Apple Pay enabled devices."
}

return data

def charge(self, requestDetails, hasFailed=False):
""" This is the charge method for Apple Pay payments.\n
Parameters include:\n
requestDetails (dict) -- The request parameters for charging your customers with this payment method\n
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
"""

# setting the endpoint
endpoint = self._baseUrl + self._endpointMap['account']['charge']
feature_name = "ApplePay"

# It is faster to just update rather than check if it is already
# present

requestDetails.update({'payment_type': 'applepay'})

# Generate transaction reference if txRef doesn't exist
requestDetails.setdefault('txRef', generateTransactionReference())

# Checking for required account components
requiredParameters = [
'amount',
'email',
'firstname',
'lastname',
'currency'
]

return super(ApplePay, self).charge(feature_name, requestDetails, requiredParameters, endpoint)

"""
TO DOs
1. Get mocking credentials to test the verify and refund methods for Apple Pay Transactions.
2. Add unittests for verify and refund methods.
"""

# def verify(self, txRef):
# endpoint = self._baseUrl + self._endpointMap['account']['verify']
# feature_name = "Verify eNaira"
# return super(ApplePay, self).verify(feature_name, txRef, endpoint)

# def refund(self, flwRef, amount):
# feature_name = "Refund eNaira"
# endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
# return super(ApplePay, self).refund(feature_name, flwRef, amount)
4 changes: 2 additions & 2 deletions rave_python/rave_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def __init__(
# If we are using environment variables to store secretKey
if (usingEnv):
self.__publicKey = publicKey
self.__secretKey = os.getenv("RAVE_SECRET_KEY", None)
self.__secretKey = os.getenv("SECRET_KEY", None)

if (not self.__publicKey) or (not self.__secretKey):
raise ValueError(
"Please set your RAVE_SECRET_KEY environment variable. Otherwise, pass publicKey and secretKey as arguments and set usingEnv to false")
"Please set your SECRET_KEY environment variable. Otherwise, pass publicKey and secretKey as arguments and set usingEnv to false")

# If we are not using environment variables
else:
Expand Down
2 changes: 1 addition & 1 deletion rave_python/rave_enaira.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Enaira(Payment):
""" This is the rave object for eNaira wallet transactions. It contains the following public functions:\n
.charge -- This is for charging the eNaira wallet\n
.verify -- This checks the status of your transaction\n
.refunds -- This initiates the refund for the transaction\n
.refund -- This initiates the refund for the transaction\n
"""

def _handleChargeResponse(self, response, txRef, request=None):
Expand Down
4 changes: 2 additions & 2 deletions rave_python/rave_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class IncompletePaymentDetailsError(RaveError):
""" Raised when card details are incomplete """

def __init__(self, value, requiredParameters):
msg = "\n\"" + value + "\" was not defined in your dictionary. Please ensure you have supplied the following in the payload: \n " + \
' \n '.join(requiredParameters)
msg = "\"" + value + "\" was not defined in your dictionary. Please ensure you have supplied the following in the payload: " + \
', '.join(requiredParameters)
super(IncompletePaymentDetailsError, self).__init__(msg)


Expand Down
83 changes: 83 additions & 0 deletions rave_python/rave_fawrypay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from rave_python.rave_payment import Payment
from rave_python.rave_exceptions import AccountChargeError
from rave_python.rave_misc import generateTransactionReference

class FawryPay(Payment):
""" This is the rave object for Fawry Pay transactions. It contains the following public functions:\n
.charge -- Charge your Customers with Fawry Pay. This is only supported in Egypt.\n
.verify -- This checks the status of your transaction\n
.refund -- This initiates the refund for the transaction\n
"""

def _handleChargeResponse(self, response, txRef, request=None):
""" This handles account charge responses """
# This checks if we can parse the json successfully
res = self._preliminaryResponseChecks(
response, AccountChargeError, txRef=txRef)

response_json = res['json']
# change - added data before flwRef
response_data = response_json['data']
flw_ref = response_data['flwRef']

# If all preliminary checks are passed
data = {
'error': False,
'validationRequired': True,
'txRef': txRef,
'flwRef': flw_ref,
'message': "Please make payment with the flwRef returned in the response which should be the same as the reference sent via SMS"
}

return data

def charge(self, requestDetails, hasFailed=False):
""" This is the charge method for Fawry Pay payments.\n
Parameters include:\n
requestDetails (dict) -- The request parameters for charging your customers with this payment method\n
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
"""

# setting the endpoint
endpoint = self._baseUrl + self._endpointMap['account']['charge']
feature_name = "FawryPay"

# It is faster to just update rather than check if it is already
# present

requestDetails.update(
{
'payment_type': 'fawry_pay',
'currency': 'EGP'
}
)

# Generate transaction reference if txRef doesn't exist
requestDetails.setdefault('txRef', generateTransactionReference())

# Checking for required account components
requiredParameters = [
'amount',
'email',
'firstname',
'lastname',
'phonenumber'
]

return super(FawryPay, self).charge(feature_name, requestDetails, requiredParameters, endpoint)

"""
TO DOs
1. Get mocking credentials to test the verify and refund methods for FawryPay Transactions.
2. Add unittests for verify and refund methods.
"""

# def verify(self, txRef):
# endpoint = self._baseUrl + self._endpointMap['account']['verify']
# feature_name = "Verify eNaira"
# return super(FawryPay, self).verify(feature_name, txRef, endpoint)

# def refund(self, flwRef, amount):
# feature_name = "Refund eNaira"
# endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
# return super(FawryPay, self).refund(feature_name, flwRef, amount)
80 changes: 80 additions & 0 deletions rave_python/rave_googlepay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from rave_python.rave_payment import Payment
from rave_python.rave_exceptions import AccountChargeError
from rave_python.rave_misc import generateTransactionReference

class GooglePay(Payment):
""" This is the rave object for Google Pay transactions. It contains the following public functions:\n
.charge -- This is for charging a Customer with Google Pay\n
.verify -- This checks the status of your transaction\n
.refund -- This initiates the refund for the transaction\n
"""

def _handleChargeResponse(self, response, txRef, request=None):
""" This handles account charge responses """
# This checks if we can parse the json successfully
res = self._preliminaryResponseChecks(
response, AccountChargeError, txRef=txRef)

response_json = res['json']
# change - added data before flwRef
response_data = response_json['data']
flw_ref = response_data['flwRef']
auth_url = response_data['authurl']

# If all preliminary checks are passed
data = {
'error': False,
'validationRequired': True,
'authurl': auth_url,
'txRef': txRef,
'flwRef': flw_ref,
'message': "Kindly redirect your user to the authurl to complete the payment using their Google Pay Wallets."
}

return data

def charge(self, requestDetails, hasFailed=False):
""" This is the charge method for Google Pay payments.\n
Parameters include:\n
requestDetails (dict) -- The request parameters for charging your customers with this payment method\n
hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
"""

# setting the endpoint
endpoint = self._baseUrl + self._endpointMap['account']['charge']
feature_name = "GooglePay"

# It is faster to just update rather than check if it is already
# present

requestDetails.update({'payment_type': 'googlepay'})

# Generate transaction reference if txRef doesn't exist
requestDetails.setdefault('txRef', generateTransactionReference())

# Checking for required account components
requiredParameters = [
'amount',
'email',
'firstname',
'lastname',
'currency'
]

return super(GooglePay, self).charge(feature_name, requestDetails, requiredParameters, endpoint)

"""
TO DOs
1. Get mocking credentials to test the verify and refund methods for GooglePay Transactions.
2. Add unittests for verify and refund methods.
"""

# def verify(self, txRef):
# endpoint = self._baseUrl + self._endpointMap['account']['verify']
# feature_name = "Verify eNaira"
# return super(GooglePay, self).verify(feature_name, txRef, endpoint)

# def refund(self, flwRef, amount):
# feature_name = "Refund eNaira"
# endpoint = self._baseUrl + self._endpointMap["account"]["refund"]
# return super(GooglePay, self).refund(feature_name, flwRef, amount)
Loading
Loading