|
|
|
|
@ -7,8 +7,9 @@ from django.urls import reverse_lazy |
|
|
|
|
from paymentwall import Pingback, Product, Widget |
|
|
|
|
|
|
|
|
|
from apps.course.models import Course |
|
|
|
|
from .models import CoursePayment |
|
|
|
|
# from .models import Purchase |
|
|
|
|
from apps.school.models import SchoolSchedule |
|
|
|
|
|
|
|
|
|
from .models import AuthorBalance, CoursePayment, SchoolPayment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CourseBuyView(TemplateView): |
|
|
|
|
@ -22,7 +23,7 @@ class CourseBuyView(TemplateView): |
|
|
|
|
course=course, |
|
|
|
|
) |
|
|
|
|
product = Product( |
|
|
|
|
f'course_{course.id}', |
|
|
|
|
f'course_{course_payment.id}', |
|
|
|
|
course.price, |
|
|
|
|
'RUB', |
|
|
|
|
f'Курс "{course.title}"', |
|
|
|
|
@ -42,68 +43,50 @@ class CourseBuyView(TemplateView): |
|
|
|
|
return self.render_to_response(context={'widget': widget.get_html_code()}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @method_decorator(csrf_exempt, name='dispatch') |
|
|
|
|
# class PaymentwallCallbackView(View): |
|
|
|
|
|
|
|
|
|
# CHARGEBACK = '1' |
|
|
|
|
# CREDIT_CARD_FRAUD = '2' |
|
|
|
|
# ORDER_FRAUD = '3' |
|
|
|
|
# BAD_DATA = '4' |
|
|
|
|
# FAKE_PROXY_USER = '5' |
|
|
|
|
# REJECTED_BY_ADVERTISER = '6' |
|
|
|
|
# DUPLICATED_CONVERSIONS = '7' |
|
|
|
|
# GOODWILL_CREDIT_TAKEN_BACK = '8' |
|
|
|
|
# CANCELLED_ORDER = '9' |
|
|
|
|
# PARTIALLY_REVERSED = '10' |
|
|
|
|
|
|
|
|
|
# def get_request_ip(self): |
|
|
|
|
# x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') |
|
|
|
|
# if x_forwarded_for: |
|
|
|
|
# ip = x_forwarded_for.split(',')[0] |
|
|
|
|
# else: |
|
|
|
|
# ip = self.request.META.get('REMOTE_ADDR') |
|
|
|
|
# return ip |
|
|
|
|
|
|
|
|
|
# def get(self, request, *args, **kwargs): |
|
|
|
|
# pingback = Pingback(request.GET.copy(), self.get_request_ip()) |
|
|
|
|
|
|
|
|
|
# if pingback.validate(): |
|
|
|
|
# cart_id = pingback.get_product().get_id() |
|
|
|
|
|
|
|
|
|
# # try: |
|
|
|
|
# # cart = CartModel.objects.get(pk=cart_id) |
|
|
|
|
# # except CartModel.DoesNotExist: |
|
|
|
|
# # log.error('Paymentwall pingback: Cant find cart, Paymentwall sent this data: {}'.format(request.GET.copy())) |
|
|
|
|
# # 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 |
|
|
|
|
@method_decorator(csrf_exempt, name='dispatch') |
|
|
|
|
class PaymentwallCallbackView(View): |
|
|
|
|
|
|
|
|
|
def get_request_ip(self): |
|
|
|
|
x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') |
|
|
|
|
if x_forwarded_for: |
|
|
|
|
ip = x_forwarded_for.split(',')[0] |
|
|
|
|
else: |
|
|
|
|
ip = self.request.META.get('REMOTE_ADDR') |
|
|
|
|
return ip |
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
payment_raw_data = request.GET.copy() |
|
|
|
|
pingback = Pingback(payment_raw_data, self.get_request_ip()) |
|
|
|
|
|
|
|
|
|
if pingback.validate(): |
|
|
|
|
product_type_name, payment_id = pingback.get_product().get_id().split('_') |
|
|
|
|
|
|
|
|
|
if product_type_name == 'course': |
|
|
|
|
product_payment_class = CoursePayment |
|
|
|
|
elif product_type_name == 'school': |
|
|
|
|
product_payment_class = SchoolPayment |
|
|
|
|
else: |
|
|
|
|
return HttpResponse(status=403) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
payment = product_payment_class.objects.get(pk=payment_id) |
|
|
|
|
except product_payment_class.DoesNotExist: |
|
|
|
|
return HttpResponse(status=403) |
|
|
|
|
|
|
|
|
|
payment.status = pingback.get_type() |
|
|
|
|
payment.data = payment_raw_data |
|
|
|
|
payment.save() |
|
|
|
|
|
|
|
|
|
author_balance = getattr(payment, 'author_balance', None) |
|
|
|
|
if author_balance: |
|
|
|
|
if pingback.is_deliverable(): |
|
|
|
|
payment.author_balance.status = AuthorBalance.ACCEPTED |
|
|
|
|
elif pingback.is_under_review(): |
|
|
|
|
payment.author_balance.status = AuthorBalance.PENDING |
|
|
|
|
else: |
|
|
|
|
payment.author_balance.status = AuthorBalance.DECLINED |
|
|
|
|
|
|
|
|
|
payment.author_balance.save() |
|
|
|
|
return HttpResponse('OK', status=403) |
|
|
|
|
else: |
|
|
|
|
return |
|
|
|
|
|