Skip to content

Commit 1db842a

Browse files
authored
PTHMINT-84: Fix field/method type inconsistency (#34)
1 parent c7afd53 commit 1db842a

File tree

16 files changed

+288
-176
lines changed

16 files changed

+288
-176
lines changed

src/multisafepay/api/paths/orders/order_id/capture/request/capture_request.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class CaptureOrderRequest(RequestModel):
4141

4242
def add_amount(
4343
self: "CaptureOrderRequest",
44-
amount: Union[Amount, int],
44+
amount: Optional[Union[Amount, int]],
4545
) -> "CaptureOrderRequest":
4646
"""
4747
Adds the amount to the capture request.
4848
4949
Parameters
5050
----------
51-
amount (Amount | int): The amount to add.
51+
amount (Optional[Amount | int]): The amount to add.
5252
5353
Returns
5454
-------
@@ -57,19 +57,19 @@ def add_amount(
5757
"""
5858
if isinstance(amount, int):
5959
amount = Amount(amount=amount)
60-
self.amount = amount.get()
60+
self.amount = amount.get() if amount is not None else None
6161
return self
6262

6363
def add_new_order_id(
6464
self: "CaptureOrderRequest",
65-
new_order_id: str,
65+
new_order_id: Optional[str],
6666
) -> "CaptureOrderRequest":
6767
"""
6868
Adds the new order ID to the capture request.
6969
7070
Parameters
7171
----------
72-
new_order_id (str): The new order ID to add.
72+
new_order_id (Optional[str]): The new order ID to add.
7373
7474
Returns
7575
-------
@@ -81,14 +81,14 @@ def add_new_order_id(
8181

8282
def add_new_order_status(
8383
self: "CaptureOrderRequest",
84-
new_order_status: str,
84+
new_order_status: Optional[str],
8585
) -> "CaptureOrderRequest":
8686
"""
8787
Adds the new order status to the capture request.
8888
8989
Parameters
9090
----------
91-
new_order_status (str): The new order status to add.
91+
new_order_status (Optional[str]): The new order status to add.
9292
9393
Returns
9494
-------
@@ -100,14 +100,14 @@ def add_new_order_status(
100100

101101
def add_invoice_id(
102102
self: "CaptureOrderRequest",
103-
invoice_id: str,
103+
invoice_id: Optional[str],
104104
) -> "CaptureOrderRequest":
105105
"""
106106
Adds the invoice ID to the capture request.
107107
108108
Parameters
109109
----------
110-
invoice_id (str): The invoice ID to add.
110+
invoice_id (Optional[str]): The invoice ID to add.
111111
112112
Returns
113113
-------
@@ -119,14 +119,14 @@ def add_invoice_id(
119119

120120
def add_carrier(
121121
self: "CaptureOrderRequest",
122-
carrier: str,
122+
carrier: Optional[str],
123123
) -> "CaptureOrderRequest":
124124
"""
125125
Adds the carrier information to the capture request.
126126
127127
Parameters
128128
----------
129-
carrier (str): The carrier information to add.
129+
carrier (Optional[str]): The carrier information to add.
130130
131131
Returns
132132
-------
@@ -138,14 +138,14 @@ def add_carrier(
138138

139139
def add_reason(
140140
self: "CaptureOrderRequest",
141-
reason: str,
141+
reason: Optional[str],
142142
) -> "CaptureOrderRequest":
143143
"""
144144
Adds the reason for the capture to the capture request.
145145
146146
Parameters
147147
----------
148-
reason (str): The reason to add.
148+
reason (Optional[str]): The reason to add.
149149
150150
Returns
151151
-------
@@ -157,14 +157,14 @@ def add_reason(
157157

158158
def add_tracktrace_code(
159159
self: "CaptureOrderRequest",
160-
tracktrace_code: str,
160+
tracktrace_code: Optional[str],
161161
) -> "CaptureOrderRequest":
162162
"""
163163
Adds the tracktrace code to the capture request.
164164
165165
Parameters
166166
----------
167-
tracktrace_code (str): The tracktrace code to add.
167+
tracktrace_code (Optional[str]): The tracktrace code to add.
168168
169169
Returns
170170
-------
@@ -176,14 +176,14 @@ def add_tracktrace_code(
176176

177177
def add_description(
178178
self: "CaptureOrderRequest",
179-
description: str,
179+
description: Optional[str],
180180
) -> "CaptureOrderRequest":
181181
"""
182182
Adds a description to the capture request.
183183
184184
Parameters
185185
----------
186-
description (str): The description to add.
186+
description (Optional[str]): The description to add.
187187
188188
Returns
189189
-------

src/multisafepay/api/paths/orders/order_id/refund/request/components/checkout_data.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,56 +29,63 @@ class CheckoutData(RequestModel):
2929

3030
def add_items(
3131
self: "CheckoutData",
32-
items: List[CartItem] = (),
32+
items: Optional[List[CartItem]] = None,
3333
) -> "CheckoutData":
3434
"""
3535
Adds multiple items to the checkout data.
3636
3737
Parameters
3838
----------
39-
items (List[CartItem]): The list of items to add.
39+
items (Optional[List[CartItem]]): The list of items to add. Defaults to None.
4040
4141
Returns
4242
-------
4343
CheckoutData: The updated checkout data.
4444
4545
"""
46+
if items is None:
47+
return self
4648
if self.items is None:
4749
self.items = []
4850
for item in items:
4951
self.add_item(item)
5052
return self
5153

52-
def add_item(self: "CheckoutData", item: CartItem) -> "CheckoutData":
54+
def add_item(
55+
self: "CheckoutData",
56+
item: Optional[CartItem],
57+
) -> "CheckoutData":
5358
"""
5459
Adds a single item to the checkout data.
5560
5661
Parameters
5762
----------
58-
item (CartItem): The item to add.
63+
item (Optional[CartItem]): The item to add.
5964
6065
Returns
6166
-------
6267
CheckoutData: The updated checkout data.
6368
6469
"""
70+
if item is None:
71+
return self
6572
if self.items is None:
6673
self.items = []
6774
self.items.append(item)
6875
return self
6976

70-
def get_items(self: "CheckoutData") -> List[CartItem]:
77+
def get_items(self: "CheckoutData") -> Optional[List[CartItem]]:
7178
"""
7279
Retrieves all items from the checkout data.
7380
7481
Returns
7582
-------
76-
List[CartItem]: The list of items.
83+
Optional[List[CartItem]]: The list of items, or None if no items exist.
7784
7885
"""
7986
return self.items
8087

81-
def get_item(self: "CheckoutData", index: int) -> CartItem:
88+
def get_item(self: "CheckoutData", index: int) -> Optional[CartItem]:
8289
"""
8390
Retrieves an item by its index from the checkout data.
8491
@@ -88,28 +95,33 @@ def get_item(self: "CheckoutData", index: int) -> CartItem:
8895
8996
Returns
9097
-------
91-
CartItem: The retrieved item.
98+
Optional[CartItem]: The retrieved item, or None if items is None.
9299
93100
"""
101+
if self.items is None:
102+
return None
94103
return self.items[index]
95104

96105
def generate_from_shopping_cart(
97106
self: "CheckoutData",
98-
shopping_cart: ShoppingCart,
99-
tax_table_selector: str = "",
107+
shopping_cart: Optional[ShoppingCart],
108+
tax_table_selector: Optional[str] = None,
100109
) -> None:
101110
"""
102111
Generates checkout data from a shopping cart.
103112
104113
Parameters
105114
----------
106-
shopping_cart (ShoppingCart): The shopping cart to generate data from.
107-
tax_table_selector (str): The tax table selector to use.
115+
shopping_cart (Optional[ShoppingCart]): The shopping cart to generate data from.
116+
tax_table_selector (Optional[str]): The tax table selector to use.
108117
109118
"""
110119
if shopping_cart is None:
111120
return
112-
for shopping_cart_item in shopping_cart.get_items():
121+
items = shopping_cart.get_items()
122+
if items is None:
123+
return
124+
for shopping_cart_item in items:
113125
if tax_table_selector:
114126
shopping_cart_item.add_tax_table_selector(tax_table_selector)
115127
self.add_item(shopping_cart_item)
@@ -132,7 +144,7 @@ def refund_by_merchant_item_id(
132144
InvalidArgumentException: If no items are provided or the item is not found.
133145
134146
"""
135-
if len(self.items) < 1:
147+
if self.items is None or len(self.items) < 1:
136148
raise InvalidArgumentException(
137149
"No items provided in checkout data",
138150
)
@@ -167,6 +179,11 @@ def get_item_by_merchant_item_id(
167179
InvalidArgumentException: If no item is found with the given merchant item ID.
168180
169181
"""
182+
if self.items is None:
183+
raise InvalidArgumentException(
184+
"No items provided in checkout data",
185+
)
186+
170187
for item in self.items:
171188
if item.merchant_item_id == merchant_item_id:
172189
return item

src/multisafepay/api/paths/orders/order_id/refund/request/refund_request.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class RefundOrderRequest(RequestModel):
3838

3939
def add_currency(
4040
self: "RefundOrderRequest",
41-
currency: Union[Currency, str],
41+
currency: Optional[Union[Currency, str]],
4242
) -> "RefundOrderRequest":
4343
"""
4444
Adds the currency to the refund request.
4545
4646
Parameters
4747
----------
48-
currency (Currency | str): The currency to add.
48+
currency (Optional[Currency | str]): The currency to add.
4949
5050
Returns
5151
-------
@@ -54,19 +54,19 @@ def add_currency(
5454
"""
5555
if isinstance(currency, str):
5656
currency = Currency(currency=currency)
57-
self.currency = currency.get()
57+
self.currency = currency.get() if currency is not None else None
5858
return self
5959

6060
def add_amount(
6161
self: "RefundOrderRequest",
62-
amount: Union[Amount, int],
62+
amount: Optional[Union[Amount, int]],
6363
) -> "RefundOrderRequest":
6464
"""
6565
Adds the amount to the refund request.
6666
6767
Parameters
6868
----------
69-
amount (Amount | int): The amount to add.
69+
amount (Optional[Amount | int]): The amount to add.
7070
7171
Returns
7272
-------
@@ -75,19 +75,19 @@ def add_amount(
7575
"""
7676
if isinstance(amount, int):
7777
amount = Amount(amount=amount)
78-
self.amount = amount.get()
78+
self.amount = amount.get() if amount is not None else None
7979
return self
8080

8181
def add_description(
8282
self: "RefundOrderRequest",
83-
description: Union[Description, str],
83+
description: Optional[Union[Description, str]],
8484
) -> "RefundOrderRequest":
8585
"""
8686
Adds the description to the refund request.
8787
8888
Parameters
8989
----------
90-
description (Description | str): The description to add.
90+
description (Optional[Description | str]): The description to add.
9191
9292
Returns
9393
-------
@@ -96,19 +96,21 @@ def add_description(
9696
"""
9797
if isinstance(description, str):
9898
description = Description(description=description)
99-
self.description = description.get()
99+
self.description = (
100+
description.get() if description is not None else None
101+
)
100102
return self
101103

102104
def add_checkout_data(
103105
self: "RefundOrderRequest",
104-
checkout_data: CheckoutData,
106+
checkout_data: Optional[CheckoutData],
105107
) -> "RefundOrderRequest":
106108
"""
107109
Adds the checkout data to the refund request.
108110
109111
Parameters
110112
----------
111-
checkout_data (CheckoutData): The checkout data to add.
113+
checkout_data (Optional[CheckoutData]): The checkout data to add.
112114
113115
Returns
114116
-------

0 commit comments

Comments
 (0)