|
|
|
|
@ -160,12 +160,13 @@ class SchoolBuyView(TemplateView): |
|
|
|
|
@method_decorator(csrf_exempt, name='dispatch') |
|
|
|
|
class PaymentwallCallbackView(View): |
|
|
|
|
|
|
|
|
|
def add_months(self, sourcedate, months): |
|
|
|
|
month = sourcedate.month - 1 + months |
|
|
|
|
year = sourcedate.year + month // 12 |
|
|
|
|
month = month % 12 + 1 |
|
|
|
|
day = min(sourcedate.day, calendar.monthrange(year, month)[1]) |
|
|
|
|
return datetime.date(year, month, day) |
|
|
|
|
def add_months(self, sourcedate, months=1): |
|
|
|
|
result = arrow.get(sourcedate, settings.TIME_ZONE).shift(months=months) |
|
|
|
|
if months == 1: |
|
|
|
|
if (sourcedate.month == 2 and sourcedate.day >= 28) or (sourcedate.day == 31 and result.day <= 30)\ |
|
|
|
|
or (sourcedate.month == 1 and sourcedate.day >= 29 and result.day == 28): |
|
|
|
|
result = result.replace(day=1, month=result.month + 1) |
|
|
|
|
return result |
|
|
|
|
|
|
|
|
|
def get_request_ip(self): |
|
|
|
|
x_forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR') |
|
|
|
|
@ -178,7 +179,6 @@ class PaymentwallCallbackView(View): |
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
payment_raw_data = request.GET.copy() |
|
|
|
|
pingback = Pingback(payment_raw_data, self.get_request_ip()) |
|
|
|
|
september2018 = datetime.date(2018, 9, 1) |
|
|
|
|
|
|
|
|
|
if pingback.validate(): |
|
|
|
|
product_type_name, payment_id = pingback.get_product().get_id().split('_') |
|
|
|
|
@ -231,12 +231,10 @@ class PaymentwallCallbackView(View): |
|
|
|
|
date_end = school_payment.date_end |
|
|
|
|
else: |
|
|
|
|
date_start = arrow.get(school_payment.date_end, settings.TIME_ZONE).shift(days=1).datetime |
|
|
|
|
date_end = arrow.get(date_start, settings.TIME_ZONE).shift(months=1).datetime |
|
|
|
|
date_end = self.add_months(date_start) |
|
|
|
|
else: |
|
|
|
|
date_start = now().date() |
|
|
|
|
if date_start < september2018: |
|
|
|
|
date_start = september2018 |
|
|
|
|
date_end = arrow.get(date_start, settings.TIME_ZONE).shift(months=1, minutes=-1).datetime |
|
|
|
|
date_end = self.add_months(date_start) |
|
|
|
|
payment.date_start = date_start |
|
|
|
|
payment.date_end = date_end |
|
|
|
|
if product_type_name == 'course': |
|
|
|
|
|