@henrylabs-interview/payment-processor 0.1.11 → 0.1.12

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 (2) hide show
  1. package/README.md +120 -66
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,15 @@
1
- # Henry Labs - Interview: Payment Processor
1
+ # Henry Labs Interview: Payment Processor
2
2
 
3
- A lightweight payments SDK for creating and confirming checkouts, with built-in webhook support.
3
+ A lightweight payments SDK for creating and confirming checkouts, with built-in webhook support and an embeddable checkout UI.
4
4
 
5
- This SDK simulates a real-world payment processing system, including fraud detection, transient errors, retries, and asynchronous authorization flows.
5
+ This SDK simulates a real-world payment processing system, including:
6
+
7
+ - Fraud detection
8
+ - Transient system errors
9
+ - Retry scenarios
10
+ - Asynchronous authorization flows
11
+
12
+ It is designed to test robustness, error handling, and webhook integration.
6
13
 
7
14
  ---
8
15
 
@@ -20,35 +27,48 @@ bun run build
20
27
 
21
28
  ---
22
29
 
23
- ## Overview
30
+ # Overview
24
31
 
25
- The SDK provides three primary capabilities:
32
+ The SDK provides:
26
33
 
27
- - Create a checkout
28
- - Confirm a checkout
29
- - Register webhook endpoints
34
+ - Checkout creation
35
+ - Checkout confirmation
36
+ - Webhook endpoint registration
37
+ - Embeddable checkout UI (frontend)
38
+ - API key validation
30
39
 
31
- The system performs internal validation, fraud screening, and risk checks.
32
- Depending on system conditions, operations may:
40
+ The system performs internal validation, fraud screening, and simulated load conditions.
41
+
42
+ Operations may:
33
43
 
34
44
  - Succeed immediately
35
- - Succeed asynchronously
36
- - Require a retry
37
- - Fail due to risk controls
45
+ - Resolve asynchronously
46
+ - Require retries
47
+ - Fail due to fraud controls
38
48
  - Fail due to temporary system overload
39
49
 
40
- Consumers should always handle both synchronous responses and webhook events.
41
-
42
50
  ---
43
51
 
44
- ## Usage
52
+ # Usage
45
53
 
46
- ### Initialize
54
+ ---
55
+
56
+ ## Initialize (Backend)
47
57
 
48
58
  ```ts
49
- import { PaymentSDK } from 'henry-labs/take-home';
59
+ import { PaymentProcessor } from 'henry-labs/take-home';
50
60
 
51
- const sdk = new PaymentSDK();
61
+ const processor = new PaymentProcessor({
62
+ apiKey: ...,
63
+ });
64
+ ```
65
+
66
+ # Checkout API
67
+
68
+ Available under:
69
+
70
+ ```ts
71
+ processor.checkout;
52
72
  ```
53
73
 
54
74
  ---
@@ -56,96 +76,130 @@ const sdk = new PaymentSDK();
56
76
  ## Create a Checkout
57
77
 
58
78
  ```ts
59
- const response = await sdk.create({
79
+ const response = await processor.checkout.create({
60
80
  amount: 1000,
61
81
  currency: 'USD',
62
82
  customerId: 'cust_123',
63
83
  });
64
84
  ```
65
85
 
66
- ### Behavior
86
+ ---
67
87
 
68
- Creating a checkout may:
88
+ ## Confirm a Checkout (Backend)
89
+
90
+ ```ts
91
+ const response = await processor.checkout.confirm({
92
+ checkoutId: ...,
93
+ type: 'raw-card',
94
+ data: {
95
+ number: ...,
96
+ expMonth: XX,
97
+ expYear: XXXX,
98
+ cvc: XXX,
99
+ },
100
+ });
101
+ ```
69
102
 
70
- - Return immediate approval
71
- - Return a pending authorization state
72
- - Return a retryable error
73
- - Return a fraud-related failure
74
- - Fail due to temporary internal errors
103
+ # Embedded Checkout (Frontend)
75
104
 
76
- If the checkout is authorized asynchronously, the final outcome will be delivered via webhook.
105
+ The SDK provides an optional embeddable checkout UI for collecting card details in the browser.
77
106
 
78
107
  ---
79
108
 
80
- ## Confirm a Checkout
109
+ ## Initialize Embedded Checkout
81
110
 
82
111
  ```ts
83
- const response = await sdk.confirm({
84
- checkoutId: '...',
85
- type: 'raw-card',
86
- data: {
87
- number: '4242424242424242',
88
- expMonth: 12,
89
- expYear: 2030,
90
- cvc: '123',
91
- },
112
+ import { EmbeddedCheckout } from 'henry-labs/take-home';
113
+
114
+ const embedded = new EmbeddedCheckout({
115
+ checkoutId: 'chk_123',
92
116
  });
93
117
  ```
94
118
 
95
- ### Behavior
119
+ ---
120
+
121
+ ## Render Embedded Checkout
122
+
123
+ ```ts
124
+ embedded.render('checkout-container', (paymentToken) => {
125
+ console.log('Received payment token:', paymentToken);
96
126
 
97
- Confirmation requests are subject to:
127
+ // Send token to backend for confirmation
128
+ });
129
+ ```
130
+
131
+ ### Parameters
132
+
133
+ | Parameter | Description |
134
+ | -------------------- | ------------------------------------- |
135
+ | `containerElementId` | ID of DOM element to render into |
136
+ | `callbackFn` | Called with a generated payment token |
137
+
138
+ ### Behavior
98
139
 
99
- - Card validation
100
- - Fraud screening
101
- - Retry conditions
102
- - System load conditions
140
+ - Renders a secure card collection UI
141
+ - Collects card number, expiry, and CVC
142
+ - Generates a payment token
143
+ - Returns the token via callback
144
+ - Token should be sent to your backend for confirmation
103
145
 
104
- Confirmations may resolve immediately or asynchronously.
105
- Webhook handling is required to receive final outcomes in deferred cases.
146
+ The embedded checkout is intended for **browser environments only**.
106
147
 
107
148
  ---
108
149
 
109
- ## Webhooks
150
+ # Webhooks
110
151
 
111
- You can register webhook endpoints to receive event notifications.
152
+ Available under:
112
153
 
113
154
  ```ts
114
- sdk.webhooks.createEndpoint({
155
+ processor.webhooks;
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Register Webhook Endpoint
161
+
162
+ ```ts
163
+ processor.webhooks.createEndpoint({
115
164
  url: 'https://example.com/webhooks',
116
165
  event: 'checkout.confirm',
117
166
  secret: 'whsec_...',
118
167
  });
119
168
  ```
120
169
 
121
- ### Webhook Events
170
+ ---
122
171
 
123
- Events are emitted for:
172
+ ## Webhook Events
124
173
 
125
- - Checkout creation
126
- - Checkout confirmation
127
- - Success outcomes
128
- - Failure outcomes
174
+ Events may be emitted for:
129
175
 
130
- Webhooks may be triggered for both synchronous and asynchronous results.
176
+ - `checkout.create`
177
+ - `checkout.confirm`
178
+ - `checkout.success`
179
+ - `checkout.failure`
131
180
 
132
- All webhook deliveries are signed if a secret is provided.
181
+ Events are triggered for:
133
182
 
134
- Consumers are responsible for verifying signatures and handling retries idempotently.
183
+ - Immediate outcomes
184
+ - Asynchronous resolutions
185
+ - Retry scenarios
135
186
 
136
187
  ---
137
188
 
138
- ## Important Notes
189
+ ## Webhook Security
139
190
 
140
- - Not all operations resolve immediately.
141
- - Some failures are retryable.
142
- - The system may simulate temporary overload conditions.
143
- - Fraud checks may result in blocked transactions.
144
- - Consumers should implement robust retry and webhook handling logic.
191
+ If a secret is provided:
192
+
193
+ - Deliveries are signed
194
+ - Consumers must verify signatures
195
+ - Handlers must be idempotent
196
+
197
+ Retries may occur if delivery fails.
145
198
 
146
199
  ---
147
200
 
148
- ## Disclaimer
201
+ # Disclaimer
149
202
 
150
203
  This SDK is intended for evaluation and sandbox purposes only.
151
- It does not process real payments.
204
+
205
+ It does **not** process real payments and should not be used in production.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henrylabs-interview/payment-processor",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",