From 63699581c8dbcb7605a7c097e0793e65bda9ae52 Mon Sep 17 00:00:00 2001 From: gzbender Date: Fri, 22 Feb 2019 02:58:05 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B9=D1=82=D0=B8=20?= =?UTF-8?q?=D1=81=20PaymentWall=20=D0=BD=D0=B0=20cloudpayments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/payment/views.py | 30 ++++++++++++++++++++++++++++-- project/urls.py | 4 +++- requirements.txt | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/payment/views.py b/apps/payment/views.py index f1399ff2..50a7e4de 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -3,13 +3,13 @@ import short_url import arrow import json import logging - from datetime import timedelta from urllib.parse import urlsplit - import datetime import calendar +import random +from cloudpayments import CloudPayments from django.contrib import messages from django.contrib.auth.decorators import login_required from django.http import HttpResponse, Http404 @@ -397,3 +397,29 @@ class GiftCertificateGetView(TemplateView): context = self.get_context_data(**kwargs) return self.render_to_response(context) + +class CloudPaymentsTestView(TemplateView): + template_name = 'payment/cloud_payments_test.html' + + def get(self, request, *args, **kwargs): + context = self.get_context_data(**kwargs) + context['invoice_id'] = random.randrange(1000, 100000000) + return self.render_to_response(context) + + +class CloudPaymentsCallbackTestView(TemplateView): + template_name = 'payment/cloud_payments_callback_test.html' + + def get(self, request, *args, **kwargs): + context = self.get_context_data(**kwargs) + invoice_id = request.GET.get('invoice_id') + client = CloudPayments('pk_9ae020cd5fed74499dee247067d17', 'a7d5f88ea69ef59f8b5db2252e39cedf') + context['test_ok'] = bool(client.test()) + try: + t = client.find_payment(int(invoice_id)) + print('transaction.status', t.status, 'transaction.reason', t.reason) + # status = 'Completed', reason = 'Approved' + context['transaction'] = t + except: + context['transaction'] = None + return self.render_to_response(context) diff --git a/project/urls.py b/project/urls.py index 9b0a5b00..c29a1803 100644 --- a/project/urls.py +++ b/project/urls.py @@ -35,7 +35,7 @@ from apps.payment.views import ( CourseBuySuccessView, CourseBuyView, PaymentwallCallbackView, SchoolBuySuccessView, SchoolBuyView, GiftCertificatesView, GiftCertificateBuyView, - GiftCertificateBuySuccessView, GiftCertificateGetView) + GiftCertificateBuySuccessView, GiftCertificateGetView, CloudPaymentsTestView, CloudPaymentsCallbackTestView) from .views import AboutView, IndexView, SchoolSchedulesView @@ -98,6 +98,8 @@ urlpatterns = [ name='gift-certificate-payment-success'), path('gift-certificate//get', GiftCertificateGetView.as_view(), name='gift-certificate-get'), path('faq', FAQView.as_view(), name='faq'), + path('cloud_payments_callback_test', CloudPaymentsCallbackTestView.as_view(), name='cloud_payments_callback_test'), + path('cloud_payments_test', CloudPaymentsTestView.as_view(), name='cloud_payments_test'), ] diff --git a/requirements.txt b/requirements.txt index 78736651..5fe65315 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,3 +37,4 @@ sendgrid drf_dynamic_fields flower==0.9.2 unidecode +cloudpayments