revaly-sdk 0.5.1__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.
Files changed (101) hide show
  1. revaly_sdk-0.5.1/LICENSE +201 -0
  2. revaly_sdk-0.5.1/NOTICE +2 -0
  3. revaly_sdk-0.5.1/PKG-INFO +227 -0
  4. revaly_sdk-0.5.1/README.md +208 -0
  5. revaly_sdk-0.5.1/core/revaly_sdk_core/__init__.py +168 -0
  6. revaly_sdk-0.5.1/core/revaly_sdk_core/api/__init__.py +8 -0
  7. revaly_sdk-0.5.1/core/revaly_sdk_core/api/notify_api.py +353 -0
  8. revaly_sdk-0.5.1/core/revaly_sdk_core/api/payment_methods_api.py +1918 -0
  9. revaly_sdk-0.5.1/core/revaly_sdk_core/api/payments_api.py +1956 -0
  10. revaly_sdk-0.5.1/core/revaly_sdk_core/api/transactions_api.py +1089 -0
  11. revaly_sdk-0.5.1/core/revaly_sdk_core/api_client.py +808 -0
  12. revaly_sdk-0.5.1/core/revaly_sdk_core/api_response.py +21 -0
  13. revaly_sdk-0.5.1/core/revaly_sdk_core/configuration.py +630 -0
  14. revaly_sdk-0.5.1/core/revaly_sdk_core/exceptions.py +222 -0
  15. revaly_sdk-0.5.1/core/revaly_sdk_core/models/__init__.py +75 -0
  16. revaly_sdk-0.5.1/core/revaly_sdk_core/models/accepted_cards.py +126 -0
  17. revaly_sdk-0.5.1/core/revaly_sdk_core/models/address.py +153 -0
  18. revaly_sdk-0.5.1/core/revaly_sdk_core/models/authorize_request.py +258 -0
  19. revaly_sdk-0.5.1/core/revaly_sdk_core/models/billing_plan.py +54 -0
  20. revaly_sdk-0.5.1/core/revaly_sdk_core/models/capture_request.py +100 -0
  21. revaly_sdk-0.5.1/core/revaly_sdk_core/models/card_features.py +111 -0
  22. revaly_sdk-0.5.1/core/revaly_sdk_core/models/create_payment_method_request.py +116 -0
  23. revaly_sdk-0.5.1/core/revaly_sdk_core/models/credit_card.py +171 -0
  24. revaly_sdk-0.5.1/core/revaly_sdk_core/models/error_response.py +111 -0
  25. revaly_sdk-0.5.1/core/revaly_sdk_core/models/gateway.py +194 -0
  26. revaly_sdk-0.5.1/core/revaly_sdk_core/models/gateway_payment_method.py +178 -0
  27. revaly_sdk-0.5.1/core/revaly_sdk_core/models/get_transaction_by_id200_response.py +229 -0
  28. revaly_sdk-0.5.1/core/revaly_sdk_core/models/get_transaction_by_merchant_transaction_id200_response.py +249 -0
  29. revaly_sdk-0.5.1/core/revaly_sdk_core/models/initiated_by.py +41 -0
  30. revaly_sdk-0.5.1/core/revaly_sdk_core/models/notify_contact_information.py +118 -0
  31. revaly_sdk-0.5.1/core/revaly_sdk_core/models/notify_data.py +201 -0
  32. revaly_sdk-0.5.1/core/revaly_sdk_core/models/notify_request.py +108 -0
  33. revaly_sdk-0.5.1/core/revaly_sdk_core/models/notify_response.py +99 -0
  34. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method.py +182 -0
  35. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_recache_request.py +96 -0
  36. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_recache_request_payment_method.py +96 -0
  37. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_recache_request_payment_method_credit_card.py +103 -0
  38. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_response.py +301 -0
  39. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_write_response.py +322 -0
  40. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_method_write_response_transaction.py +134 -0
  41. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_plan_data.py +140 -0
  42. revaly_sdk-0.5.1/core/revaly_sdk_core/models/payment_request.py +258 -0
  43. revaly_sdk-0.5.1/core/revaly_sdk_core/models/pending_transaction_response.py +120 -0
  44. revaly_sdk-0.5.1/core/revaly_sdk_core/models/previous_transaction.py +162 -0
  45. revaly_sdk-0.5.1/core/revaly_sdk_core/models/recovery.py +155 -0
  46. revaly_sdk-0.5.1/core/revaly_sdk_core/models/refund_cancel_request.py +102 -0
  47. revaly_sdk-0.5.1/core/revaly_sdk_core/models/refund_request.py +100 -0
  48. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data.py +150 -0
  49. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_additional_transaction_data.py +186 -0
  50. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_billing_data.py +105 -0
  51. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_custom_data.py +93 -0
  52. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_customer_data.py +299 -0
  53. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_device_data.py +153 -0
  54. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_merchant_data.py +130 -0
  55. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_order_data.py +178 -0
  56. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_partner_risk_data.py +103 -0
  57. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_seller_data.py +137 -0
  58. revaly_sdk-0.5.1/core/revaly_sdk_core/models/rtn_data_shipping_data.py +170 -0
  59. revaly_sdk-0.5.1/core/revaly_sdk_core/models/stored_credential.py +127 -0
  60. revaly_sdk-0.5.1/core/revaly_sdk_core/models/stored_credential_reason_type.py +42 -0
  61. revaly_sdk-0.5.1/core/revaly_sdk_core/models/stored_credential_response.py +127 -0
  62. revaly_sdk-0.5.1/core/revaly_sdk_core/models/three_ds.py +205 -0
  63. revaly_sdk-0.5.1/core/revaly_sdk_core/models/transaction_gateway.py +118 -0
  64. revaly_sdk-0.5.1/core/revaly_sdk_core/models/transaction_group_response.py +105 -0
  65. revaly_sdk-0.5.1/core/revaly_sdk_core/models/transaction_list_item.py +314 -0
  66. revaly_sdk-0.5.1/core/revaly_sdk_core/models/transaction_response.py +342 -0
  67. revaly_sdk-0.5.1/core/revaly_sdk_core/models/transaction_response_details.py +132 -0
  68. revaly_sdk-0.5.1/core/revaly_sdk_core/models/update_payment_method_request.py +96 -0
  69. revaly_sdk-0.5.1/core/revaly_sdk_core/models/vault_payment_method.py +178 -0
  70. revaly_sdk-0.5.1/core/revaly_sdk_core/models/void_request.py +93 -0
  71. revaly_sdk-0.5.1/core/revaly_sdk_core/py.typed +0 -0
  72. revaly_sdk-0.5.1/core/revaly_sdk_core/rest.py +267 -0
  73. revaly_sdk-0.5.1/pyproject.toml +64 -0
  74. revaly_sdk-0.5.1/revaly_sdk.egg-info/PKG-INFO +227 -0
  75. revaly_sdk-0.5.1/revaly_sdk.egg-info/SOURCES.txt +99 -0
  76. revaly_sdk-0.5.1/revaly_sdk.egg-info/dependency_links.txt +1 -0
  77. revaly_sdk-0.5.1/revaly_sdk.egg-info/requires.txt +7 -0
  78. revaly_sdk-0.5.1/revaly_sdk.egg-info/top_level.txt +2 -0
  79. revaly_sdk-0.5.1/runtime/revaly_sdk/__init__.py +106 -0
  80. revaly_sdk-0.5.1/runtime/revaly_sdk/_scrub.py +133 -0
  81. revaly_sdk-0.5.1/runtime/revaly_sdk/_useragent.py +45 -0
  82. revaly_sdk-0.5.1/runtime/revaly_sdk/_version.py +8 -0
  83. revaly_sdk-0.5.1/runtime/revaly_sdk/_wire_trace.py +28 -0
  84. revaly_sdk-0.5.1/runtime/revaly_sdk/client.py +451 -0
  85. revaly_sdk-0.5.1/runtime/revaly_sdk/errors.py +260 -0
  86. revaly_sdk-0.5.1/runtime/revaly_sdk/py.typed +0 -0
  87. revaly_sdk-0.5.1/runtime/revaly_sdk/reconcile.py +336 -0
  88. revaly_sdk-0.5.1/runtime/revaly_sdk/testing/__init__.py +12 -0
  89. revaly_sdk-0.5.1/runtime/revaly_sdk/testing/mock_transport.py +346 -0
  90. revaly_sdk-0.5.1/runtime/revaly_sdk/testing/synthetic_data.py +59 -0
  91. revaly_sdk-0.5.1/runtime/revaly_sdk/transport.py +321 -0
  92. revaly_sdk-0.5.1/setup.cfg +4 -0
  93. revaly_sdk-0.5.1/tests/test_classification.py +206 -0
  94. revaly_sdk-0.5.1/tests/test_log_capture.py +155 -0
  95. revaly_sdk-0.5.1/tests/test_mock_transport.py +142 -0
  96. revaly_sdk-0.5.1/tests/test_model_serialization.py +177 -0
  97. revaly_sdk-0.5.1/tests/test_quickstart.py +119 -0
  98. revaly_sdk-0.5.1/tests/test_real_wire.py +231 -0
  99. revaly_sdk-0.5.1/tests/test_reconcile.py +208 -0
  100. revaly_sdk-0.5.1/tests/test_scrubber.py +111 -0
  101. revaly_sdk-0.5.1/tests/test_transport_headers.py +202 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ Revaly RAP SDK
2
+ Copyright 2026 Revaly Technologies Inc.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: revaly-sdk
3
+ Version: 0.5.1
4
+ Summary: Revaly RAP V2 server-side SDK for Python (payments, payment methods, transactions, notify) with the merchant failover contract built in
5
+ License: Apache-2.0
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Requires-Dist: urllib3<3.0.0,>=2.7.0
13
+ Requires-Dist: python-dateutil>=2.8.2
14
+ Requires-Dist: pydantic>=2.11
15
+ Requires-Dist: typing-extensions>=4.7.1
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8.0; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # Revaly RAP SDK for Python
21
+
22
+ Server-side Python SDK for the RAP V2 API: payments, payment methods, transactions and
23
+ notify — with a **merchant-facing failover contract** built in. Every failed payment
24
+ call raises exactly one of three typed classes that tell you what you may safely do
25
+ next.
26
+
27
+ > **Package status:** the PyPI name `revaly-sdk` is **[Proposed]** until registry
28
+ > provisioning (OQ-3), and registry publish is embargoed — install from the
29
+ > per-language GitHub release artifact until then. Requires Python ≥ 3.9.
30
+
31
+ ## Why the error classes matter (read this first)
32
+
33
+ A failed `charge(...)` does **not** mean the payment didn't happen. If you
34
+ blind-fail-over to your own gateway on an ambiguous failure, the cardholder can be
35
+ charged **twice**. The SDK classifies every failure so you never have to guess:
36
+
37
+ | Class | Meaning | What you do |
38
+ | --- | --- | --- |
39
+ | `RapPermanentRejection` | Received and rejected (400/401/403/404/422) | Fix or decline. **Never fail over** — the same request fails anywhere. |
40
+ | `RapTransientFailure` | **Definitively not processed** (provably never sent, or `503` + `code: not_processed`) | Route to your own gateway immediately. |
41
+ | `RapOutcomeUnknown` | **May have been processed** (timeout after send, reset, 5xx) | **Reconcile before acting** — see below. |
42
+
43
+ ## Quickstart (sandbox key → first charge, ≤ 15 minutes)
44
+
45
+ Your API key's scope selects the environment: sandbox and live share the same URL —
46
+ there is no separate sandbox host. Use the sandbox-scoped key issued by Enablement.
47
+
48
+ ```bash
49
+ # Download revaly-sdk-python.tar.gz from the release, verify its .sha256, then:
50
+ pip install ./revaly-sdk-python.tar.gz
51
+ # (the release also attaches a wheel — either file installs the same package)
52
+ ```
53
+
54
+ ```python
55
+ import os
56
+
57
+ from revaly_sdk import (
58
+ CreditCard,
59
+ Found,
60
+ NotFoundYet,
61
+ PaymentMethod,
62
+ PaymentRequest,
63
+ RapClient,
64
+ RapOutcomeUnknown,
65
+ RapPermanentRejection,
66
+ RapTransactionOutcome,
67
+ RapTransientFailure,
68
+ ReconcilePolicy,
69
+ )
70
+
71
+ client = RapClient(os.environ["RAP_API_KEY"])
72
+
73
+ request = PaymentRequest(
74
+ amount=1999,
75
+ currency="USD",
76
+ merchant_transaction_id="order-1042", # required on every payment — it is your reconcile handle
77
+ order_id="order-1042", # orderId + email below: the sandbox simulator requires both for an approval
78
+ # paymentMethodType is omitted — inferred from the one populated method object
79
+ payment_method=PaymentMethod(
80
+ full_name="Ada Lovelace", # creditCard requires a cardholder name
81
+ email="ada@example.com",
82
+ credit_card=CreditCard(
83
+ number="4111111111111111", # sandbox test PAN
84
+ card_verification_code="999",
85
+ expiry_month="12",
86
+ expiry_year="2030",
87
+ )
88
+ ),
89
+ )
90
+
91
+ try:
92
+ transaction = client.charge(request)
93
+ print("approved", transaction.transaction_id)
94
+ except RapPermanentRejection as failure:
95
+ # Fix or decline. Never fail over — the same request fails anywhere.
96
+ print("rejected", failure.status, failure.api_error, failure.correlation_id)
97
+ except RapTransientFailure:
98
+ # Definitively not processed — route to your own gateway immediately.
99
+ route_to_own_gateway()
100
+ except RapOutcomeUnknown:
101
+ # May have been processed — reconcile BEFORE acting (double-charge hazard).
102
+ verdict = client.reconcile(
103
+ "order-1042",
104
+ ReconcilePolicy(max_attempts=5, overall_budget=30.0, initial_delay=0.5),
105
+ )
106
+ if isinstance(verdict, Found):
107
+ # The record IS visible. Found(APPROVED) means the money moved —
108
+ # failing over now would double-charge.
109
+ print("resolved", verdict.outcome, verdict.correlation_id)
110
+ elif isinstance(verdict, NotFoundYet):
111
+ # Not visible YET — absence is not provable in V1. Hold and escalate
112
+ # per your risk policy; do not treat this as "safe to fail over".
113
+ print("hold", verdict.attempts, verdict.last_correlation_id)
114
+ else:
115
+ # Verdicts are open for extension (SafeToFailover arrives with
116
+ # platform P-2 as a minor release). Always keep this branch.
117
+ escalate_to_operator(verdict)
118
+ ```
119
+
120
+ ### Timeouts
121
+
122
+ `overall_deadline` defaults to **75 seconds** (`DEFAULT_OVERALL_DEADLINE`) — ratified
123
+ from production latency telemetry (ADR-SDK-027): it clears every observed gateway
124
+ tail cluster (the worst non-hung tail seen in 14 fleet days was 64 s), clips ≲0.007%
125
+ of charges, and still classifies well before the platform's own ≈100 s ceiling.
126
+ Tighten it per your checkout budget (RAP routes gateways server-side, so the default
127
+ must cover the slowest common class), or pass an explicit `overall_deadline=None` to
128
+ disable the SDK deadline. `connect_timeout` defaults to **10 seconds**
129
+ (`DEFAULT_CONNECT_TIMEOUT`) — ratified from the OQ-11 edge verification (ADR-SDK-029):
130
+ roughly 25× the observed cold client→edge TLS envelope, and 65 s below the overall
131
+ deadline. Pass an explicit `connect_timeout=None` to disable the SDK connect bound.
132
+ All timeouts are seconds:
133
+
134
+ ```python
135
+ client = RapClient(api_key, connect_timeout=3.0, overall_deadline=10.0)
136
+ # or per call:
137
+ client.charge(request, overall_deadline=5.0)
138
+ ```
139
+
140
+ Note the per-call asymmetry: passing `overall_deadline=None` (or omitting it) on a call
141
+ means "use the client's configured value", never "disable" — disabling the deadline is
142
+ a client-construction decision only (`RapClient(..., overall_deadline=None)`),
143
+ deliberately without a per-call equivalent (the safe direction). The same asymmetry
144
+ applies to `connect_timeout`.
145
+
146
+ - `overall_deadline` expiry **after send** classifies `RapOutcomeUnknown` (reconcile),
147
+ never TransientFailure.
148
+ - `connect_timeout` expiry proves the request never left the client and classifies
149
+ `RapTransientFailure` — urllib3 reports the connect phase distinctly even when only
150
+ an overall deadline is set.
151
+
152
+ Python has no ambient cancellation token: bound calls with these timeout arguments and
153
+ bound reconciliation with the `ReconcilePolicy` budget — that is this SDK's
154
+ cancellation idiom.
155
+
156
+ ### API versioning
157
+
158
+ Requests pin `X-Api-Version: 2.1` by default. `"2.0"` is selectable
159
+ (`api_version="2.0"`) but narrows the contract: `ErrorResponse.code` is not part of
160
+ the 2.0 documented surface, so a `503` + `not_processed` classifies
161
+ `RapOutcomeUnknown` (reconcile) instead of `RapTransientFailure` (immediate failover).
162
+ Pin 2.1 unless you have a frozen 2.0 integration.
163
+
164
+ ## Testing your failover handler — no network
165
+
166
+ The mock transport scripts every row of the failure taxonomy and both reconcile
167
+ verdicts, and asserts your requests carry the SDK User-Agent. It replaces only the
168
+ wire: header injection and classification run exactly as in production.
169
+
170
+ ```python
171
+ from revaly_sdk import RapClient
172
+ from revaly_sdk.testing import RapMockTransport
173
+
174
+ mock = RapMockTransport()
175
+ mock.charge().returns_not_processed_503() # → RapTransientFailure
176
+ mock.reconcile().not_found_yet(2).then_found_approved()
177
+
178
+ client = RapClient("sk-synthetic", transport=mock)
179
+ # exercise YOUR suppression/escalation logic against scripted consecutive outcomes:
180
+ mock.charge().returns_bare_503().throws_connection_refused().returns_approved()
181
+ ```
182
+
183
+ Scenario methods mirror the contract: `returns_permanent_rejection(status)`,
184
+ `returns_not_processed_503()`, `throws_connection_refused()`, `throws_dns_failure()`,
185
+ `throws_ssl_handshake_failure()`, `throws_connect_timeout()`,
186
+ `throws_timeout_after_send()`, `throws_connection_reset()`, `returns_bare_503()`,
187
+ `returns_server_error()`, `pending()`, and raw escapes `returns(...)` /
188
+ `throws_io(...)`. Transport failures are simulated with real urllib3 exception
189
+ instances, so classification in your tests exercises the production code path.
190
+ Synthetic data only — no real PAN/CVV/PII ever appears in the mock.
191
+
192
+ ## Logging & debugging
193
+
194
+ - Logging uses the stdlib `logging` module (logger name `revaly_sdk`; silent until
195
+ your application configures handlers, or pass `logger=`). Default output is
196
+ **values-free** — operation, status, class, correlation id. `DEBUG` level carries
197
+ **allowlist-scrubbed** payloads only; PAN/CVV/PII and the API key can never appear
198
+ (the API key is also absent from every error message).
199
+ - `wire_trace_hook`: a request/response observer for Enablement escalations —
200
+ payloads arrive already scrubbed by the runtime's central allowlist scrubber.
201
+ - Every response and every typed error carries the `X-Correlation-ID`; quote it in
202
+ support tickets to join RAP-core telemetry directly.
203
+
204
+ ## What this SDK never does
205
+
206
+ No hidden retries, no resubmission, no circuit breaker, no cross-request state, no
207
+ `bypassPlatform`. The explicit, caller-bounded reconcile re-poll is the only loop the
208
+ SDK owns. Classification never derives from message text, latency, or wait
209
+ heuristics. (Concretely: urllib3's default connect retries and redirect-following are
210
+ disabled on every request — a `307` on `POST /payments` comes back as a response and
211
+ classifies `RapOutcomeUnknown` instead of being silently re-sent.)
212
+
213
+ ## Beyond payments
214
+
215
+ The full generated V2 surface ships in the same package and flows through the same
216
+ transport, headers and classification:
217
+
218
+ ```python
219
+ methods = client.payment_methods.list_payment_methods()
220
+ raw = client.transactions.get_transaction_by_id_without_preload_content("txn-1")
221
+ ```
222
+
223
+ One logging caution on this surface: raw core operations raise the generator's
224
+ `ApiException`, not the three typed classes — and `str(ApiException)` embeds the full
225
+ HTTP response body. Response bodies can contain PII (names, emails, masked card data):
226
+ never log raw core exceptions or response bodies; log the correlation id and the typed
227
+ runtime errors (values-free by design) instead.
@@ -0,0 +1,208 @@
1
+ # Revaly RAP SDK for Python
2
+
3
+ Server-side Python SDK for the RAP V2 API: payments, payment methods, transactions and
4
+ notify — with a **merchant-facing failover contract** built in. Every failed payment
5
+ call raises exactly one of three typed classes that tell you what you may safely do
6
+ next.
7
+
8
+ > **Package status:** the PyPI name `revaly-sdk` is **[Proposed]** until registry
9
+ > provisioning (OQ-3), and registry publish is embargoed — install from the
10
+ > per-language GitHub release artifact until then. Requires Python ≥ 3.9.
11
+
12
+ ## Why the error classes matter (read this first)
13
+
14
+ A failed `charge(...)` does **not** mean the payment didn't happen. If you
15
+ blind-fail-over to your own gateway on an ambiguous failure, the cardholder can be
16
+ charged **twice**. The SDK classifies every failure so you never have to guess:
17
+
18
+ | Class | Meaning | What you do |
19
+ | --- | --- | --- |
20
+ | `RapPermanentRejection` | Received and rejected (400/401/403/404/422) | Fix or decline. **Never fail over** — the same request fails anywhere. |
21
+ | `RapTransientFailure` | **Definitively not processed** (provably never sent, or `503` + `code: not_processed`) | Route to your own gateway immediately. |
22
+ | `RapOutcomeUnknown` | **May have been processed** (timeout after send, reset, 5xx) | **Reconcile before acting** — see below. |
23
+
24
+ ## Quickstart (sandbox key → first charge, ≤ 15 minutes)
25
+
26
+ Your API key's scope selects the environment: sandbox and live share the same URL —
27
+ there is no separate sandbox host. Use the sandbox-scoped key issued by Enablement.
28
+
29
+ ```bash
30
+ # Download revaly-sdk-python.tar.gz from the release, verify its .sha256, then:
31
+ pip install ./revaly-sdk-python.tar.gz
32
+ # (the release also attaches a wheel — either file installs the same package)
33
+ ```
34
+
35
+ ```python
36
+ import os
37
+
38
+ from revaly_sdk import (
39
+ CreditCard,
40
+ Found,
41
+ NotFoundYet,
42
+ PaymentMethod,
43
+ PaymentRequest,
44
+ RapClient,
45
+ RapOutcomeUnknown,
46
+ RapPermanentRejection,
47
+ RapTransactionOutcome,
48
+ RapTransientFailure,
49
+ ReconcilePolicy,
50
+ )
51
+
52
+ client = RapClient(os.environ["RAP_API_KEY"])
53
+
54
+ request = PaymentRequest(
55
+ amount=1999,
56
+ currency="USD",
57
+ merchant_transaction_id="order-1042", # required on every payment — it is your reconcile handle
58
+ order_id="order-1042", # orderId + email below: the sandbox simulator requires both for an approval
59
+ # paymentMethodType is omitted — inferred from the one populated method object
60
+ payment_method=PaymentMethod(
61
+ full_name="Ada Lovelace", # creditCard requires a cardholder name
62
+ email="ada@example.com",
63
+ credit_card=CreditCard(
64
+ number="4111111111111111", # sandbox test PAN
65
+ card_verification_code="999",
66
+ expiry_month="12",
67
+ expiry_year="2030",
68
+ )
69
+ ),
70
+ )
71
+
72
+ try:
73
+ transaction = client.charge(request)
74
+ print("approved", transaction.transaction_id)
75
+ except RapPermanentRejection as failure:
76
+ # Fix or decline. Never fail over — the same request fails anywhere.
77
+ print("rejected", failure.status, failure.api_error, failure.correlation_id)
78
+ except RapTransientFailure:
79
+ # Definitively not processed — route to your own gateway immediately.
80
+ route_to_own_gateway()
81
+ except RapOutcomeUnknown:
82
+ # May have been processed — reconcile BEFORE acting (double-charge hazard).
83
+ verdict = client.reconcile(
84
+ "order-1042",
85
+ ReconcilePolicy(max_attempts=5, overall_budget=30.0, initial_delay=0.5),
86
+ )
87
+ if isinstance(verdict, Found):
88
+ # The record IS visible. Found(APPROVED) means the money moved —
89
+ # failing over now would double-charge.
90
+ print("resolved", verdict.outcome, verdict.correlation_id)
91
+ elif isinstance(verdict, NotFoundYet):
92
+ # Not visible YET — absence is not provable in V1. Hold and escalate
93
+ # per your risk policy; do not treat this as "safe to fail over".
94
+ print("hold", verdict.attempts, verdict.last_correlation_id)
95
+ else:
96
+ # Verdicts are open for extension (SafeToFailover arrives with
97
+ # platform P-2 as a minor release). Always keep this branch.
98
+ escalate_to_operator(verdict)
99
+ ```
100
+
101
+ ### Timeouts
102
+
103
+ `overall_deadline` defaults to **75 seconds** (`DEFAULT_OVERALL_DEADLINE`) — ratified
104
+ from production latency telemetry (ADR-SDK-027): it clears every observed gateway
105
+ tail cluster (the worst non-hung tail seen in 14 fleet days was 64 s), clips ≲0.007%
106
+ of charges, and still classifies well before the platform's own ≈100 s ceiling.
107
+ Tighten it per your checkout budget (RAP routes gateways server-side, so the default
108
+ must cover the slowest common class), or pass an explicit `overall_deadline=None` to
109
+ disable the SDK deadline. `connect_timeout` defaults to **10 seconds**
110
+ (`DEFAULT_CONNECT_TIMEOUT`) — ratified from the OQ-11 edge verification (ADR-SDK-029):
111
+ roughly 25× the observed cold client→edge TLS envelope, and 65 s below the overall
112
+ deadline. Pass an explicit `connect_timeout=None` to disable the SDK connect bound.
113
+ All timeouts are seconds:
114
+
115
+ ```python
116
+ client = RapClient(api_key, connect_timeout=3.0, overall_deadline=10.0)
117
+ # or per call:
118
+ client.charge(request, overall_deadline=5.0)
119
+ ```
120
+
121
+ Note the per-call asymmetry: passing `overall_deadline=None` (or omitting it) on a call
122
+ means "use the client's configured value", never "disable" — disabling the deadline is
123
+ a client-construction decision only (`RapClient(..., overall_deadline=None)`),
124
+ deliberately without a per-call equivalent (the safe direction). The same asymmetry
125
+ applies to `connect_timeout`.
126
+
127
+ - `overall_deadline` expiry **after send** classifies `RapOutcomeUnknown` (reconcile),
128
+ never TransientFailure.
129
+ - `connect_timeout` expiry proves the request never left the client and classifies
130
+ `RapTransientFailure` — urllib3 reports the connect phase distinctly even when only
131
+ an overall deadline is set.
132
+
133
+ Python has no ambient cancellation token: bound calls with these timeout arguments and
134
+ bound reconciliation with the `ReconcilePolicy` budget — that is this SDK's
135
+ cancellation idiom.
136
+
137
+ ### API versioning
138
+
139
+ Requests pin `X-Api-Version: 2.1` by default. `"2.0"` is selectable
140
+ (`api_version="2.0"`) but narrows the contract: `ErrorResponse.code` is not part of
141
+ the 2.0 documented surface, so a `503` + `not_processed` classifies
142
+ `RapOutcomeUnknown` (reconcile) instead of `RapTransientFailure` (immediate failover).
143
+ Pin 2.1 unless you have a frozen 2.0 integration.
144
+
145
+ ## Testing your failover handler — no network
146
+
147
+ The mock transport scripts every row of the failure taxonomy and both reconcile
148
+ verdicts, and asserts your requests carry the SDK User-Agent. It replaces only the
149
+ wire: header injection and classification run exactly as in production.
150
+
151
+ ```python
152
+ from revaly_sdk import RapClient
153
+ from revaly_sdk.testing import RapMockTransport
154
+
155
+ mock = RapMockTransport()
156
+ mock.charge().returns_not_processed_503() # → RapTransientFailure
157
+ mock.reconcile().not_found_yet(2).then_found_approved()
158
+
159
+ client = RapClient("sk-synthetic", transport=mock)
160
+ # exercise YOUR suppression/escalation logic against scripted consecutive outcomes:
161
+ mock.charge().returns_bare_503().throws_connection_refused().returns_approved()
162
+ ```
163
+
164
+ Scenario methods mirror the contract: `returns_permanent_rejection(status)`,
165
+ `returns_not_processed_503()`, `throws_connection_refused()`, `throws_dns_failure()`,
166
+ `throws_ssl_handshake_failure()`, `throws_connect_timeout()`,
167
+ `throws_timeout_after_send()`, `throws_connection_reset()`, `returns_bare_503()`,
168
+ `returns_server_error()`, `pending()`, and raw escapes `returns(...)` /
169
+ `throws_io(...)`. Transport failures are simulated with real urllib3 exception
170
+ instances, so classification in your tests exercises the production code path.
171
+ Synthetic data only — no real PAN/CVV/PII ever appears in the mock.
172
+
173
+ ## Logging & debugging
174
+
175
+ - Logging uses the stdlib `logging` module (logger name `revaly_sdk`; silent until
176
+ your application configures handlers, or pass `logger=`). Default output is
177
+ **values-free** — operation, status, class, correlation id. `DEBUG` level carries
178
+ **allowlist-scrubbed** payloads only; PAN/CVV/PII and the API key can never appear
179
+ (the API key is also absent from every error message).
180
+ - `wire_trace_hook`: a request/response observer for Enablement escalations —
181
+ payloads arrive already scrubbed by the runtime's central allowlist scrubber.
182
+ - Every response and every typed error carries the `X-Correlation-ID`; quote it in
183
+ support tickets to join RAP-core telemetry directly.
184
+
185
+ ## What this SDK never does
186
+
187
+ No hidden retries, no resubmission, no circuit breaker, no cross-request state, no
188
+ `bypassPlatform`. The explicit, caller-bounded reconcile re-poll is the only loop the
189
+ SDK owns. Classification never derives from message text, latency, or wait
190
+ heuristics. (Concretely: urllib3's default connect retries and redirect-following are
191
+ disabled on every request — a `307` on `POST /payments` comes back as a response and
192
+ classifies `RapOutcomeUnknown` instead of being silently re-sent.)
193
+
194
+ ## Beyond payments
195
+
196
+ The full generated V2 surface ships in the same package and flows through the same
197
+ transport, headers and classification:
198
+
199
+ ```python
200
+ methods = client.payment_methods.list_payment_methods()
201
+ raw = client.transactions.get_transaction_by_id_without_preload_content("txn-1")
202
+ ```
203
+
204
+ One logging caution on this surface: raw core operations raise the generator's
205
+ `ApiException`, not the three typed classes — and `str(ApiException)` embeds the full
206
+ HTTP response body. Response bodies can contain PII (names, emails, masked card data):
207
+ never log raw core exceptions or response bodies; log the correlation id and the typed
208
+ runtime errors (values-free by design) instead.