From fd41a6d69ae1399a06746f1192c4071446f627ec Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Sat, 30 Jun 2018 16:24:41 +0300 Subject: [PATCH] LIL-553. Send order to roistat --- apps/payment/tasks.py | 19 +++++++++++++++++++ apps/payment/views.py | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/payment/tasks.py b/apps/payment/tasks.py index 3f487f76..9c9de3d7 100644 --- a/apps/payment/tasks.py +++ b/apps/payment/tasks.py @@ -30,3 +30,22 @@ def product_payment_to_mixpanel(user_id, event_name, time, properties): event_name, properties=props, ) + + +@app.task +def transaction_to_roistat(user_id, payment_id, event_name, amount, time, status, product_type): + body = [{ + 'id': str(payment_id), + 'name': event_name, + 'date_create': time, + 'status': str(status), + 'price': str(amount), + 'client_id': str(user_id), + 'fields': { + 'product_type': product_type, + } + }] + project = settings.ROISTAT_PROJECT + key = settings.ROISTAT_KEY + url = settings.ROISTAT_API_URL + f'/project/add-orders?key={key}&project={project}' + resp = requests.post(url, json=body) diff --git a/apps/payment/views.py b/apps/payment/views.py index 84772ffa..492a43af 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -22,7 +22,7 @@ from paymentwall import Pingback, Product, Widget from apps.course.models import Course from apps.school.models import SchoolSchedule -from apps.payment.tasks import transaction_to_mixpanel, product_payment_to_mixpanel +from apps.payment.tasks import transaction_to_mixpanel, product_payment_to_mixpanel, transaction_to_roistat from .models import AuthorBalance, CoursePayment, SchoolPayment @@ -251,6 +251,15 @@ class PaymentwallCallbackView(View): properties, ) + transaction_to_roistat.delay( + payment.user.id, + payment.id, + f'{product_type_name.title()} payment', + payment.amount, + now().strftime('%Y-%m-%dT%H:%M:%S'), + pingback.get_type(), + product_type_name, + ) author_balance = getattr(payment, 'author_balance', None) if author_balance and author_balance.type == AuthorBalance.IN: if pingback.is_deliverable():