Перейти с PaymentWall на cloudpayments

remotes/origin/feature/cloudpayments
gzbender 7 years ago
parent 51191256f8
commit ffcaef0ae0
  1. 19
      apps/payment/templates/payment/cloudpayments_widget.html
  2. 50
      apps/payment/tests/test_views.py
  3. 39
      apps/payment/views.py
  4. 3
      project/tests/__init__.py
  5. 10
      project/tests/factories.py
  6. 9
      project/utils/selenium_utils.py
  7. 1
      requirements.txt

@ -2,9 +2,12 @@
{% block head %}
<script src="https://widget.cloudpayments.ru/bundles/cloudpayments"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
{% endblock head %}
{% block content %}
{% csrf_token %}
<!--<div class="section">
<div class="section__center center">
<div style="margin-bottom: 25px;">
@ -28,7 +31,7 @@
function pay() {
var widget = new cp.CloudPayments();
widget.charge({ // options
publicId: '{% setting "CLOUD_PAYMENTS_PUBLIC_ID" %}', //id из личного кабинета
publicId: '{% setting "CLOUD_PAYMENTS_PUBLIC_ID" %}',
{% if payment.course %}
description: 'Оплата курса {{ payment.course.title }}',
{% endif %}
@ -36,15 +39,23 @@
description: 'Оплата подарочного сертификата на {{ payment.gift_certificate.price }} руб.',
{% endif %}
{% if not payment.course and not payment.gift_certificate %}
description: 'Оплата школы до {{ payment.date_end_humanize }}, {{ payment.weekdays_str }}',
description: 'Оплата школы до {{ payment.date_end|date:"j b" }}, {{ payment.weekdays_str }}',
{% endif %}
amount: {{ payment.amount|floatformat }}, //сумма
currency: 'RUB', //валюта
invoiceId: '{{ payment.id }}', //номер заказа (необязательно)
invoiceId: '{{ payment.id }}',
requireEmail: false,
},
function(payment_data){
function(paymentData){
var url = "{% url 'payment-success' payment.id %}";
axios.post(url, JSON.stringify(paymentData), {
'Content-Type': 'application/json',
headers: {
'X-CSRFToken': '{{ csrf_token }}'
}
}).then(response => {
window.location.href = response;
});
},
function(reason){
showNotification(reason);

@ -1,18 +1,60 @@
# -*- coding: utf-8 -*-
import time
from datetime import datetime, timedelta
from django.test import TestCase
from django.shortcuts import reverse
from django.utils.timezone import now
from selene.api import *
from project.tests import SeleniumTestCase
from project.tests.factories import UserFactory, User
from project.tests.factories import UserFactory, User, CourseFactory, LiveLessonFactory
from project.utils.selenium_utils import SeleniumExtensions as SE
class PaymentsTestCase(SeleniumTestCase):
fixtures = ['school_schedules.json']
@classmethod
def setUpTestData(cls):
cls.simple_user = UserFactory(role=User.USER_ROLE)
UserFactory.create_batch(2, role=User.AUTHOR_ROLE)
UserFactory(role=User.USER_ROLE)
CourseFactory.create_batch(4, user=User.objects.filter(role=User.AUTHOR_ROLE))
for i in range(11):
LiveLessonFactory(date=now() - timedelta(i + 2))
def test_can_buy_school(self):
self.client.force_login(self.simple_user)
self.driver.get(reverse(''))
simple_user = UserFactory(role=User.USER_ROLE)
self.login(simple_user)
browser.set_driver(self.driver)
browser.open_url(self.get_url(reverse('index')))
self.wait_for_js_load()
pay_btn = s('#lilcity-vue-app > div.main.main_default > div > div.main__actions > a[data-popup=".js-popup-buy"]')
h = s('header.header').size.get('height')
location = pay_btn.location
self.driver.execute_script("window.scrollTo({x},{y});".format(x=location['x'], y=location['y'] - h - 10))
pay_btn.should(be.visible)
pay_btn.click()
popup = s('.js-popup-buy')
popup.should(be.visible)
popup.s('a.buy__btn').click()
SE.switch_iframe_css('[allowpaymentrequest]')
s('#cardNumber').set_value('4242424242424242')
s('#inputMonth').set_value('12')
s('#inputYear').set_value('33')
s('div.cvv > div > div > input[type="text"]').set_value('333')
s('#cardHolder').set_value('TEST')
s('#sizingContainer button[type=submit]').click()
SE.switch_iframe_css('#threeDSContainer > iframe')
s('#password').set_value('4')
s('button[type=submit]').click()
SE.switch_iframe_css('[allowpaymentrequest]')
s('#statusContainer > div.bottom > a.button').click()

@ -397,7 +397,7 @@ class CloudPaymentsTestView(TemplateView):
class PaymentSuccessView(View):
def post(self, request, payment_id):
payment_data = request.POST.get('payment_data')
payment_data = json.loads(request.body)
try:
payment = Payment.objects.get(id=payment_id)
except Payment.DoesNotExist:
@ -451,23 +451,24 @@ class PaymentSuccessView(View):
}
redirect_to = reverse('gift-certificate-payment-success', args=[payment_id])
product_payment_to_mixpanel.delay(
payment.user.id,
f'{product_type_name.title()} payment',
now().strftime('%Y-%m-%dT%H:%M:%S'),
properties,
)
if not settings.DEBUG:
product_payment_to_mixpanel.delay(
payment.user.id,
f'{product_type_name.title()} payment',
now().strftime('%Y-%m-%dT%H:%M:%S'),
properties,
)
transaction_to_roistat.delay(
payment.user.id,
payment.id,
f'{product_type_name.title()} payment',
payment.amount,
now().strftime('%Y-%m-%d %H:%M:%S'),
payment.STATUS_PAID,
product_type_name,
payment.roistat_visit,
)
transaction_to_roistat.delay(
payment.user.id,
payment.id,
f'{product_type_name.title()} payment',
payment.amount,
now().strftime('%Y-%m-%d %H:%M:%S'),
payment.STATUS_PAID,
product_type_name,
payment.roistat_visit,
)
return redirect_to
return reverse('payment-error')
return HttpResponse(redirect_to)
return HttpResponse(reverse('payment-error'))

@ -60,3 +60,6 @@ class SeleniumTestCase(LiveServerTestCase):
def wait_for_request(self, path, wait_time=10):
return SE.wait_for_request(self.driver, path, wait_time)
def wait_for_js_load(self, wait_time=10):
SE.wait_for_js_load(self.driver, wait_time)

@ -10,6 +10,7 @@ from django.utils.text import slugify
from apps.course.models import *
from apps.content.models import *
from apps.user.models import *
from apps.school.models import *
ADMIN_EMAIL = 'admin@mail.com'
@ -94,3 +95,12 @@ class CourseFactory(DjangoModelFactory):
cover = None #factory.SubFactory(ImageObjectFactory)
gallery = None
status = factory.Iterator([s[0] for s in Course.STATUS_CHOICES])
class LiveLessonFactory(DjangoModelFactory):
class Meta:
model = LiveLesson
title = factory.Faker('sentence', nb_words=6)
short_description = factory.Faker('sentence', nb_words=10)
cover = None

@ -2,6 +2,7 @@
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
class ElementIn(object):
@ -91,3 +92,11 @@ class SeleniumExtensions(object):
return !!r && r[2].readyState == 4;
''', path) is True)
return driver.execute_script('return window._findRequest(arguments[0]);', path)
@classmethod
def switch_iframe_css(cls, driver, css_selector, wait_time=10):
WebDriverWait(driver, wait_time).until(EC.frame_to_be_available_and_switch_to_it(By.CSS_SELECTOR, css_selector))
@classmethod
def switch_iframe_xpath(cls, driver, xpath, wait_time=10):
WebDriverWait(driver, wait_time).until(EC.frame_to_be_available_and_switch_to_it(By.XPATH, xpath))

@ -52,3 +52,4 @@ selenium
# sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
# sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
cloudpayments
git+https://github.com/yashaka/selene.git

Loading…
Cancel
Save