Exemplo n.º 1
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the ghMobile 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
        """

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

        # It is faster to add boilerplate than to check if each one is present
        accountDetails.update({
            "type": "mobile_money_ghana",
            "currency": "GHS"
        })

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

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

        # Checking for required account components
        requiredParameters = [
            "amount", "email", "phone_number", "network", "currency", "tx_ref"
        ]
        return super(GhMobile, self).charge(accountDetails, requiredParameters,
                                            endpoint)
    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", "account_bank", "account_number"
        ]
        checkIfParametersAreComplete(requiredParameters, transferDetails)
        checkTransferParameters(requiredParameters, transferDetails)

        # Collating request headers
        headers = {
            'content-type': 'application/json',
            'authorization': 'Bearer ' + self._getSecretKey(),
        }

        endpoint = self._baseUrl + self._endpointMap["transfer"]["initiate"]
        response = requests.post(endpoint,
                                 headers=headers,
                                 data=json.dumps(transferDetails))
        return self._handleInitiateResponse(response, transferDetails)
    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"] + "?type=" + cardDetails["type"]
            requiredParameters = ["card_number", "cvv", "expiry_month", "expiry_year", "amount", "email", "currency", "tx_ref"]
            # 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", "tx_ref", "IP"]
            # optionalParameters = ["firstname", "lastname"]
            # add token to requiredParameters
            # requiredParameters.append("token")

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

        
        return super(Card, self).charge(cardDetails, requiredParameters, endpoint)
Exemplo n.º 4
0
    def charge(self, accountDetails, hasFailed=False):
        """ This is the 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'] + "?type=" + accountDetails["type"]

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

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

        # Checking for required account components
        if accountDetails["type"] != "ach_payment":
            requiredParameters = [
                'account_bank', 'account_number', 'amount', 'email', 'tx_ref'
            ]
        else:
            requiredParameters = ['amount', 'email', 'currency', 'tx_ref']

        return super(Account, self).charge(accountDetails, requiredParameters,
                                           endpoint)
Exemplo n.º 5
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"] + "?type=" + accountDetails["type"]

        # Adding boilerplate mpesa requirements
        accountDetails.update({
            "payment_type": "mpesa",
            "country": "KE",
            "currency": "KES"
        })

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

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

        # Checking for required account components
        requiredParameters = [
            "amount", "email", "phone_number", "currency", "tx_ref"
        ]
        res = super(Mpesa, self).charge(accountDetails,
                                        requiredParameters,
                                        endpoint,
                                        isMpesa=True)
        return res
Exemplo n.º 6
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 ("tx_ref" in ussdDetails):
            ussdDetails.update({"tx_ref": generateTransactionReference()})
        if not ("orderRef" in ussdDetails):
            ussdDetails.update({"orderRef": generateTransactionReference()})
        # Checking for required ussd components (not checking for payment_type, is_ussd, tx_ref 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)