обернул весь код переодического платежа в try/except + команда для тестирования See merge request !409remotes/origin/revert-6d879fe8
commit
bf454987d9
3 changed files with 79 additions and 37 deletions
@ -0,0 +1,44 @@ |
|||||||
|
from django.core.management.base import BaseCommand |
||||||
|
|
||||||
|
import os |
||||||
|
import requests |
||||||
|
from dateutil.relativedelta import relativedelta |
||||||
|
from yandex_money.models import Payment |
||||||
|
|
||||||
|
from finance.models import InvoiceRebilling |
||||||
|
from django.conf import settings |
||||||
|
from django.utils import timezone |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
|
||||||
|
def handle(self, *args, **options): |
||||||
|
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) |
||||||
Loading…
Reference in new issue