@alphawebai/hs-prism 0.1.0-rc.27

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 (39) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +493 -0
  3. package/dist/src/alphaweb/contracts.d.ts +6 -0
  4. package/dist/src/alphaweb/contracts.js +14 -0
  5. package/dist/src/alphaweb/error.d.ts +13 -0
  6. package/dist/src/alphaweb/error.js +100 -0
  7. package/dist/src/alphaweb/index.d.ts +3 -0
  8. package/dist/src/alphaweb/index.js +22 -0
  9. package/dist/src/alphaweb/manifest.d.ts +28 -0
  10. package/dist/src/alphaweb/manifest.js +55 -0
  11. package/dist/src/alphaweb/money.d.ts +19 -0
  12. package/dist/src/alphaweb/money.js +128 -0
  13. package/dist/src/alphaweb/stripe-connector.d.ts +58 -0
  14. package/dist/src/alphaweb/stripe-connector.js +1402 -0
  15. package/dist/src/alphaweb/types.d.ts +255 -0
  16. package/dist/src/alphaweb/types.js +3 -0
  17. package/dist/src/http_client.d.ts +58 -0
  18. package/dist/src/http_client.js +179 -0
  19. package/dist/src/index.d.ts +10 -0
  20. package/dist/src/index.js +41 -0
  21. package/dist/src/payments/_generated_connector_client_flows.d.ts +112 -0
  22. package/dist/src/payments/_generated_connector_client_flows.js +215 -0
  23. package/dist/src/payments/_generated_flows.js +141 -0
  24. package/dist/src/payments/_generated_grpc_client.d.ts +194 -0
  25. package/dist/src/payments/_generated_grpc_client.js +905 -0
  26. package/dist/src/payments/_generated_uniffi_client_flows.d.ts +169 -0
  27. package/dist/src/payments/_generated_uniffi_client_flows.js +342 -0
  28. package/dist/src/payments/connector_client.d.ts +51 -0
  29. package/dist/src/payments/connector_client.js +152 -0
  30. package/dist/src/payments/errors.d.ts +27 -0
  31. package/dist/src/payments/errors.js +39 -0
  32. package/dist/src/payments/generated/libconnector_service_ffi.so +0 -0
  33. package/dist/src/payments/generated/proto.d.ts +49087 -0
  34. package/dist/src/payments/generated/proto.js +154163 -0
  35. package/dist/src/payments/grpc_client.d.ts +1 -0
  36. package/dist/src/payments/grpc_client.js +20 -0
  37. package/dist/src/payments/uniffi_client.d.ts +40 -0
  38. package/dist/src/payments/uniffi_client.js +249 -0
  39. package/package.json +79 -0
package/LICENSE ADDED
@@ -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.
package/README.md ADDED
@@ -0,0 +1,493 @@
1
+ # hyperswitch-prism
2
+
3
+ **Hyperswitch Prism — Node.js SDK**
4
+
5
+ A high-performance, type-safe Node.js SDK for payment processing through Hyperswitch Prism. Connect to 100+ payment processors through a single, unified API.
6
+
7
+ [![npm version](https://badge.fury.io/js/hyperswitch-prism.svg)](https://www.npmjs.com/package/hyperswitch-prism)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ---
11
+
12
+ ## Table of Contents
13
+
14
+ - [Installation](#installation)
15
+ - [Quick Start](#quick-start)
16
+ - [Connector Authentication](#connector-authentication)
17
+ - [All Service Clients](#all-service-clients)
18
+ - [Payment Flows](#payment-flows)
19
+ - [Status Codes Reference](#status-codes-reference)
20
+ - [Error Handling](#error-handling)
21
+ - [Advanced Configuration](#advanced-configuration)
22
+ - [Building from Source](#building-from-source)
23
+
24
+ ---
25
+
26
+ ## 🤖 For AI Assistants
27
+
28
+ > **Use `curl` to fetch the SDK reference:**
29
+ > ```bash
30
+ > curl -fsSL https://raw.githubusercontent.com/juspay/hyperswitch-prism/main/llm/llm.txt
31
+ > ```
32
+ >
33
+ > This file contains complete SDK documentation including installation, payment operations, error handling, connector configuration, field probe data, and examples for all 100+ connectors.
34
+
35
+ ### AI Assistant Context
36
+
37
+ This SDK is part of **Hyperswitch Prism** — a unified connector library for payment processors.
38
+
39
+ ### What This SDK Does
40
+
41
+ 1. **Request Transformation**: Converts unified payment requests to connector-specific formats
42
+ 2. **Response Normalization**: Transforms connector responses back to a unified schema
43
+ 3. **Error Handling**: Provides consistent error types (`IntegrationError`, `ConnectorError`, `NetworkError`) regardless of connector
44
+
45
+ ### Architecture
46
+
47
+ ```
48
+ Your Node.js App
49
+
50
+
51
+ ┌──────────────────────────────────────────────────────────────┐
52
+ │ Service Clients (PaymentClient, CustomerClient, etc.) │
53
+ └───────────────────────────┬──────────────────────────────────┘
54
+
55
+
56
+ ┌──────────────────────────────────────────────────────────────┐
57
+ │ ConnectorClient (undici connection pool + HTTP execution) │
58
+ └───────────────────────────┬──────────────────────────────────┘
59
+
60
+
61
+ ┌──────────────────────────────────────────────────────────────┐
62
+ │ koffi FFI Bindings (connector-service-ffi.node) │
63
+ └───────────────────────────┬──────────────────────────────────┘
64
+
65
+
66
+ ┌──────────────────────────────────────────────────────────────┐
67
+ │ Rust Core (connector transformation logic) │
68
+ └───────────────────────────┬──────────────────────────────────┘
69
+
70
+
71
+ Payment Processor APIs
72
+ ```
73
+
74
+ ### Key Files
75
+
76
+ | File | Purpose |
77
+ |------|---------|
78
+ | `src/index.ts` | Public API exports (clients, types, errors) |
79
+ | `src/connector-client.ts` | HTTP execution layer with undici |
80
+ | `src/ffi/connector-service-ffi.ts` | koffi FFI bindings |
81
+ | `src/proto/payment_pb.ts` | Protobuf message definitions |
82
+
83
+ ### Package & Import
84
+
85
+ - **Package Name**: `hyperswitch-prism`
86
+ - **Installation**: `npm install hyperswitch-prism`
87
+ - **Import**: `import { PaymentClient, types } from 'hyperswitch-prism'`
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ ```bash
94
+ npm install hyperswitch-prism
95
+ ```
96
+
97
+ **Requirements:**
98
+ - Node.js 18+ (LTS recommended)
99
+ - macOS (x64, arm64), Linux (x64, arm64), or Windows (x64)
100
+
101
+ ---
102
+
103
+ ## Quick Start
104
+
105
+ ```typescript
106
+ import { PaymentClient, types } from 'hyperswitch-prism';
107
+
108
+ const config: types.ConnectorConfig = {
109
+ connectorConfig: {
110
+ // Configure your connector credentials here
111
+ // See connector documentation for specific auth patterns
112
+ }
113
+ };
114
+
115
+ const client = new PaymentClient(config);
116
+
117
+ const response = await client.authorize({
118
+ merchantTransactionId: 'txn_001',
119
+ amount: { minorAmount: 1000, currency: types.Currency.USD },
120
+ captureMethod: types.CaptureMethod.AUTOMATIC,
121
+ paymentMethod: {
122
+ card: {
123
+ cardNumber: { value: '4111111111111111' },
124
+ cardExpMonth: { value: '12' },
125
+ cardExpYear: { value: '2027' },
126
+ cardCvc: { value: '123' },
127
+ cardHolderName: { value: 'John Doe' },
128
+ }
129
+ },
130
+ address: { billingAddress: {} },
131
+ authType: types.AuthenticationType.NO_THREE_DS,
132
+ returnUrl: 'https://example.com/return',
133
+ orderDetails: [],
134
+ testMode: true,
135
+ });
136
+
137
+ console.log('Status:', response.status);
138
+ console.log('Transaction ID:', response.connectorTransactionId);
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Connector Authentication
144
+
145
+ Each connector uses a different authentication scheme. All configs are set inside `connectorConfig` as a single key matching the connector name.
146
+
147
+ See the SDK reference for complete connector authentication patterns:
148
+
149
+ ```bash
150
+ curl -fsSL https://raw.githubusercontent.com/juspay/hyperswitch-prism/main/llm/llm.txt
151
+ ```
152
+
153
+ Common authentication patterns include:
154
+
155
+ ```typescript
156
+ // Single API Key
157
+ { connectorConfig: { [connectorName]: { apiKey: { value: '...' } } } }
158
+
159
+ // API Key + Merchant Account
160
+ { connectorConfig: { [connectorName]: { apiKey: { value: '...' }, merchantAccount: { value: '...' } } } }
161
+
162
+ // Client ID + Secret (OAuth-style)
163
+ { connectorConfig: { [connectorName]: { clientId: { value: '...' }, clientSecret: { value: '...' } } } }
164
+
165
+ // Username + Password
166
+ { connectorConfig: { [connectorName]: { username: { value: '...' }, password: { value: '...' } } } }
167
+ ```
168
+
169
+ ---
170
+
171
+ ## All Service Clients
172
+
173
+ ```typescript
174
+ import {
175
+ PaymentClient,
176
+ CustomerClient,
177
+ PaymentMethodClient,
178
+ MerchantAuthenticationClient,
179
+ PaymentMethodAuthenticationClient,
180
+ RecurringPaymentClient,
181
+ RefundClient,
182
+ DisputeClient,
183
+ PayoutClient,
184
+ EventClient,
185
+ GrpcPaymentClient,
186
+ GrpcCustomerClient,
187
+ types,
188
+ IntegrationError,
189
+ ConnectorError,
190
+ NetworkError,
191
+ } from 'hyperswitch-prism';
192
+ ```
193
+
194
+ | Client | Methods |
195
+ |--------|---------|
196
+ | `PaymentClient` | `authorize()`, `capture()`, `refund()`, `void()`, `createOrder()`, `get()`, `sync()`, `incrementalAuthorization()` |
197
+ | `RefundClient` | `get()`, `createRefund()`, `updateRefund()` |
198
+ | `CustomerClient` | `create()` |
199
+ | `PaymentMethodClient` | `tokenize()` |
200
+ | `MerchantAuthenticationClient` | `createServerAuthenticationToken()`, `createClientAuthenticationToken()`, `createServerSessionAuthenticationToken()` |
201
+ | `PaymentMethodAuthenticationClient` | `preAuthenticate()`, `authenticate()`, `postAuthenticate()` |
202
+ | `RecurringPaymentClient` | `setup()`, `charge()`, `revoke()` |
203
+ | `DisputeClient` | `accept()`, `defend()`, `submitEvidence()`, `get()` |
204
+ | `PayoutClient` | Payout operations |
205
+ | `EventClient` | `handleEvent()` (webhook processing) |
206
+
207
+ ---
208
+
209
+ ## Payment Flows
210
+
211
+ ### Authorize with Auto Capture
212
+
213
+ ```typescript
214
+ const client = new PaymentClient(config);
215
+
216
+ const response = await client.authorize({
217
+ merchantTransactionId: 'txn_001',
218
+ amount: { minorAmount: 1000, currency: types.Currency.USD },
219
+ captureMethod: types.CaptureMethod.AUTOMATIC,
220
+ paymentMethod: {
221
+ card: {
222
+ cardNumber: { value: '4111111111111111' },
223
+ cardExpMonth: { value: '12' },
224
+ cardExpYear: { value: '2027' },
225
+ cardCvc: { value: '123' },
226
+ cardHolderName: { value: 'John Doe' },
227
+ }
228
+ },
229
+ address: { billingAddress: {} },
230
+ authType: types.AuthenticationType.NO_THREE_DS,
231
+ returnUrl: 'https://example.com/return',
232
+ orderDetails: [],
233
+ testMode: true,
234
+ });
235
+ // response.status === 8 (CHARGED) on success
236
+ ```
237
+
238
+ ### Authorize + Manual Capture
239
+
240
+ ```typescript
241
+ // Step 1: Authorize only
242
+ const authResponse = await client.authorize({
243
+ // ...
244
+ captureMethod: types.CaptureMethod.MANUAL,
245
+ });
246
+ // authResponse.status === 6 (AUTHORIZED)
247
+
248
+ // Step 2: Capture later
249
+ const captureResponse = await client.capture({
250
+ merchantCaptureId: 'cap_001',
251
+ connectorTransactionId: authResponse.connectorTransactionId!,
252
+ amountToCapture: { minorAmount: 1000, currency: types.Currency.USD },
253
+ testMode: true,
254
+ });
255
+ // captureResponse.status === 8 (CHARGED) or 20 (PENDING) — both are success
256
+ ```
257
+
258
+ ### Refund
259
+
260
+ ```typescript
261
+ const refundResponse = await client.refund({
262
+ merchantRefundId: 'ref_001',
263
+ connectorTransactionId: authResponse.connectorTransactionId!,
264
+ refundAmount: { minorAmount: 500, currency: types.Currency.USD },
265
+ paymentAmount: 1000,
266
+ reason: 'RETURN',
267
+ testMode: true,
268
+ });
269
+ // refundResponse.status === 4 (REFUND_SUCCESS) or 3 (REFUND_PENDING) — both are success
270
+ ```
271
+
272
+ ### Void (Cancel Authorization)
273
+
274
+ ```typescript
275
+ const voidResponse = await client.void({
276
+ merchantVoidId: 'void_001',
277
+ connectorTransactionId: authResponse.connectorTransactionId!,
278
+ cancellationReason: 'Customer cancelled',
279
+ testMode: true,
280
+ });
281
+ // voidResponse.status === 11 (VOIDED)
282
+ ```
283
+
284
+ ---
285
+
286
+ ## Status Codes Reference
287
+
288
+ ### PaymentStatus
289
+
290
+ The `response.status` field is always a **number**, not a string:
291
+
292
+ ```typescript
293
+ // ❌ Always false — response.status is a number
294
+ if (response.status === 'CHARGED') { ... }
295
+
296
+ // ✅ Correct — compare against the numeric enum constant
297
+ if (response.status === types.PaymentStatus.CHARGED) { ... }
298
+ ```
299
+
300
+ **Important: a `FAILURE` status is returned in the response body — it does NOT throw an exception.** Always check `response.status` explicitly.
301
+
302
+ > **`PaymentStatus` and `RefundStatus` are two separate enums with overlapping integer values.** Use `types.PaymentStatus` for authorize/capture/void responses and `types.RefundStatus` for refund responses.
303
+
304
+ | Name | Value | Meaning |
305
+ |------|-------|---------|
306
+ | `PAYMENT_STATUS_UNSPECIFIED` | 0 | Unknown |
307
+ | `STARTED` | 1 | Payment initiated |
308
+ | `AUTHENTICATION_PENDING` | 4 | Awaiting 3DS redirect |
309
+ | `AUTHENTICATION_SUCCESSFUL` | 5 | 3DS passed |
310
+ | `AUTHENTICATION_FAILED` | 2 | 3DS failed |
311
+ | `AUTHORIZED` | 6 | Auth succeeded, not yet captured |
312
+ | `AUTHORIZATION_FAILED` | 7 | Auth declined |
313
+ | `CHARGED` | 8 | Captured / auto-captured successfully |
314
+ | `PARTIAL_CHARGED` | 17 | Partially captured |
315
+ | `CAPTURE_INITIATED` | 13 | Async capture in progress |
316
+ | `CAPTURE_FAILED` | 14 | Capture failed |
317
+ | `VOIDED` | 11 | Authorization voided/cancelled |
318
+ | `VOID_INITIATED` | 12 | Async void in progress |
319
+ | `VOID_FAILED` | 15 | Void failed |
320
+ | `PENDING` | 20 | Processing / async |
321
+ | `FAILURE` | 21 | Soft decline — check `response.error` |
322
+ | `ROUTER_DECLINED` | 3 | Declined by routing layer |
323
+ | `EXPIRED` | 26 | Payment expired |
324
+ | `PARTIALLY_AUTHORIZED` | 25 | Partial authorization |
325
+ | `UNRESOLVED` | 19 | Requires manual review |
326
+
327
+ **Checking status safely:**
328
+
329
+ ```typescript
330
+ const response = await client.authorize(request);
331
+
332
+ if (response.status === types.PaymentStatus.FAILURE) {
333
+ console.error('Declined:', response.error?.message, response.error?.code);
334
+ } else if (response.status === types.PaymentStatus.CHARGED ||
335
+ response.status === types.PaymentStatus.AUTHORIZED) {
336
+ console.log('Success:', response.connectorTransactionId);
337
+ } else if (response.status === types.PaymentStatus.AUTHENTICATION_PENDING) {
338
+ console.log('Redirect to:', response.redirectionData);
339
+ }
340
+ ```
341
+
342
+ ### RefundStatus
343
+
344
+ | Name | Value | Meaning |
345
+ |------|-------|---------|
346
+ | `REFUND_STATUS_UNSPECIFIED` | 0 | Unknown |
347
+ | `REFUND_FAILURE` | 1 | Refund failed |
348
+ | `REFUND_MANUAL_REVIEW` | 2 | Pending manual review |
349
+ | `REFUND_PENDING` | 3 | Processing |
350
+ | `REFUND_SUCCESS` | 4 | Completed |
351
+ | `REFUND_TRANSACTION_FAILURE` | 5 | Transaction-level failure |
352
+
353
+ > `REFUND_PENDING` is a normal success state for many connectors. Treat both `REFUND_PENDING` and `REFUND_SUCCESS` as successful outcomes.
354
+
355
+ ---
356
+
357
+ ## Error Handling
358
+
359
+ The SDK raises exceptions **only for hard failures** (network errors, invalid configuration, serialization errors). Soft payment declines come back as an in-band `status: FAILURE` in the response body.
360
+
361
+ ```typescript
362
+ import { IntegrationError, ConnectorError, NetworkError, types } from 'hyperswitch-prism';
363
+
364
+ try {
365
+ const response = await client.authorize(request);
366
+
367
+ if (response.status === types.PaymentStatus.FAILURE) {
368
+ console.error('Payment declined:', response.error?.message);
369
+ return;
370
+ }
371
+
372
+ } catch (error) {
373
+ if (error instanceof IntegrationError) {
374
+ // Request-phase error: bad config, missing required field, serialization failure
375
+ console.error('Integration error:', error.errorCode, error.message);
376
+
377
+ } else if (error instanceof ConnectorError) {
378
+ // Response-phase error: connector returned unexpected format, transform failed
379
+ console.error('Connector error:', error.errorCode, error.message);
380
+
381
+ } else if (error instanceof NetworkError) {
382
+ // Network-level: timeout, connection refused, DNS failure
383
+ console.error('Network error:', error.message);
384
+ }
385
+ }
386
+ ```
387
+
388
+ ### `response.error` is a Protobuf Object — Not JSON-Serializable
389
+
390
+ ```typescript
391
+ // ❌ Throws or produces empty object
392
+ res.json({ error: response.error });
393
+ JSON.stringify(response.error);
394
+
395
+ // ✅ Extract the primitive fields you need
396
+ res.json({
397
+ error: {
398
+ message: response.error?.message,
399
+ code: response.error?.code,
400
+ reason: response.error?.reason,
401
+ }
402
+ });
403
+ ```
404
+
405
+ ### Common Error Codes
406
+
407
+ | Code | Type | Cause | Fix |
408
+ |------|------|-------|-----|
409
+ | `MISSING_REQUIRED_FIELD: browser_info` | `IntegrationError` | Connector requires `browserInfo` | Add `browserInfo` to request |
410
+ | `INVALID_CONFIGURATION` | `IntegrationError` | Wrong credentials or missing required config field | Check connector config fields |
411
+ | `CLIENT_INITIALIZATION` | `IntegrationError` | SDK failed to initialize native library | Check platform compatibility |
412
+ | `CONNECT_TIMEOUT` | `NetworkError` | Could not reach connector | Check network / proxy config |
413
+ | `RESPONSE_TIMEOUT` | `NetworkError` | Connector took too long | Increase `totalTimeoutMs` |
414
+ | `TOTAL_TIMEOUT` | `NetworkError` | Request exceeded total timeout | Increase `totalTimeoutMs` |
415
+
416
+ ---
417
+
418
+ ## Advanced Configuration
419
+
420
+ ### Timeouts
421
+
422
+ ```typescript
423
+ const client = new PaymentClient(config, {
424
+ http: {
425
+ totalTimeoutMs: 30000,
426
+ connectTimeoutMs: 10000,
427
+ responseTimeoutMs: 25000,
428
+ keepAliveTimeoutMs: 60000,
429
+ }
430
+ });
431
+ ```
432
+
433
+ ### Proxy
434
+
435
+ ```typescript
436
+ const client = new PaymentClient(config, {
437
+ http: {
438
+ proxy: {
439
+ httpsUrl: 'https://proxy.company.com:8443',
440
+ bypassUrls: ['http://localhost']
441
+ }
442
+ }
443
+ });
444
+ ```
445
+
446
+ ### Per-Request Overrides
447
+
448
+ ```typescript
449
+ const response = await client.authorize(request, {
450
+ http: { totalTimeoutMs: 60000 }
451
+ });
452
+ ```
453
+
454
+ ### Connection Pooling
455
+
456
+ Create the client once and reuse it:
457
+
458
+ ```typescript
459
+ // Good: create once, reuse
460
+ const client = new PaymentClient(config);
461
+ for (const payment of payments) {
462
+ await client.authorize(payment);
463
+ }
464
+ ```
465
+
466
+ ### CA Certificate Pinning
467
+
468
+ ```typescript
469
+ const client = new PaymentClient(config, {
470
+ http: {
471
+ caCert: fs.readFileSync('ca.pem', 'utf8')
472
+ }
473
+ });
474
+ ```
475
+
476
+ ---
477
+
478
+ ## Building from Source
479
+
480
+ ```bash
481
+ # Clone the repository
482
+ git clone https://github.com/juspay/hyperswitch-prism.git
483
+ cd hyperswitch-prism/sdk/javascript
484
+
485
+ # Build native library, generate bindings, and pack
486
+ make pack
487
+
488
+ # Run tests
489
+ make test-pack
490
+
491
+ # With live API credentials
492
+ STRIPE_API_KEY=sk_test_xxx make test-pack
493
+ ```
@@ -0,0 +1,6 @@
1
+ export { ALPHAWEB_PRISM_COMPATIBILITY_MANIFEST } from './manifest';
2
+ export type { AlphaWebPrismCompatibilityManifest } from './manifest';
3
+ export { PrismOperationError, normalizePrismError } from './error';
4
+ export { assertSafeProviderMoney, fromProviderMinorAmount, getCurrencyRule, toProviderMinorAmount, } from './money';
5
+ export type { CurrencyRule } from './money';
6
+ export type * from './types';