swarmauri_billing_authorize_net 0.1.3.dev2__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,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_billing_authorize_net
3
+ Version: 0.11.0.dev1
4
+ Summary: Authorize.Net JSON API backed Swarmauri billing provider for transactions, captures, voids, refunds, customer profiles, and webhook validation.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,billing,authorize.net,authorize.net billing provider,authorize.net payments,authorize.net json api,community,payments,online payments,payment gateway,card-present,card-not-present,refunds,customer profiles,payment methods,reports,webhooks,webhook hmac validation,merchant services
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_authorize_net/">
39
+ <img src="https://static.pepy.tech/badge/swarmauri_billing_authorize_net/month" alt="PyPI - Downloads"/></a>
40
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net/">
41
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net.svg"/></a>
42
+ <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
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_authorize_net/">
45
+ <img src="https://img.shields.io/pypi/l/swarmauri_billing_authorize_net" alt="PyPI - License"/></a>
46
+ <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
47
+ <img src="https://img.shields.io/pypi/v/swarmauri_billing_authorize_net?label=swarmauri_billing_authorize_net&color=green" alt="PyPI - swarmauri_billing_authorize_net"/></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 Authorize.Net
52
+
53
+ `swarmauri_billing_authorize_net` provides an Authorize.Net JSON API backed billing provider for Swarmauri payment workflows. It connects Swarmauri billing interfaces to Authorize.Net transaction creation, prior-auth capture, voids, refunds, customer profiles, transaction details, webhook parsing, and HMAC-SHA512 webhook validation.
54
+
55
+ ## Why Swarmauri Billing Authorize.Net?
56
+
57
+ `swarmauri_billing_authorize_net` gives billing integrators an Authorize.Net payment provider behind Swarmauri billing interfaces. Applications can authorize, capture, void, refund, create customer profiles, and validate webhook notifications without hard-coding Authorize.Net request payloads throughout the codebase.
58
+
59
+ ## FAQ
60
+
61
+ ### Q: Does this package call Authorize.Net APIs?
62
+
63
+ A: Yes for transaction and customer-profile workflows. It posts JSON requests to Authorize.Net sandbox or production endpoints with merchant authentication.
64
+
65
+ ### Q: Which billing areas does it cover?
66
+
67
+ A: It covers online payments, prior-auth capture, voids, refunds, customer profile create/get, transaction detail lookup for refunds, webhook parsing, and HMAC-SHA512 signature validation. Some payment-method and reporting helpers remain compatibility placeholders.
68
+
69
+ ### Q: What credentials are required?
70
+
71
+ A: Provide `login_id` for the API Login ID and `api_key` for the transaction key. Use `environment="sandbox"` for test accounts and `environment="production"` for live accounts.
72
+
73
+ ## Features
74
+
75
+ - Authorize.Net provider class registered as `AuthorizeNetBillingProvider`.
76
+ - JSON API transaction creation for `authCaptureTransaction` and `authOnlyTransaction`.
77
+ - Prior authorization capture and void transaction support.
78
+ - Refund transaction creation and transaction detail lookup.
79
+ - Customer profile creation and retrieval.
80
+ - HMAC-SHA512 webhook signature validation using `X-ANET-Signature`.
81
+ - Webhook JSON event parsing.
82
+ - Uses Swarmauri billing specs and refs from `swarmauri_base.billing`.
83
+ - Advertises an explicit subset of `swarmauri_core.billing.Capability`.
84
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
85
+
86
+ ## Installation
87
+
88
+ Install with `uv`:
89
+
90
+ ```bash
91
+ uv add swarmauri_billing_authorize_net
92
+ ```
93
+
94
+ Install with `pip`:
95
+
96
+ ```bash
97
+ pip install swarmauri_billing_authorize_net
98
+ ```
99
+
100
+ ## Usage
101
+
102
+ Create and refund an Authorize.Net-style payment:
103
+
104
+ ```python
105
+ from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
106
+ from swarmauri_base.billing import PaymentIntentRequest, RefundRequest
107
+
108
+ provider = AuthorizeNetBillingProvider(
109
+ api_key="authorize-net-transaction-key",
110
+ login_id="authorize-net-login-id",
111
+ )
112
+
113
+ payment = provider.create_payment_intent(
114
+ PaymentIntentRequest(
115
+ amount_minor=4200,
116
+ currency="USD",
117
+ confirm=True,
118
+ metadata={
119
+ "opaque_data": {
120
+ "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
121
+ "dataValue": "opaque-payment-token",
122
+ }
123
+ },
124
+ )
125
+ )
126
+ refund = provider.create_refund(
127
+ payment,
128
+ RefundRequest(amount_minor=4200),
129
+ idempotency_key="refund-anet-1",
130
+ )
131
+
132
+ print(payment.status, refund["id"])
133
+ ```
134
+
135
+ List payment methods for a customer reference:
136
+
137
+ ```python
138
+ from swarmauri_base.billing import CustomerSpec, PaymentMethodSpec
139
+ from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
140
+
141
+ provider = AuthorizeNetBillingProvider(
142
+ api_key="authorize-net-transaction-key",
143
+ login_id="authorize-net-login-id",
144
+ )
145
+ customer = provider.create_customer(
146
+ CustomerSpec(payload={"email": "buyer@example.com"}),
147
+ idempotency_key="customer-anet-1",
148
+ )
149
+ payment_method = provider.create_payment_method(
150
+ PaymentMethodSpec(payload={"type": "credit_card"}),
151
+ idempotency_key="pm-anet-1",
152
+ )
153
+
154
+ provider.attach_payment_method_to_customer(customer, payment_method)
155
+ methods = provider.list_payment_methods(customer, type="credit_card")
156
+
157
+ print(customer.id, len(methods))
158
+ ```
159
+
160
+ ## Important Scope Notes
161
+
162
+ This package uses live Authorize.Net JSON API calls for transaction and customer-profile workflows. Payment data should be supplied through Accept.js opaque data or other compliant tokenized payloads. Do not place raw card data in application code unless your environment is explicitly PCI scoped.
163
+
164
+ ## Entry Point
165
+
166
+ The package exposes a Swarmauri billing provider entry point:
167
+
168
+ ```toml
169
+ [project.entry-points.'swarmauri.billing_providers']
170
+ AuthorizeNetBillingProvider = "swarmauri_billing_authorize_net.provider:AuthorizeNetBillingProvider"
171
+ ```
172
+
173
+ ## Related Packages
174
+
175
+ Billing provider packages:
176
+
177
+ - [swarmauri_billing_adyen](https://pypi.org/project/swarmauri_billing_adyen/)
178
+ - [swarmauri_billing_braintree](https://pypi.org/project/swarmauri_billing_braintree/)
179
+ - [swarmauri_billing_mock](https://pypi.org/project/swarmauri_billing_mock/)
180
+ - [swarmauri_billing_paypal](https://pypi.org/project/swarmauri_billing_paypal/)
181
+ - [swarmauri_billing_paystack](https://pypi.org/project/swarmauri_billing_paystack/)
182
+ - [swarmauri_billing_razorpay](https://pypi.org/project/swarmauri_billing_razorpay/)
183
+ - [swarmauri_billing_square](https://pypi.org/project/swarmauri_billing_square/)
184
+ - [swarmauri_billing_stripe](https://pypi.org/project/swarmauri_billing_stripe/)
185
+
186
+ Foundational packages:
187
+
188
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines billing capabilities and provider interfaces.
189
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides billing specs, refs, mixins, and `BillingProviderBase`.
190
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace imports and plugin discovery.
191
+
192
+ ## License
193
+
194
+ Apache-2.0
195
+
196
+ ## Contributing
197
+
198
+ If you connect this provider to live Authorize.Net APIs, keep the stub behavior separately testable, document required credentials and webhook behavior, and add tests for every supported billing capability.
199
+
200
+
201
+
@@ -0,0 +1,166 @@
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_authorize_net/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_billing_authorize_net/month" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
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_authorize_net/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_billing_authorize_net" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_billing_authorize_net?label=swarmauri_billing_authorize_net&color=green" alt="PyPI - swarmauri_billing_authorize_net"/></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 Authorize.Net
18
+
19
+ `swarmauri_billing_authorize_net` provides an Authorize.Net JSON API backed billing provider for Swarmauri payment workflows. It connects Swarmauri billing interfaces to Authorize.Net transaction creation, prior-auth capture, voids, refunds, customer profiles, transaction details, webhook parsing, and HMAC-SHA512 webhook validation.
20
+
21
+ ## Why Swarmauri Billing Authorize.Net?
22
+
23
+ `swarmauri_billing_authorize_net` gives billing integrators an Authorize.Net payment provider behind Swarmauri billing interfaces. Applications can authorize, capture, void, refund, create customer profiles, and validate webhook notifications without hard-coding Authorize.Net request payloads throughout the codebase.
24
+
25
+ ## FAQ
26
+
27
+ ### Q: Does this package call Authorize.Net APIs?
28
+
29
+ A: Yes for transaction and customer-profile workflows. It posts JSON requests to Authorize.Net sandbox or production endpoints with merchant authentication.
30
+
31
+ ### Q: Which billing areas does it cover?
32
+
33
+ A: It covers online payments, prior-auth capture, voids, refunds, customer profile create/get, transaction detail lookup for refunds, webhook parsing, and HMAC-SHA512 signature validation. Some payment-method and reporting helpers remain compatibility placeholders.
34
+
35
+ ### Q: What credentials are required?
36
+
37
+ A: Provide `login_id` for the API Login ID and `api_key` for the transaction key. Use `environment="sandbox"` for test accounts and `environment="production"` for live accounts.
38
+
39
+ ## Features
40
+
41
+ - Authorize.Net provider class registered as `AuthorizeNetBillingProvider`.
42
+ - JSON API transaction creation for `authCaptureTransaction` and `authOnlyTransaction`.
43
+ - Prior authorization capture and void transaction support.
44
+ - Refund transaction creation and transaction detail lookup.
45
+ - Customer profile creation and retrieval.
46
+ - HMAC-SHA512 webhook signature validation using `X-ANET-Signature`.
47
+ - Webhook JSON event parsing.
48
+ - Uses Swarmauri billing specs and refs from `swarmauri_base.billing`.
49
+ - Advertises an explicit subset of `swarmauri_core.billing.Capability`.
50
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14 support.
51
+
52
+ ## Installation
53
+
54
+ Install with `uv`:
55
+
56
+ ```bash
57
+ uv add swarmauri_billing_authorize_net
58
+ ```
59
+
60
+ Install with `pip`:
61
+
62
+ ```bash
63
+ pip install swarmauri_billing_authorize_net
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ Create and refund an Authorize.Net-style payment:
69
+
70
+ ```python
71
+ from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
72
+ from swarmauri_base.billing import PaymentIntentRequest, RefundRequest
73
+
74
+ provider = AuthorizeNetBillingProvider(
75
+ api_key="authorize-net-transaction-key",
76
+ login_id="authorize-net-login-id",
77
+ )
78
+
79
+ payment = provider.create_payment_intent(
80
+ PaymentIntentRequest(
81
+ amount_minor=4200,
82
+ currency="USD",
83
+ confirm=True,
84
+ metadata={
85
+ "opaque_data": {
86
+ "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
87
+ "dataValue": "opaque-payment-token",
88
+ }
89
+ },
90
+ )
91
+ )
92
+ refund = provider.create_refund(
93
+ payment,
94
+ RefundRequest(amount_minor=4200),
95
+ idempotency_key="refund-anet-1",
96
+ )
97
+
98
+ print(payment.status, refund["id"])
99
+ ```
100
+
101
+ List payment methods for a customer reference:
102
+
103
+ ```python
104
+ from swarmauri_base.billing import CustomerSpec, PaymentMethodSpec
105
+ from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
106
+
107
+ provider = AuthorizeNetBillingProvider(
108
+ api_key="authorize-net-transaction-key",
109
+ login_id="authorize-net-login-id",
110
+ )
111
+ customer = provider.create_customer(
112
+ CustomerSpec(payload={"email": "buyer@example.com"}),
113
+ idempotency_key="customer-anet-1",
114
+ )
115
+ payment_method = provider.create_payment_method(
116
+ PaymentMethodSpec(payload={"type": "credit_card"}),
117
+ idempotency_key="pm-anet-1",
118
+ )
119
+
120
+ provider.attach_payment_method_to_customer(customer, payment_method)
121
+ methods = provider.list_payment_methods(customer, type="credit_card")
122
+
123
+ print(customer.id, len(methods))
124
+ ```
125
+
126
+ ## Important Scope Notes
127
+
128
+ This package uses live Authorize.Net JSON API calls for transaction and customer-profile workflows. Payment data should be supplied through Accept.js opaque data or other compliant tokenized payloads. Do not place raw card data in application code unless your environment is explicitly PCI scoped.
129
+
130
+ ## Entry Point
131
+
132
+ The package exposes a Swarmauri billing provider entry point:
133
+
134
+ ```toml
135
+ [project.entry-points.'swarmauri.billing_providers']
136
+ AuthorizeNetBillingProvider = "swarmauri_billing_authorize_net.provider:AuthorizeNetBillingProvider"
137
+ ```
138
+
139
+ ## Related Packages
140
+
141
+ Billing provider packages:
142
+
143
+ - [swarmauri_billing_adyen](https://pypi.org/project/swarmauri_billing_adyen/)
144
+ - [swarmauri_billing_braintree](https://pypi.org/project/swarmauri_billing_braintree/)
145
+ - [swarmauri_billing_mock](https://pypi.org/project/swarmauri_billing_mock/)
146
+ - [swarmauri_billing_paypal](https://pypi.org/project/swarmauri_billing_paypal/)
147
+ - [swarmauri_billing_paystack](https://pypi.org/project/swarmauri_billing_paystack/)
148
+ - [swarmauri_billing_razorpay](https://pypi.org/project/swarmauri_billing_razorpay/)
149
+ - [swarmauri_billing_square](https://pypi.org/project/swarmauri_billing_square/)
150
+ - [swarmauri_billing_stripe](https://pypi.org/project/swarmauri_billing_stripe/)
151
+
152
+ Foundational packages:
153
+
154
+ - [swarmauri_core](https://pypi.org/project/swarmauri_core/) defines billing capabilities and provider interfaces.
155
+ - [swarmauri_base](https://pypi.org/project/swarmauri_base/) provides billing specs, refs, mixins, and `BillingProviderBase`.
156
+ - [swarmauri](https://pypi.org/project/swarmauri/) provides namespace imports and plugin discovery.
157
+
158
+ ## License
159
+
160
+ Apache-2.0
161
+
162
+ ## Contributing
163
+
164
+ If you connect this provider to live Authorize.Net APIs, keep the stub behavior separately testable, document required credentials and webhook behavior, and add tests for every supported billing capability.
165
+
166
+
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "swarmauri_billing_authorize_net"
3
- version = "0.1.3.dev2"
4
- description = "Authorize.Net billing provider for the Swarmauri SDK."
3
+ version = "0.11.0.dev1"
4
+ description = "Authorize.Net JSON API backed Swarmauri billing provider for transactions, captures, voids, refunds, customer profiles, 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,18 +31,29 @@ 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
  "authorize.net",
36
- "standards",
41
+ "authorize.net billing provider",
42
+ "authorize.net payments",
43
+ "authorize.net json api",
44
+ "community",
37
45
  "payments",
46
+ "online payments",
47
+ "payment gateway",
38
48
  "card-present",
39
49
  "card-not-present",
50
+ "refunds",
51
+ "customer profiles",
52
+ "payment methods",
53
+ "reports",
54
+ "webhooks",
55
+ "webhook hmac validation",
40
56
  "merchant services",
41
- "reporting",
42
57
  ]
43
58
 
44
59
  [tool.uv.sources]
@@ -79,7 +94,7 @@ dev = [
79
94
  "pytest-xdist>=3.6.1",
80
95
  "pytest-json-report>=1.5.0",
81
96
  "python-dotenv",
82
- "requests>=2.32.3",
97
+ "httpx>=0.27",
83
98
  "flake8>=7.0",
84
99
  "pytest-timeout>=2.3.1",
85
100
  "ruff>=0.9.9",
@@ -0,0 +1,411 @@
1
+ """Authorize.Net billing provider for the Swarmauri SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import hmac
7
+ import json
8
+ from typing import Any, Mapping, Optional, Sequence, cast
9
+ from uuid import uuid4
10
+
11
+ import httpx
12
+ from pydantic import Field
13
+
14
+ from swarmauri_base.billing import (
15
+ BillingProviderBase,
16
+ CustomersMixin,
17
+ OnlinePaymentsMixin,
18
+ PaymentMethodsMixin,
19
+ RefundsMixin,
20
+ ReportsMixin,
21
+ RiskMixin,
22
+ WebhooksMixin,
23
+ )
24
+ from swarmauri_core.billing import Capability
25
+
26
+
27
+ class AuthorizeNetBillingProvider(
28
+ OnlinePaymentsMixin,
29
+ RefundsMixin,
30
+ CustomersMixin,
31
+ PaymentMethodsMixin,
32
+ ReportsMixin,
33
+ RiskMixin,
34
+ WebhooksMixin,
35
+ BillingProviderBase,
36
+ ):
37
+ """
38
+ Authorize.Net JSON API provider focusing on card transaction workflows.
39
+ """
40
+
41
+ CAPABILITIES = frozenset(
42
+ {
43
+ Capability.ONLINE_PAYMENTS,
44
+ Capability.REFUNDS,
45
+ Capability.CUSTOMERS,
46
+ Capability.PAYMENT_METHODS,
47
+ Capability.REPORTS,
48
+ Capability.RISK,
49
+ Capability.WEBHOOKS,
50
+ }
51
+ )
52
+ component_name: str = "authorize_net"
53
+ login_id: str | None = Field(
54
+ default=None, description="Authorize.Net API login ID."
55
+ )
56
+ environment: str = Field(
57
+ default="sandbox", description="Authorize.Net environment"
58
+ )
59
+
60
+ @property
61
+ def _endpoint(self) -> str:
62
+ if self.base_url:
63
+ return self.base_url.rstrip("/")
64
+ if self.environment.lower() == "production":
65
+ return "https://api.authorize.net/xml/v1/request.api"
66
+ return "https://apitest.authorize.net/xml/v1/request.api"
67
+
68
+ def _merchant_auth(self) -> Mapping[str, str]:
69
+ if not self.login_id:
70
+ raise ValueError(
71
+ "login_id is required for Authorize.Net API calls"
72
+ )
73
+ return {
74
+ "name": self.login_id,
75
+ "transactionKey": self.api_key,
76
+ }
77
+
78
+ def _post(
79
+ self, request_name: str, payload: Mapping[str, Any]
80
+ ) -> Mapping[str, Any]:
81
+ body = {
82
+ request_name: {
83
+ "merchantAuthentication": self._merchant_auth(),
84
+ **dict(payload),
85
+ }
86
+ }
87
+ response = httpx.post(
88
+ self._endpoint,
89
+ json=body,
90
+ headers={"Content-Type": "application/json"},
91
+ timeout=self.timeout,
92
+ )
93
+ if response.status_code >= 400:
94
+ raise RuntimeError(
95
+ (
96
+ f"Authorize.Net API error {response.status_code}: "
97
+ f"{response.text}"
98
+ )
99
+ )
100
+ raw = response.content.decode("utf-8-sig")
101
+ data = json.loads(raw)
102
+ result = data.get(request_name.replace("Request", "Response"), data)
103
+ messages = result.get("messages", {})
104
+ if messages.get("resultCode") == "Error":
105
+ raise RuntimeError(str(messages.get("message", result)))
106
+ return result
107
+
108
+ # ---------------------------------------------------------------------
109
+ # utils
110
+ @staticmethod
111
+ def _dump(obj: Any) -> Mapping[str, Any]:
112
+ if hasattr(obj, "model_dump"):
113
+ return cast(Mapping[str, Any], obj.model_dump(exclude_none=True))
114
+ if hasattr(obj, "dict"):
115
+ return cast(Mapping[str, Any], obj.dict(exclude_none=True))
116
+ if isinstance(obj, Mapping):
117
+ return obj
118
+ return {}
119
+
120
+ def _stub(self, action: str, **payload: Any) -> Mapping[str, Any]:
121
+ return {
122
+ "provider": self.component_name,
123
+ "action": action,
124
+ "payload": payload,
125
+ }
126
+
127
+ # ----------------------------------------------------------- online
128
+ # payments
129
+ def _create_payment_intent(self, req: Any) -> Mapping[str, Any]:
130
+ amount = int(req.resolve("amount_minor") or 0)
131
+ currency = (req.resolve("currency") or "USD").upper()
132
+ metadata = dict(req.resolve("metadata") or {})
133
+ payment = metadata.get("payment") or metadata.get("opaque_data")
134
+ if not payment:
135
+ raise ValueError(
136
+ (
137
+ "Authorize.Net payments require metadata['payment'] or "
138
+ "metadata['opaque_data']"
139
+ )
140
+ )
141
+ if "dataDescriptor" in payment or "dataValue" in payment:
142
+ payment_payload = {"opaqueData": payment}
143
+ else:
144
+ payment_payload = payment
145
+ raw = self._post(
146
+ "createTransactionRequest",
147
+ {
148
+ "transactionRequest": {
149
+ "transactionType": "authCaptureTransaction"
150
+ if req.resolve("capture")
151
+ else "authOnlyTransaction",
152
+ "amount": f"{amount / 100:.2f}",
153
+ "payment": payment_payload,
154
+ "currencyCode": currency,
155
+ "order": {"invoiceNumber": req.resolve("idempotency_key")}
156
+ if req.resolve("idempotency_key")
157
+ else None,
158
+ }
159
+ },
160
+ )
161
+ transaction = raw.get("transactionResponse", {})
162
+ return {
163
+ "id": str(transaction.get("transId") or uuid4().hex),
164
+ "status": transaction.get("responseCode"),
165
+ "amount_minor": amount,
166
+ "currency": currency,
167
+ "provider": self.component_name,
168
+ "raw": raw,
169
+ }
170
+
171
+ def _capture_payment(
172
+ self, payment_id: str, *, idempotency_key: Optional[str] = None
173
+ ) -> Mapping[str, Any]:
174
+ raw = self._post(
175
+ "createTransactionRequest",
176
+ {
177
+ "transactionRequest": {
178
+ "transactionType": "priorAuthCaptureTransaction",
179
+ "refTransId": payment_id,
180
+ }
181
+ },
182
+ )
183
+ transaction = raw.get("transactionResponse", {})
184
+ return {
185
+ "id": str(transaction.get("transId") or payment_id),
186
+ "status": transaction.get("responseCode"),
187
+ "provider": self.component_name,
188
+ "raw": raw,
189
+ }
190
+
191
+ def _cancel_payment(
192
+ self,
193
+ payment_id: str,
194
+ *,
195
+ reason: Optional[str] = None,
196
+ idempotency_key: Optional[str] = None,
197
+ ) -> Mapping[str, Any]:
198
+ raw = self._post(
199
+ "createTransactionRequest",
200
+ {
201
+ "transactionRequest": {
202
+ "transactionType": "voidTransaction",
203
+ "refTransId": payment_id,
204
+ }
205
+ },
206
+ )
207
+ transaction = raw.get("transactionResponse", {})
208
+ return {
209
+ "id": str(transaction.get("transId") or payment_id),
210
+ "status": transaction.get("responseCode"),
211
+ "provider": self.component_name,
212
+ "raw": raw,
213
+ }
214
+
215
+ # ---------------------------------------------------------------------
216
+ # refund
217
+ def _create_refund(
218
+ self, payment: Any, req: Any, *, idempotency_key: str
219
+ ) -> Mapping[str, Any]:
220
+ metadata = dict(req.resolve("metadata") or {})
221
+ payment_payload = metadata.get("payment") or metadata.get(
222
+ "credit_card"
223
+ )
224
+ if not payment_payload:
225
+ raise ValueError(
226
+ "Authorize.Net refunds require payment card metadata"
227
+ )
228
+ raw = self._post(
229
+ "createTransactionRequest",
230
+ {
231
+ "transactionRequest": {
232
+ "transactionType": "refundTransaction",
233
+ "amount": f"{int(req.resolve('amount_minor') or 0) / 100:.2f}", # noqa: E501
234
+ "payment": payment_payload,
235
+ "refTransId": getattr(payment, "id", ""),
236
+ }
237
+ },
238
+ )
239
+ transaction = raw.get("transactionResponse", {})
240
+ return {
241
+ "id": str(transaction.get("transId") or uuid4().hex),
242
+ "status": transaction.get("responseCode"),
243
+ "provider": self.component_name,
244
+ "raw": raw,
245
+ }
246
+
247
+ def _get_refund(self, refund_id: str) -> Mapping[str, Any]:
248
+ raw = self._post(
249
+ "getTransactionDetailsRequest",
250
+ {"transId": refund_id},
251
+ )
252
+ return {
253
+ "id": refund_id,
254
+ "status": raw.get("transaction", {}).get("transactionStatus"),
255
+ "provider": self.component_name,
256
+ "raw": raw,
257
+ }
258
+
259
+ # -------------------------------------------------------------------
260
+ # customer
261
+ def _create_customer(
262
+ self, spec: Any, *, idempotency_key: str
263
+ ) -> Mapping[str, Any]:
264
+ raw = self._post(
265
+ "createCustomerProfileRequest",
266
+ {
267
+ "profile": {
268
+ "merchantCustomerId": idempotency_key,
269
+ "description": spec.resolve("name", ""),
270
+ "email": spec.resolve("email"),
271
+ }
272
+ },
273
+ )
274
+ return {
275
+ "id": str(raw.get("customerProfileId") or uuid4().hex),
276
+ "provider": self.component_name,
277
+ "raw": raw,
278
+ }
279
+
280
+ def _get_customer(self, customer_id: str) -> Mapping[str, Any]:
281
+ raw = self._post(
282
+ "getCustomerProfileRequest",
283
+ {"customerProfileId": customer_id},
284
+ )
285
+ return {
286
+ "id": customer_id,
287
+ "provider": self.component_name,
288
+ "raw": raw,
289
+ }
290
+
291
+ def _attach_payment_method_to_customer(
292
+ self, customer: Any, pm: Any
293
+ ) -> Mapping[str, Any]:
294
+ return self._stub(
295
+ "attach_payment_method",
296
+ customer_id=getattr(customer, "id", ""),
297
+ payment_method_id=getattr(pm, "id", ""),
298
+ )
299
+
300
+ # --------------------------------------------------------------- payment
301
+ # info
302
+ def _create_payment_method(
303
+ self, spec: Any, *, idempotency_key: str
304
+ ) -> Mapping[str, Any]:
305
+ return {
306
+ "id": f"anet_pm_{uuid4().hex[:10]}",
307
+ "provider": self.component_name,
308
+ "raw": self._stub(
309
+ "create_payment_method",
310
+ idempotency_key=idempotency_key,
311
+ spec=self._dump(spec),
312
+ ),
313
+ }
314
+
315
+ def _detach_payment_method(
316
+ self, payment_method_id: str
317
+ ) -> Mapping[str, Any]:
318
+ return self._stub(
319
+ "detach_payment_method", payment_method_id=payment_method_id
320
+ )
321
+
322
+ def _list_payment_methods(
323
+ self,
324
+ customer: Any,
325
+ *,
326
+ type: Optional[str] = None,
327
+ limit: int = 10,
328
+ ) -> Sequence[Mapping[str, Any]]:
329
+ payment_type = type or "credit_card"
330
+ methods = []
331
+ for index in range(min(limit, 3)):
332
+ methods.append(
333
+ {
334
+ "id": f"anet_pm_{index}",
335
+ "provider": self.component_name,
336
+ "type": payment_type,
337
+ "raw": self._stub(
338
+ "list_payment_methods",
339
+ customer_id=getattr(customer, "id", ""),
340
+ type=payment_type,
341
+ limit=limit,
342
+ ),
343
+ }
344
+ )
345
+ return methods
346
+
347
+ # ---------------------------------------------------------------------
348
+ # reports
349
+ def _create_report(
350
+ self, req: Any, *, idempotency_key: str
351
+ ) -> Mapping[str, Any]:
352
+ return {
353
+ "report_id": f"anet_report_{uuid4().hex[:10]}",
354
+ "status": "QUEUED",
355
+ "provider": self.component_name,
356
+ "raw": self._stub(
357
+ "create_report",
358
+ idempotency_key=idempotency_key,
359
+ request=self._dump(req),
360
+ ),
361
+ }
362
+
363
+ # ------------------------------------------------------------------------
364
+ # risk
365
+ def _verify_webhook_signature(
366
+ self, raw_body: bytes, headers: Mapping[str, str], secret: str
367
+ ) -> bool:
368
+ signature = headers.get("X-ANET-Signature", "")
369
+ if signature.lower().startswith("sha512="):
370
+ signature = signature.split("=", 1)[1]
371
+ digest = hmac.new(
372
+ bytes.fromhex(secret),
373
+ raw_body,
374
+ hashlib.sha512,
375
+ ).hexdigest()
376
+ return hmac.compare_digest(digest.upper(), signature.upper())
377
+
378
+ def _list_disputes(
379
+ self, *, limit: int = 50
380
+ ) -> Sequence[Mapping[str, Any]]:
381
+ if limit <= 0:
382
+ return tuple()
383
+ return (
384
+ {
385
+ "id": "anet_dispute_0",
386
+ "status": "UNDER_REVIEW",
387
+ "provider": self.component_name,
388
+ "raw": self._stub("list_disputes"),
389
+ },
390
+ )
391
+
392
+ # ---------------------------------------------------------------------
393
+ # webhooks
394
+ def _parse_event(
395
+ self, raw_body: bytes, headers: Mapping[str, str]
396
+ ) -> Mapping[str, Any]:
397
+ payload = json.loads(raw_body.decode("utf-8"))
398
+ event_type = payload.get("eventType") or headers.get(
399
+ "X-ANET-Event-Type", "authorize_net.event"
400
+ )
401
+ return {
402
+ "event_id": payload.get(
403
+ "notificationId", f"anet_evt_{uuid4().hex[:10]}"
404
+ ),
405
+ "type": event_type,
406
+ "provider": self.component_name,
407
+ "raw": payload,
408
+ }
409
+
410
+
411
+ __all__ = ["AuthorizeNetBillingProvider"]
@@ -1,95 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: swarmauri_billing_authorize_net
3
- Version: 0.1.3.dev2
4
- Summary: Authorize.Net billing provider for the Swarmauri SDK.
5
- License-Expression: Apache-2.0
6
- License-File: LICENSE
7
- Keywords: swarmauri,sdk,billing,authorize.net,standards,payments,card-present,card-not-present,merchant services,reporting
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_authorize_net/">
34
- <img src="https://static.pepy.tech/badge/swarmauri_billing_authorize_net/month" alt="PyPI - Downloads"/></a>
35
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net/">
36
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net.svg"/></a>
37
- <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
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_authorize_net/">
40
- <img src="https://img.shields.io/pypi/l/swarmauri_billing_authorize_net" alt="PyPI - License"/></a>
41
- <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
42
- <img src="https://img.shields.io/pypi/v/swarmauri_billing_authorize_net?label=swarmauri_billing_authorize_net&color=green" alt="PyPI - swarmauri_billing_authorize_net"/></a>
43
- </p>
44
- ---
45
-
46
- # Swarmauri Billing Authorize.Net
47
-
48
- The **Swarmauri Billing Authorize.Net** package exposes a payments-first provider that mirrors the Authorize.Net API surface inside the Swarmauri SDK. Use it to validate card-not-present flows, refunds, and customer profile operations before you integrate the official SDK.
49
-
50
- ## Features
51
-
52
- - ✅ Focuses on the Authorize.Net core: transactions, refunds, customer profiles, and reporting.
53
- - ✅ Emits deterministic payloads keyed by the provider namespace for straightforward assertions.
54
- - ✅ Provides webhook parsing hooks for signature verification and fraud review flows.
55
- - ✅ Designed as a drop-in replacement that can later call the Authorize.Net XML/JSON APIs.
56
-
57
- ## Installation
58
-
59
- Install from PyPI using either `pip` or `uv`:
60
-
61
- ```bash
62
- pip install swarmauri_billing_authorize_net
63
- ```
64
-
65
- ```bash
66
- uv add swarmauri_billing_authorize_net
67
- ```
68
-
69
- ## Usage
70
-
71
- ```python
72
- from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
73
- from swarmauri_base.billing import PaymentIntentRequest, RefundRequest
74
-
75
- provider = AuthorizeNetBillingProvider(api_key="test-key")
76
-
77
- payment_intent = provider.create_payment_intent(
78
- PaymentIntentRequest(payload={"amount_minor": 4200, "currency": "USD", "confirm": True}),
79
- )
80
- refund = provider.create_refund(
81
- payment_intent,
82
- RefundRequest(payload={"amount_minor": 4200}),
83
- )
84
-
85
- print(payment_intent.status, refund["status"])
86
- ```
87
-
88
- ## Capability Mapping
89
-
90
- Capability metadata maps to `tigrbl_billing` identifiers via `capabilities_to_tigrbl`. That ensures your feature toggles and documentation stay aligned when swapping between this stub and a real Authorize.Net integration.
91
-
92
- ## Contributing
93
-
94
- If you connect the stub to the live Authorize.Net API, please share integration notes, test coverage, and examples in the README to help the community adopt the changes.
95
-
@@ -1,65 +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_authorize_net/">
5
- <img src="https://static.pepy.tech/badge/swarmauri_billing_authorize_net/month" alt="PyPI - Downloads"/></a>
6
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net/">
7
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_billing_authorize_net.svg"/></a>
8
- <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
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_authorize_net/">
11
- <img src="https://img.shields.io/pypi/l/swarmauri_billing_authorize_net" alt="PyPI - License"/></a>
12
- <a href="https://pypi.org/project/swarmauri_billing_authorize_net/">
13
- <img src="https://img.shields.io/pypi/v/swarmauri_billing_authorize_net?label=swarmauri_billing_authorize_net&color=green" alt="PyPI - swarmauri_billing_authorize_net"/></a>
14
- </p>
15
- ---
16
-
17
- # Swarmauri Billing Authorize.Net
18
-
19
- The **Swarmauri Billing Authorize.Net** package exposes a payments-first provider that mirrors the Authorize.Net API surface inside the Swarmauri SDK. Use it to validate card-not-present flows, refunds, and customer profile operations before you integrate the official SDK.
20
-
21
- ## Features
22
-
23
- - ✅ Focuses on the Authorize.Net core: transactions, refunds, customer profiles, and reporting.
24
- - ✅ Emits deterministic payloads keyed by the provider namespace for straightforward assertions.
25
- - ✅ Provides webhook parsing hooks for signature verification and fraud review flows.
26
- - ✅ Designed as a drop-in replacement that can later call the Authorize.Net XML/JSON APIs.
27
-
28
- ## Installation
29
-
30
- Install from PyPI using either `pip` or `uv`:
31
-
32
- ```bash
33
- pip install swarmauri_billing_authorize_net
34
- ```
35
-
36
- ```bash
37
- uv add swarmauri_billing_authorize_net
38
- ```
39
-
40
- ## Usage
41
-
42
- ```python
43
- from swarmauri_billing_authorize_net import AuthorizeNetBillingProvider
44
- from swarmauri_base.billing import PaymentIntentRequest, RefundRequest
45
-
46
- provider = AuthorizeNetBillingProvider(api_key="test-key")
47
-
48
- payment_intent = provider.create_payment_intent(
49
- PaymentIntentRequest(payload={"amount_minor": 4200, "currency": "USD", "confirm": True}),
50
- )
51
- refund = provider.create_refund(
52
- payment_intent,
53
- RefundRequest(payload={"amount_minor": 4200}),
54
- )
55
-
56
- print(payment_intent.status, refund["status"])
57
- ```
58
-
59
- ## Capability Mapping
60
-
61
- Capability metadata maps to `tigrbl_billing` identifiers via `capabilities_to_tigrbl`. That ensures your feature toggles and documentation stay aligned when swapping between this stub and a real Authorize.Net integration.
62
-
63
- ## Contributing
64
-
65
- If you connect the stub to the live Authorize.Net API, please share integration notes, test coverage, and examples in the README to help the community adopt the changes.
@@ -1,253 +0,0 @@
1
- """Authorize.Net billing provider stub for the Swarmauri SDK."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Any, Mapping, Optional, Sequence, cast
6
- from uuid import uuid4
7
-
8
- from swarmauri_base.billing import (
9
- BillingProviderBase,
10
- CustomersMixin,
11
- OnlinePaymentsMixin,
12
- PaymentMethodsMixin,
13
- RefundsMixin,
14
- ReportsMixin,
15
- RiskMixin,
16
- WebhooksMixin,
17
- )
18
- from swarmauri_core.billing import Capability
19
-
20
-
21
- class AuthorizeNetBillingProvider(
22
- OnlinePaymentsMixin,
23
- RefundsMixin,
24
- CustomersMixin,
25
- PaymentMethodsMixin,
26
- ReportsMixin,
27
- RiskMixin,
28
- WebhooksMixin,
29
- BillingProviderBase,
30
- ):
31
- """Stubbed Authorize.Net provider focusing on card transaction workflows."""
32
-
33
- CAPABILITIES = frozenset(
34
- {
35
- Capability.ONLINE_PAYMENTS,
36
- Capability.REFUNDS,
37
- Capability.CUSTOMERS,
38
- Capability.PAYMENT_METHODS,
39
- Capability.REPORTS,
40
- Capability.RISK,
41
- Capability.WEBHOOKS,
42
- }
43
- )
44
- component_name: str = "authorize_net"
45
-
46
- # --------------------------------------------------------------------- utils
47
- @staticmethod
48
- def _dump(obj: Any) -> Mapping[str, Any]:
49
- if hasattr(obj, "model_dump"):
50
- return cast(Mapping[str, Any], obj.model_dump(exclude_none=True))
51
- if hasattr(obj, "dict"):
52
- return cast(Mapping[str, Any], obj.dict(exclude_none=True))
53
- if isinstance(obj, Mapping):
54
- return obj
55
- return {}
56
-
57
- def _stub(self, action: str, **payload: Any) -> Mapping[str, Any]:
58
- return {
59
- "provider": self.component_name,
60
- "action": action,
61
- "payload": payload,
62
- }
63
-
64
- # ----------------------------------------------------------- online payments
65
- def _create_payment_intent(self, req: Any) -> Mapping[str, Any]:
66
- amount = int(req.resolve("amount_minor") or 0)
67
- currency = (req.resolve("currency") or "USD").upper()
68
- return {
69
- "id": f"anet_txn_{uuid4().hex[:10]}",
70
- "status": "AUTHORIZED" if req.resolve("confirm") else "PENDING_REVIEW",
71
- "amount_minor": amount,
72
- "currency": currency,
73
- "provider": self.component_name,
74
- "raw": self._stub("create_payment_intent", request=self._dump(req)),
75
- }
76
-
77
- def _capture_payment(
78
- self, payment_id: str, *, idempotency_key: Optional[str] = None
79
- ) -> Mapping[str, Any]:
80
- return {
81
- "id": payment_id,
82
- "status": "SETTLED",
83
- "provider": self.component_name,
84
- "raw": self._stub(
85
- "capture_payment",
86
- payment_id=payment_id,
87
- idempotency_key=idempotency_key,
88
- ),
89
- }
90
-
91
- def _cancel_payment(
92
- self,
93
- payment_id: str,
94
- *,
95
- reason: Optional[str] = None,
96
- idempotency_key: Optional[str] = None,
97
- ) -> Mapping[str, Any]:
98
- return {
99
- "id": payment_id,
100
- "status": "VOIDED",
101
- "provider": self.component_name,
102
- "raw": self._stub(
103
- "cancel_payment",
104
- payment_id=payment_id,
105
- reason=reason,
106
- idempotency_key=idempotency_key,
107
- ),
108
- }
109
-
110
- # --------------------------------------------------------------------- refund
111
- def _create_refund(
112
- self, payment: Any, req: Any, *, idempotency_key: str
113
- ) -> Mapping[str, Any]:
114
- return {
115
- "id": f"anet_refund_{uuid4().hex[:10]}",
116
- "status": "SUBMITTED",
117
- "provider": self.component_name,
118
- "raw": self._stub(
119
- "create_refund",
120
- payment_id=getattr(payment, "id", ""),
121
- request=self._dump(req),
122
- idempotency_key=idempotency_key,
123
- ),
124
- }
125
-
126
- def _get_refund(self, refund_id: str) -> Mapping[str, Any]:
127
- return {
128
- "id": refund_id,
129
- "status": "SETTLED",
130
- "provider": self.component_name,
131
- "raw": self._stub("get_refund", refund_id=refund_id),
132
- }
133
-
134
- # ------------------------------------------------------------------- customer
135
- def _create_customer(self, spec: Any, *, idempotency_key: str) -> Mapping[str, Any]:
136
- return {
137
- "id": f"anet_customer_{uuid4().hex[:10]}",
138
- "provider": self.component_name,
139
- "raw": self._stub(
140
- "create_customer",
141
- idempotency_key=idempotency_key,
142
- spec=self._dump(spec),
143
- ),
144
- }
145
-
146
- def _get_customer(self, customer_id: str) -> Mapping[str, Any]:
147
- return {
148
- "id": customer_id,
149
- "provider": self.component_name,
150
- "raw": self._stub("get_customer", customer_id=customer_id),
151
- }
152
-
153
- def _attach_payment_method_to_customer(
154
- self, customer: Any, pm: Any
155
- ) -> Mapping[str, Any]:
156
- return self._stub(
157
- "attach_payment_method",
158
- customer_id=getattr(customer, "id", ""),
159
- payment_method_id=getattr(pm, "id", ""),
160
- )
161
-
162
- # --------------------------------------------------------------- payment info
163
- def _create_payment_method(
164
- self, spec: Any, *, idempotency_key: str
165
- ) -> Mapping[str, Any]:
166
- return {
167
- "id": f"anet_pm_{uuid4().hex[:10]}",
168
- "provider": self.component_name,
169
- "raw": self._stub(
170
- "create_payment_method",
171
- idempotency_key=idempotency_key,
172
- spec=self._dump(spec),
173
- ),
174
- }
175
-
176
- def _detach_payment_method(self, payment_method_id: str) -> Mapping[str, Any]:
177
- return self._stub("detach_payment_method", payment_method_id=payment_method_id)
178
-
179
- def _list_payment_methods(
180
- self,
181
- customer: Any,
182
- *,
183
- type: Optional[str] = None,
184
- limit: int = 10,
185
- ) -> Sequence[Mapping[str, Any]]:
186
- payment_type = type or "credit_card"
187
- methods = []
188
- for index in range(min(limit, 3)):
189
- methods.append(
190
- {
191
- "id": f"anet_pm_{index}",
192
- "provider": self.component_name,
193
- "type": payment_type,
194
- "raw": self._stub(
195
- "list_payment_methods",
196
- customer_id=getattr(customer, "id", ""),
197
- type=payment_type,
198
- limit=limit,
199
- ),
200
- }
201
- )
202
- return methods
203
-
204
- # --------------------------------------------------------------------- reports
205
- def _create_report(self, req: Any, *, idempotency_key: str) -> Mapping[str, Any]:
206
- return {
207
- "report_id": f"anet_report_{uuid4().hex[:10]}",
208
- "status": "QUEUED",
209
- "provider": self.component_name,
210
- "raw": self._stub(
211
- "create_report",
212
- idempotency_key=idempotency_key,
213
- request=self._dump(req),
214
- ),
215
- }
216
-
217
- # ------------------------------------------------------------------------ risk
218
- def _verify_webhook_signature(
219
- self, raw_body: bytes, headers: Mapping[str, str], secret: str
220
- ) -> bool:
221
- signature = headers.get("X-ANET-Signature", "")
222
- return bool(signature and secret)
223
-
224
- def _list_disputes(self, *, limit: int = 50) -> Sequence[Mapping[str, Any]]:
225
- if limit <= 0:
226
- return tuple()
227
- return (
228
- {
229
- "id": "anet_dispute_0",
230
- "status": "UNDER_REVIEW",
231
- "provider": self.component_name,
232
- "raw": self._stub("list_disputes"),
233
- },
234
- )
235
-
236
- # --------------------------------------------------------------------- webhooks
237
- def _parse_event(
238
- self, raw_body: bytes, headers: Mapping[str, str]
239
- ) -> Mapping[str, Any]:
240
- event_type = headers.get("X-ANET-Event-Type", "authorize_net.event")
241
- return {
242
- "event_id": f"anet_evt_{uuid4().hex[:10]}",
243
- "type": event_type,
244
- "provider": self.component_name,
245
- "raw": self._stub(
246
- "parse_event",
247
- headers=dict(headers),
248
- raw_body=raw_body.decode("utf-8", errors="ignore"),
249
- ),
250
- }
251
-
252
-
253
- __all__ = ["AuthorizeNetBillingProvider"]