def post(self, request, *args, **kwargs): data = request.POST log_message('TOYOTA Request', params=data) email_text = """Sveiki, nosūtīts pieprasījums no velo.lv lapas. Pārstāvis: %(dealer)s Modelis: %(model)s Vārds: %(name)s E-pasts vai tel: %(contact)s Ziņa: %(message)s valoda: %(language)s Ar cieņu, velo.lv """ % data emails = { 'Amserv Motors': ['*****@*****.**', '*****@*****.**'], 'WESS Motors Rīgā': ['*****@*****.**', '*****@*****.**', '*****@*****.**'], 'WESS Motors Berģos': ['*****@*****.**', '*****@*****.**', '*****@*****.**'] } send_mail(subject='Ziņa no velo.lv', message=email_text, from_email=settings.SERVER_EMAIL, recipient_list=emails.get(data.get('dealer', None), ['*****@*****.**']),) return HttpResponse("ok")
def timeout_old_transactions(): transactions = Transaction.objects.filter(status__in=[Transaction.STATUSES.new, Transaction.STATUSES.pending], modified__lt=(timezone.now() - datetime.timedelta(minutes=15))) for t in transactions: log_message('TIMEOUT Transaction', object=t) t.status = Transaction.STATUSES.timeout t.save()
def request_transaction_code(self): transaction_id = None language = self.transaction.language if language == "ru": language = "en" params = { 'command': 'v', 'amount': int(self.transaction.amount * 100), 'currency': "978", # ISO 4217 - EUR = 978 'description': self.transaction.information, 'language': language } try: params.update({'client_ip_addr': self.request.META.get('REMOTE_ADDR', None)}) except AttributeError: params.update({'client_ip_addr': '127.0.0.1'}) resp = requests.post( self.transaction.channel.server_url, cert=(self.transaction.channel.cert_file.path, self.transaction.channel.key_file.path), data=params, verify=False, ) log_message('GOT FD response', resp.text, object=self.transaction) if resp.text[0:14] == 'TRANSACTION_ID': transaction_id = resp.text.strip()[16:] self.transaction.external_code = transaction_id self.transaction.external_code_requested = timezone.now() self.transaction.save() return transaction_id else: return transaction_id
def server_check_transaction(self, request=None): _get = {} for key in request.GET: _get.update({key: request.GET.get(key)}) resp_obj = BankSignature(self.transaction) if resp_obj.verify_signature( _get.get('IB_CRC'), self.generate_digest(_get, _get.get('IB_SERVICE'))): log_message('VERIFIED Transaction', params=_get, object=self.transaction) if _get.get('IB_SERVICE') == '0003': self.transaction.status = Transaction.STATUSES.pending else: self.transaction.server_response = _get.get('IB_STATUS', '') self.transaction.status = self.get_transaction_status( _get.get('IB_STATUS')) self.transaction.server_response_at = timezone.now() self.transaction.returned_server_ip = get_client_ip(request) self.transaction.save() return _get else: log_message('ERROR Transaction', 'Invalid MAC', params=_get, object=self.transaction) raise Exception('Invalid MAC')
def timeout_old_transactions(): transactions = Transaction.objects.filter( status__in=[Transaction.STATUSES.new, Transaction.STATUSES.pending], modified__lt=(timezone.now() - datetime.timedelta(minutes=15))) for t in transactions: log_message('TIMEOUT Transaction', object=t) t.status = Transaction.STATUSES.timeout t.save()
def check_transaction(self, request=None): post = {} for key in request.POST: post.update({key: request.POST.get(key)}) resp_obj = BankSignature(self.transaction) if resp_obj.verify_signature(post.get('IB_CRC'), self.generate_digest(post, post.get('IB_SERVICE'))): log_message('VERIFIED Transaction', params=post, object=self.transaction) del post['IB_CRC'] # No need, because already verified return post else: log_message('ERROR Transaction', 'Invalid MAC', params=post, object=self.transaction) return False
def dispatch(self, request, *args, **kwargs): log = log_message('TransactionReturnView %s' % request.method, params={ 'GET': request.GET, 'POST': request.POST }) if request.POST.get("trans_id", None): transaction = Transaction.objects.get( external_code=request.POST.get("trans_id")) else: if request.POST.get('VK_REF', None): _id = request.POST.get('VK_REF', None) elif request.GET.get('VK_REF', None): _id = request.GET.get('VK_REF', None) elif request.POST.get('IB_PAYMENT_ID', None): _id = request.POST.get('IB_PAYMENT_ID', None) elif request.GET.get('IB_PAYMENT_ID', None): _id = request.GET.get('IB_PAYMENT_ID', None) else: log.set_message("ERROR") raise Http404("ERROR") transaction = Transaction.objects.get(id=_id) log.set_object(transaction) integration_object = transaction.channel.get_class(transaction) return integration_object.verify_return(request)
def check_transaction(self, request=None): post = {} for key in request.POST: post.update({key: request.POST.get(key)}) resp_obj = BankSignature(self.transaction) if resp_obj.verify_signature(post.get('VK_MAC'), self.generate_digest(post)): log_message('VERIFIED Transaction', params=post, object=self.transaction) del post['VK_MAC'] # No need, because already verified return post else: log_message('ERROR Transaction', 'Invalid MAC', params=post, object=self.transaction) return False
def server_check_transaction(self, request=None): _get = {} for key in request.GET: _get.update({key: request.GET.get(key)}) resp_obj = BankSignature(self.transaction) if resp_obj.verify_signature(_get.get('VK_MAC'), self.generate_digest(_get)): log_message('VERIFIED Transaction', params=_get, object=self.transaction) if _get.get('VK_SERVICE') == '1101': self.transaction.server_response = 'OK' else: self.transaction.server_response = 'FAILED' self.transaction.status = self.get_transaction_status(_get.get('VK_SERVICE')) self.transaction.server_response_at = timezone.now() self.transaction.returned_server_ip = get_client_ip(request) self.transaction.save() return _get else: log_message('ERROR Transaction', 'Invalid MAC', params=_get, object=self.transaction) raise Exception('Invalid MAC')
def check_transaction(self, request=None): params = { 'command': 'c', 'trans_id': self.transaction.external_code, } try: params.update({'client_ip_addr': self.request.META.get('REMOTE_ADDR', None)}) except AttributeError: params.update({'client_ip_addr': '127.0.0.1'}) resp = requests.post( self.transaction.channel.server_url, cert=(self.transaction.channel.cert_file.path, self.transaction.channel.key_file.path), data=params, verify=False, ) if resp.status_code != 200: log_message('FAILED VERIFY Transaction', "%i -- %s" % (resp.status_code, resp.text), object=self.transaction) return False else: if 'error: ' in resp.text: log_message('ERROR Transaction', resp.text, object=self.transaction) return False dict_obj = {} for _ in resp.text.split('\n'): key, value = _.split(': ') dict_obj.update({key: value}) log_message('VERIFIED Transaction', resp.text, params=dict_obj, object=self.transaction) return dict_obj
def reverse_transaction(self, amount=None): if not amount: amount = self.transaction.amount params = { 'command': 'r', 'trans_id': self.transaction.external_code, 'amount': int(float(amount)*100), } resp = requests.post( self.transaction.channel.server_url, cert=(self.transaction.channel.cert_file.path, self.transaction.channel.key_file.path), data=params, verify=False, ) if resp.status_code != 200: log_message('FAILED VERIFY Transaction', "%i -- %s" % (resp.status_code, resp.text), object=self.transaction) return False else: if 'error: ' in resp.text: log_message('ERROR Transaction', resp.text, object=self.transaction) return False self.transaction.status = self.transaction.STATUSES.reversed self.transaction.save() dict_obj = {} for _ in resp.text.split('\n'): key, value = _.split(': ') dict_obj.update({key: value}) log_message('REVERSED Transaction', resp.text, params=dict_obj, object=self.transaction) return dict_obj
def request_transaction_code(self): transaction_id = None language = self.transaction.language if language == "ru": language = "en" params = { 'command': 'v', 'amount': int(self.transaction.amount * 100), 'currency': "978", # ISO 4217 - EUR = 978 'description': self.transaction.information, 'language': language } try: params.update( {'client_ip_addr': self.request.META.get('REMOTE_ADDR', None)}) except AttributeError: params.update({'client_ip_addr': '127.0.0.1'}) resp = requests.post( self.transaction.channel.server_url, cert=(self.transaction.channel.cert_file.path, self.transaction.channel.key_file.path), data=params, verify=False, ) log_message('GOT FD response', resp.text, object=self.transaction) if resp.text[0:14] == 'TRANSACTION_ID': transaction_id = resp.text.strip()[16:] self.transaction.external_code = transaction_id self.transaction.external_code_requested = timezone.now() self.transaction.save() return transaction_id else: return transaction_id
def dispatch(self, request, *args, **kwargs): log = log_message('TransactionReturnView %s' % request.method, params={'GET': request.GET, 'POST': request.POST}) if request.POST.get("trans_id", None): transaction = Transaction.objects.get(external_code=request.POST.get("trans_id")) else: if request.POST.get('VK_REF', None): _id = request.POST.get('VK_REF', None) elif request.GET.get('VK_REF', None): _id = request.GET.get('VK_REF', None) elif request.POST.get('IB_PAYMENT_ID', None): _id = request.POST.get('IB_PAYMENT_ID', None) elif request.GET.get('IB_PAYMENT_ID', None): _id = request.GET.get('IB_PAYMENT_ID', None) else: log.set_message("ERROR") raise Http404("ERROR") transaction = Transaction.objects.get(id=_id) log.set_object(transaction) integration_object = transaction.channel.get_class(transaction) return integration_object.verify_return(request)
def check_transaction(self, request=None): params = { 'command': 'c', 'trans_id': self.transaction.external_code, } try: params.update( {'client_ip_addr': self.request.META.get('REMOTE_ADDR', None)}) except AttributeError: params.update({'client_ip_addr': '127.0.0.1'}) resp = requests.post( self.transaction.channel.server_url, cert=(self.transaction.channel.cert_file.path, self.transaction.channel.key_file.path), data=params, verify=False, ) if resp.status_code != 200: log_message('FAILED VERIFY Transaction', "%i -- %s" % (resp.status_code, resp.text), object=self.transaction) return False else: if 'error: ' in resp.text: log_message('ERROR Transaction', resp.text, object=self.transaction) return False dict_obj = {} for _ in resp.text.split('\n'): key, value = _.split(': ') dict_obj.update({key: value}) log_message('VERIFIED Transaction', resp.text, params=dict_obj, object=self.transaction) return dict_obj