LIL-268, LIL-274. Add buy templates & integrate paymentwall widget

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent 6e204263a5
commit 8a0cd6bf81
  1. 12
      apps/payment/templates/payment/payment_error.html
  2. 12
      apps/payment/templates/payment/payment_success.html
  3. 9
      apps/payment/templates/payment/paymentwall_widget.html
  4. 177
      apps/payment/views.py
  5. 8
      project/settings.py
  6. 4
      project/urls.py

@ -0,0 +1,12 @@
{% extends "templates/lilcity/index.html" %} {% load static %} {% block content %}
<div class="section">
<div class="section__center center center_xs">
<div class="done">
<div class="done__title title">Произошла ошибка!</div>
<div class="done__foot">
<a class="done__btn btn btn_md btn_stroke" href="/">ПЕРЕЙТИ К ГЛАВНОЙ</a>
</div>
</div>
</div>
</div>
{% endblock content %}

@ -0,0 +1,12 @@
{% extends "templates/lilcity/index.html" %} {% load static %} {% block content %}
<div class="section">
<div class="section__center center center_xs">
<div class="done">
<div class="done__title title">Вы успешно приобрели курс!</div>
<div class="done__foot">
<a class="done__btn btn btn_md btn_stroke" href="/">ПЕРЕЙТИ К ГЛАВНОЙ</a>
</div>
</div>
</div>
</div>
{% endblock content %}

@ -0,0 +1,9 @@
{% extends "templates/lilcity/index.html" %} {% load static %} {% block content %}
<div class="section">
<div class="section__center center">
{% autoescape off %}
{{ widget }}
{% endautoescape %}
</div>
</div>
{% endblock content %}

@ -1,76 +1,107 @@
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.generic import View from django.views.generic import View, TemplateView
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse from django.http import HttpResponse
from django.urls import reverse_lazy
from paymentwall.pingback import Pingback
from paymentwall import Pingback, Product, Widget
from .models import Purchase
from apps.course.models import Course
from .models import CoursePayment
@method_decorator(csrf_exempt, name='dispatch') # from .models import Purchase
class PaymentwallCallbackView(View):
CHARGEBACK = '1' class CourseBuyView(TemplateView):
CREDIT_CARD_FRAUD = '2' template_name = 'payment/paymentwall_widget.html'
ORDER_FRAUD = '3'
BAD_DATA = '4' def get(self, request, pk=None, *args, **kwargs):
FAKE_PROXY_USER = '5' course = Course.objects.get(id=pk)
REJECTED_BY_ADVERTISER = '6' course_payment = CoursePayment.objects.create(
DUPLICATED_CONVERSIONS = '7' user=request.user,
GOODWILL_CREDIT_TAKEN_BACK = '8' course=course,
CANCELLED_ORDER = '9' )
PARTIALLY_REVERSED = '10' product = Product(
f'course_{course.id}',
def get_request_ip(self): course.price,
x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') 'RUB',
if x_forwarded_for: 'test',
ip = x_forwarded_for.split(',')[0] )
else: widget = Widget(
ip = self.request.META.get('REMOTE_ADDR') request.user.id,
return ip 'pw',
[product],
def get(self, request, *args, **kwargs): extra_params={
pingback = Pingback(request.GET.copy(), self.get_request_ip()) 'lang': 'ru_RU',
'success_url': reverse_lazy('payment-success'),
if pingback.validate(): 'failure_url': reverse_lazy('payment-error'),
cart_id = pingback.get_product().get_id() }
)
# try:
# cart = CartModel.objects.get(pk=cart_id) return self.render_to_response(context={'widget': widget.get_html_code()})
# except CartModel.DoesNotExist:
# log.error('Paymentwall pingback: Cant find cart, Paymentwall sent this data: {}'.format(request.GET.copy()))
# return HttpResponse(status=403) # @method_decorator(csrf_exempt, name='dispatch')
# class PaymentwallCallbackView(View):
try:
purchase = Purchase.objects.get(transaction_id=pingback.get_reference_id()) # CHARGEBACK = '1'
except Purchase.DoesNotExist: # CREDIT_CARD_FRAUD = '2'
# purchase = cart.create_purchase(transaction_id=pingback.get_reference_id()) # ORDER_FRAUD = '3'
pass # BAD_DATA = '4'
# FAKE_PROXY_USER = '5'
if pingback.is_deliverable(): # REJECTED_BY_ADVERTISER = '6'
purchase.status = Purchase.COMPLETE # DUPLICATED_CONVERSIONS = '7'
# GOODWILL_CREDIT_TAKEN_BACK = '8'
elif pingback.is_cancelable(): # CANCELLED_ORDER = '9'
reason = pingback.get_parameter('reason') # PARTIALLY_REVERSED = '10'
if reason == self.CHARGEBACK or reason == self.CREDIT_CARD_FRAUD or reason == self.ORDER_FRAUD or reason == self.PARTIALLY_REVERSED: # def get_request_ip(self):
purchase.status = Purchase.CHARGEBACK # x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR')
elif reason == self.CANCELLED_ORDER: # if x_forwarded_for:
purchase.status = Purchase.REFUNDED # ip = x_forwarded_for.split(',')[0]
else: # else:
purchase.status = Purchase.ERROR # ip = self.request.META.get('REMOTE_ADDR')
# return ip
elif pingback.is_under_review():
purchase.status = Purchase.PENDING # def get(self, request, *args, **kwargs):
# pingback = Pingback(request.GET.copy(), self.get_request_ip())
else:
# log.error('Paymentwall pingback: Unknown pingback type, Paymentwall sent this data: {}'.format(request.GET.copy())) # if pingback.validate():
pass # cart_id = pingback.get_product().get_id()
# purchase.save() # # try:
return HttpResponse('OK', status=200) # # cart = CartModel.objects.get(pk=cart_id)
else: # # except CartModel.DoesNotExist:
# log.error('Paymentwall pingback: Cant validate pingback, error: {} Paymentwall sent this data: {}'.format(pingback.get_error_summary(), request.GET.copy())) # # log.error('Paymentwall pingback: Cant find cart, Paymentwall sent this data: {}'.format(request.GET.copy()))
pass # # return HttpResponse(status=403)
# try:
# purchase = Purchase.objects.get(transaction_id=pingback.get_reference_id())
# except Purchase.DoesNotExist:
# # purchase = cart.create_purchase(transaction_id=pingback.get_reference_id())
# pass
# if pingback.is_deliverable():
# purchase.status = Purchase.COMPLETE
# elif pingback.is_cancelable():
# reason = pingback.get_parameter('reason')
# if reason == self.CHARGEBACK or reason == self.CREDIT_CARD_FRAUD or reason == self.ORDER_FRAUD or reason == self.PARTIALLY_REVERSED:
# purchase.status = Purchase.CHARGEBACK
# elif reason == self.CANCELLED_ORDER:
# purchase.status = Purchase.REFUNDED
# else:
# purchase.status = Purchase.ERROR
# elif pingback.is_under_review():
# purchase.status = Purchase.PENDING
# else:
# # log.error('Paymentwall pingback: Unknown pingback type, Paymentwall sent this data: {}'.format(request.GET.copy()))
# pass
# # purchase.save()
# return HttpResponse('OK', status=200)
# else:
# # log.error('Paymentwall pingback: Cant validate pingback, error: {} Paymentwall sent this data: {}'.format(pingback.get_error_summary(), request.GET.copy()))
# pass

@ -232,6 +232,14 @@ try:
except ImportError: except ImportError:
pass pass
try:
from paymentwall import *
except ImportError:
pass
else:
Paymentwall.set_api_type(Paymentwall.API_GOODS)
Paymentwall.set_app_key('d6f02b90cf6b16220932f4037578aff7')
Paymentwall.set_secret_key('4ea515bf94e34cf28646c2e12a7b8707')
# CORS settings # CORS settings

@ -29,6 +29,7 @@ from apps.user.views import (
UserView, UserEditView, NotificationEditView, UserView, UserEditView, NotificationEditView,
PaymentHistoryView, resend_email_verify, PaymentHistoryView, resend_email_verify,
) )
from apps.payment.views import CourseBuyView
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
@ -38,12 +39,15 @@ urlpatterns = [
path('course/on-moderation', CourseOnModerationView.as_view(), name='course-on-moderation'), path('course/on-moderation', CourseOnModerationView.as_view(), name='course-on-moderation'),
path('course/<int:pk>/', CourseView.as_view(), name='course'), path('course/<int:pk>/', CourseView.as_view(), name='course'),
path('course/<str:slug>/', CourseView.as_view(), name='course'), path('course/<str:slug>/', CourseView.as_view(), name='course'),
path('course/<int:pk>/checkout', CourseBuyView.as_view(), name='course-checkout'),
path('course/<int:pk>/edit', CourseEditView.as_view(), name='course_edit'), path('course/<int:pk>/edit', CourseEditView.as_view(), name='course_edit'),
path('course/<int:pk>/lessons', CourseView.as_view(template_name='course/course_only_lessons.html'), name='course-only-lessons'), path('course/<int:pk>/lessons', CourseView.as_view(template_name='course/course_only_lessons.html'), name='course-only-lessons'),
path('course/<int:course_id>/like', likes, name='likes'), path('course/<int:course_id>/like', likes, name='likes'),
path('course/<int:course_id>/comment', coursecomment, name='coursecomment'), path('course/<int:course_id>/comment', coursecomment, name='coursecomment'),
path('lesson/<int:pk>/', LessonView.as_view(), name='lesson'), path('lesson/<int:pk>/', LessonView.as_view(), name='lesson'),
path('lesson/<int:lesson_id>/comment', lessoncomment, name='lessoncomment'), path('lesson/<int:lesson_id>/comment', lessoncomment, name='lessoncomment'),
path('payments/success', TemplateView.as_view(template_name='payment/payment_success.html'), name='payment-success'),
path('payments/error', TemplateView.as_view(template_name='payment/payment_error.html'), name='payment-error'),
path('search/', SearchView.as_view(), name='search'), path('search/', SearchView.as_view(), name='search'),
path('user/<int:pk>/', UserView.as_view(), name='user'), path('user/<int:pk>/', UserView.as_view(), name='user'),
path('user/<int:pk>/edit', UserEditView.as_view(), name='user-edit-profile'), path('user/<int:pk>/edit', UserEditView.as_view(), name='user-edit-profile'),

Loading…
Cancel
Save