swarmauri_billing_adyen 0.9.3.dev3__tar.gz → 0.11.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_billing_adyen
3
+ Version: 0.11.0.dev1
4
+ Summary: Adyen Checkout API backed Swarmauri billing provider for hosted sessions, payments, captures, cancels, refunds, and webhook validation.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,billing,adyen,adyen billing provider,adyen payments,community,payments,payment gateway,checkout,hosted checkout,adyen checkout api,payment sessions,captures,cancellations,recurring billing,subscription management,invoicing,refunds,webhooks,marketplace payments,webhook hmac validation,merchant services,e-commerce integration
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
10
+ Requires-Python: >=3.10,<3.15
11
+ Classifier: Development Status :: 1 - Planning
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Topic :: Internet :: WWW/HTTP
17
+ Classifier: Topic :: Office/Business :: Financial
18
+ Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
19
+ Classifier: Topic :: Software Development :: Libraries
20
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Classifier: Programming Language :: Python
23
+ Classifier: Programming Language :: Python :: 3
24
+ Classifier: Programming Language :: Python :: 3 :: Only
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Programming Language :: Python :: 3.13
29
+ Classifier: Programming Language :: Python :: 3.14
30
+ Requires-Dist: httpx (>=0.27)
31
+ Requires-Dist: swarmauri_base
32
+ Requires-Dist: swarmauri_core
33
+ Description-Content-Type: text/markdown
34
+
35
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
36
+
37
+ <p align="center">
38
+ <a href="https://pepy.tech/project/swarmauri_billing_adyen/">
39
+ <img src="https://static.pepy.tech/badge/swarmauri_billing_adyen/month" alt="PyPI - Downloads"/></a>
40
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen/">
41
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen.svg"/></a>
42
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
43
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
44
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
45
+ <img src="https://img.shields.io/pypi/l/swarmauri_billing_adyen" alt="PyPI - License"/></a>
46
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
47
+ <img src="https://img.shields.io/pypi/v/swarmauri_billing_adyen?label=swarmauri_billing_adyen&color=green" alt="PyPI - swarmauri_billing_adyen"/></a>
48
+ <a href="https://discord.gg/N4UpBuQv8T">
49
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
50
+
51
+ # Swarmauri Billing Adyen
52
+
53
+ `swarmauri_billing_adyen` provides an Adyen Checkout API backed billing provider for the Swarmauri SDK. It connects Swarmauri billing interfaces to Adyen hosted sessions, `/payments`, captures, cancels, refunds, notification parsing, and HMAC webhook validation.
54
+
55
+ ## Why Swarmauri Billing Adyen?
56
+
57
+ `swarmauri_billing_adyen` gives billing integrators an Adyen payment provider behind Swarmauri billing interfaces. Applications can create Adyen Checkout Sessions, submit payment requests, capture or cancel authorized payments, refund payments, and validate Adyen notifications without coupling the rest of the codebase to Adyen request payloads.
58
+
59
+ ## FAQ
60
+
61
+ ### Q: Does this package call Adyen APIs?
62
+
63
+ A: Yes for payment-oriented flows. Checkout sessions, payments, captures, cancels, and refunds call Adyen Checkout API endpoints using `X-API-Key` authentication. Some non-payment Swarmauri mixins remain local placeholders where Adyen has no direct one-to-one Checkout API object.
64
+
65
+ ### Q: Which capabilities does it advertise?
66
+
67
+ A: The runtime-backed paths cover hosted checkout, online payments, capture, cancel, refunds, notification parsing, and webhook HMAC validation. The package still exposes the broader Swarmauri billing surface for compatibility.
68
+
69
+ ### Q: When should I use this package?
70
+
71
+ A: Use it when a Swarmauri application needs Adyen Checkout payment flows while preserving provider-neutral billing interfaces.
72
+
73
+ ## Features
74
+
75
+ - Adyen provider class registered as `AdyenBillingProvider`.
76
+ - Hosted Checkout Session creation through Adyen `/sessions`.
77
+ - Payment submission through Adyen `/payments`.
78
+ - Capture, cancel, and refund calls through Adyen payment modification endpoints.
79
+ - Adyen notification parsing for `notificationItems` payloads.
80
+ - HMAC webhook verification using Adyen notification signing fields.
81
+ - Compatibility placeholders for Swarmauri billing mixins that do not have direct Adyen Checkout API equivalents.
82
+ - Supports serialization through `swarmauri_base.billing.BillingProviderBase`.
83
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
84
+
85
+ ## Installation
86
+
87
+ Install with `uv`:
88
+
89
+ ```bash
90
+ uv add swarmauri_billing_adyen
91
+ ```
92
+
93
+ Install with `pip`:
94
+
95
+ ```bash
96
+ pip install swarmauri_billing_adyen
97
+ ```
98
+
99
+ ## Usage
100
+
101
+ Create a product, price, and hosted checkout session:
102
+
103
+ ```python
104
+ from swarmauri_billing_adyen import AdyenBillingProvider
105
+ from swarmauri_base.billing import CheckoutRequest, PriceSpec, ProductSpec
106
+
107
+ provider = AdyenBillingProvider(
108
+ api_key="adyen-test-key",
109
+ merchant_account="YourMerchantAccount",
110
+ )
111
+
112
+ product = provider.create_product(
113
+ ProductSpec(name="Enterprise Plan"),
114
+ idempotency_key="prod-ady-1",
115
+ )
116
+ price = provider.create_price(
117
+ product,
118
+ PriceSpec(currency="USD", unit_amount_minor=49900),
119
+ idempotency_key="price-ady-1",
120
+ )
121
+ checkout = provider.create_checkout(
122
+ price,
123
+ CheckoutRequest(success_url="https://merchant.example/success"),
124
+ )
125
+
126
+ print(product.id, price.id, checkout.id)
127
+ ```
128
+
129
+ Inspect provider capabilities:
130
+
131
+ ```python
132
+ from swarmauri_billing_adyen import AdyenBillingProvider
133
+
134
+ provider = AdyenBillingProvider(api_key="adyen-test-key")
135
+ capabilities = sorted(cap.value for cap in provider.capabilities)
136
+
137
+ print(capabilities)
138
+ ```
139
+
140
+ Serialize provider configuration:
141
+
142
+ ```python
143
+ provider = AdyenBillingProvider(api_key="adyen-test-key", timeout=10.0)
144
+ payload = provider.model_dump_json()
145
+ restored = AdyenBillingProvider.model_validate_json(payload)
146
+
147
+ assert restored.api_key == provider.api_key
148
+ ```
149
+
150
+ ## Important Scope Notes
151
+
152
+ This package uses live Adyen Checkout API calls for payment-oriented workflows. Product, price, subscription, invoice, customer, payout, report, coupon, and promotion methods remain compatibility placeholders where Adyen Checkout does not expose a direct object matching the Swarmauri billing interface. Production use requires a valid `merchant_account`, an Adyen API key, correct test/live environment selection, and a live URL prefix for production.
153
+
154
+ ## Entry Point
155
+
156
+ The package exposes a Swarmauri billing provider entry point:
157
+
158
+ ```toml
159
+ [project.entry-points.'swarmauri.billing_providers']
160
+ AdyenBillingProvider = "swarmauri_billing_adyen.provider:AdyenBillingProvider"
161
+ ```
162
+
163
+ ## Related Packages
164
+
165
+ Billing provider packages:
166
+
167
+ - [swarmauri_billing_stripe](https://pypi.org/project/swarmauri_billing_stripe/)
168
+ - [swarmauri_billing_mock](https://pypi.org/project/swarmauri_billing_mock/)
169
+ - [swarmauri_billing_paypal](https://pypi.org/project/swarmauri_billing_paypal/)
170
+ - [swarmauri_billing_square](https://pypi.org/project/swarmauri_billing_square/)
171
+ - [swarmauri_billing_braintree](https://pypi.org/project/swarmauri_billing_braintree/)
172
+ - [swarmauri_billing_authorize_net](https://pypi.org/project/swarmauri_billing_authorize_net/)
173
+ - [swarmauri_billing_paystack](https://pypi.org/project/swarmauri_billing_paystack/)
174
+ - [swarmauri_billing_razorpay](https://pypi.org/project/swarmauri_billing_razorpay/)
175
+
176
+ Foundational packages:
177
+
178
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines the billing capability and protocol interfaces.
179
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides billing refs, specs, mixins, and `BillingProviderBase`.
180
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace and plugin discovery.
181
+
182
+ ## License
183
+
184
+ Apache-2.0
185
+
186
+ ## Contributing
187
+
188
+ Community contributions are welcome. Keep behavior deterministic unless adding an explicitly documented live-client mode, preserve the Swarmauri billing interfaces, and add tests for new billing capability methods.
189
+
190
+
191
+
@@ -0,0 +1,156 @@
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
+
3
+ <p align="center">
4
+ <a href="https://pepy.tech/project/swarmauri_billing_adyen/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_billing_adyen/month" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
9
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_billing_adyen" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_billing_adyen/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_billing_adyen?label=swarmauri_billing_adyen&color=green" alt="PyPI - swarmauri_billing_adyen"/></a>
14
+ <a href="https://discord.gg/N4UpBuQv8T">
15
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
16
+
17
+ # Swarmauri Billing Adyen
18
+
19
+ `swarmauri_billing_adyen` provides an Adyen Checkout API backed billing provider for the Swarmauri SDK. It connects Swarmauri billing interfaces to Adyen hosted sessions, `/payments`, captures, cancels, refunds, notification parsing, and HMAC webhook validation.
20
+
21
+ ## Why Swarmauri Billing Adyen?
22
+
23
+ `swarmauri_billing_adyen` gives billing integrators an Adyen payment provider behind Swarmauri billing interfaces. Applications can create Adyen Checkout Sessions, submit payment requests, capture or cancel authorized payments, refund payments, and validate Adyen notifications without coupling the rest of the codebase to Adyen request payloads.
24
+
25
+ ## FAQ
26
+
27
+ ### Q: Does this package call Adyen APIs?
28
+
29
+ A: Yes for payment-oriented flows. Checkout sessions, payments, captures, cancels, and refunds call Adyen Checkout API endpoints using `X-API-Key` authentication. Some non-payment Swarmauri mixins remain local placeholders where Adyen has no direct one-to-one Checkout API object.
30
+
31
+ ### Q: Which capabilities does it advertise?
32
+
33
+ A: The runtime-backed paths cover hosted checkout, online payments, capture, cancel, refunds, notification parsing, and webhook HMAC validation. The package still exposes the broader Swarmauri billing surface for compatibility.
34
+
35
+ ### Q: When should I use this package?
36
+
37
+ A: Use it when a Swarmauri application needs Adyen Checkout payment flows while preserving provider-neutral billing interfaces.
38
+
39
+ ## Features
40
+
41
+ - Adyen provider class registered as `AdyenBillingProvider`.
42
+ - Hosted Checkout Session creation through Adyen `/sessions`.
43
+ - Payment submission through Adyen `/payments`.
44
+ - Capture, cancel, and refund calls through Adyen payment modification endpoints.
45
+ - Adyen notification parsing for `notificationItems` payloads.
46
+ - HMAC webhook verification using Adyen notification signing fields.
47
+ - Compatibility placeholders for Swarmauri billing mixins that do not have direct Adyen Checkout API equivalents.
48
+ - Supports serialization through `swarmauri_base.billing.BillingProviderBase`.
49
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
50
+
51
+ ## Installation
52
+
53
+ Install with `uv`:
54
+
55
+ ```bash
56
+ uv add swarmauri_billing_adyen
57
+ ```
58
+
59
+ Install with `pip`:
60
+
61
+ ```bash
62
+ pip install swarmauri_billing_adyen
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ Create a product, price, and hosted checkout session:
68
+
69
+ ```python
70
+ from swarmauri_billing_adyen import AdyenBillingProvider
71
+ from swarmauri_base.billing import CheckoutRequest, PriceSpec, ProductSpec
72
+
73
+ provider = AdyenBillingProvider(
74
+ api_key="adyen-test-key",
75
+ merchant_account="YourMerchantAccount",
76
+ )
77
+
78
+ product = provider.create_product(
79
+ ProductSpec(name="Enterprise Plan"),
80
+ idempotency_key="prod-ady-1",
81
+ )
82
+ price = provider.create_price(
83
+ product,
84
+ PriceSpec(currency="USD", unit_amount_minor=49900),
85
+ idempotency_key="price-ady-1",
86
+ )
87
+ checkout = provider.create_checkout(
88
+ price,
89
+ CheckoutRequest(success_url="https://merchant.example/success"),
90
+ )
91
+
92
+ print(product.id, price.id, checkout.id)
93
+ ```
94
+
95
+ Inspect provider capabilities:
96
+
97
+ ```python
98
+ from swarmauri_billing_adyen import AdyenBillingProvider
99
+
100
+ provider = AdyenBillingProvider(api_key="adyen-test-key")
101
+ capabilities = sorted(cap.value for cap in provider.capabilities)
102
+
103
+ print(capabilities)
104
+ ```
105
+
106
+ Serialize provider configuration:
107
+
108
+ ```python
109
+ provider = AdyenBillingProvider(api_key="adyen-test-key", timeout=10.0)
110
+ payload = provider.model_dump_json()
111
+ restored = AdyenBillingProvider.model_validate_json(payload)
112
+
113
+ assert restored.api_key == provider.api_key
114
+ ```
115
+
116
+ ## Important Scope Notes
117
+
118
+ This package uses live Adyen Checkout API calls for payment-oriented workflows. Product, price, subscription, invoice, customer, payout, report, coupon, and promotion methods remain compatibility placeholders where Adyen Checkout does not expose a direct object matching the Swarmauri billing interface. Production use requires a valid `merchant_account`, an Adyen API key, correct test/live environment selection, and a live URL prefix for production.
119
+
120
+ ## Entry Point
121
+
122
+ The package exposes a Swarmauri billing provider entry point:
123
+
124
+ ```toml
125
+ [project.entry-points.'swarmauri.billing_providers']
126
+ AdyenBillingProvider = "swarmauri_billing_adyen.provider:AdyenBillingProvider"
127
+ ```
128
+
129
+ ## Related Packages
130
+
131
+ Billing provider packages:
132
+
133
+ - [swarmauri_billing_stripe](https://pypi.org/project/swarmauri_billing_stripe/)
134
+ - [swarmauri_billing_mock](https://pypi.org/project/swarmauri_billing_mock/)
135
+ - [swarmauri_billing_paypal](https://pypi.org/project/swarmauri_billing_paypal/)
136
+ - [swarmauri_billing_square](https://pypi.org/project/swarmauri_billing_square/)
137
+ - [swarmauri_billing_braintree](https://pypi.org/project/swarmauri_billing_braintree/)
138
+ - [swarmauri_billing_authorize_net](https://pypi.org/project/swarmauri_billing_authorize_net/)
139
+ - [swarmauri_billing_paystack](https://pypi.org/project/swarmauri_billing_paystack/)
140
+ - [swarmauri_billing_razorpay](https://pypi.org/project/swarmauri_billing_razorpay/)
141
+
142
+ Foundational packages:
143
+
144
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines the billing capability and protocol interfaces.
145
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides billing refs, specs, mixins, and `BillingProviderBase`.
146
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace and plugin discovery.
147
+
148
+ ## License
149
+
150
+ Apache-2.0
151
+
152
+ ## Contributing
153
+
154
+ Community contributions are welcome. Keep behavior deterministic unless adding an explicitly documented live-client mode, preserve the Swarmauri billing interfaces, and add tests for new billing capability methods.
155
+
156
+
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "swarmauri_billing_adyen"
3
- version = "0.9.3.dev3"
4
- description = "Adyen billing provider for the Swarmauri SDK."
3
+ version = "0.11.0.dev1"
4
+ description = "Adyen Checkout API backed Swarmauri billing provider for hosted sessions, payments, captures, cancels, refunds, and webhook validation."
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
7
  repository = "http://github.com/swarmauri/swarmauri-sdk"
@@ -12,8 +12,12 @@ classifiers = [
12
12
  "Intended Audience :: Information Technology",
13
13
  "License :: OSI Approved :: Apache Software License",
14
14
  "Operating System :: OS Independent",
15
+ "Topic :: Internet :: WWW/HTTP",
16
+ "Topic :: Office/Business :: Financial",
15
17
  "Topic :: Office/Business :: Financial :: Point-Of-Sale",
18
+ "Topic :: Software Development :: Libraries",
16
19
  "Topic :: Software Development :: Libraries :: Application Frameworks",
20
+ "Topic :: Software Development :: Testing",
17
21
  "Programming Language :: Python",
18
22
  "Programming Language :: Python :: 3",
19
23
  "Programming Language :: Python :: 3 :: Only",
@@ -27,17 +31,31 @@ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
27
31
  dependencies = [
28
32
  "swarmauri_core",
29
33
  "swarmauri_base",
34
+ "httpx>=0.27",
30
35
  ]
31
36
  keywords = [
32
37
  "swarmauri",
33
38
  "sdk",
34
39
  "billing",
35
40
  "adyen",
41
+ "adyen billing provider",
42
+ "adyen payments",
36
43
  "community",
37
44
  "payments",
38
45
  "payment gateway",
46
+ "checkout",
47
+ "hosted checkout",
48
+ "adyen checkout api",
49
+ "payment sessions",
50
+ "captures",
51
+ "cancellations",
39
52
  "recurring billing",
40
53
  "subscription management",
54
+ "invoicing",
55
+ "refunds",
56
+ "webhooks",
57
+ "marketplace payments",
58
+ "webhook hmac validation",
41
59
  "merchant services",
42
60
  "e-commerce integration",
43
61
  ]
@@ -80,7 +98,7 @@ dev = [
80
98
  "pytest-xdist>=3.6.1",
81
99
  "pytest-json-report>=1.5.0",
82
100
  "python-dotenv",
83
- "requests>=2.32.3",
101
+ "httpx>=0.27",
84
102
  "flake8>=7.0",
85
103
  "pytest-timeout>=2.3.1",
86
104
  "ruff>=0.9.9",
@@ -2,9 +2,16 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import base64
6
+ import hashlib
7
+ import hmac
8
+ import json
5
9
  from typing import Any, Mapping, Optional, Sequence
6
10
  from uuid import uuid4
7
11
 
12
+ import httpx
13
+ from pydantic import Field
14
+
8
15
  from swarmauri_base.billing import (
9
16
  BalanceTransfersMixin,
10
17
  BillingProviderBase,
@@ -44,9 +51,61 @@ class AdyenBillingProvider(
44
51
  PromotionsMixin,
45
52
  BillingProviderBase,
46
53
  ):
47
- """Example Adyen provider returning deterministic stubbed responses."""
54
+ """
55
+ Adyen Checkout API backed provider for payment-oriented billing flows.
56
+ """
48
57
 
49
58
  CAPABILITIES = ALL_CAPABILITIES
59
+ component_name: str = "adyen"
60
+ merchant_account: str | None = Field(
61
+ default=None,
62
+ description="Adyen merchant account used for Checkout httpx.",
63
+ )
64
+ environment: str = Field(default="test", description="Adyen environment")
65
+ live_url_prefix: str | None = Field(
66
+ default=None,
67
+ description="Adyen live URL prefix for production httpx.",
68
+ )
69
+ api_version: str = Field(
70
+ default="v71", description="Adyen Checkout API version"
71
+ )
72
+
73
+ @property
74
+ def _checkout_url(self) -> str:
75
+ if self.base_url:
76
+ return self.base_url.rstrip("/")
77
+ if self.environment.lower() == "live":
78
+ if not self.live_url_prefix:
79
+ raise ValueError(
80
+ "Adyen live environment requires live_url_prefix"
81
+ )
82
+ return f"https://{self.live_url_prefix}-checkout-live.adyenpayments.com/checkout/{self.api_version}"
83
+ return f"https://checkout-test.adyen.com/{self.api_version}"
84
+
85
+ def _post(
86
+ self, path: str, payload: Mapping[str, Any]
87
+ ) -> Mapping[str, Any]:
88
+ response = httpx.post(
89
+ f"{self._checkout_url}/{path.lstrip('/')}",
90
+ headers={
91
+ "X-API-Key": self.api_key,
92
+ "Content-Type": "application/json",
93
+ },
94
+ json=dict(payload),
95
+ timeout=self.timeout,
96
+ )
97
+ if response.status_code >= 400:
98
+ raise RuntimeError(
99
+ f"Adyen API error {response.status_code}: {response.text}"
100
+ )
101
+ return response.json() if response.content else {}
102
+
103
+ def _merchant(self) -> str:
104
+ if not self.merchant_account:
105
+ raise ValueError(
106
+ "merchant_account is required for live Adyen API calls"
107
+ )
108
+ return self.merchant_account
50
109
 
51
110
  def _stub(self, action: str, **payload: Any) -> Mapping[str, Any]:
52
111
  return {
@@ -56,7 +115,8 @@ class AdyenBillingProvider(
56
115
  "payload": payload,
57
116
  }
58
117
 
59
- # ---------------------------------------------------------------- Products & Prices
118
+ # ---------------------------------------------------------------- Products
119
+ # & Prices
60
120
  def _create_product(
61
121
  self, product_spec: Any, *, idempotency_key: str
62
122
  ) -> Mapping[str, Any]:
@@ -83,34 +143,96 @@ class AdyenBillingProvider(
83
143
  }
84
144
  return result
85
145
 
86
- # ---------------------------------------------------------------- Hosted Checkout
146
+ # ---------------------------------------------------------------- Hosted
147
+ # Checkout
87
148
  def _create_checkout(self, price: Any, request: Any) -> Mapping[str, Any]:
149
+ amount_minor = getattr(
150
+ price, "unit_amount_minor", None
151
+ ) or price.raw.get("amount", {}).get("value")
152
+ currency = getattr(price, "currency", None) or price.raw.get(
153
+ "amount", {}
154
+ ).get("currency", "USD")
155
+ payload = {
156
+ "merchantAccount": self._merchant(),
157
+ "reference": request.resolve("idempotency_key")
158
+ or f"chk-{price.id}",
159
+ "amount": {
160
+ "value": int(amount_minor or 0) * int(request.quantity or 1),
161
+ "currency": str(currency).upper(),
162
+ },
163
+ "returnUrl": request.resolve("success_url"),
164
+ "countryCode": request.resolve("country_code", "US"),
165
+ "shopperEmail": request.resolve("customer_email"),
166
+ "metadata": request.resolve("metadata") or None,
167
+ }
168
+ raw = self._post(
169
+ "sessions", {k: v for k, v in payload.items() if v is not None}
170
+ )
88
171
  result = {
89
- "id": f"ady_chk_{uuid4().hex[:10]}",
90
- "url": "https://checkout.adyen.example/session",
91
- "provider": "adyen",
92
- "raw": self._stub("checkout"),
172
+ "id": raw["id"],
173
+ "url": raw.get("url"),
174
+ "provider": self.component_name,
175
+ "raw": raw,
93
176
  }
94
177
  return result
95
178
 
96
- # ---------------------------------------------------------------- Online Payments
179
+ # ---------------------------------------------------------------- Online
180
+ # Payments
97
181
  def _create_payment_intent(self, req: Any) -> Mapping[str, Any]:
182
+ metadata = dict(req.resolve("metadata") or {})
183
+ payment_method = metadata.pop("payment_method", None)
184
+ if not payment_method:
185
+ raise ValueError(
186
+ "Adyen payments require metadata['payment_method']"
187
+ )
188
+ reference = req.resolve("idempotency_key") or f"pay-{uuid4().hex[:12]}"
189
+ payload = {
190
+ "merchantAccount": self._merchant(),
191
+ "reference": reference,
192
+ "amount": {
193
+ "value": int(req.resolve("amount_minor") or 0),
194
+ "currency": str(req.resolve("currency") or "USD").upper(),
195
+ },
196
+ "paymentMethod": payment_method,
197
+ "shopperReference": metadata.pop("shopper_reference", None),
198
+ "shopperInteraction": metadata.pop(
199
+ "shopper_interaction", "Ecommerce"
200
+ ),
201
+ "recurringProcessingModel": metadata.pop(
202
+ "recurring_processing_model", None
203
+ ),
204
+ "returnUrl": metadata.pop("return_url", None),
205
+ "captureDelayHours": 0 if req.resolve("capture") else None,
206
+ "metadata": metadata or None,
207
+ }
208
+ raw = self._post(
209
+ "payments", {k: v for k, v in payload.items() if v is not None}
210
+ )
98
211
  result = {
99
- "id": f"ady_pi_{uuid4().hex[:10]}",
100
- "status": "requires_action",
101
- "provider": "adyen",
102
- "raw": self._stub("payment_intent"),
212
+ "id": raw.get("pspReference") or reference,
213
+ "status": raw.get("resultCode"),
214
+ "amount_minor": req.resolve("amount_minor"),
215
+ "currency": req.resolve("currency"),
216
+ "provider": self.component_name,
217
+ "raw": raw,
103
218
  }
104
219
  return result
105
220
 
106
221
  def _capture_payment(
107
222
  self, payment_id: str, *, idempotency_key: Optional[str] = None
108
223
  ) -> Mapping[str, Any]:
224
+ raw = self._post(
225
+ f"payments/{payment_id}/captures",
226
+ {
227
+ "merchantAccount": self._merchant(),
228
+ "reference": idempotency_key or f"cap-{payment_id}",
229
+ },
230
+ )
109
231
  result = {
110
- "id": payment_id,
111
- "status": "succeeded",
112
- "provider": "adyen",
113
- "raw": self._stub("capture", payment_id=payment_id),
232
+ "id": raw.get("pspReference", payment_id),
233
+ "status": raw.get("status", "received"),
234
+ "provider": self.component_name,
235
+ "raw": raw,
114
236
  }
115
237
  return result
116
238
 
@@ -121,15 +243,23 @@ class AdyenBillingProvider(
121
243
  reason: Optional[str] = None,
122
244
  idempotency_key: Optional[str] = None,
123
245
  ) -> Mapping[str, Any]:
246
+ raw = self._post(
247
+ f"payments/{payment_id}/cancels",
248
+ {
249
+ "merchantAccount": self._merchant(),
250
+ "reference": idempotency_key or f"cancel-{payment_id}",
251
+ },
252
+ )
124
253
  result = {
125
- "id": payment_id,
126
- "status": "canceled",
127
- "provider": "adyen",
128
- "raw": self._stub("cancel", payment_id=payment_id, reason=reason),
254
+ "id": raw.get("pspReference", payment_id),
255
+ "status": raw.get("status", "received"),
256
+ "provider": self.component_name,
257
+ "raw": raw,
129
258
  }
130
259
  return result
131
260
 
132
- # ---------------------------------------------------------------- Subscriptions
261
+ # ----------------------------------------------------------------
262
+ # Subscriptions
133
263
  def _create_subscription(
134
264
  self, spec: Any, *, idempotency_key: str
135
265
  ) -> Mapping[str, Any]:
@@ -152,8 +282,11 @@ class AdyenBillingProvider(
152
282
  }
153
283
  return result
154
284
 
155
- # ---------------------------------------------------------------- Invoicing
156
- def _create_invoice(self, spec: Any, *, idempotency_key: str) -> Mapping[str, Any]:
285
+ # ----------------------------------------------------------------
286
+ # Invoicing
287
+ def _create_invoice(
288
+ self, spec: Any, *, idempotency_key: str
289
+ ) -> Mapping[str, Any]:
157
290
  result = {
158
291
  "invoice_id": f"ady_inv_{uuid4().hex[:8]}",
159
292
  "status": "draft",
@@ -189,8 +322,11 @@ class AdyenBillingProvider(
189
322
  }
190
323
  return result
191
324
 
192
- # ---------------------------------------------------------------- Marketplace
193
- def _create_split(self, spec: Any, *, idempotency_key: str) -> Mapping[str, Any]:
325
+ # ----------------------------------------------------------------
326
+ # Marketplace
327
+ def _create_split(
328
+ self, spec: Any, *, idempotency_key: str
329
+ ) -> Mapping[str, Any]:
194
330
  result = {
195
331
  "split": self._stub("split_create"),
196
332
  "provider": "adyen",
@@ -217,9 +353,40 @@ class AdyenBillingProvider(
217
353
  def _verify_webhook_signature(
218
354
  self, raw_body: bytes, headers: Mapping[str, str], secret: str
219
355
  ) -> bool:
220
- return True
221
-
222
- def _list_disputes(self, *, limit: int = 50) -> Sequence[Mapping[str, Any]]:
356
+ payload = json.loads(raw_body.decode("utf-8"))
357
+ items = payload.get("notificationItems") or []
358
+ if not items:
359
+ return False
360
+ item = items[0].get("NotificationRequestItem", items[0])
361
+ additional = item.get("additionalData") or {}
362
+ signature = additional.get("hmacSignature") or headers.get(
363
+ "HmacSignature", ""
364
+ )
365
+ signing_parts = [
366
+ item.get("pspReference", ""),
367
+ item.get("originalReference", ""),
368
+ item.get("merchantAccountCode", ""),
369
+ item.get("merchantReference", ""),
370
+ str((item.get("amount") or {}).get("value", "")),
371
+ (item.get("amount") or {}).get("currency", ""),
372
+ item.get("eventCode", ""),
373
+ str(item.get("success", "")).lower(),
374
+ ]
375
+ signing_string = ":".join(
376
+ str(part).replace("\\", "\\\\").replace(":", "\\:")
377
+ for part in signing_parts
378
+ )
379
+ digest = hmac.new(
380
+ base64.b64decode(secret),
381
+ signing_string.encode("utf-8"),
382
+ hashlib.sha256,
383
+ ).digest()
384
+ expected = base64.b64encode(digest).decode("ascii")
385
+ return hmac.compare_digest(expected, signature)
386
+
387
+ def _list_disputes(
388
+ self, *, limit: int = 50
389
+ ) -> Sequence[Mapping[str, Any]]:
223
390
  disputes = [
224
391
  {
225
392
  "id": f"ady_dispute_{uuid4().hex[:8]}",
@@ -233,15 +400,39 @@ class AdyenBillingProvider(
233
400
  def _create_refund(
234
401
  self, payment: Any, req: Any, *, idempotency_key: str
235
402
  ) -> Mapping[str, Any]:
236
- result = self._stub("refund_create", idempotency_key=idempotency_key)
403
+ raw = self._post(
404
+ f"payments/{payment.id}/refunds",
405
+ {
406
+ "merchantAccount": self._merchant(),
407
+ "reference": idempotency_key,
408
+ "amount": {
409
+ "value": req.resolve("amount_minor")
410
+ or getattr(payment, "amount_minor", None),
411
+ "currency": (
412
+ req.resolve("currency")
413
+ or getattr(payment, "currency", None)
414
+ or "USD"
415
+ ).upper(),
416
+ },
417
+ },
418
+ )
419
+ result = {
420
+ "id": raw.get("pspReference", payment.id),
421
+ "status": raw.get("status", "received"),
422
+ "provider": self.component_name,
423
+ "raw": raw,
424
+ }
237
425
  return result
238
426
 
239
427
  def _get_refund(self, refund_id: str) -> Mapping[str, Any]:
240
428
  result = self._stub("refund_get", refund_id=refund_id)
241
429
  return result
242
430
 
243
- # ---------------------------------------------------------------- Customers
244
- def _create_customer(self, spec: Any, *, idempotency_key: str) -> Mapping[str, Any]:
431
+ # ----------------------------------------------------------------
432
+ # Customers
433
+ def _create_customer(
434
+ self, spec: Any, *, idempotency_key: str
435
+ ) -> Mapping[str, Any]:
245
436
  result = {
246
437
  "id": f"ady_cus_{uuid4().hex[:8]}",
247
438
  "provider": "adyen",
@@ -267,7 +458,8 @@ class AdyenBillingProvider(
267
458
  )
268
459
  return result
269
460
 
270
- # ---------------------------------------------------------------- Payment Methods
461
+ # ---------------------------------------------------------------- Payment
462
+ # Methods
271
463
  def _create_payment_method(
272
464
  self, spec: Any, *, idempotency_key: str
273
465
  ) -> Mapping[str, Any]:
@@ -278,7 +470,9 @@ class AdyenBillingProvider(
278
470
  }
279
471
  return result
280
472
 
281
- def _detach_payment_method(self, payment_method_id: str) -> Mapping[str, Any]:
473
+ def _detach_payment_method(
474
+ self, payment_method_id: str
475
+ ) -> Mapping[str, Any]:
282
476
  result = self._stub(
283
477
  "payment_method_detach", payment_method_id=payment_method_id
284
478
  )
@@ -301,11 +495,14 @@ class AdyenBillingProvider(
301
495
  return methods
302
496
 
303
497
  # ---------------------------------------------------------------- Payouts
304
- def _create_payout(self, req: Any, *, idempotency_key: str) -> Mapping[str, Any]:
498
+ def _create_payout(
499
+ self, req: Any, *, idempotency_key: str
500
+ ) -> Mapping[str, Any]:
305
501
  result = self._stub("payout_create", idempotency_key=idempotency_key)
306
502
  return result
307
503
 
308
- # ---------------------------------------------------------------- Balance & Transfers
504
+ # ---------------------------------------------------------------- Balance
505
+ # & Transfers
309
506
  def _get_balance(self) -> Mapping[str, Any]:
310
507
  result = {
311
508
  "snapshot_id": f"ady_bal_{uuid4().hex[:6]}",
@@ -314,12 +511,16 @@ class AdyenBillingProvider(
314
511
  }
315
512
  return result
316
513
 
317
- def _create_transfer(self, req: Any, *, idempotency_key: str) -> Mapping[str, Any]:
514
+ def _create_transfer(
515
+ self, req: Any, *, idempotency_key: str
516
+ ) -> Mapping[str, Any]:
318
517
  result = self._stub("transfer_create", idempotency_key=idempotency_key)
319
518
  return result
320
519
 
321
520
  # ---------------------------------------------------------------- Reports
322
- def _create_report(self, req: Any, *, idempotency_key: str) -> Mapping[str, Any]:
521
+ def _create_report(
522
+ self, req: Any, *, idempotency_key: str
523
+ ) -> Mapping[str, Any]:
323
524
  result = self._stub("report_create", idempotency_key=idempotency_key)
324
525
  return result
325
526
 
@@ -327,23 +528,33 @@ class AdyenBillingProvider(
327
528
  def _parse_event(
328
529
  self, raw_body: bytes, headers: Mapping[str, str]
329
530
  ) -> Mapping[str, Any]:
531
+ payload = json.loads(raw_body.decode("utf-8"))
532
+ items = payload.get("notificationItems") or []
533
+ item = (
534
+ items[0].get("NotificationRequestItem", items[0]) if items else {}
535
+ )
330
536
  result = {
331
- "event_id": f"ady_evt_{uuid4().hex[:8]}",
332
- "provider": "adyen",
333
- "type": "AUTHORISATION",
334
- "raw": self._stub("event"),
537
+ "event_id": item.get("pspReference", f"ady_evt_{uuid4().hex[:8]}"),
538
+ "provider": self.component_name,
539
+ "type": item.get("eventCode"),
540
+ "raw": payload,
335
541
  }
336
542
  return result
337
543
 
338
- # ---------------------------------------------------------------- Promotions
339
- def _create_coupon(self, spec: Any, *, idempotency_key: str) -> Mapping[str, Any]:
544
+ # ----------------------------------------------------------------
545
+ # Promotions
546
+ def _create_coupon(
547
+ self, spec: Any, *, idempotency_key: str
548
+ ) -> Mapping[str, Any]:
340
549
  result = self._stub("coupon_create", idempotency_key=idempotency_key)
341
550
  return result
342
551
 
343
552
  def _create_promotion(
344
553
  self, spec: Any, *, idempotency_key: str
345
554
  ) -> Mapping[str, Any]:
346
- result = self._stub("promotion_create", idempotency_key=idempotency_key)
555
+ result = self._stub(
556
+ "promotion_create", idempotency_key=idempotency_key
557
+ )
347
558
  return result
348
559
 
349
560
 
@@ -1,86 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: swarmauri_billing_adyen
3
- Version: 0.9.3.dev3
4
- Summary: Adyen billing provider for the Swarmauri SDK.
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
- Keywords: swarmauri,sdk,billing,adyen,community,payments,payment gateway,recurring billing,subscription management,merchant services,e-commerce integration
8
- Author: Jacob Stewart
9
- Author-email: jacob@swarmauri.com
10
- Requires-Python: >=3.10,<3.15
11
- Classifier: Development Status :: 1 - Planning
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Intended Audience :: Information Technology
14
- Classifier: License :: OSI Approved :: Apache Software License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Topic :: Office/Business :: Financial :: Point-Of-Sale
17
- Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
18
- Classifier: Programming Language :: Python
19
- Classifier: Programming Language :: Python :: 3
20
- Classifier: Programming Language :: Python :: 3 :: Only
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Programming Language :: Python :: 3.13
25
- Classifier: Programming Language :: Python :: 3.14
26
- Requires-Dist: swarmauri_base
27
- Requires-Dist: swarmauri_core
28
- Description-Content-Type: text/markdown
29
-
30
- ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
31
-
32
- <p align="center">
33
- <a href="https://pepy.tech/project/swarmauri_billing_adyen/">
34
- <img src="https://static.pepy.tech/badge/swarmauri_billing_adyen/month" alt="PyPI - Downloads"/></a>
35
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen/">
36
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen.svg"/></a>
37
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
38
- <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
39
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
40
- <img src="https://img.shields.io/pypi/l/swarmauri_billing_adyen" alt="PyPI - License"/></a>
41
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
42
- <img src="https://img.shields.io/pypi/v/swarmauri_billing_adyen?label=swarmauri_billing_adyen&color=green" alt="PyPI - swarmauri_billing_adyen"/></a>
43
- </p>
44
-
45
- # Swarmauri Billing Adyen
46
-
47
- The **Swarmauri Billing Adyen** package provides an Adyen-style billing provider that adheres to the Swarmauri billing interfaces. It mirrors the behaviours of Adyen's platform while returning Pydantic models for simple serialization and testing.
48
-
49
- ## Features
50
-
51
- - ✅ Simulates all Swarmauri billing capabilities for an Adyen-like provider.
52
- - ✅ Generates deterministic webhook events and dispute lists for integration testing.
53
- - ✅ Makes it easy to evaluate tigrbl strategy coverage by mapping `Capability` values.
54
- - ✅ Ships as a ready-made baseline for extending into production-grade Adyen clients.
55
-
56
- ## Installation
57
-
58
- ```bash
59
- pip install swarmauri_billing_adyen
60
- ```
61
-
62
- ```bash
63
- uv add swarmauri_billing_adyen
64
- ```
65
-
66
- ## Usage
67
-
68
- ```python
69
- from swarmauri_billing_adyen import AdyenBillingProvider
70
- from swarmauri_base.billing import CheckoutRequest, ProductSpec
71
-
72
- provider = AdyenBillingProvider(api_key="ady_test_123")
73
- product = provider.create_product(ProductSpec(payload={"name": "Enterprise"}), idempotency_key="prod-ady-1")
74
- checkout = provider.create_checkout(product, CheckoutRequest(payload={"return_url": "https://merchant.example"}))
75
-
76
- print(product.id, checkout.id)
77
- ```
78
-
79
- ## Capability Mapping
80
-
81
- All advertised capabilities come directly from `swarmauri_core.billing.Capability` and can be translated to `tigrbl_billing` requirements via `capabilities_to_tigrbl`.
82
-
83
- ## Contributing
84
-
85
- Community contributions are welcome! Share improvements that better reflect Adyen's API surface or add additional fixtures.
86
-
@@ -1,56 +0,0 @@
1
- ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
-
3
- <p align="center">
4
- <a href="https://pepy.tech/project/swarmauri_billing_adyen/">
5
- <img src="https://static.pepy.tech/badge/swarmauri_billing_adyen/month" alt="PyPI - Downloads"/></a>
6
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen/">
7
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_adyen.svg"/></a>
8
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
9
- <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
11
- <img src="https://img.shields.io/pypi/l/swarmauri_billing_adyen" alt="PyPI - License"/></a>
12
- <a href="https://pypi.org/project/swarmauri_billing_adyen/">
13
- <img src="https://img.shields.io/pypi/v/swarmauri_billing_adyen?label=swarmauri_billing_adyen&color=green" alt="PyPI - swarmauri_billing_adyen"/></a>
14
- </p>
15
-
16
- # Swarmauri Billing Adyen
17
-
18
- The **Swarmauri Billing Adyen** package provides an Adyen-style billing provider that adheres to the Swarmauri billing interfaces. It mirrors the behaviours of Adyen's platform while returning Pydantic models for simple serialization and testing.
19
-
20
- ## Features
21
-
22
- - ✅ Simulates all Swarmauri billing capabilities for an Adyen-like provider.
23
- - ✅ Generates deterministic webhook events and dispute lists for integration testing.
24
- - ✅ Makes it easy to evaluate tigrbl strategy coverage by mapping `Capability` values.
25
- - ✅ Ships as a ready-made baseline for extending into production-grade Adyen clients.
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install swarmauri_billing_adyen
31
- ```
32
-
33
- ```bash
34
- uv add swarmauri_billing_adyen
35
- ```
36
-
37
- ## Usage
38
-
39
- ```python
40
- from swarmauri_billing_adyen import AdyenBillingProvider
41
- from swarmauri_base.billing import CheckoutRequest, ProductSpec
42
-
43
- provider = AdyenBillingProvider(api_key="ady_test_123")
44
- product = provider.create_product(ProductSpec(payload={"name": "Enterprise"}), idempotency_key="prod-ady-1")
45
- checkout = provider.create_checkout(product, CheckoutRequest(payload={"return_url": "https://merchant.example"}))
46
-
47
- print(product.id, checkout.id)
48
- ```
49
-
50
- ## Capability Mapping
51
-
52
- All advertised capabilities come directly from `swarmauri_core.billing.Capability` and can be translated to `tigrbl_billing` requirements via `capabilities_to_tigrbl`.
53
-
54
- ## Contributing
55
-
56
- Community contributions are welcome! Share improvements that better reflect Adyen's API surface or add additional fixtures.