From 5393d6127b6685a49676af63c24d1df3609094c3 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 19 Jul 2018 15:12:14 +0300 Subject: [PATCH] LIL-575. Effective amount from payment provider --- apps/payment/models.py | 2 +- apps/payment/views.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/payment/models.py b/apps/payment/models.py index 32d7a0e9..ec97fe1a 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -189,7 +189,7 @@ class SchoolPayment(Payment): month_price_sum = aggregate.get('month_price__sum', 0) * weekday_count // all_weekday_count else: month_price_sum = aggregate.get('month_price__sum', 0) - if month_price_sum >= config.SERVICE_DISCOUNT_MIN_AMOUNT: + if self.id is None and month_price_sum >= config.SERVICE_DISCOUNT_MIN_AMOUNT: discount = config.SERVICE_DISCOUNT else: discount = 0 diff --git a/apps/payment/views.py b/apps/payment/views.py index 2f70df36..58bc5c8e 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -196,12 +196,18 @@ class PaymentwallCallbackView(View): payment.status = pingback.get_type() payment.data = payment_raw_data if pingback.is_deliverable(): + effective_amount = pingback.get_parameter('effective_price_amount') + + if effective_amount: + payment.amount = effective_amount + transaction_to_mixpanel.delay( payment.user.id, payment.amount, now().strftime('%Y-%m-%dT%H:%M:%S'), product_type_name, ) + if product_type_name == 'school': school_payment = SchoolPayment.objects.filter( user=payment.user, @@ -251,6 +257,7 @@ class PaymentwallCallbackView(View): 'update_at': payment.update_at, } payment.save() + product_payment_to_mixpanel.delay( payment.user.id, f'{product_type_name.title()} payment', @@ -268,6 +275,7 @@ class PaymentwallCallbackView(View): product_type_name, payment.roistat_visit, ) + author_balance = getattr(payment, 'author_balance', None) if author_balance and author_balance.type == AuthorBalance.IN: if pingback.is_deliverable(): @@ -276,7 +284,6 @@ class PaymentwallCallbackView(View): payment.author_balance.status = AuthorBalance.PENDING else: payment.author_balance.status = AuthorBalance.DECLINED - payment.author_balance.save() return HttpResponse('OK') else: