Ejemplo n.º 1
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the mpesa charge call.\n
             Parameters include:\n
            accountDetails (dict) -- These are the parameters passed to the function for processing\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"]
        # Adding boilerplate mpesa requirements
        accountDetails.update({
            "payment_type": "mpesa",
            "country": "KE",
            "is_mpesa": "1",
            "currency": "KES"
        })
        # If transaction reference is not set
        if not ("txRef" in accountDetails):
            accountDetails.update({"txRef": generateTransactionReference()})
        # If order reference is not set
        if not ("orderRef" in accountDetails):
            accountDetails.update({"orderRef": generateTransactionReference()})

        # Checking for required account components
        requiredParameters = ["amount", "email", "phonenumber", "IP"]
        res = super(Mpesa, self).charge(accountDetails,
                                        requiredParameters,
                                        endpoint,
                                        isMpesa=True)
        return res
Ejemplo n.º 2
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the charge call for central francophone countries.
             Parameters include:\n
            accountDetails (dict) -- These are the parameters passed to the function for processing\n
            hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
        """

        endpoint = self._baseUrl + self._endpointMap["account"]["charge"]
        # It is faster to add boilerplate than to check if each one is present
        accountDetails.update({
            "payment_type": "mobilemoneyfrancophone",
            "is_mobile_money_franco": "1"
        })

        # If transaction reference is not set
        if not ("txRef" in accountDetails):
            accountDetails.update({"txRef": generateTransactionReference()})
        # If order reference is not set
        if not ("orderRef" in accountDetails):
            accountDetails.update({"orderRef": generateTransactionReference()})
        # Checking for required account components
        # requiredParameters = ["amount", "email", "phonenumber", "IP", "redirect_url"]
        requiredParameters = ["amount"]
        return super(Francophone, self).charge(accountDetails,
                                               requiredParameters, endpoint)
Ejemplo n.º 3
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the RWMobile charge call.
             Parameters include:\n
            accountDetails (dict) -- These are the parameters passed to the function for processing\n
            hasFailed (boolean) -- This is a flag to determine if the attempt had previously failed due to a timeout\n
        """

        #feature logic
        feature_name = "Rwanda-MoMo-charge"
        endpoint = self._baseUrl + self._endpointMap["account"]["charge"]

        # It is faster to add boilerplate than to check if each one is present
        accountDetails.update({
            "payment_type": "mobilemoneygh",
            "country": "NG",
            "is_mobile_money_gh": "1",
            "currency": "RWF",
            "network": "RWF"
        })
        # If transaction reference is not set

        if not ("txRef" in accountDetails):
            accountDetails.update({"txRef": generateTransactionReference()})
        # If order reference is not set

        if not ("orderRef" in accountDetails):
            accountDetails.update({"orderRef": generateTransactionReference()})
        # Checking for required account components

        requiredParameters = [
            "amount", "email", "phonenumber", "network", "IP", "redirect_url"
        ]
        return super(RWMobile, self).charge(feature_name, accountDetails,
                                            requiredParameters, endpoint)
Ejemplo n.º 4
0
    def charge(self, ussdDetails, hasFailed=False):
        """ This is used to charge through ussd.\n
             Parameters are:\n
            ussdDetails (dict) -- This is a dictionary comprising payload parameters.\n
            hasFailed (bool) -- This indicates whether the request had previously failed for timeout handling
        """

        endpoint = self._baseUrl + self._endpointMap["account"]["charge"]

        # Add boilerplate ussd code
        ussdDetails.update({"is_ussd": "1", "payment_type": "ussd"})
        # if transaction reference is not present, generate
        if not ("txRef" in ussdDetails):
            ussdDetails.update({"txRef": generateTransactionReference()})
        if not ("orderRef" in ussdDetails):
            ussdDetails.update({"orderRef": generateTransactionReference()})
        # Checking for required ussd components (not checking for payment_type, is_ussd, txRef or orderRef again to increase efficiency)
        requiredParameters = [
            "accountbank", "accountnumber", "amount", "email", "phonenumber",
            "IP"
        ]

        # Should return request is a less efficient call but it is required here because we need bank code in _handleResponses
        return super(Ussd, self).charge(ussdDetails,
                                        requiredParameters,
                                        endpoint,
                                        shouldReturnRequest=True)
Ejemplo n.º 5
0
    def initiate(self, transferDetails):
        # Performing shallow copy of transferDetails to avoid public exposing payload with secret key
        transferDetails = copy.copy(transferDetails)

        # adding reference if not already included
        if not ("reference" in transferDetails):
            transferDetails.update(
                {"reference": generateTransactionReference()})
        transferDetails.update({"seckey": self._getSecretKey()})

        # These are the parameters required to initiate a transfer
        requiredParameters = ["amount", "currency", "beneficiary_name"]

        checkIfParametersAreComplete(requiredParameters, transferDetails)
        checkTransferParameters(requiredParameters, transferDetails)

        # Collating request headers
        headers = {
            'content-type': 'application/json',
        }

        endpoint = self._baseUrl + self._endpointMap["transfer"]["initiate"]
        response = requests.post(endpoint,
                                 headers=headers,
                                 data=json.dumps(transferDetails))
        return self._handleInitiateResponse(response, transferDetails)
Ejemplo n.º 6
0
    def charge(self, cardDetails, hasFailed=False, chargeWithToken=False):
        """ This is called to initiate the charge process.\n
             Parameters include:\n
            cardDetails (dict) -- This is a dictionary comprising payload parameters.\n
            hasFailed (bool) -- This indicates whether the request had previously failed for timeout handling
        """
        # setting the endpoint
        if not chargeWithToken:
            endpoint = self._baseUrl + self._endpointMap["card"]["charge"]
            requiredParameters = ["cardno", "cvv", "expirymonth", "expiryyear", "amount", "email", "IP", "phonenumber", "firstname", "lastname"]
            # optionalParameters = ["phonenumber", "firstname", "lastname"]
        else: 
            if "charge_type" in cardDetails and cardDetails["charge_type"] == 'preauth':
                endpoint = self._baseUrl + self._endpointMap["preauth"]["charge"]
            else: 
                endpoint = self._baseUrl + self._endpointMap["card"]["chargeSavedCard"]

            requiredParameters = ["currency", "token", "country", "amount", "email", "txRef", "IP"]
            # optionalParameters = ["firstname", "lastname"]
            # add token to requiredParameters
            # requiredParameters.append("token")

        if not ("txRef" in cardDetails):
            cardDetails.update({"txRef":generateTransactionReference()})

        
        return super(Card, self).charge(cardDetails, requiredParameters, endpoint)
Ejemplo n.º 7
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the direct account charge call.\n
             Parameters include:\n
            accountDetails (dict) -- These are the parameters passed to the function for processing\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 = "Initiate-Account-charge"

        # It is faster to just update rather than check if it is already present
        accountDetails.update({'payment_type': 'account'})

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

        # Checking for required account components
        requiredParameters = [
            'accountbank', 'accountnumber', 'amount', 'email', 'phonenumber',
            'IP'
        ]

        return super().charge(feature_name, accountDetails, requiredParameters,
                              endpoint)
Ejemplo n.º 8
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the ghMobile charge call.\n
             Parameters include:\n
            accountDetails (dict) -- These are the parameters passed to the function for processing\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"]

        # It is faster to just update rather than check if it is already present
        accountDetails.update({"payment_type": "account"})
        # Here we check because txRef could be set by user
        if not ("txRef" in accountDetails):
            accountDetails.update({"txRef": generateTransactionReference()})
        # Checking for required account components
        requiredParameters = [
            "accountbank", "accountnumber", "amount", "email", "phonenumber",
            "IP"
        ]
        return super(Account, self).charge(accountDetails, requiredParameters,
                                           endpoint)
Ejemplo n.º 9
0
    def initiate(self, transferDetails):
        
        
        ## feature logic
        # Performing shallow copy of transferDetails to avoid public exposing payload with secret key
        transferDetails = copy.copy(transferDetails)
        
        # adding reference if not already included
        if not ("reference" in transferDetails):
            transferDetails.update({"reference": generateTransactionReference()})
        transferDetails.update({"seckey": self._getSecretKey()})
        
        # These are the parameters required to initiate a transfer
        requiredParameters = ["amount", "currency","beneficiary_name"]
        checkIfParametersAreComplete(requiredParameters, transferDetails)
        checkTransferParameters(requiredParameters, transferDetails)
        
        # Collating request headers
        headers = {
            'content-type': 'application/json',
        }

        endpoint = self._baseUrl + self._endpointMap["transfer"]["initiate"]
        response = requests.post(endpoint, headers=headers, data=json.dumps(transferDetails))

        if response.ok == False:
            #feature logging
            tracking_endpoint = self._trackingMap
            responseTime = response.elapsed.total_seconds()
            tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.13", "title": "Initiate-Transfer-error","message": responseTime}
            tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
        else:
            tracking_endpoint = self._trackingMap
            responseTime = response.elapsed.total_seconds()
            tracking_payload = {"publicKey": self._getPublicKey(),"language": "Python v2", "version": "1.2.13", "title": "Initiate-Transfer","message": responseTime}
            tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload))
        return self._handleInitiateResponse(response, transferDetails)