Skip to content

Commit

Permalink
Combine PlainAmount and AmountWithCurrency into Amount to simpl…
Browse files Browse the repository at this point in the history
…ify API
  • Loading branch information
GLEF1X committed Jul 11, 2022
1 parent c9abaf7 commit 282278b
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 106 deletions.
6 changes: 3 additions & 3 deletions glQiwiApi/core/event_fetching/class_based/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from glQiwiApi.core.event_fetching.class_based.base import Handler
from glQiwiApi.qiwi.clients.p2p.types import Bill
from glQiwiApi.types.amount import PlainAmount
from glQiwiApi.types.amount import Amount

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

@property
def bill_sum(self) -> PlainAmount:
return self.event.amount
def bill_sum(self) -> Amount:
return self.event.value

@property
def pay_url(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions glQiwiApi/core/event_fetching/class_based/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, cast

from glQiwiApi.qiwi.clients.wallet.types.transaction import Transaction
from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount

from .base import Handler

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

@property
def transaction_sum(self) -> AmountWithCurrency:
def transaction_sum(self) -> Amount:
return self.event.sum
4 changes: 2 additions & 2 deletions glQiwiApi/qiwi/clients/p2p/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from glQiwiApi.qiwi.clients.p2p.methods.refund_bill import RefundBill
from glQiwiApi.qiwi.clients.p2p.methods.reject_p2p_bill import RejectP2PBill
from glQiwiApi.qiwi.clients.p2p.types import Bill, Customer, PairOfP2PKeys, RefundedBill
from glQiwiApi.types.amount import PlainAmount
from glQiwiApi.types.amount import Amount
from glQiwiApi.utils.compat import remove_suffix
from glQiwiApi.utils.deprecated import warn_deprecated
from glQiwiApi.utils.validators import String
Expand Down Expand Up @@ -175,7 +175,7 @@ async def refund_bill(
self,
bill_id: Union[str, int],
refund_id: Union[str, int],
json_bill_data: Union[PlainAmount, Dict[str, Union[str, int]]],
json_bill_data: Union[Amount, Dict[str, Union[str, int]]],
) -> RefundedBill:
"""
The method allows you to make a refund on a paid invoice.
Expand Down
6 changes: 3 additions & 3 deletions glQiwiApi/qiwi/clients/p2p/methods/refund_bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from glQiwiApi.core.abc.api_method import Request
from glQiwiApi.qiwi.base import QiwiAPIMethod
from glQiwiApi.qiwi.clients.p2p.types import RefundedBill
from glQiwiApi.types.amount import PlainAmount
from glQiwiApi.types.amount import Amount


class RefundBill(QiwiAPIMethod[RefundedBill]):
Expand All @@ -15,11 +15,11 @@ class RefundBill(QiwiAPIMethod[RefundedBill]):
bill_id: str = Field(..., path_runtime_value=True)
refund_id: str = Field(..., path_runtime_value=True)

json_bill_data: Union[PlainAmount, Dict[str, Union[str, int]]]
json_bill_data: Union[Amount, Dict[str, Union[str, int]]]

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

return Request(
Expand Down
12 changes: 6 additions & 6 deletions glQiwiApi/qiwi/clients/p2p/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pydantic import BaseConfig, Extra, Field

from glQiwiApi.types.amount import HashablePlainAmount, PlainAmount
from glQiwiApi.types.amount import Amount, HashableAmount
from glQiwiApi.types.base import HashableBase
from glQiwiApi.types.exceptions import WebhookSignatureUnverifiedError

Expand Down Expand Up @@ -39,7 +39,7 @@ class BillError(HashableBase):


class Bill(HashableBase):
amount: HashablePlainAmount
value: HashableAmount
status: BillStatus
site_id: str = Field(..., alias='siteId')
id: str = Field(..., alias='billId')
Expand All @@ -61,13 +61,13 @@ def invoice_uid(self) -> str:
class RefundedBill(HashableBase):
"""object: RefundedBill"""

amount: PlainAmount
value: Amount
datetime: datetime
refund_id: str = Field(..., alias='refundId')
status: str

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


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

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

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

invoice_params = f'{bill.amount.currency}|{bill.amount.value}|{bill.id}|{bill.site_id}|{bill.status.value}'
invoice_params = f'{bill.value.currency}|{bill.value.value}|{bill.id}|{bill.site_id}|{bill.status.value}'
generated_signature = hmac.new(
webhook_key, invoice_params.encode('utf-8'), hashlib.sha256
).hexdigest()
Expand Down
6 changes: 3 additions & 3 deletions glQiwiApi/qiwi/clients/wallet/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from glQiwiApi.qiwi.clients.wallet.methods.webhook.send_test_notification import (
SendTestWebhookNotification,
)
from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.arbitrary import File
from glQiwiApi.utils.validators import PhoneNumber, String

Expand Down Expand Up @@ -381,7 +381,7 @@ async def get_list_of_balances(self) -> List[Balance]:
GetBalances(), phone_number=self.phone_number_without_plus_sign
)

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

async def payment_by_payment_details(
self,
payment_sum: AmountWithCurrency,
payment_sum: Amount,
payment_method: PaymentMethod,
fields: PaymentDetails,
payment_id: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions glQiwiApi/qiwi/clients/wallet/methods/payment_by_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from glQiwiApi.core.abc.api_method import RuntimeValue
from glQiwiApi.qiwi.base import QiwiAPIMethod
from glQiwiApi.qiwi.clients.wallet.types import PaymentDetails, PaymentInfo, PaymentMethod
from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount


class MakePaymentByDetails(QiwiAPIMethod[PaymentInfo]):
Expand All @@ -20,7 +20,7 @@ class MakePaymentByDetails(QiwiAPIMethod[PaymentInfo]):
'fields': RuntimeValue(),
}

payment_sum: AmountWithCurrency = Field(..., scheme_path='sum')
payment_sum: Amount = Field(..., scheme_path='sum')
payment_method: PaymentMethod = Field(..., scheme_path='paymentMethod')
details: PaymentDetails = Field(..., scheme_path='fields')
payment_id: Optional[str] = Field(None, scheme_path='id')
5 changes: 2 additions & 3 deletions glQiwiApi/qiwi/clients/wallet/types/account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount, Currency
from glQiwiApi.types.base import Base
from glQiwiApi.types.currency import Currency


class PassInfo(Base):
Expand Down Expand Up @@ -48,7 +47,7 @@ class AuthInfo(Base):
class SmsNotification(Base):
"""object: SmsNotification"""

price: AmountWithCurrency
price: Amount
enabled: bool
active: bool
end_date: Optional[datetime] = Field(None, alias='endDate')
Expand Down
5 changes: 2 additions & 3 deletions glQiwiApi/qiwi/clients/wallet/types/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount, Currency
from glQiwiApi.types.base import HashableBase
from glQiwiApi.types.currency import Currency


class AvailableBalance(HashableBase):
Expand All @@ -20,7 +19,7 @@ class Balance(HashableBase):
fs_alias: str = Field(alias='fsAlias')
bank_alias: str = Field(alias='bankAlias')
has_balance: bool = Field(alias='hasBalance')
balance: Optional[AmountWithCurrency] = None
balance: Optional[Amount] = None
currency: Currency
account_type: Optional[Dict[str, Any]] = Field(None, alias='type')
is_default_account: bool = Field(alias='defaultAccount')
8 changes: 4 additions & 4 deletions glQiwiApi/qiwi/clients/wallet/types/commission.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.base import Base


class Commission(Base):
provider_id: int = Field(alias='providerId')
withdraw_sum: AmountWithCurrency = Field(alias='withdrawSum')
enrollment_sum: AmountWithCurrency = Field(alias='enrollmentSum')
qiwi_commission: AmountWithCurrency = Field(alias='qwCommission')
withdraw_sum: Amount = Field(alias='withdrawSum')
enrollment_sum: Amount = Field(alias='enrollmentSum')
qiwi_commission: Amount = Field(alias='qwCommission')
withdraw_to_enrollment_rate: int = Field(alias='withdrawToEnrollmentRate')
2 changes: 1 addition & 1 deletion glQiwiApi/qiwi/clients/wallet/types/limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pydantic import Field

from glQiwiApi.types.amount import Currency
from glQiwiApi.types.base import Base
from glQiwiApi.types.currency import Currency


class Interval(Base):
Expand Down
2 changes: 1 addition & 1 deletion glQiwiApi/qiwi/clients/wallet/types/other.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import Field

from glQiwiApi.types.amount import Currency
from glQiwiApi.types.base import Base, HashableBase
from glQiwiApi.types.currency import Currency


class CrossRate(HashableBase):
Expand Down
6 changes: 3 additions & 3 deletions glQiwiApi/qiwi/clients/wallet/types/payment_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.base import Base


Expand All @@ -29,7 +29,7 @@ class PaymentInfo(Base):
"""object: PaymentInfo"""

id: int
amount: AmountWithCurrency = Field(..., alias='sum')
value: Amount = Field(..., alias='sum')
terms: str
fields: Fields
source: str
Expand All @@ -44,7 +44,7 @@ class PaymentMethod(Base):

class QiwiPayment(Base):
id: int
sum: AmountWithCurrency
sum: Amount
method: PaymentMethod = Field(..., alias='paymentMethod')
fields: Dict[Any, Any]
comment: Optional[str] = None
Expand Down
8 changes: 4 additions & 4 deletions glQiwiApi/qiwi/clients/wallet/types/qiwi_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.base import Base, HashableBase


Expand All @@ -19,7 +19,7 @@ class OrderDetails(Base):
order_id: str = Field(..., alias='id')
card_alias: str = Field(..., alias='cardAlias')
status: str
price: Optional[AmountWithCurrency] = None
price: Optional[Amount] = None
card_id: Optional[str] = Field(alias='cardId', default=None)


Expand Down Expand Up @@ -58,13 +58,13 @@ class CardInfo(Base):
id_: int = Field(..., alias='id')
name: str
alias: str
price: AmountWithCurrency
price: Amount
period: str
type_: str = Field(..., alias='type')
details: Details


class Card(HashableBase):
details: CardCredentials = Field(..., alias='qvx')
balance: Optional[AmountWithCurrency] = None
balance: Optional[Amount] = None
info: CardInfo
6 changes: 3 additions & 3 deletions glQiwiApi/qiwi/clients/wallet/types/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.base import Base


class Statistic(Base):
"""object: Statistic"""

incoming: List[AmountWithCurrency] = Field(alias='incomingTotal')
out: List[AmountWithCurrency] = Field(alias='outgoingTotal')
incoming: List[Amount] = Field(alias='incomingTotal')
out: List[Amount] = Field(alias='outgoingTotal')


__all__ = ['Statistic']
8 changes: 4 additions & 4 deletions glQiwiApi/qiwi/clients/wallet/types/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pydantic import Field

from glQiwiApi.types.amount import AmountWithCurrency
from glQiwiApi.types.amount import Amount
from glQiwiApi.types.base import Base


Expand Down Expand Up @@ -100,13 +100,13 @@ class Transaction(Base):
Для пополнений - номер отправителя,
терминала или название агента пополнения кошелька
"""
sum: AmountWithCurrency
sum: Amount
"""Данные о сумме платежа или пополнения."""

commission: AmountWithCurrency
commission: Amount
"""Данные о комиссии"""

total: AmountWithCurrency
total: Amount
"""Общие данные о платеже в формате объекта Sum"""

provider: Provider
Expand Down
8 changes: 4 additions & 4 deletions glQiwiApi/qiwi/clients/wallet/types/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pydantic import Field, root_validator

from glQiwiApi.types.amount import HashableSum
from glQiwiApi.types.amount import HashableAmount
from glQiwiApi.types.base import Base, HashableBase
from glQiwiApi.types.exceptions import WebhookSignatureUnverifiedError

Expand All @@ -25,9 +25,9 @@ class WebhookPayment(HashableBase):
status: str = Field(..., alias='status')
txn_id: str = Field(..., alias='txnId')
type: str = Field(..., alias='type')
commission: Optional[HashableSum] = Field(default=None, alias='calc_commission')
sum: HashableSum = Field(..., alias='sum')
total: HashableSum = Field(..., alias='total')
commission: Optional[HashableAmount] = Field(default=None, alias='calc_commission')
sum: HashableAmount = Field(..., alias='sum')
total: HashableAmount = Field(..., alias='total')


class TransactionWebhook(HashableBase):
Expand Down
Loading

0 comments on commit 282278b

Please sign in to comment.