Skip to content

Commit

Permalink
feat: Add support for notification settings traffic source (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle authored Nov 18, 2024
1 parent c1614dc commit 337ee58
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-python-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.

## [Unreleased]

### Added
- Added `traffic_source` property to `paddle_billing.Entities.NotificationSetting` entity

## 1.1.1 - 2024-11-14

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion paddle_billing/Entities/NotificationSetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from paddle_billing.Entities.Entity import Entity
from paddle_billing.Entities.EventType import EventType
from paddle_billing.Entities.NotificationSettings import NotificationSettingType
from paddle_billing.Entities.NotificationSettings import NotificationSettingType, NotificationSettingTrafficSource


@dataclass
Expand All @@ -17,6 +17,7 @@ class NotificationSetting(Entity):
include_sensitive_fields: bool
subscribed_events: list[EventType]
endpoint_secret_key: str
traffic_source: NotificationSettingTrafficSource

@staticmethod
def from_dict(data: dict) -> NotificationSetting:
Expand All @@ -30,4 +31,5 @@ def from_dict(data: dict) -> NotificationSetting:
include_sensitive_fields=data["include_sensitive_fields"],
subscribed_events=[EventType.from_dict(event) for event in data.get("subscribed_events", [])],
endpoint_secret_key=data["endpoint_secret_key"],
traffic_source=NotificationSettingTrafficSource(data["traffic_source"]),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from paddle_billing.PaddleStrEnum import PaddleStrEnum, PaddleStrEnumMeta


class NotificationSettingTrafficSource(PaddleStrEnum, metaclass=PaddleStrEnumMeta):
All: "NotificationSettingTrafficSource" = "all"
Platform: "NotificationSettingTrafficSource" = "platform"
Simulation: "NotificationSettingTrafficSource" = "simulation"
3 changes: 3 additions & 0 deletions paddle_billing/Entities/NotificationSettings/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from paddle_billing.Entities.NotificationSettings.NotificationSettingTrafficSource import (
NotificationSettingTrafficSource,
)
from paddle_billing.Entities.NotificationSettings.NotificationSettingType import NotificationSettingType
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from paddle_billing.Operation import Operation
from paddle_billing.Undefined import Undefined
from paddle_billing.Entities.Events import EventTypeName
from paddle_billing.Entities.NotificationSettings import NotificationSettingType
from paddle_billing.Entities.NotificationSettings import NotificationSettingType, NotificationSettingTrafficSource


@dataclass
Expand All @@ -14,3 +14,4 @@ class CreateNotificationSetting(Operation):
type: NotificationSettingType
include_sensitive_fields: bool
api_version: int | Undefined = Undefined()
traffic_source: NotificationSettingTrafficSource | Undefined = Undefined()
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

from paddle_billing.Resources.Shared.Operations import Pager

from paddle_billing.Entities.NotificationSettings import NotificationSettingTrafficSource


class ListNotificationSettings(HasParameters):
def __init__(
self,
pager: Pager | None = None,
active: bool | None = None,
traffic_source: NotificationSettingTrafficSource | None = None,
):
self.pager = pager
self.active = active
self.traffic_source = traffic_source

def get_parameters(self) -> dict:
parameters = {}
if self.pager:
parameters.update(self.pager.get_parameters())
if self.active is not None:
parameters["active"] = "true" if self.active else "false"
if self.traffic_source is not None:
parameters["traffic_source"] = self.traffic_source.value

return parameters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from paddle_billing.Operation import Operation
from paddle_billing.Undefined import Undefined
from paddle_billing.Entities.Events import EventTypeName
from paddle_billing.Entities.NotificationSettings import NotificationSettingTrafficSource


@dataclass
Expand All @@ -13,3 +14,4 @@ class UpdateNotificationSetting(Operation):
api_version: int | Undefined = Undefined()
include_sensitive_fields: bool | Undefined = Undefined()
subscribed_events: list[EventTypeName] | Undefined = Undefined()
traffic_source: NotificationSettingTrafficSource | Undefined = Undefined()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Slack notifications",
"type": "url",
"destination": "https://hooks.slack.com/example",
"include_sensitive_fields": false,
"subscribed_events": [
"transaction.created"
],
"traffic_source": "all"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Slack notifications",
"type": "url",
"destination": "https://hooks.slack.com/example",
"include_sensitive_fields": false,
"subscribed_events": [
"transaction.created"
],
"traffic_source": "platform"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "Slack notifications",
"type": "url",
"destination": "https://hooks.slack.com/example",
"include_sensitive_fields": false,
"subscribed_events": [
"transaction.created"
],
"traffic_source": "simulation"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"traffic_source": "all"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"traffic_source": "platform"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"traffic_source": "simulation"
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
"meta": {
"request_id": "fd55d51a-6242-4645-8572-af2a8b6f41b6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "all"
},
{
"id": "ntfset_01gkpop8bkm3tm53itgkx6klk7",
Expand Down Expand Up @@ -202,7 +203,27 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
{
"id": "ntfset_02gkpop8bkm3tm53itgkx6klk7",
"description": "Discord notifications",
"type": "url",
"destination": "https://hooks.discord.com/example",
"active": true,
"api_version": 1,
"include_sensitive_fields": false,
"subscribed_events": [
{
"name": "transaction.billed",
"description": "Occurs when a transaction is billed.",
"group": "Transaction",
"available_versions": [1]
}
],
"endpoint_secret_key": "ntfset_02gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "simulation"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "ntfset_01gkpop8bkm3tm53itgkx6klk7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
}
],
"meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"available_versions": [1]
}
],
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI"
"endpoint_secret_key": "pdl_ntfset_01gkpjp8bkm3tm53kdgkx6sms7_6h3qd3uFSi9YCD3OLYAShQI90XTI5vEI",
"traffic_source": "platform"
},
"meta": {
"request_id": "fd55d51a-6242-4645-8572-af2a8b6f41b6"
Expand Down
Loading

0 comments on commit 337ee58

Please sign in to comment.