def get(self, request): """ Only admin user is allowed to access the private bank mandate pipe file. :param request: the email_id of the pertinent user is received from this. :return: send the generated pipe file """ # makes sure that only superuser can access this file. if request.user.is_superuser: order_detail = OrderDetail.objects.get( order_id=request.GET.get('order_id')) if order_detail.is_lumpsum == False: fund_order_item = order_detail.fund_order_items.first() if fund_order_item: order_detail = OrderDetail.objects.filter( is_lumpsum=True, fund_order_items__portfolio_item=fund_order_item. portfolio_item).first() if is_investable(order_detail.user): exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() order_vendor = order_detail.vendor if order_vendor: exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance(order_vendor.name) if exch_backend: mandate_helper_instance = bank_mandate_helper.BankMandateHelper( ) is_mandate_required, bank_mandate = mandate_helper_instance.is_new_mandate_required( order_detail.user, order_detail, True) status, output_file = exch_backend.generate_bank_mandate_registration( order_detail.user.id, bank_mandate) if status == constants.RETURN_CODE_SUCCESS: if output_file: output_file = output_file.split('/')[-1] prefix = 'webapp' my_file_path = prefix + constants.STATIC + output_file my_file = open(my_file_path, "rb") content_type = 'text/plain' response = HttpResponse(my_file, content_type=content_type, status=200) response[ 'Content-Disposition'] = 'attachment;filename=%s' % str( order_detail.id) + '_order.txt' my_file.close() return response # contains the pipe file of the pertinent user else: return HttpResponse(constants.SUCCESS, status=200) # file doesn't exist because investor vault is incomplete. return HttpResponse(payment_constant.CANNOT_GENERATE_FILE, status=404) else: # non-admin is trying to access the file. Prevent access. return HttpResponse(constants.FORBIDDEN_ERROR, status=403)
def get(self, request): """ Only admin user is allowed to access the private Bse info Tiff file. :param request: the email_id of the pertinent user is received from this. :return: send the generated tiff file """ # makes sure that only superuser can access this file. if request.user.is_superuser: exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() if exch_backend: user = pr_models.User.objects.get( email=request.GET.get('email')) if is_investable(user) and user.signature != "": result = exch_backend.upload_aof_image(user.id) if result == constants.RETURN_CODE_SUCCESS: return HttpResponse(constants.SUCCESS, status=200) # file doesn't exist because investor vault is incomplete. return HttpResponse(payment_constant.CANNOT_GENERATE_FILE, status=404) else: # non-admin is trying to access the file. Prevent access. return HttpResponse(constants.FORBIDDEN_ERROR, status=403)
def get_current_mandate(self, user): mandate_vendor = helpers.get_exchange_vendor_helper( ).get_active_vendor() latest_mandate = self.get_latest_mandate(user, mandate_vendor) if not latest_mandate: mandate_amount = self.get_investor_mandate_amount(0) latest_mandate = self.create_new_mandate(self, user, None, mandate_vendor, mandate_amount) return latest_mandate
def get(self, request): """ :param request: :return: """ active_exchange_backend = external_api_helpers.get_exchange_vendor_helper( ).get_backend_instance() # if profile_utils.check_if_all_set(request.user) and request.user.investorinfo.kra_verified: bank_name = request.user.investorbankdetails.ifsc_code.name product_id_array = constants.bank_product_id_map.get(bank_name, None) if product_id_array is not None: txt_bank_id, product_id = product_id_array[0], product_id_array[1] if txt_bank_id == "" or product_id == "": return api_utils.response( {"message": constants.UNAVAILABE_BANK}, status.HTTP_404_NOT_FOUND, constants.UNAVAILABE_BANK) else: return api_utils.response({"message": constants.UNAVAILABE_BANK}, status.HTTP_404_NOT_FOUND, constants.UNAVAILABE_BANK) serializer = serailizers.TransactionSerializer( data=request.query_params) if serializer.is_valid(): # txt_bank_id = request.query_params.get('txt_bank_id') # product_id = request.query_params.get('product_id') web = False if request.query_params.get('web'): web = True kwargs = { "txn_amount": request.query_params.get('txn_amount'), "txt_bank_id": txt_bank_id, "product_id": product_id, "additional_info_1": code_generator(40), "additional_info_3": request.user.finaskus_id, "customer_id": code_generator(7), "user_id": request.user.id, } billdesk = models.Transaction.objects.create(**kwargs) logger = logging.getLogger('django.info') payment_link, error_status = active_exchange_backend.generate_payment_link( billdesk, web) if payment_link: logger.info(payment_link) return api_utils.response(payment_link) return api_utils.response({"message": error_status}, status.HTTP_428_PRECONDITION_REQUIRED, error_status) return api_utils.response(serializer.errors, status.HTTP_404_NOT_FOUND, constants.MALFORMED_REQUEST)
def get(self, request): """ :param request: :return: Bypass view to make order details before payment is made """ active_exchange_vendor = external_api_helpers.get_exchange_vendor_helper( ).get_active_vendor() bank_name = request.user.investorbankdetails.ifsc_code.name txt_bank_id = 'XXX' product_id = bank_name product_id_array = constants.bank_product_id_map.get(bank_name, None) if product_id_array is not None: txt_bank_id, product_id = product_id_array[0], product_id_array[1] serializer = serailizers.TransactionSerializer( data=request.query_params) if serializer.is_valid(): logger = logging.getLogger('django.info') try: kwargs = { "txn_amount": request.query_params.get('txn_amount'), "txt_bank_id": txt_bank_id, "product_id": product_id, "additional_info_1": code_generator(40), "additional_info_3": request.user.finaskus_id, "customer_id": code_generator(7), "user_id": request.user.id, } billdesk = models.Transaction.objects.create(**kwargs) core_utils.convert_to_investor(billdesk, active_exchange_vendor) return api_utils.response({"message": "success"}) except IntegrityError as e: logger.info("Integrity Error creating order: " + str(e)) return api_utils.response({"message": "failure"}, status.HTTP_404_NOT_FOUND, constants.ORDER_CREATION_FAILED) except Exception as e: logger.info("Error creating order: " + str(e)) return api_utils.response({"message": "failure"}, status.HTTP_404_NOT_FOUND, constants.ORDER_CREATION_FAILED) return api_utils.response(serializer.errors, status.HTTP_404_NOT_FOUND, constants.MALFORMED_REQUEST)
def generate_mandate_pdf(self, bank_mandate_instance): if not bank_mandate_instance: return None, "Invalid Mandate" output_file = None error_str = None mandate_vendor = bank_mandate_instance.vendor exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance(mandate_vendor.name) if exch_backend: user = bank_mandate_instance.user if utils.is_investable(user) and user.signature != "": output_file, error_str = exch_backend.generate_bank_mandate( user.id, bank_mandate_instance) return output_file, error_str
def get(self, user_list): """ :param request: the email_id of the pertinent user is received from this. :return: send the generated pipe file """ exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() if exch_backend: not_set = [] for i in user_list: user = pr_models.User.objects.get(id=i) if not is_investable(user): not_set.append(user.id) if len(not_set) > 0: return not_set return exch_backend.bulk_create_customer(user_list)
def get(self, request): """ Only admin user is allowed to access the private Bse info Tiff file. :param request: the email_id of the pertinent user is received from this. :return: send the generated tiff file """ # makes sure that only superuser can access this file. if request.user.is_superuser: exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() if exch_backend: user = pr_models.User.objects.get( email=request.GET.get('email')) if is_investable(user) and user.signature != "": output_file = exch_backend.generate_aof_image( user.id).split('/')[-1] prefix = 'webapp' my_file_path = prefix + constants.STATIC + output_file my_file = open(my_file_path, "rb") content_type = 'image/tiff' try: invest_info = pr_models.InvestorInfo.objects.get( user=user) download_name = invest_info.pan_number except: download_name = user.id response = HttpResponse(my_file, content_type=content_type, status=200) response[ 'Content-Disposition'] = 'attachment;filename=%s' % download_name + ".tiff" my_file.close() return response # contains the pdf of the pertinent user else: # file doesn't exist because investor vault is incomplete. return HttpResponse(payment_constant.CANNOT_GENERATE_FILE, status=404) else: # non-admin is trying to access the file. Prevent access. return HttpResponse(constants.FORBIDDEN_ERROR, status=403)
def get(self, request): """ Only admin user is allowed to access the private Bse redeem pipe file. :param request: the email_id of the pertinent user is received from this. :return: send the generated pipe file """ # makes sure that only superuser can access this file. if request.user.is_superuser: group_redeem_detail = GroupedRedeemDetail.objects.get( id=request.GET.get('group_redeem_id')) if is_investable(group_redeem_detail.user): exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() if exch_backend: error_status, output_file = exch_backend.create_redeem( group_redeem_detail.user.id, group_redeem_detail) if error_status == constants.RETURN_CODE_SUCCESS: if output_file: output_file = output_file.split('/')[-1] prefix = 'webapp' my_file_path = prefix + constants.STATIC + output_file my_file = open(my_file_path, "rb") content_type = 'text/plain' response = HttpResponse(my_file, content_type=content_type, status=200) response[ 'Content-Disposition'] = 'attachment;filename=%s' % str( group_redeem_detail.id) + 'redeem.txt' my_file.close() return response # contains the pdf of the pertinent user # file doesn't exist because investor vault is incomplete. return HttpResponse(payment_constant.CANNOT_GENERATE_FILE, status=404) else: # non-admin is trying to access the file. Prevent access. return HttpResponse(constants.FORBIDDEN_ERROR, status=403)
def get(self, request): """ :return: """ if request.user.is_superuser: try: portfolio_item = core_models.PortfolioItem.objects.get( id=request.GET.get('portfolio_id')) except core_models.PortfolioItem.DoesNotExist: portfolio_item = None if portfolio_item is not None: user = portfolio_item.portfolio.user exch_backend = helpers.get_exchange_vendor_helper( ).get_backend_instance() if exch_backend: error, output_file = exch_backend.create_xsip_cancellation( user, portfolio_item) #error , output_file = bulk_upload.generate_sip_cancellation_pipe_file(user,portfolio_item) if output_file: output_file = output_file.split('/')[-1] prefix = 'webapp' my_file_path = prefix + constants.STATIC + output_file my_file = open(my_file_path, "rb") content_type = 'text/plain' response = HttpResponse(my_file, content_type=content_type, status=200) response[ 'Content-Disposition'] = 'attachment;filename=%s' % str( portfolio_item.id) + '_portfolioitem.txt' my_file.close() return response else: return HttpResponse("Error at creating the file") else: return HttpResponse("Portfolio item details not found") else: return HttpResponse(constants.FORBIDDEN_ERROR, status=403)
def is_new_mandate_required(self, user, order_detail, create_new=False): if not order_detail: return False, None if order_detail.bank_mandate: return False, order_detail.bank_mandate need_mandate = False mandate_vendor = order_detail.vendor if not mandate_vendor: mandate_vendor = helpers.get_exchange_vendor_helper( ).get_active_vendor() latest_mandate = self.get_latest_mandate(user, mandate_vendor) if not latest_mandate: need_mandate = True order_sip_amount = utils.get_order_sip_amount(user, order_detail) if latest_mandate: current_mandate_sip_amount = utils.get_mandate_total_sip_amount( user, latest_mandate) if latest_mandate.mandate_amount < (order_sip_amount + current_mandate_sip_amount): need_mandate = True if need_mandate: mandate_amount = self.get_investor_mandate_amount(order_sip_amount) mandate = self.create_new_mandate(user, order_detail, mandate_vendor, mandate_amount) return True, mandate else: order_detail.bank_mandate = latest_mandate order_detail.save() return False, latest_mandate
def get(self, request): """ :param request: :return: """ if request.user.is_superuser: logger = logging.getLogger('django.info') try: billdesk = models.Transaction.objects.get( id=request.GET.get('transaction_id')) except models.Transaction.DoesNotExist: billdesk = None if billdesk.txn_status != 1: request_type = ext_api_bse_cons.BILLDESK_QUERY_REQUEST_TYPE now = datetime.today() + timedelta(hours=5, minutes=30) #IST parts = [ request_type, billdesk.merchant_id, billdesk.additional_info_1, now.strftime("%Y%m%d%H%M%S") ] msg = "|".join(parts) checksum = utils.get_billdesk_checksum( msg, settings.BILLDESK_SECRET_KEY) parts.append(checksum) query_data_pipe = "|".join(parts) msg_data = dict(msg=query_data_pipe) resp = requests.post(ext_api_bse_cons.BILLDESK_QUERY_URL, data=msg_data) response = resp.text order_id, ref_no, txn_amount, auth_status, txn_time = payment_billdesk.parse_billdesk_query_response( response) txn_time_dt = None if all(v != 'NA' for v in (order_id, ref_no, txn_amount, auth_status, txn_time)): if txn_time: try: txn_time_dt = datetime.strptime( txn_time, '%d-%m-%Y %H:%M:%S') except: logger.info( "Billdesk response: Error parsing transaction time: " + txn_time) if payment_billdesk.verify_billdesk_checksum(response): if auth_status == "0399": txn = payment_billdesk.update_transaction_failure( order_id, ref_no, float(txn_amount), auth_status, response, txn_time_dt) message = "failed to update transaction" elif auth_status == "0300": txn = payment_billdesk.update_transaction_success( order_id, ref_no, float(txn_amount), auth_status, response, txn_time_dt) active_exchange_vendor = external_api_helpers.get_exchange_vendor_helper( ).get_active_vendor() core_utils.convert_to_investor( txn, active_exchange_vendor) message = "successfully update the transaction" else: message = "Invalid Request: " + str(response) return HttpResponse(message) else: return HttpResponse("Invalid Request") else: return HttpResponse("Invalid Request") else: return HttpResponse("Payment already in success status") else: return HttpResponse("Not authenticated user")