Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class CaptureOrderRequest(RequestModel):

def add_amount(
self: "CaptureOrderRequest",
amount: Union[Amount, int],
amount: Optional[Union[Amount, int]],
) -> "CaptureOrderRequest":
"""
Adds the amount to the capture request.

Parameters
----------
amount (Amount | int): The amount to add.
amount (Optional[Amount | int]): The amount to add.

Returns
-------
Expand All @@ -57,19 +57,19 @@ def add_amount(
"""
if isinstance(amount, int):
amount = Amount(amount=amount)
self.amount = amount.get()
self.amount = amount.get() if amount is not None else None
return self

def add_new_order_id(
self: "CaptureOrderRequest",
new_order_id: str,
new_order_id: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the new order ID to the capture request.

Parameters
----------
new_order_id (str): The new order ID to add.
new_order_id (Optional[str]): The new order ID to add.

Returns
-------
Expand All @@ -81,14 +81,14 @@ def add_new_order_id(

def add_new_order_status(
self: "CaptureOrderRequest",
new_order_status: str,
new_order_status: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the new order status to the capture request.

Parameters
----------
new_order_status (str): The new order status to add.
new_order_status (Optional[str]): The new order status to add.

Returns
-------
Expand All @@ -100,14 +100,14 @@ def add_new_order_status(

def add_invoice_id(
self: "CaptureOrderRequest",
invoice_id: str,
invoice_id: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the invoice ID to the capture request.

Parameters
----------
invoice_id (str): The invoice ID to add.
invoice_id (Optional[str]): The invoice ID to add.

Returns
-------
Expand All @@ -119,14 +119,14 @@ def add_invoice_id(

def add_carrier(
self: "CaptureOrderRequest",
carrier: str,
carrier: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the carrier information to the capture request.

Parameters
----------
carrier (str): The carrier information to add.
carrier (Optional[str]): The carrier information to add.

Returns
-------
Expand All @@ -138,14 +138,14 @@ def add_carrier(

def add_reason(
self: "CaptureOrderRequest",
reason: str,
reason: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the reason for the capture to the capture request.

Parameters
----------
reason (str): The reason to add.
reason (Optional[str]): The reason to add.

Returns
-------
Expand All @@ -157,14 +157,14 @@ def add_reason(

def add_tracktrace_code(
self: "CaptureOrderRequest",
tracktrace_code: str,
tracktrace_code: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds the tracktrace code to the capture request.

Parameters
----------
tracktrace_code (str): The tracktrace code to add.
tracktrace_code (Optional[str]): The tracktrace code to add.

Returns
-------
Expand All @@ -176,14 +176,14 @@ def add_tracktrace_code(

def add_description(
self: "CaptureOrderRequest",
description: str,
description: Optional[str],
) -> "CaptureOrderRequest":
"""
Adds a description to the capture request.

Parameters
----------
description (str): The description to add.
description (Optional[str]): The description to add.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,63 @@ class CheckoutData(RequestModel):

def add_items(
self: "CheckoutData",
items: List[CartItem] = (),
items: Optional[List[CartItem]] = None,
) -> "CheckoutData":
"""
Adds multiple items to the checkout data.

Parameters
----------
items (List[CartItem]): The list of items to add.
items (Optional[List[CartItem]]): The list of items to add. Defaults to None.

Returns
-------
CheckoutData: The updated checkout data.

"""
if items is None:
return self
if self.items is None:
self.items = []
for item in items:
self.add_item(item)
return self

def add_item(self: "CheckoutData", item: CartItem) -> "CheckoutData":
def add_item(
self: "CheckoutData",
item: Optional[CartItem],
) -> "CheckoutData":
"""
Adds a single item to the checkout data.

Parameters
----------
item (CartItem): The item to add.
item (Optional[CartItem]): The item to add.

Returns
-------
CheckoutData: The updated checkout data.

"""
if item is None:
return self
if self.items is None:
self.items = []
self.items.append(item)
return self

def get_items(self: "CheckoutData") -> List[CartItem]:
def get_items(self: "CheckoutData") -> Optional[List[CartItem]]:
"""
Retrieves all items from the checkout data.

Returns
-------
List[CartItem]: The list of items.
Optional[List[CartItem]]: The list of items, or None if no items exist.

"""
return self.items

def get_item(self: "CheckoutData", index: int) -> CartItem:
def get_item(self: "CheckoutData", index: int) -> Optional[CartItem]:
"""
Retrieves an item by its index from the checkout data.

Expand All @@ -88,28 +95,33 @@ def get_item(self: "CheckoutData", index: int) -> CartItem:

Returns
-------
CartItem: The retrieved item.
Optional[CartItem]: The retrieved item, or None if items is None.

"""
if self.items is None:
return None
return self.items[index]

def generate_from_shopping_cart(
self: "CheckoutData",
shopping_cart: ShoppingCart,
tax_table_selector: str = "",
shopping_cart: Optional[ShoppingCart],
tax_table_selector: Optional[str] = None,
) -> None:
"""
Generates checkout data from a shopping cart.

Parameters
----------
shopping_cart (ShoppingCart): The shopping cart to generate data from.
tax_table_selector (str): The tax table selector to use.
shopping_cart (Optional[ShoppingCart]): The shopping cart to generate data from.
tax_table_selector (Optional[str]): The tax table selector to use.

"""
if shopping_cart is None:
return
for shopping_cart_item in shopping_cart.get_items():
items = shopping_cart.get_items()
if items is None:
return
for shopping_cart_item in items:
if tax_table_selector:
shopping_cart_item.add_tax_table_selector(tax_table_selector)
self.add_item(shopping_cart_item)
Expand All @@ -132,7 +144,7 @@ def refund_by_merchant_item_id(
InvalidArgumentException: If no items are provided or the item is not found.

"""
if len(self.items) < 1:
if self.items is None or len(self.items) < 1:
raise InvalidArgumentException(
"No items provided in checkout data",
)
Expand Down Expand Up @@ -167,6 +179,11 @@ def get_item_by_merchant_item_id(
InvalidArgumentException: If no item is found with the given merchant item ID.

"""
if self.items is None:
raise InvalidArgumentException(
"No items provided in checkout data",
)

for item in self.items:
if item.merchant_item_id == merchant_item_id:
return item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class RefundOrderRequest(RequestModel):

def add_currency(
self: "RefundOrderRequest",
currency: Union[Currency, str],
currency: Optional[Union[Currency, str]],
) -> "RefundOrderRequest":
"""
Adds the currency to the refund request.

Parameters
----------
currency (Currency | str): The currency to add.
currency (Optional[Currency | str]): The currency to add.

Returns
-------
Expand All @@ -54,19 +54,19 @@ def add_currency(
"""
if isinstance(currency, str):
currency = Currency(currency=currency)
self.currency = currency.get()
self.currency = currency.get() if currency is not None else None
return self

def add_amount(
self: "RefundOrderRequest",
amount: Union[Amount, int],
amount: Optional[Union[Amount, int]],
) -> "RefundOrderRequest":
"""
Adds the amount to the refund request.

Parameters
----------
amount (Amount | int): The amount to add.
amount (Optional[Amount | int]): The amount to add.

Returns
-------
Expand All @@ -75,19 +75,19 @@ def add_amount(
"""
if isinstance(amount, int):
amount = Amount(amount=amount)
self.amount = amount.get()
self.amount = amount.get() if amount is not None else None
return self

def add_description(
self: "RefundOrderRequest",
description: Union[Description, str],
description: Optional[Union[Description, str]],
) -> "RefundOrderRequest":
"""
Adds the description to the refund request.

Parameters
----------
description (Description | str): The description to add.
description (Optional[Description | str]): The description to add.

Returns
-------
Expand All @@ -96,19 +96,21 @@ def add_description(
"""
if isinstance(description, str):
description = Description(description=description)
self.description = description.get()
self.description = (
description.get() if description is not None else None
)
return self

def add_checkout_data(
self: "RefundOrderRequest",
checkout_data: CheckoutData,
checkout_data: Optional[CheckoutData],
) -> "RefundOrderRequest":
"""
Adds the checkout data to the refund request.

Parameters
----------
checkout_data (CheckoutData): The checkout data to add.
checkout_data (Optional[CheckoutData]): The checkout data to add.

Returns
-------
Expand Down
Loading