You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.9 KiB
109 lines
3.9 KiB
from django.utils.decorators import method_decorator
|
|
from django.views.generic import View, TemplateView
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.http import HttpResponse
|
|
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
|
|
|
|
|
|
class CourseBuyView(TemplateView):
|
|
template_name = 'payment/paymentwall_widget.html'
|
|
|
|
def get(self, request, pk=None, *args, **kwargs):
|
|
host = request.scheme + '://' + request.get_host()
|
|
course = Course.objects.get(id=pk)
|
|
course_payment = CoursePayment.objects.create(
|
|
user=request.user,
|
|
course=course,
|
|
)
|
|
product = Product(
|
|
f'course_{course.id}',
|
|
course.price,
|
|
'RUB',
|
|
f'Курс "{course.title}"',
|
|
)
|
|
widget = Widget(
|
|
str(request.user.id),
|
|
'p1',
|
|
[product],
|
|
extra_params={
|
|
'lang': 'ru',
|
|
'evaluation': 1,
|
|
'success_url': host + str(reverse_lazy('payment-success')),
|
|
'failure_url': host + str(reverse_lazy('payment-error')),
|
|
}
|
|
)
|
|
|
|
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
|
|
|