From 782cb9cf8b6fbf30cabc7c7529172333a3824b3d Mon Sep 17 00:00:00 2001 From: Marcin Warzybok Date: Wed, 28 Feb 2024 10:29:01 +0100 Subject: [PATCH 1/3] SP-883 Python 5.0.3 - Pydantic validation --- src/bitpay/models/invoice/invoice.py | 5 +++-- .../models/invoice/invoice_refund_address.py | 14 ++++++++++++++ tests/unit/json/create_invoice_response.json | 10 +++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/bitpay/models/invoice/invoice_refund_address.py diff --git a/src/bitpay/models/invoice/invoice.py b/src/bitpay/models/invoice/invoice.py index 318b3b1..ebaf00a 100644 --- a/src/bitpay/models/invoice/invoice.py +++ b/src/bitpay/models/invoice/invoice.py @@ -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 @@ -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 diff --git a/src/bitpay/models/invoice/invoice_refund_address.py b/src/bitpay/models/invoice/invoice_refund_address.py new file mode 100644 index 0000000..e865b31 --- /dev/null +++ b/src/bitpay/models/invoice/invoice_refund_address.py @@ -0,0 +1,14 @@ +""" +InvoiceRefundAddress +""" + +from typing import Union + +from bitpay.models.bitpay_model import BitPayModel + + +class InvoiceRefundAddress(BitPayModel): + type: str + date: str + tag: Union[int, None] = None + email: Union[str, None] = None diff --git a/tests/unit/json/create_invoice_response.json b/tests/unit/json/create_invoice_response.json index 98e7678..191c07d 100644 --- a/tests/unit/json/create_invoice_response.json +++ b/tests/unit/json/create_invoice_response.json @@ -31,7 +31,15 @@ "notify": true }, "autoRedirect": true, - "refundAddresses": [], + "refundAddresses": [ + { + "n2MDYgEhxCAnuoVd1JpPmvxZShE6rQA6zv": { + "type": "buyerSupplied", + "date": "2024-01-08T23:50:56.556Z", + "email": "email@email.com" + } + } + ], "refundAddressRequestPending": false, "buyerProvidedEmail": "m.warzybok@sumoheavy.com", "buyerProvidedInfo": { From 42596284e3981317d113c4e545b0462fa860aa7c Mon Sep 17 00:00:00 2001 From: Marcin Warzybok Date: Wed, 28 Feb 2024 10:38:41 +0100 Subject: [PATCH 2/3] SP-883 Python 5.0.3 - Pydantic validation --- src/bitpay/models/invoice/invoice_refund_address.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bitpay/models/invoice/invoice_refund_address.py b/src/bitpay/models/invoice/invoice_refund_address.py index e865b31..12d6ec1 100644 --- a/src/bitpay/models/invoice/invoice_refund_address.py +++ b/src/bitpay/models/invoice/invoice_refund_address.py @@ -1,14 +1,19 @@ """ InvoiceRefundAddress """ - +from datetime import datetime from typing import Union +from pydantic import field_serializer from bitpay.models.bitpay_model import BitPayModel class InvoiceRefundAddress(BitPayModel): - type: str - date: str - tag: Union[int, None] = None + 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) From 33677530cf73242f514ff983c2ef6c7eb61b522b Mon Sep 17 00:00:00 2001 From: Marcin Warzybok Date: Wed, 28 Feb 2024 10:44:06 +0100 Subject: [PATCH 3/3] SP-883 Python 5.0.3 - Pydantic validation --- src/bitpay/models/invoice/invoice_refund_address.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitpay/models/invoice/invoice_refund_address.py b/src/bitpay/models/invoice/invoice_refund_address.py index 12d6ec1..63f1ed7 100644 --- a/src/bitpay/models/invoice/invoice_refund_address.py +++ b/src/bitpay/models/invoice/invoice_refund_address.py @@ -1,6 +1,7 @@ """ InvoiceRefundAddress """ + from datetime import datetime from typing import Union from pydantic import field_serializer