Yandex Money into Wallets integration

remotes/origin/PR-39
ArturBaybulatov 10 years ago
parent 500ff3ec01
commit cdee589e41
  1. 31
      wallets/migrations/0006_transaction.py
  2. 26
      wallets/models.py
  3. 39
      wallets/templates/score-detail.html
  4. 3
      wallets/templates/tmp_yandex_money_request_example.html
  5. 2
      wallets/templates/tmp_yandex_money_responses_sumulation.html
  6. 5
      wallets/urls.py
  7. 40
      wallets/views.py

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-08-18 14:18
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('wallets', '0005_auto_20160809_1727'),
]
operations = [
migrations.CreateModel(
name='Transaction',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('complete', models.BooleanField(default=False, editable=False)),
('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
('voids_at', models.DateTimeField()),
('sum', models.DecimalField(decimal_places=0, max_digits=20)),
('type', models.CharField(choices=[('add', 'Пополнение'), ('reservation', 'Резервирование')], max_length=20)),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='customer_transactions', to=settings.AUTH_USER_MODEL)),
],
),
]

@ -48,3 +48,29 @@ class WithDraw(models.Model):
verbose_name = 'Заявка на вывод средств'
verbose_name_plural = 'Заявки на вывод средств'
ordering = ('-created',)
class Transaction(models.Model):
TYPES = (
('add', 'Пополнение'),
('reservation', 'Резервирование'),
)
complete = models.BooleanField(default=False, editable=False) # Not editable in admin
created_at = models.DateTimeField(default=timezone.now, editable=False)
customer = models.ForeignKey(User, related_name='customer_transactions')
voids_at = models.DateTimeField()
sum = models.DecimalField(max_digits=20, decimal_places=0)
type = models.CharField(max_length=20, choices=TYPES)
def save(self, *args, **kwargs):
if not self.pk and self.created_at:
self.voids_at = self.created_at + timezone.timedelta(minutes=9000)
super().save(*args, **kwargs)
def is_void(self):
return timezone.now() > self.voids_at
def __str__(self):
return str(self.pk)

@ -18,7 +18,7 @@
{% if user_score.is_customer %}
<div class="col-lg-6">
<a href="javascript:void(0)" class="linkS linkS1">пополнить</a>
<a href="javascript:void(0)" data-toggle="modal" data-target="#fullfill-balance"class="linkS linkS1">пополнить</a>
</div>
{% endif %}
@ -62,6 +62,43 @@
</div>
</div>
<div id="fullfill-balance" class="modal fade" role="dialog">
<div class="modal-dialog" role="document" style="width:900px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
</button>
<h4 class="modal-title">Пополнить счет</h4>
</div>
<form id="withdraw-form" action="{{ YANDEX_MONEY.url }}" method="POST">{% csrf_token %}
<div class="modal-body">
<div style="height: 150px;">
<div class="textAreaBlock2 text-nn box-sizing disTab">
<p>Кол-во денег {{ YANDEX_MONEY.scid }}</p>
<input type="text" name="sum">
<p>shopId: <input type='hidden' name='shopId' value='{{ YANDEX_MONEY.shop_id }}'></p>
<p>scid: <input type='hidden' name='scid' value='{{ YANDEX_MONEY.scid }}'></p>
<p>customerNumber: <input type='hidden' name='customerNumber' value='{{ user_score.pk }}'></p>
<p>paymentType: <input type='hidden' name='paymentType' value='AC'></p>
<p>transactionId: <input type='hidden' name='transactionId' value='{{ transaction.pk }}'></p>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
<button type="submit" class="btn btn-primary">Вывести</button>
</div>
</form>
</div>
</div>
</div>
<table>
<tr>

@ -9,9 +9,10 @@
<p>scid: <input type='text' name='scid' value='{{ YANDEX_MONEY.scid }}'></p>
<p>sum: <input type='text' name='sum' value='100'></p>
<p>customerNumber: <input type='text' name='customerNumber' value='123'></p>
<p>paymentType: <input type='text' name='paymentType' value='AC'></p>
<p>transactionId: <input type='text' name='transactionId' value='{{ transaction.pk }}'></p>
<p><button type='submit'>Simulate check</button></p>
</form>
</div>

@ -44,7 +44,7 @@
<p>orderSumBankPaycash: <input name='orderSumBankPaycash' value='1001'></p>
<p>shopPassword: <input name='shopPassword' value='x1uvmS9Iq8WBE3Oo'></p>
<p>orderNumber: <input name='orderNumber' value='123'></p>
<p>transactionId: <input name='transactionId' value='1'></p>
<p><button type='submit'>Simulate aviso</button></p>
</form>

@ -1,13 +1,14 @@
from django.conf import urls, settings
from django.views.generic import TemplateView
from .views import ScoreDetailView, WithDrawCreate
from .views import ScoreDetailView, WithDrawCreate, ScoreView
app_name = 'wallets'
urlpatterns = [
urls.url(r'^score/(?P<pk>\d+)/$', ScoreDetailView.as_view(), name='score-detail'),
# urls.url(r'^score/(?P<pk>\d+)/$', ScoreDetailView.as_view(), name='score-detail'),
urls.url(r'^score/(?P<pk>\d+)/$', ScoreView.as_view(), name='score-detail'),
urls.url(r'^withdraw/create/$', WithDrawCreate.as_view(), name='withdraw-create'),
urls.url(

@ -1,6 +1,8 @@
from django.conf import urls, settings
from django.contrib import messages
from django.db.models import Sum
from django.http import HttpResponse, JsonResponse
from django.http import HttpResponse, JsonResponse, HttpResponseForbidden
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
@ -9,7 +11,7 @@ from django.views.generic.base import View
from pprint import pprint, pformat
from .forms import WithDrawForm, TmpCheckOrderForm, TmpPaymentAvisoForm
from .models import InvoiceHistory, WithDraw
from .models import InvoiceHistory, WithDraw, Transaction
from users.mixins import CheckForUserMixin
from users.models import User
@ -18,7 +20,37 @@ class ScoreDetailView(CheckForUserMixin, DetailView):
model = User
template_name = 'score-detail.html'
context_object_name = 'user_score'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user_score_balance = InvoiceHistory.objects.filter(user=self.get_object()).aggregate(Sum('sum'))
context['user_score_balance'] = user_score_balance['sum__sum'] or 0
context['form'] = WithDrawForm
return context
class ScoreView(View):
template_name = 'score-detail.html'
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated() and request.user.is_customer():
return super().dispatch(request, *args, **kwargs)
else:
return HttpResponseForbidden('403 Forbidden')
def get(self, request, *args, **kwargs):
# transaction = Transaction.objects.create(customer=request.user)
user_score = get_object_or_404(User.customer_objects, pk=kwargs.get('pk'))
return render(request, self.template_name, {
# 'transaction': transaction,
'YANDEX_MONEY': settings.YANDEX_MONEY,
'user_score': user_score,
})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
user_score_balance = InvoiceHistory.objects.filter(user=self.get_object()).aggregate(Sum('sum'))
@ -90,7 +122,9 @@ class TmpCheckOrderView(View):
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
trans = form.cleaned_data.get('transaction')
if form.is_valid() and not trans.is_void():
res = """<?xml version="1.0" encoding="utf-8"?>
<checkOrderResponse
performedDatetime="{date}"

Loading…
Cancel
Save