@henrylabs-interview/payment-processor 0.1.2 → 0.1.3
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.
- package/README.md +141 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,151 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Henry Labs - Interview: Payment Processor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight payments SDK for creating and confirming checkouts, with built-in webhook support.
|
|
4
|
+
|
|
5
|
+
This SDK simulates a real-world payment processing system, including fraud detection, transient errors, retries, and asynchronous authorization flows.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
4
10
|
|
|
5
11
|
```bash
|
|
6
12
|
bun install
|
|
7
13
|
```
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
Build:
|
|
10
16
|
|
|
11
17
|
```bash
|
|
12
|
-
bun run
|
|
18
|
+
bun run build
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
The SDK provides three primary capabilities:
|
|
26
|
+
|
|
27
|
+
- Create a checkout
|
|
28
|
+
- Confirm a checkout
|
|
29
|
+
- Register webhook endpoints
|
|
30
|
+
|
|
31
|
+
The system performs internal validation, fraud screening, and risk checks.
|
|
32
|
+
Depending on system conditions, operations may:
|
|
33
|
+
|
|
34
|
+
- Succeed immediately
|
|
35
|
+
- Succeed asynchronously
|
|
36
|
+
- Require a retry
|
|
37
|
+
- Fail due to risk controls
|
|
38
|
+
- Fail due to temporary system overload
|
|
39
|
+
|
|
40
|
+
Consumers should always handle both synchronous responses and webhook events.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### Initialize
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { PaymentSDK } from 'henry-labs/take-home';
|
|
50
|
+
|
|
51
|
+
const sdk = new PaymentSDK();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Create a Checkout
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const response = await sdk.create({
|
|
60
|
+
amount: 1000,
|
|
61
|
+
currency: 'USD',
|
|
62
|
+
customerId: 'cust_123',
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Behavior
|
|
67
|
+
|
|
68
|
+
Creating a checkout may:
|
|
69
|
+
|
|
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
|
|
75
|
+
|
|
76
|
+
If the checkout is authorized asynchronously, the final outcome will be delivered via webhook.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Confirm a Checkout
|
|
81
|
+
|
|
82
|
+
```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
|
+
},
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Behavior
|
|
96
|
+
|
|
97
|
+
Confirmation requests are subject to:
|
|
98
|
+
|
|
99
|
+
- Card validation
|
|
100
|
+
- Fraud screening
|
|
101
|
+
- Retry conditions
|
|
102
|
+
- System load conditions
|
|
103
|
+
|
|
104
|
+
Confirmations may resolve immediately or asynchronously.
|
|
105
|
+
Webhook handling is required to receive final outcomes in deferred cases.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Webhooks
|
|
110
|
+
|
|
111
|
+
You can register webhook endpoints to receive event notifications.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
sdk.webhooks.createEndpoint({
|
|
115
|
+
url: 'https://example.com/webhooks',
|
|
116
|
+
event: 'checkout.confirm',
|
|
117
|
+
secret: 'whsec_...',
|
|
118
|
+
});
|
|
13
119
|
```
|
|
14
120
|
|
|
15
|
-
|
|
121
|
+
### Webhook Events
|
|
122
|
+
|
|
123
|
+
Events are emitted for:
|
|
124
|
+
|
|
125
|
+
- Checkout creation
|
|
126
|
+
- Checkout confirmation
|
|
127
|
+
- Success outcomes
|
|
128
|
+
- Failure outcomes
|
|
129
|
+
|
|
130
|
+
Webhooks may be triggered for both synchronous and asynchronous results.
|
|
131
|
+
|
|
132
|
+
All webhook deliveries are signed if a secret is provided.
|
|
133
|
+
|
|
134
|
+
Consumers are responsible for verifying signatures and handling retries idempotently.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Important Notes
|
|
139
|
+
|
|
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.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Disclaimer
|
|
149
|
+
|
|
150
|
+
This SDK is intended for evaluation and sandbox purposes only.
|
|
151
|
+
It does not process real payments.
|