def process(self, request): """Submits a request to be processed by Secure Trading. This method takes the details of the request and then connects and sends the data to Secure Trading, waiting for a reply or timeout before returning the response. Args: request: Either a securetrading.Request or a securetrading.Requests object containing the details of the request. Returns: A securetrading.Response object containing all the response details Usage: >>> response = st_api.process(request) """ request_reference = "" try: if type(request) == dict: st_request = securetrading.Request() st_request.update(request) request = st_request self._verify_request(request) request_reference = request["requestreference"] info = "{0} Begin request".format(request_reference) securetrading.util.logger.info(info) http_client = httpclient._get_client(request_reference, self.config) request.verify() url = request.get("datacenterurl", self.config.datacenterurl) url += "/json/" converter = securetrading.Converter(self.config) request_data = converter._encode(request) response, response_headers = http_client._main(url, request_data, request_reference, request) result = converter._decode(response, response_headers, request_reference) self._verify_result(result, request_reference) except securetrading.SecureTradingError as e: result = self._generate_st_error(e, request_reference) except Exception as e: result = self._generate_error(e, request_reference) info = "{0} Finished request".format(request_reference) get_error_message = securetrading.util._get_errormessage for response in result["responses"]: response["errormessage"] =\ get_error_message(response["errorcode"], response.get("errormessage", ""), self.phrasebook) securetrading.util.logger.info(info) return result
def get_request(self, data={}): default = { "pan": "4111111111111111", "expirydate": "12/2031", "securitycode": "123", "requesttypedescriptions": ["AUTH"], "accounttypedescription": "ECOM", "sitereference": "live2", "paymenttypedescription": "VISA", "currencyiso3a": "OMR", "baseamount": "100", } default.update(data) request = securetrading.Request() request.update(default) return request
def test__verify_request(self): request = securetrading.Request() tests = [ ({}, securetrading.SecureTradingError, ["Incorrect type of request specified" ], "10 Incorrect type of request specified", "10"), (request, None, None, None, None), ] config = self.get_config() api = securetrading.Api(config) for request, exp_exception, exp_data, exp_eng, exp_code in tests: if exp_exception is None: api._verify_request(request) else: self.check_st_exception(exp_exception, exp_data, exp_eng, exp_code, api._verify_request, func_args=(request, ))
def get_securetrading_request(self, request_dict): securetrading_request = securetrading.Request() securetrading_request.update(request_dict) return securetrading_request
def _get_st_request(self, data): st_request = securetrading.Request() st_request.update(data) return st_request