def save(self): order = Order.objects.get(id=self.checkout.storage['order_id']) order.comment = self.request.POST.get('comment', '').strip() # Выбор пользователем типа оплаты payment_type = self.request.POST.get('payment') if payment_type not in ('cash', 'robokassa'): payment_type = None # Нет доставки - заказ оптового покупателя if not order.delivery: self.checkout.storage['is_payed'] = True order.status = Order.STATUS_PAYMENT_WAITING order.is_emails_sended = True order.save() self.checkout.save() send_order_mails(order, self.request.user) self.checkout.storage['is_notified'] = True return # Самовывоз - не нужна оплата # Оплата наличкой - не нужна оплата elif payment_type == 'cash': self.checkout.storage['is_payed'] = True order.payment_type = Order.PAYMENT_CASHPICK order.status = Order.STATUS_PAYED order.is_emails_sended = True order.save() self.checkout.save() send_order_mails(order, self.request.user) self.checkout.storage['is_notified'] = True return order.payment_type = Order.PAYMENT_ROBOKASSA order.save() form = RobokassaForm(initial={ 'OutSum': order.net, 'InvId': order.id, 'Desc': u'Заказ №%s в интернет-магазине «Томат»' % order.id, 'Email': self.request.user.email, 'Culture': 'ru', }) if settings.DEBUG: form.target = reverse('checkout.views.rk_test_start') url = form.get_redirect_url() else: url = form.get_redirect_url() self.checkout.save() return HttpResponseRedirect(url)
class RobokassaFormTest(TestCase): def setUp(self): self.form = RobokassaForm( initial={ 'OutSum': 100.00, 'InvId': 58, 'Desc': u'Холодильник "Бирюса"', 'Email': '*****@*****.**' }) def testSignature(self): self.assertEqual( self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial={'InvId': 5}) self.assertEqual( form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin="******"test_login&OutSum=100.0&InvId=58&Desc=%D5%EE%EB%EE%E4%" \ "E8%EB%FC%ED%E8%EA+%22%C1%E8%F0%FE%F1%E0%22&SignatureVa" \ "lue=0EC23BE40003640B35EC07F6615FFB57&Email=vasia%40exa" \ "mple.com&shpparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)
class RobokassaFormTest(TestCase): def setUp(self): self.form = RobokassaForm( initial={ 'OutSum': 100.00, 'InvId': 58, 'Desc': u'Холодильник "Бирюса"', 'Email': '*****@*****.**' }) def testSignature(self): self.assertEqual( self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1) ) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial={'InvId': 5}) self.assertEqual( form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1) ) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin="******"test_login&OutSum=100.0&InvId=58&Desc=%D5%EE%EB%EE%E4%" \ "E8%EB%FC%ED%E8%EA+%22%C1%E8%F0%FE%F1%E0%22&SignatureVa" \ "lue=0EC23BE40003640B35EC07F6615FFB57&Email=vasia%40exa" \ "mple.com&shpparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)
def buy(request): if request.method == 'POST': from robokassa.forms import RobokassaForm from datetime import datetime deal_id = request.POST.get('deal_id',False) if not deal_id: return direct_to_template(request,'error.html') deal = Dealings.objects.get(pk = deal_id) deal.state = "WP" deal.product.last_purchase = datetime.now() deal.product.save() deal.save() form = RobokassaForm(initial={ 'OutSum': str(deal.cost), 'InvId': deal.id, 'Desc': '', 'Email': request.user.email, # 'IncCurrLabel': '', 'Culture': 'ru', }) return redirect(form.get_redirect_url()) return direct_to_template(request,'error.html')
class RobokassaFormTest(TestCase): def setUp(self): self.form = RobokassaForm( initial={ "OutSum": 100.00, "InvId": 58, "Desc": 'Холодильник "Бирюса"', "Email": "*****@*****.**", }) def testSignature(self): self.assertEqual( self.form._get_signature_string(), "%s:100.0:58:%s:shpparam1=None:shpparam2=None" % (LOGIN, PASSWORD1), ) self.assertEqual(len(self.form.fields["SignatureValue"].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial={"InvId": 5}) self.assertEqual( form._get_signature_string(), "%s::5:%s:shpparam1=None:shpparam2=None" % (LOGIN, PASSWORD1), ) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin=test_login&OutSum=100.0&InvId=58&Desc=%D5%EE%EB%EE%E4%E8%EB%FC%ED%E8%EA+%22%C1%E8%F0%FE%F1%E0%22&SignatureValue=0EC23BE40003640B35EC07F6615FFB57&Email=vasia%40example.com&shpparam1=None&shpparam2=None" # noqa self.assertEqual(self.form.get_redirect_url(), url)
class RobokassaFormTest(TestCase): def setUp(self): self.form = RobokassaForm( initial={ 'OutSum': 100.00, 'InvId': 58, 'Desc': u'Холодильник "Бирюса"', 'Email': '*****@*****.**' }) def testSignature(self): self.assertEqual( self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial={'InvId': 5}) self.assertEqual( form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) def testGetRedirectParams(self): self.assertEqual( dict(self.form.get_redirect_params()), { 'MrchLogin': '******', 'OutSum': '100.0', 'InvId': '58', 'Desc': 'Холодильник "Бирюса"', 'SignatureValue': '0EC23BE40003640B35EC07F6615FFB57', 'Email': '*****@*****.**', 'Encoding': 'utf-8', 'shpparam1': 'None', 'shpparam2': 'None' }) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin=test_login&OutSum=100.0&InvId=58" \ "&Desc=%D0%A5%D0%BE%D0%BB%D0%BE%D0%B4%D0%B8%D0%BB%D1%8C%D0%BD%D0%B8%D0%BA+%22%D0%91%D0%B8%D1%80%D1%8E%D1%81%D0%B0%22" \ "&SignatureValue=0EC23BE40003640B35EC07F6615FFB57&Email=vasia%40example.com&Encoding=utf-8&shpparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)
class RobokassaFormTest(TestCase): def setUp(self): self.form = RobokassaForm(initial = { 'OutSum': 100.00, 'InvId': 58, 'Desc' : u'Холодильник "Бирюса"', 'Email' : '*****@*****.**' }) def testSignature(self): self.assertEqual(self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial = {'InvId': 5}) self.assertEqual(form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % (LOGIN, PASSWORD1)) def testGetRedirectParams(self): self.assertEqual( dict(self.form.get_redirect_params()), { 'MrchLogin': '******', 'OutSum': '100.0', 'InvId': '58', 'Desc': 'Холодильник "Бирюса"', 'SignatureValue': '0EC23BE40003640B35EC07F6615FFB57', 'Email': '*****@*****.**', 'Encoding': 'utf-8', 'shpparam1': 'None', 'shpparam2': 'None' } ) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin=test_login&OutSum=100.0&InvId=58" \ "&Desc=%D0%A5%D0%BE%D0%BB%D0%BE%D0%B4%D0%B8%D0%BB%D1%8C%D0%BD%D0%B8%D0%BA+%22%D0%91%D0%B8%D1%80%D1%8E%D1%81%D0%B0%22" \ "&SignatureValue=0EC23BE40003640B35EC07F6615FFB57&Email=vasia%40example.com&Encoding=utf-8&shpparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)
def robokassa_redirect(request, basket_num, amount, **kwargs): """ This will be called from PaymentDetailsView.handle_payment, it supposed to generate url for Robokassa, inject it into RedirectRequired error and raise it We also have to save the session and to use its number as parameter """ initial = {'OutSum': amount, 'InvId': basket_num} for key in kwargs: if key in EXTRA_PARAMS or key in OPTIONAL_PARAMS: initial[key] = kwargs[key] session = request.session session.save() if session.session_key is not None: initial['session_key'] = session.session_key else: log.error('session_key is empty') form = RobokassaForm(initial=initial) err = RedirectRequired(form.get_redirect_url()) raise err
def robokassa_redirect(request, basket_num, amount, **kwargs): """ This will be called from PaymentDetailsView.handle_payment, it supposed to generate url for Robokassa, inject it into RedirectRequired error and raise it We also have to save the session and to use its number as parameter """ initial={'OutSum': amount, 'InvId': basket_num} for key in kwargs: if key in EXTRA_PARAMS or key in OPTIONAL_PARAMS: initial[key] = kwargs[key] session = request.session session.save() if session.session_key is not None: initial['session_key'] = session.session_key else: log.error('session_key is empty') form = RobokassaForm(initial=initial) err = RedirectRequired(form.get_redirect_url()) raise err
def pay(request, id): order = Order.objects.get(id=id) CURRENCY = getattr(settings, 'ROBOKASSA_CURRENCY', False) if CURRENCY: valute = Valute.objects.get(slug=settings.ROBOKASSA_CURRENCY.lower()) amount = order.retail_price_with_discount / valute.rate else: amount = order.retail_price_with_discount robokassa_form = RobokassaForm(initial={ 'OutSum': amount, 'InvId': order.id, 'Desc': 'Order #%s' % order.id, 'Email': order.email, 'Encoding': 'utf8', 'Culture': 'ru' }) return redirect(robokassa_form.get_redirect_url())
class RobokassaCustomCredentialFormTest(TestCase): def setUp(self): self.form = RobokassaForm( initial={ 'OutSum': 100.00, 'InvId': 58, 'Desc': u'Холодильник "Бирюса"', 'Email': '*****@*****.**' }, login=CUSTOM_LOGIN, password1=CUSTOM_PASS1, password2=CUSTOM_PASS2 ) def testSignature(self): self.assertEqual( self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % ( CUSTOM_LOGIN, CUSTOM_PASS1) ) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm( initial={'InvId': 5}, login=CUSTOM_LOGIN, password1=CUSTOM_PASS1, password2=CUSTOM_PASS2) self.assertEqual( form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % ( CUSTOM_LOGIN, CUSTOM_PASS1) ) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin="******"test_login2&OutSum=100.0&InvId=58&Desc=%D5%EE%EB%EE%E4%E8%" \ "EB%FC%ED%E8%EA+%22%C1%E8%F0%FE%F1%E0%22&SignatureValue=659" \ "9E0D576E94D4E8616A40B16B8288F&Email=vasia%40example.com&sh" \ "pparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)
class RobokassaCustomCredentialFormTest(TestCase): def setUp(self): self.form = RobokassaForm(initial={ 'OutSum': 100.00, 'InvId': 58, 'Desc': u'Холодильник "Бирюса"', 'Email': '*****@*****.**' }, login=CUSTOM_LOGIN, password1=CUSTOM_PASS1, password2=CUSTOM_PASS2) def testSignature(self): self.assertEqual( self.form._get_signature_string(), '%s:100.0:58:%s:shpparam1=None:shpparam2=None' % (CUSTOM_LOGIN, CUSTOM_PASS1)) self.assertEqual(len(self.form.fields['SignatureValue'].initial), 32) def testSignatureMissingParams(self): form = RobokassaForm(initial={'InvId': 5}, login=CUSTOM_LOGIN, password1=CUSTOM_PASS1, password2=CUSTOM_PASS2) self.assertEqual( form._get_signature_string(), '%s::5:%s:shpparam1=None:shpparam2=None' % (CUSTOM_LOGIN, CUSTOM_PASS1)) def testRedirectUrl(self): url = "https://merchant.roboxchange.com/Index.aspx?MrchLogin="******"test_login2&OutSum=100.0&InvId=58&Desc=%D5%EE%EB%EE%E4%E8%" \ "EB%FC%ED%E8%EA+%22%C1%E8%F0%FE%F1%E0%22&SignatureValue=659" \ "9E0D576E94D4E8616A40B16B8288F&Email=vasia%40example.com&sh" \ "pparam1=None&shpparam2=None" self.assertEqual(self.form.get_redirect_url(), url)