You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.6 KiB

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)