Skip to content

Commit 025a8c0

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

File tree

26 files changed

+84
-105
lines changed

26 files changed

+84
-105
lines changed

glQiwiApi/core/event_fetching/class_based/bill.py

Lines changed: 2 additions & 2 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,7 +21,7 @@ def bill_id(self) -> str:
2121
return self.event.id
2222

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

2727
@property

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: 3 additions & 3 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
@@ -105,7 +105,7 @@ async def get_bill_status(self, bill_id: str) -> str:
105105
:param bill_id:
106106
:return: status of bill
107107
"""
108-
return (await self.get_bill_by_id(bill_id)).status.value
108+
return (await self.get_bill_by_id(bill_id)).status.amount
109109

110110
async def create_p2p_bill(
111111
self,
@@ -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: 5 additions & 5 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

@@ -20,7 +20,7 @@ class Customer(HashableBase):
2020

2121

2222
class BillStatus(HashableBase):
23-
value: str
23+
amount: str
2424
changed_datetime: Optional[datetime] = Field(None, alias='changedDateTime')
2525

2626

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

4040

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

64-
amount: PlainAmount
64+
amount: Amount
6565
datetime: datetime
6666
refund_id: str = Field(..., alias='refundId')
6767
status: str
@@ -85,7 +85,7 @@ 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.amount.currency}|{bill.amount.amount}|{bill.id}|{bill.site_id}|{bill.status.amount}'
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/detect_mobile_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DetectMobileNumber(QiwiAPIMethod[MobileOperator]):
1818
@classmethod
1919
def parse_http_response(cls, response: HTTPResponse) -> ReturningType:
2020
mobile_operator: MobileOperator = super().parse_http_response(response)
21-
if mobile_operator.code.value == '2' or mobile_operator.code.name == 'ERROR':
21+
if mobile_operator.code.amount == '2' or mobile_operator.code.name == 'ERROR':
2222
raise MobileOperatorCannotBeDeterminedError(
2323
response, custom_message=mobile_operator.message
2424
)

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')

0 commit comments

Comments
 (0)