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)
def bulk(self, bulkDetails): # feature logic bulkDetails = copy.copy(bulkDetails) bulkDetails.update({"seckey": self._getSecretKey()}) requiredParameters = ["title", "bulk_data"] checkIfParametersAreComplete(requiredParameters, bulkDetails) checkTransferParameters(requiredParameters, bulkDetails) endpoint = self._baseUrl + self._endpointMap["transfer"]["bulk"] # Collating request headers headers = { 'content-type': 'application/json', } response = requests.post(endpoint, headers=headers, data=json.dumps(bulkDetails)) 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-Bulk-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-Bulk","message": responseTime} tracking_response = requests.post(tracking_endpoint, data=json.dumps(tracking_payload)) return self._handleBulkResponse(response, bulkDetails)
def bulk(self, bulkDetails): bulkDetails = copy.copy(bulkDetails) # Collating request headers headers = { 'content-type': 'application/json', } bulkDetails.update({"seckey": self._getSecretKey()}) requiredParameters = ["title", "bulk_data"] checkIfParametersAreComplete(requiredParameters, bulkDetails) checkTransferParameters(requiredParameters, bulkDetails) endpoint = self._baseUrl + self._endpointMap["transfer"]["bulk"] # Collating request headers headers = { 'content-type': 'application/json', } response = requests.post(endpoint, headers=headers, data=json.dumps(bulkDetails)) return self._handleBulkResponse(response, bulkDetails)
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)