Skip to content

Commit

Permalink
Merge pull request #90 from mwarzybok-sumoheavy/feature/SP-883
Browse files Browse the repository at this point in the history
SP-883 Python 5.0.3 - Pydantic validation
  • Loading branch information
bobbrodie authored Feb 29, 2024
2 parents dbae5d0 + 3367753 commit 75c377d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/bitpay/models/invoice/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Invoice
"""

from typing import List, Union
from typing import List, Union, Dict
from pydantic import Field
from .buyer import Buyer
from .buyer_provided_info import BuyerProvidedInfo
from .invoice_refund_address import InvoiceRefundAddress
from .miner_fees import MinerFees
from .refund_info import RefundInfo
from .shopper import Shopper
Expand Down Expand Up @@ -47,7 +48,7 @@ class Invoice(BitPayModel):
payment_codes: Union[dict, None] = None
acceptance_window: Union[int, None] = None
buyer: Union[Buyer, None] = None
refund_addresses: Union[List[str], None] = None
refund_addresses: Union[List[Dict[str, InvoiceRefundAddress]], None] = None
close_url: Union[str, None] = Field(alias="closeURL", default=None)
auto_redirect: Union[bool, None] = False
json_paypro_required: bool = False
Expand Down
20 changes: 20 additions & 0 deletions src/bitpay/models/invoice/invoice_refund_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
InvoiceRefundAddress
"""

from datetime import datetime
from typing import Union
from pydantic import field_serializer

from bitpay.models.bitpay_model import BitPayModel


class InvoiceRefundAddress(BitPayModel):
date: Union[datetime, None] = None
email: Union[str, None] = None
tag: Union[int, None] = None
type: Union[str, None] = None

@field_serializer("date")
def serialize_datetime(self, dt: datetime) -> str:
return super().serialize_datetime_to_iso8601(dt)
10 changes: 9 additions & 1 deletion tests/unit/json/create_invoice_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
"notify": true
},
"autoRedirect": true,
"refundAddresses": [],
"refundAddresses": [
{
"n2MDYgEhxCAnuoVd1JpPmvxZShE6rQA6zv": {
"type": "buyerSupplied",
"date": "2024-01-08T23:50:56.556Z",
"email": "[email protected]"
}
}
],
"refundAddressRequestPending": false,
"buyerProvidedEmail": "[email protected]",
"buyerProvidedInfo": {
Expand Down

0 comments on commit 75c377d

Please sign in to comment.