def report(): report_list = [] form = ReportForm() if form.validate_on_submit(): data = { "fromDate": form.fromDate.data.strftime('%Y-%m-%d'), "toDate": form.toDate.data.strftime('%Y-%m-%d') } data = utils.add_to_dict_if_form_field_exist(data, 'acquirer', form.acquirer.data, True) data = utils.add_to_dict_if_form_field_exist(data, 'merchant', form.merchant.data, True) current_app.logger.debug("filter data for report is {}".format(data)) response = services.post_query(current_app.config['REPORT_URL'], data) response_status = response['status'] response_list = response['response'] if len(response_list) == 0: current_app.logger.debug( "no response_data found {}".format(response_list)) abort(404) current_app.logger.debug( "response from report url is {}".format(response)) report_list = utils.convert_report_json_2_object_list(response_list) return render_template('report.html', form=form, reports=report_list)
def client(): customer_info = None form = TransactionForm() if form.validate_on_submit(): data = {"transactionId": form.transaction_id.data} current_app.logger.debug( "filter data for transaction is {}".format(data)) response = services.post_query(current_app.config['CLIENT_URL'], data) customer_info = response['customerInfo'] if customer_info is None: current_app.logger.debug( "no response_data found {}".format(customer_info)) abort(404) current_app.logger.debug( "response from report url is {}".format(response)) customer_info = utils.convert_customer_json_2_object(customer_info) return render_template('client.html', form=form, customer=customer_info)
def transaction(): transaction = None form = TransactionForm() if form.validate_on_submit(): data = {"transactionId": form.transaction_id.data} current_app.logger.debug( "filter data for transaction is {}".format(data)) response = services.post_query(current_app.config['TRANSACTION_URL'], data) transaction = response['transaction'] if transaction is None: current_app.logger.debug( "no response_data found {}".format(transaction)) abort(404) current_app.logger.debug( "response from report url is {}".format(response)) transaction = utils.convert_transaction_json_2_object(transaction) return render_template('transaction.html', form=form, transaction=transaction)
def test_client(self): token = self.token_response['token'] data = {"transactionId": "1011028-1539357144-1293"} response = post_query(current_app.config['CLIENT_URL'], token, data) customer_info = response['customerInfo'] self.assertGreater(len(customer_info), 0, "response should contain data")
def test_transaction_query_request(self): token = self.token_response['token'] data = {"fromDate": "2000-01-01", "toDate": "2020-04-01"} response = post_query(current_app.config['TRANSACTION_QUERY_URL'], token, data) per_page = response['per_page'] self.assertEqual(per_page, 50, "per page is not found")
def test_report_request_with_invalid_token(self): token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtZXJjaGFudFVzZXJJZCI6NTMsInJvbGUiOiJ1c2VyIiwibWVyY2hhbnRJZCI6Mywic3ViTWVyY2hhbnRJZHMiOlszLDc0LDkzLDExOTEsMTI5NSwxMTEsMTM3LDEzOCwxNDIsMTQ1LDE0NiwxNTMsMzM0LDE3NSwxODQsMjIwLDIyMSwyMjIsMjIzLDI5NCwzMjIsMzIzLDMyNywzMjksMzMwLDM0OSwzOTAsMzkxLDQ1NSw0NTYsNDc5LDQ4OCw1NjMsMTE0OSw1NzAsMTEzOCwxMTU2LDExNTcsMTE1OCwxMTc5LDEyOTMsMTI5NCwxMzA2LDEzMDddLCJ0aW1lc3RhbXAiOjE1ODU0MjgyOTF9.qlO2DtNL9FFGIitVWZySqWCuYq6EsoTPp0P0P_NT1wM" data = {"fromDate": "2000-01-01", "toDate": "2020-04-01"} response = post_query(current_app.config['REPORT_URL'], token, data) status = response['status'] self.assertEqual(status, "DECLINED", "status is not declined")
def test_report_request_with_valid_token(self): token = self.token_response['token'] data = {"fromDate": "2000-01-01", "toDate": "2020-04-01"} response = post_query(current_app.config['REPORT_URL'], token, data) status = response['status'] self.assertEqual(status, "APPROVED", "status is not approved")
def test_transaction_query_request_for_object_conversion(self): token = self.token_response['token'] data = {"fromDate": "2000-01-01", "toDate": "2020-04-01"} response = post_query(current_app.config['TRANSACTION_QUERY_URL'], token, data) transaction_query_list = response['data'] query_list = utils.convert_transaction_query_json_2_object_list(transaction_query_list) self.assertGreater(len(query_list), 0)
def test_report_request_for_object_conversion(self): token = self.token_response['token'] data = {"fromDate": "2000-01-01", "toDate": "2020-04-01"} response_data = post_query(current_app.config['REPORT_URL'], token, data) status = response_data['status'] self.assertEqual(status, "APPROVED", "status is not approved") tmp_list = utils.convert_report_json_2_object_list(response_data['response']) self.assertGreater(len(tmp_list),0)
def transaction_query(page): next_url = prev_url = per_page = current_page = from_ = to_ = response = None transaction_query_list = [] if request.method == 'GET' and int(page) >= 1: form = TransactionQueryForm(formdata=request.form) data = session['data'] current_app.logger.debug("GET executed") response = services.post_query( current_app.config['TRANSACTION_QUERY_URL'], data, params={"page": page}) response_list = response['data'] if len(response_list) == 0: current_app.logger.debug( "no transaction_query data found {}".format(response_list)) abort(404) transaction_query_list = utils.convert_transaction_query_json_2_object_list( response_list) current_app.logger.debug( "response from report url is {}".format(transaction_query_list)) if "prev_page_url" in response and response[ "prev_page_url"] is not None: prev_url = "/transaction_query/" + utils.extract_page_number( response["prev_page_url"]) if "next_page_url" in response and response[ "next_page_url"] is not None: next_url = "/transaction_query/" + \ utils.extract_page_number(response["next_page_url"]) current_page = response['current_page'] per_page = response['per_page'] from_ = response['from'] else: form = TransactionQueryForm() if request.method == 'POST' and form.validate_on_submit(): data = { "fromDate": form.fromDate.data.strftime('%Y-%m-%d'), "toDate": form.toDate.data.strftime('%Y-%m-%d') } data = utils.add_to_dict_if_form_field_exist(data, 'status', form.status.data) data = utils.add_to_dict_if_form_field_exist(data, 'operation', form.operation.data) data = utils.add_to_dict_if_form_field_exist(data, 'merchantId', form.merchant.data, True) data = utils.add_to_dict_if_form_field_exist(data, 'acquirerId', form.acquirer.data, True) data = utils.add_to_dict_if_form_field_exist(data, 'paymentMethod', form.payment_method.data) data = utils.add_to_dict_if_form_field_exist(data, 'errorCode', form.error_code.data) data = utils.add_to_dict_if_form_field_exist(data, 'filterField', form.filter_field.data) data = utils.add_to_dict_if_form_field_exist(data, 'filterValue', form.filter_value.data) data = utils.add_to_dict_if_form_field_exist(data, 'page', form.page.data, True) session['data'] = data current_app.logger.debug("filter data for report is {}".format(data)) response = services.post_query( current_app.config['TRANSACTION_QUERY_URL'], data) # current_app.logger.debug("response from report url is {}".format(response)) response_list = response['data'] if len(response_list) == 0: current_app.logger.debug( "no transaction_query data found {}".format(response_list)) abort(404) transaction_query_list = utils.convert_transaction_query_json_2_object_list( response_list) if "prev_page_url" in response and response[ "prev_page_url"] is not None: prev_url = "/transaction_query/" + utils.extract_page_number( response["prev_page_url"]) if "next_page_url" in response and response[ "next_page_url"] is not None: next_url = "/transaction_query/"+\ utils.extract_page_number(response["next_page_url"]) current_page = response['current_page'] per_page = response['per_page'] from_ = response['from'] to_ = response['to'] return render_template('transaction_query.html', form=form, transaction_queries=transaction_query_list, next_url=next_url, prev_url=prev_url, page=current_page, per_page=per_page)