check and start payment added

This commit is contained in:
Gitea
2022-01-25 14:22:26 +09:00
parent 11d3d2644f
commit 70aaff37f1
42 changed files with 68 additions and 14 deletions

2
Atol_sell.bat Normal file
View File

@ -0,0 +1,2 @@
CD %CD%
py -3.9 payment_start.py

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
check_start.py Normal file
View File

@ -0,0 +1,3 @@
import kassa.new
kassa.new.run_get_check()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,9 +39,7 @@ class Atol:
def set_sell(self, reciept, is_refund): def set_sell(self, reciept, is_refund):
func = '/sell' if is_refund == 0 else '/sell_refund' func = '/sell' if is_refund == 0 else '/sell_refund'
print(reciept)
s = self.get_request('post', self.group_id+func, reciept) s = self.get_request('post', self.group_id+func, reciept)
print(s)
return s return s
def get_reciepts(self, uuid): def get_reciepts(self, uuid):

Binary file not shown.

View File

@ -1,3 +1,4 @@
from ast import Dict
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
import kassa.schemas as schemas import kassa.schemas as schemas
import kassa.models as models import kassa.models as models
@ -25,6 +26,7 @@ def create_doc(db: Session, doc: schemas.Doc, external_id: str = None):
def create_error(db: Session, error: schemas.Error, external_id: str = None): def create_error(db: Session, error: schemas.Error, external_id: str = None):
err = error err = error
err['external_id'] = external_id err['external_id'] = external_id
err_query = db.query(models.Error).filter( err_query = db.query(models.Error).filter(
models.Error.external_id == external_id) models.Error.external_id == external_id)
@ -32,7 +34,7 @@ def create_error(db: Session, error: schemas.Error, external_id: str = None):
err_query.update(values=err) err_query.update(values=err)
else: else:
err_query = models.Error(**err, synchronize_session=False) err_query = models.Error(**err)
db.add(err_query) db.add(err_query)
db.commit() db.commit()
@ -43,7 +45,7 @@ def create_payload(db: Session, payload: schemas.Payload, external_id: str = Non
payload_query = db.query(models.Payload).filter( payload_query = db.query(models.Payload).filter(
models.Payload.external_id == external_id) models.Payload.external_id == external_id)
if payload_query.first(): if payload_query.first():
payload_query.update(pay, synchronize_session=False) payload_query.update(pay)
else: else:
pay['external_id'] = external_id pay['external_id'] = external_id

View File

@ -46,7 +46,7 @@ class Doc(Base):
class Atol(Base): class Atol(Base):
__tablename__ = 'atol_receipts' __tablename__ = 'atol_receipts'
uuid = Column('uuid', String(length=128), primary_key=True) uuid = Column('uuid', String(length=128), primary_key=True, nullable= True)
timestamp = Column('timestamp', String(length=128)) timestamp = Column('timestamp', String(length=128))
external_id = Column('external_id', String(length=128)) external_id = Column('external_id', String(length=128))
status = Column('status', String(length=128)) status = Column('status', String(length=128))

View File

@ -1,4 +1,6 @@
from ast import While
from lib2to3.pgen2 import token from lib2to3.pgen2 import token
from re import A
from time import sleep from time import sleep
from typing import Dict, List, Tuple from typing import Dict, List, Tuple
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
@ -10,6 +12,7 @@ from sqlalchemy.sql.sqltypes import DateTime
from sqlalchemy import desc, cast, case, func from sqlalchemy import desc, cast, case, func
import kassa.schemas as schemas import kassa.schemas as schemas
import kassa.models as models import kassa.models as models
from kassa.cruds import doc
from kassa.databases import SessionLocal from kassa.databases import SessionLocal
from kassa.atol import Atol from kassa.atol import Atol
import datetime import datetime
@ -258,10 +261,11 @@ def get_sell(data: query):
def get_client(phone: str): def get_client(phone: str):
return { if phone:
'phone': phone return {
} 'phone': phone
}
return { 'email': 'test@test.ru'}
def get_vat(vat: str): def get_vat(vat: str):
return {'type': vat} return {'type': vat}
@ -291,16 +295,38 @@ def clear_dict(d):
return r return r
def add_doc(sell: schemas.Sell, is_refund, token): def add_doc(sell: schemas.Sell, is_refund, token):
atol_model = Atol(token) atol_model = Atol(token)
session = SessionLocal() session = SessionLocal()
a = atol_model.set_sell(clear_dict(sell.dict()), is_refund) a = atol_model.set_sell(clear_dict(sell.dict()), is_refund)
check = models.Atol(schemas.AtolSell(**a)) ext_id = sell.external_id
check.external_id = sell.external_id err = a.pop('error', None)
if err:
print(err)
return doc.create_error(session, error = schemas.Error(**err), external_id = ext_id )
a["external_id"]= sell.external_id
check = models.Atol(**a)
session.add(check) session.add(check)
session.commit() session.commit()
return a
def get_check(db: Session, uuid: str, external_id: str, token: str):
atol_model = Atol(token)
a = atol_model.get_reciepts(uuid)
err = a.pop('error', None)
if err:
print(err)
return doc.create_error(db, error = schemas.Error(**err), external_id = external_id )
doc.create_doc(db, a, external_id)
return a
def get_atol_wo_doc(db: Session):
return db.query(models.Atol.uuid, models.Atol.external_id).\
where(models.Atol.external_id.notin_(models.Doc.external_id)).\
all()
def get_main_payment(): def get_main_payment():
server = 'Sanctuary' server = 'Sanctuary'
user = 'sa' user = 'sa'
@ -334,5 +360,20 @@ def main():
if payment == False: if payment == False:
break break
sleep(1) sleep(1)
add_doc(sell=payment, is_refund=is_refund, token = token) doc = add_doc(sell=payment, is_refund=is_refund, token = token)
break print(doc)
def run_get_check():
session = SessionLocal()
atols = get_atol_wo_doc(session)
while len(atols)>0:
server = 'Sanctuary'
user = 'sa'
password = '159357'
db_dicts_name = 'fz54'
db = Session(autocommit=False, autoflush=False, bind=db.engine)
db_dicts = DBEngine(server, db_dicts_name, user, password)
token = get_token(db, db_dicts)
uuid, ext_id = atols.pop()
check = get_check(session, uuid, ext_id, token)
print(check)

View File

@ -212,6 +212,7 @@ class AtolSell(BaseModel):
timestamp: str timestamp: str
status: Optional[str] = None status: Optional[str] = None
error: Error = None error: Error = None
external_id: Optional[str] = None
class Config: class Config:
orm_mode = True orm_mode = True

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
payment_start.py Normal file
View File

@ -0,0 +1,3 @@
import kassa.new
kassa.new.main()

2
start.bat Normal file
View File

@ -0,0 +1,2 @@
CD %CD%
py -3.9 main.py

View File

@ -0,0 +1,2 @@
CD %CD%
py -3.9 main.py