Skip to content

Commit 282278b

Browse files
committed
Combine PlainAmount and AmountWithCurrency into Amount to simplify API
1 parent c9abaf7 commit 282278b

File tree

26 files changed

+85
-106
lines changed

26 files changed

+85
-106
lines changed

glQiwiApi/core/event_fetching/class_based/bill.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from glQiwiApi.core.event_fetching.class_based.base import Handler
77
from glQiwiApi.qiwi.clients.p2p.types import Bill
8-
from glQiwiApi.types.amount import PlainAmount
8+
from glQiwiApi.types.amount import Amount
99

1010
if TYPE_CHECKING:
1111
from glQiwiApi.qiwi.clients.p2p.client import QiwiP2PClient
@@ -21,8 +21,8 @@ def bill_id(self) -> str:
2121
return self.event.id
2222

2323
@property
24-
def bill_sum(self) -> PlainAmount:
25-
return self.event.amount
24+
def bill_sum(self) -> Amount:
25+
return self.event.value
2626

2727
@property
2828
def pay_url(self) -> str:

glQiwiApi/core/event_fetching/class_based/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, cast
55

66
from glQiwiApi.qiwi.clients.wallet.types.transaction import Transaction
7-
from glQiwiApi.types.amount import AmountWithCurrency
7+
from glQiwiApi.types.amount import Amount
88

99
from .base import Handler
1010

@@ -22,5 +22,5 @@ def transaction_id(self) -> int:
2222
return self.event.id
2323

2424
@property
25-
def transaction_sum(self) -> AmountWithCurrency:
25+
def transaction_sum(self) -> Amount:
2626
return self.event.sum

glQiwiApi/qiwi/clients/p2p/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from glQiwiApi.qiwi.clients.p2p.methods.refund_bill import RefundBill
1212
from glQiwiApi.qiwi.clients.p2p.methods.reject_p2p_bill import RejectP2PBill
1313
from glQiwiApi.qiwi.clients.p2p.types import Bill, Customer, PairOfP2PKeys, RefundedBill
14-
from glQiwiApi.types.amount import PlainAmount
14+
from glQiwiApi.types.amount import Amount
1515
from glQiwiApi.utils.compat import remove_suffix
1616
from glQiwiApi.utils.deprecated import warn_deprecated
1717
from glQiwiApi.utils.validators import String
@@ -175,7 +175,7 @@ async def refund_bill(
175175
self,
176176
bill_id: Union[str, int],
177177
refund_id: Union[str, int],
178-
json_bill_data: Union[PlainAmount, Dict[str, Union[str, int]]],
178+
json_bill_data: Union[Amount, Dict[str, Union[str, int]]],
179179
) -> RefundedBill:
180180
"""
181181
The method allows you to make a refund on a paid invoice.

glQiwiApi/qiwi/clients/p2p/methods/refund_bill.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from glQiwiApi.core.abc.api_method import Request
66
from glQiwiApi.qiwi.base import QiwiAPIMethod
77
from glQiwiApi.qiwi.clients.p2p.types import RefundedBill
8-
from glQiwiApi.types.amount import PlainAmount
8+
from glQiwiApi.types.amount import Amount
99

1010

1111
class RefundBill(QiwiAPIMethod[RefundedBill]):
@@ -15,11 +15,11 @@ class RefundBill(QiwiAPIMethod[RefundedBill]):
1515
bill_id: str = Field(..., path_runtime_value=True)
1616
refund_id: str = Field(..., path_runtime_value=True)
1717

18-
json_bill_data: Union[PlainAmount, Dict[str, Union[str, int]]]
18+
json_bill_data: Union[Amount, Dict[str, Union[str, int]]]
1919

2020
def build_request(self, **url_format_kw: Any) -> 'Request':
2121
json_payload = self.json_bill_data
22-
if isinstance(self.json_bill_data, PlainAmount):
22+
if isinstance(self.json_bill_data, Amount):
2323
json_payload = self.json_bill_data.json(encoder=self.Config.json_dumps) # type: ignore
2424

2525
return Request(

glQiwiApi/qiwi/clients/p2p/types.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pydantic import BaseConfig, Extra, Field
1010

11-
from glQiwiApi.types.amount import HashablePlainAmount, PlainAmount
11+
from glQiwiApi.types.amount import Amount, HashableAmount
1212
from glQiwiApi.types.base import HashableBase
1313
from glQiwiApi.types.exceptions import WebhookSignatureUnverifiedError
1414

@@ -39,7 +39,7 @@ class BillError(HashableBase):
3939

4040

4141
class Bill(HashableBase):
42-
amount: HashablePlainAmount
42+
value: HashableAmount
4343
status: BillStatus
4444
site_id: str = Field(..., alias='siteId')
4545
id: str = Field(..., alias='billId')
@@ -61,13 +61,13 @@ def invoice_uid(self) -> str:
6161
class RefundedBill(HashableBase):
6262
"""object: RefundedBill"""
6363

64-
amount: PlainAmount
64+
value: Amount
6565
datetime: datetime
6666
refund_id: str = Field(..., alias='refundId')
6767
status: str
6868

6969
def __str__(self) -> str:
70-
return f'№{self.refund_id} {self.status} {self.amount} {self.datetime}'
70+
return f'№{self.refund_id} {self.status} {self.value} {self.datetime}'
7171

7272

7373
class BillWebhookPayload(Bill):
@@ -79,13 +79,13 @@ class BillWebhook(HashableBase):
7979
bill: BillWebhookPayload = Field(..., alias='bill')
8080

8181
def __repr__(self) -> str:
82-
return f'#{self.bill.id} {self.bill.amount} {self.bill.status} '
82+
return f'#{self.bill.id} {self.bill.value} {self.bill.status} '
8383

8484
def verify_signature(self, sha256_signature: str, secret_p2p_key: str) -> None:
8585
webhook_key = base64.b64decode(bytes(secret_p2p_key, 'utf-8'))
8686
bill = self.bill
8787

88-
invoice_params = f'{bill.amount.currency}|{bill.amount.value}|{bill.id}|{bill.site_id}|{bill.status.value}'
88+
invoice_params = f'{bill.value.currency}|{bill.value.value}|{bill.id}|{bill.site_id}|{bill.status.value}'
8989
generated_signature = hmac.new(
9090
webhook_key, invoice_params.encode('utf-8'), hashlib.sha256
9191
).hexdigest()

glQiwiApi/qiwi/clients/wallet/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from glQiwiApi.qiwi.clients.wallet.methods.webhook.send_test_notification import (
5050
SendTestWebhookNotification,
5151
)
52-
from glQiwiApi.types.amount import AmountWithCurrency
52+
from glQiwiApi.types.amount import Amount
5353
from glQiwiApi.types.arbitrary import File
5454
from glQiwiApi.utils.validators import PhoneNumber, String
5555

@@ -381,7 +381,7 @@ async def get_list_of_balances(self) -> List[Balance]:
381381
GetBalances(), phone_number=self.phone_number_without_plus_sign
382382
)
383383

384-
async def get_balance(self, *, account_number: int = 1) -> AmountWithCurrency:
384+
async def get_balance(self, *, account_number: int = 1) -> Amount:
385385
resp: List[Balance] = await self._request_service.execute_api_method(
386386
GetBalances(),
387387
phone_number=self._phone_number,
@@ -506,7 +506,7 @@ async def get_cross_rates(self) -> List[CrossRate]:
506506

507507
async def payment_by_payment_details(
508508
self,
509-
payment_sum: AmountWithCurrency,
509+
payment_sum: Amount,
510510
payment_method: PaymentMethod,
511511
fields: PaymentDetails,
512512
payment_id: Optional[str] = None,

glQiwiApi/qiwi/clients/wallet/methods/payment_by_details.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from glQiwiApi.core.abc.api_method import RuntimeValue
77
from glQiwiApi.qiwi.base import QiwiAPIMethod
88
from glQiwiApi.qiwi.clients.wallet.types import PaymentDetails, PaymentInfo, PaymentMethod
9-
from glQiwiApi.types.amount import AmountWithCurrency
9+
from glQiwiApi.types.amount import Amount
1010

1111

1212
class MakePaymentByDetails(QiwiAPIMethod[PaymentInfo]):
@@ -20,7 +20,7 @@ class MakePaymentByDetails(QiwiAPIMethod[PaymentInfo]):
2020
'fields': RuntimeValue(),
2121
}
2222

23-
payment_sum: AmountWithCurrency = Field(..., scheme_path='sum')
23+
payment_sum: Amount = Field(..., scheme_path='sum')
2424
payment_method: PaymentMethod = Field(..., scheme_path='paymentMethod')
2525
details: PaymentDetails = Field(..., scheme_path='fields')
2626
payment_id: Optional[str] = Field(None, scheme_path='id')

glQiwiApi/qiwi/clients/wallet/types/account_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
from pydantic import Field
66

7-
from glQiwiApi.types.amount import AmountWithCurrency
7+
from glQiwiApi.types.amount import Amount, Currency
88
from glQiwiApi.types.base import Base
9-
from glQiwiApi.types.currency import Currency
109

1110

1211
class PassInfo(Base):
@@ -48,7 +47,7 @@ class AuthInfo(Base):
4847
class SmsNotification(Base):
4948
"""object: SmsNotification"""
5049

51-
price: AmountWithCurrency
50+
price: Amount
5251
enabled: bool
5352
active: bool
5453
end_date: Optional[datetime] = Field(None, alias='endDate')

glQiwiApi/qiwi/clients/wallet/types/balance.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
from pydantic import Field
44

5-
from glQiwiApi.types.amount import AmountWithCurrency
5+
from glQiwiApi.types.amount import Amount, Currency
66
from glQiwiApi.types.base import HashableBase
7-
from glQiwiApi.types.currency import Currency
87

98

109
class AvailableBalance(HashableBase):
@@ -20,7 +19,7 @@ class Balance(HashableBase):
2019
fs_alias: str = Field(alias='fsAlias')
2120
bank_alias: str = Field(alias='bankAlias')
2221
has_balance: bool = Field(alias='hasBalance')
23-
balance: Optional[AmountWithCurrency] = None
22+
balance: Optional[Amount] = None
2423
currency: Currency
2524
account_type: Optional[Dict[str, Any]] = Field(None, alias='type')
2625
is_default_account: bool = Field(alias='defaultAccount')
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from pydantic import Field
22

3-
from glQiwiApi.types.amount import AmountWithCurrency
3+
from glQiwiApi.types.amount import Amount
44
from glQiwiApi.types.base import Base
55

66

77
class Commission(Base):
88
provider_id: int = Field(alias='providerId')
9-
withdraw_sum: AmountWithCurrency = Field(alias='withdrawSum')
10-
enrollment_sum: AmountWithCurrency = Field(alias='enrollmentSum')
11-
qiwi_commission: AmountWithCurrency = Field(alias='qwCommission')
9+
withdraw_sum: Amount = Field(alias='withdrawSum')
10+
enrollment_sum: Amount = Field(alias='enrollmentSum')
11+
qiwi_commission: Amount = Field(alias='qwCommission')
1212
withdraw_to_enrollment_rate: int = Field(alias='withdrawToEnrollmentRate')

0 commit comments

Comments
 (0)