Skip to content

Commit 75c377d

Browse files
authored
Merge pull request #90 from mwarzybok-sumoheavy/feature/SP-883
SP-883 Python 5.0.3 - Pydantic validation
2 parents dbae5d0 + 3367753 commit 75c377d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/bitpay/models/invoice/invoice.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
Invoice
33
"""
44

5-
from typing import List, Union
5+
from typing import List, Union, Dict
66
from pydantic import Field
77
from .buyer import Buyer
88
from .buyer_provided_info import BuyerProvidedInfo
9+
from .invoice_refund_address import InvoiceRefundAddress
910
from .miner_fees import MinerFees
1011
from .refund_info import RefundInfo
1112
from .shopper import Shopper
@@ -47,7 +48,7 @@ class Invoice(BitPayModel):
4748
payment_codes: Union[dict, None] = None
4849
acceptance_window: Union[int, None] = None
4950
buyer: Union[Buyer, None] = None
50-
refund_addresses: Union[List[str], None] = None
51+
refund_addresses: Union[List[Dict[str, InvoiceRefundAddress]], None] = None
5152
close_url: Union[str, None] = Field(alias="closeURL", default=None)
5253
auto_redirect: Union[bool, None] = False
5354
json_paypro_required: bool = False
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
InvoiceRefundAddress
3+
"""
4+
5+
from datetime import datetime
6+
from typing import Union
7+
from pydantic import field_serializer
8+
9+
from bitpay.models.bitpay_model import BitPayModel
10+
11+
12+
class InvoiceRefundAddress(BitPayModel):
13+
date: Union[datetime, None] = None
14+
email: Union[str, None] = None
15+
tag: Union[int, None] = None
16+
type: Union[str, None] = None
17+
18+
@field_serializer("date")
19+
def serialize_datetime(self, dt: datetime) -> str:
20+
return super().serialize_datetime_to_iso8601(dt)

tests/unit/json/create_invoice_response.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@
3131
"notify": true
3232
},
3333
"autoRedirect": true,
34-
"refundAddresses": [],
34+
"refundAddresses": [
35+
{
36+
"n2MDYgEhxCAnuoVd1JpPmvxZShE6rQA6zv": {
37+
"type": "buyerSupplied",
38+
"date": "2024-01-08T23:50:56.556Z",
39+
"email": "[email protected]"
40+
}
41+
}
42+
],
3543
"refundAddressRequestPending": false,
3644
"buyerProvidedEmail": "[email protected]",
3745
"buyerProvidedInfo": {

0 commit comments

Comments
 (0)