Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simulator API Support #74

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

davidgrayston-paddle
Copy link
Contributor

@davidgrayston-paddle davidgrayston-paddle commented Nov 19, 2024

Added

  • Added simulation API support related changelog
    • Client.simulations.create
    • Client.simulations.update
    • Client.simulations.get
    • Client.simulations.list
    • Client.simulation_runs.create
    • Client.simulation_runs.get
    • Client.simulation_runs.list
    • Client.simulation_run_events.replay
    • Client.simulation_run_events.get
    • Client.simulation_run_events.list
    • Client.simulation_types.list

from paddle_billing.Resources.Subscriptions.SubscriptionsClient import SubscriptionsClient
from paddle_billing.Resources.Transactions.TransactionsClient import TransactionsClient


class PayloadEncoder(JSONEncoder):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PayloadEncoder was becoming more complex, so have moved out into paddle_billing.Json

@@ -0,0 +1,6 @@
def json_format_properties(properties: list[str]):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decorator to avoid formatting every JSON key during encoding (in next major release we could fix the related camel case properties and remove this)

@@ -0,0 +1,6 @@
def json_exclude(properties: list[str]):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decorator to exclude properties that should not be included in JSON payloads.



# Prevents circular import
from paddle_billing.Entities.Product import Product # noqa E402
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle_billing.Entities.Product is not referenced in this file (can reinstate if it's still needed)

@@ -16,7 +18,7 @@ class Product(Entity):
image_url: str | None
custom_data: CustomData | None = None
import_meta: ImportMeta | None = None
prices: list[Price] | None = None
prices: list[Price] | None = None # Deprecated: prices are not included in product notifications.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to remove this in next major version

@@ -71,7 +71,7 @@ def from_dict(data: dict) -> SubscriptionCreated:
paused_at=datetime.fromisoformat(data["paused_at"]) if data.get("paused_at") else None,
started_at=datetime.fromisoformat(data["started_at"]) if data.get("started_at") else None,
current_billing_period=(
TimePeriod.from_dict(data["current_billing_period"]) if data.get("billing_details") else None
TimePeriod.from_dict(data["current_billing_period"]) if data.get("current_billing_period") else None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix (included in changelog)

@@ -11,6 +13,7 @@


@dataclass
@json_format_properties(["lineItems"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can rename this property to line_items in next major version.

class TransactionItem:
price_id: str | None
price_id: str | None # Deprecated: price_id is no longer returned on transaction items.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this property in next major version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Payload fixtures copied from existing event unit test fixtures as some needed to be adjusted for comparison with JSON encoded result (timestamp formats / some properties needed to be set to null)

@@ -29,4 +29,8 @@ def read_json_fixture(fixture: str, base_path: str | None = None):
"""
Reads a JSON fixture file and returns its contents as a dictionary.
"""
if base_path is None:
caller_file = stack()[1].filename
base_path = Path(caller_file).parent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_raw_json_fixture wasn't resolving base_path correctly when called from read_json_fixture as it's based on the caller file path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant