-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuse_cases.py
33 lines (25 loc) · 1.22 KB
/
use_cases.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from .domain import PaymentIntent
from .payment_gateway import PaymentGateway
from .repository import PaymentIntentRepository
async def get_payment_intent(payment_intent_id: str, repository: PaymentIntentRepository) -> PaymentIntent:
return await repository.get(payment_intent_id)
async def create_payment_intent(
customer_id: str, amount: int, currency: str, repository: PaymentIntentRepository
) -> PaymentIntent:
payment_intent = PaymentIntent.create(customer_id, amount, currency)
await repository.create(payment_intent)
return payment_intent
async def change_payment_intent_amount(
payment_intent_id: str, amount: int, repository: PaymentIntentRepository
) -> PaymentIntent:
async with repository.lock(payment_intent_id) as payment_intent:
payment_intent.change_amount(amount)
await repository.update(payment_intent)
return payment_intent
async def charge_payment_intent(
payment_intent_id: str, repository: PaymentIntentRepository, payment_gateway: PaymentGateway
) -> PaymentIntent:
async with repository.lock(payment_intent_id) as payment_intent:
await payment_intent.execute_charge(payment_gateway)
await repository.update(payment_intent)
return payment_intent