powertools-x402 0.1.0 → 0.1.1

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 +64 -0
  2. package/package.json +3 -1
package/README.md CHANGED
@@ -50,6 +50,8 @@ app.post(
50
50
  export const handler = (event: unknown, context: Context) => app.resolve(event, context);
51
51
  ```
52
52
 
53
+ Dollar prices settle in USDC on the route's network. `'$0.01'` on Base Sepolia charges 0.01 USDC.
54
+
53
55
  ### Read payment details in the handler
54
56
 
55
57
  ```ts
@@ -90,6 +92,51 @@ const x402 = createX402({
90
92
  });
91
93
  ```
92
94
 
95
+ ### Settle into your Stripe balance
96
+
97
+ Stripe supports x402 through [machine payments](https://docs.stripe.com/payments/machine/x402). You point `payTo` at a Stripe crypto deposit address, settle through the Coinbase Developer Platform facilitator, and record each settled payment as a Stripe PaymentIntent. Funds land in your Stripe balance next to your card payments.
98
+
99
+ ```bash
100
+ npm install stripe @coinbase/x402
101
+ ```
102
+
103
+ ```ts
104
+ import { createFacilitatorConfig } from '@coinbase/x402';
105
+ import Stripe from 'stripe';
106
+
107
+ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
108
+ apiVersion: '2026-05-27.preview' as Stripe.LatestApiVersion,
109
+ });
110
+
111
+ const x402 = createX402({
112
+ facilitator: createFacilitatorConfig(process.env.CDP_API_KEY_ID!, process.env.CDP_API_KEY_SECRET!),
113
+ network: 'eip155:8453', // Base mainnet
114
+ payTo: process.env.STRIPE_DEPOSIT_ADDRESS!, // POST /v1/crypto/deposit_addresses, one time
115
+ });
116
+
117
+ x402.resourceServer.onAfterSettle(async ({ result, requirements }) => {
118
+ if (!result.success || !result.transaction) return;
119
+ await stripe.paymentIntents.create(
120
+ {
121
+ amount: Math.round(Number(requirements.amount) / 10_000), // atomic USDC to cents
122
+ currency: 'usd',
123
+ confirm: true,
124
+ payment_method_data: { type: 'crypto' },
125
+ payment_method_types: ['crypto'],
126
+ payment_method_options: {
127
+ crypto: {
128
+ mode: 'transaction_verification',
129
+ transaction_verification_options: { network: 'base', transaction_hash: result.transaction },
130
+ } as Stripe.PaymentIntentCreateParams.PaymentMethodOptions.Crypto,
131
+ },
132
+ },
133
+ { idempotencyKey: result.transaction }
134
+ );
135
+ });
136
+ ```
137
+
138
+ Full working version in [example/stripe.ts](example/stripe.ts). Heads up: this uses Stripe's `2026-05-27.preview` API version, and you'll need the Stablecoins and Crypto payment method approved on your Stripe account.
139
+
93
140
  ### Accept multiple payment options on one route
94
141
 
95
142
  ```ts
@@ -103,6 +150,22 @@ x402.paid({
103
150
 
104
151
  Want to take payments on non-EVM networks? Register additional schemes with the `schemes` option on `createX402`.
105
152
 
153
+ ### Price in a specific token
154
+
155
+ Dollar strings are shorthand for USDC. To pin the exact asset yourself, pass atomic units and the token address:
156
+
157
+ ```ts
158
+ x402.paid({
159
+ price: {
160
+ amount: '10000', // atomic units, USDC has 6 decimals
161
+ asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', // USDC on Base Sepolia
162
+ extra: { name: 'USDC', version: '2' }, // EIP-712 domain the payer signs against
163
+ },
164
+ });
165
+ ```
166
+
167
+ The same shape works for any EIP-3009 token. Set `extra` to the token's EIP-712 domain.
168
+
106
169
  ### Let some callers through free
107
170
 
108
171
  ```ts
@@ -178,6 +241,7 @@ Need testnet USDC? Grab some from the [Circle faucet](https://faucet.circle.com/
178
241
 
179
242
  - [example/handler.ts](example/handler.ts) - lambdalith with free and paid routes
180
243
  - [example/client.ts](example/client.ts) - paying client, step by step
244
+ - [example/stripe.ts](example/stripe.ts) - settle x402 payments into your Stripe balance
181
245
  - [example/template.yaml](example/template.yaml) - SAM deploy (esbuild, ESM, HTTP API)
182
246
 
183
247
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powertools-x402",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "x402 payment middleware for AWS Lambda Powertools Event Handler",
5
5
  "license": "MIT",
6
6
  "author": "Allen Helton <allenheltondev@gmail.com>",
@@ -57,9 +57,11 @@
57
57
  "devDependencies": {
58
58
  "@aws-lambda-powertools/event-handler": "^2.35.0",
59
59
  "@aws-lambda-powertools/logger": "^2.35.0",
60
+ "@coinbase/x402": "^2.1.0",
60
61
  "@types/aws-lambda": "^8.10.152",
61
62
  "@types/node": "^24.0.0",
62
63
  "@vitest/coverage-v8": "^3.2.7",
64
+ "stripe": "^22.6.0",
63
65
  "tsup": "^8.4.0",
64
66
  "typescript": "^5.7.0",
65
67
  "viem": "^2.48.0",