feat: cancel deal bill if exists
This commit is contained in:
@@ -30,6 +30,7 @@ class CreateCardBillRequest(BaseSchema):
|
||||
|
||||
class CancelCardBillRequest(BaseSchema):
|
||||
card_id: int
|
||||
force: Optional[bool] = False
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
@@ -180,8 +180,12 @@ class BillingService(BaseService):
|
||||
)
|
||||
)
|
||||
create_bill_response = await billing_client.create(create_bill_request)
|
||||
if not create_bill_response.ok and 'Request already exists' in create_bill_response.message:
|
||||
await self.cancel_card_billing(user, CancelCardBillRequest(card_id=request.card_id, force=True))
|
||||
return await self.create_card_billing(user, request)
|
||||
if not create_bill_response.ok:
|
||||
return CreateCardBillResponse(ok=create_bill_response.ok, message=create_bill_response.message or 'Неизвестная ошибка')
|
||||
return CreateCardBillResponse(ok=create_bill_response.ok,
|
||||
message=create_bill_response.message or 'Неизвестная ошибка')
|
||||
|
||||
if basic_card.group:
|
||||
await self.create_group_bill_request(basic_card.group)
|
||||
@@ -212,20 +216,20 @@ class BillingService(BaseService):
|
||||
|
||||
if card.group:
|
||||
bill = await self._get_group_bill_by_id(card.group.id)
|
||||
if not bill:
|
||||
if not bill and not request.force:
|
||||
return CancelCardBillResponse(ok=False, message='Заявка не найдена')
|
||||
billing_client = BillingClient(backend.config.BILLING_API_KEY)
|
||||
response = await billing_client.delete(DeleteBillRequestSchema(listener_transaction_id=card.group.id))
|
||||
else:
|
||||
bill = await self._get_card_bill_by_id(request.card_id)
|
||||
if not bill:
|
||||
if not bill and not request.force:
|
||||
return CancelCardBillResponse(ok=False, message='Заявка не найдена')
|
||||
billing_client = BillingClient(backend.config.BILLING_API_KEY)
|
||||
response = await billing_client.delete(DeleteBillRequestSchema(listener_transaction_id=request.card_id))
|
||||
|
||||
if not response.ok:
|
||||
return CancelCardBillResponse(ok=False, message='Ошибка')
|
||||
|
||||
if bill:
|
||||
await self.session.delete(bill)
|
||||
await self.session.commit()
|
||||
return CancelCardBillResponse(ok=True, message='Заявка успешно отозвана')
|
||||
|
||||
Reference in New Issue
Block a user