示例#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"]

        # It is faster to add boilerplate than to check if each one is present
        accountDetails.update({
            "payment_type": "mobilemoneygh",
            "country": "GH",
            "is_mobile_money_gh": "1",
            "currency": "GHS"
        })

        # 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(GhMobile, self).charge(accountDetails, requiredParameters,
                                            endpoint)
示例#2
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)
        return res
示例#3
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", "phonenumber", "firstname", "lastname", "IP"
            ]
        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", "firstname",
                "lastname", "txRef", "IP"
            ]
            # add token to requiredParameters
            # requiredParameters.append("token")

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

        return super(Card, self).charge(cardDetails, requiredParameters,
                                        endpoint)
示例#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)
示例#5
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)
示例#6
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 = ["meta","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)