команда вызывает таску ребилинга, обновление invoiceId после всех сейвов на моменте авизо

remotes/origin/revert-6d879fe8
wad 8 years ago
parent 74d93d00d3
commit 713649c90c
  1. 37
      finance/management/commands/yandex_repeat_payment.py
  2. 4
      finance/tasks.py
  3. 2
      finance/views.py

@ -1,14 +1,8 @@
import logging
import os
import requests
from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.core.management.base import BaseCommand
from django.utils import timezone
from yandex_money.models import Payment
from finance.models import InvoiceRebilling
from finance.tasks import periodic_billing
logger_yandex = logging.getLogger('yandex_money')
@ -18,31 +12,4 @@ class Command(BaseCommand):
def handle(self, *args, **options):
logger_yandex.info("start console repeat payment command")
print('Started')
invoices = InvoiceRebilling.objects.filter(method='Y').exclude(status='F')
for invoice in invoices.filter(
expected_date__gt=timezone.now(), expected_date__lt=timezone.now() + relativedelta(days=1)):
print('invoice', invoice)
user = invoice.bill.user
yandex_pay = Payment.objects.create(
order_amount=invoice.price,
customer_number=user.id,
user=user,
cps_email=user.email
)
invoice.yandex_pay = yandex_pay
invoice.save()
resp = requests.post(
settings.YANDEX_MONEY_MWS_URL + 'repeatCardPayment',
data={
'clientOrderId': invoice.id, # уникальное возрастающее целое число
'invoiceId': invoice.key,
'amount': invoice.price,
'orderNumber': invoice.yandex_pay.order_number
},
cert=(
os.path.join(settings.SSL_ROOT, 'skillbox.cer'),
os.path.join(settings.SSL_ROOT, 'skillbox.key')
),
verify=os.path.join(settings.SSL_ROOT, 'yamoney_chain.cer')
)
print(resp)
periodic_billing()

@ -21,6 +21,7 @@ def periodic_billing():
for invoice in invoices.filter(
expected_date__gt=timezone.now(), expected_date__lt=timezone.now() + relativedelta(days=1)):
# TODO выбирать все, даже прошлые неотработанные - что бы не потерять
user = invoice.bill.user
yandex_pay = Payment.objects.create(
@ -39,6 +40,7 @@ def periodic_billing():
logger_yandex.error('periodic billing Exception', exc_info=True, extra={
'exc': exc
})
# TODO записывать в invoice.comments ошибку яндекса
def repeat_card_payment(invoice):
@ -55,5 +57,5 @@ def repeat_card_payment(invoice):
),
verify=os.path.join(settings.SSL_ROOT, 'yamoney_chain.cer'))
logger_yandex.info('periodic billing finish', exc_info=True, extra={
'response': resp.text
'response': resp.text, 'code': resp.status_code,
})

@ -473,11 +473,11 @@ class YandexAvisoView(APIView):
# invoice = pay.invoice
# invoice.key = data['invoiceId']
# invoice.save()
InvoiceRebilling.objects.filter(bill=pay.invoice.bill).update(key=data['invoiceId'])
pay.status = Payment.STATUS.SUCCESS
now = timezone.now()
pay.performed_datetime = now.isoformat()
pay.save()
InvoiceRebilling.objects.filter(bill=pay.invoice.bill).update(key=data['invoiceId'])
xml_res = """<paymentAvisoResponse performedDatetime="%s" code="0" invoiceId="%s" shopId="%s"/>
""" % (pay.performed_datetime, str(data['invoiceId']), str(pay.shop_id))

Loading…
Cancel
Save