@mixrpay/merchant-sdk 0.3.5 → 0.4.0
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.
Potentially problematic release.
This version of @mixrpay/merchant-sdk might be problematic. Click here for more details.
- package/README.md +100 -40
- package/dist/index.d.mts +121 -48
- package/dist/index.d.ts +121 -48
- package/dist/index.js +0 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -70
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/express.d.mts +1 -7
- package/dist/middleware/express.d.ts +1 -7
- package/dist/middleware/express.js +0 -70
- package/dist/middleware/express.js.map +1 -1
- package/dist/middleware/express.mjs +0 -70
- package/dist/middleware/express.mjs.map +1 -1
- package/dist/middleware/fastify.d.mts +1 -4
- package/dist/middleware/fastify.d.ts +1 -4
- package/dist/middleware/fastify.js +0 -50
- package/dist/middleware/fastify.js.map +1 -1
- package/dist/middleware/fastify.mjs +0 -50
- package/dist/middleware/fastify.mjs.map +1 -1
- package/dist/middleware/nextjs.d.mts +2 -14
- package/dist/middleware/nextjs.d.ts +2 -14
- package/dist/middleware/nextjs.js +0 -71
- package/dist/middleware/nextjs.js.map +1 -1
- package/dist/middleware/nextjs.mjs +0 -71
- package/dist/middleware/nextjs.mjs.map +1 -1
- package/dist/{types-BwiuIaOu.d.mts → types-BO8cImOi.d.mts} +2 -58
- package/dist/{types-BwiuIaOu.d.ts → types-BO8cImOi.d.ts} +2 -58
- package/dist/widget/index.d.mts +106 -0
- package/dist/widget/index.d.ts +106 -0
- package/dist/widget/index.js +141 -0
- package/dist/widget/index.js.map +1 -0
- package/dist/widget/index.mjs +111 -0
- package/dist/widget/index.mjs.map +1 -0
- package/package.json +7 -15
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mixrpay/merchant-sdk
|
|
2
2
|
|
|
3
|
-
Accept payments from AI agents and web apps
|
|
3
|
+
Accept payments from AI agents and web apps. One SDK for backend middleware and frontend widget integration.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,19 +8,33 @@ Accept payments from AI agents and web apps with one middleware.
|
|
|
8
8
|
npm install @mixrpay/merchant-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Exports
|
|
12
|
+
|
|
13
|
+
| Import Path | Purpose |
|
|
14
|
+
|-------------|---------|
|
|
15
|
+
| `@mixrpay/merchant-sdk` | Core utilities, webhook verification |
|
|
16
|
+
| `@mixrpay/merchant-sdk/express` | Express middleware |
|
|
17
|
+
| `@mixrpay/merchant-sdk/nextjs` | Next.js App Router wrapper |
|
|
18
|
+
| `@mixrpay/merchant-sdk/fastify` | Fastify plugin |
|
|
19
|
+
| `@mixrpay/merchant-sdk/widget` | Programmatic widget injection |
|
|
20
|
+
| `@mixrpay/merchant-sdk/widget-elements` | TypeScript types for widget elements |
|
|
21
|
+
|
|
22
|
+
## Environment Variables
|
|
12
23
|
|
|
13
24
|
```bash
|
|
14
|
-
# .env
|
|
15
25
|
MIXRPAY_PUBLIC_KEY=pk_live_...
|
|
16
26
|
MIXRPAY_SECRET_KEY=sk_live_...
|
|
17
27
|
MIXRPAY_WEBHOOK_SECRET=whsec_...
|
|
18
|
-
MIXRPAY_HMAC_SECRET=hmac_...
|
|
28
|
+
MIXRPAY_HMAC_SECRET=hmac_...
|
|
19
29
|
```
|
|
20
30
|
|
|
21
31
|
Get credentials from [Developer Settings](https://www.mixrpay.com/seller/developers).
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Backend Middleware
|
|
36
|
+
|
|
37
|
+
Wrap your API routes to require payment. Works with sessions from the Widget or Agent SDK.
|
|
24
38
|
|
|
25
39
|
### Express
|
|
26
40
|
|
|
@@ -29,21 +43,22 @@ import express from 'express';
|
|
|
29
43
|
import { mixrpay } from '@mixrpay/merchant-sdk/express';
|
|
30
44
|
|
|
31
45
|
const app = express();
|
|
46
|
+
app.use(express.json());
|
|
32
47
|
|
|
33
48
|
app.post('/api/generate', mixrpay({ priceUsd: 0.05 }), (req, res) => {
|
|
34
|
-
const { payer, amountUsd } = req.mixrPayment!;
|
|
49
|
+
const { payer, amountUsd, method } = req.mixrPayment!;
|
|
35
50
|
res.json({ result: 'success' });
|
|
36
51
|
});
|
|
37
52
|
```
|
|
38
53
|
|
|
39
|
-
### Next.js
|
|
54
|
+
### Next.js (App Router)
|
|
40
55
|
|
|
41
56
|
```typescript
|
|
42
|
-
import { withMixrPay } from '@mixrpay/merchant-sdk/nextjs';
|
|
57
|
+
import { withMixrPay, MixrPayPaymentResult } from '@mixrpay/merchant-sdk/nextjs';
|
|
43
58
|
import { NextRequest, NextResponse } from 'next/server';
|
|
44
59
|
|
|
45
|
-
async function handler(req: NextRequest, payment) {
|
|
46
|
-
return NextResponse.json({ result: 'success' });
|
|
60
|
+
async function handler(req: NextRequest, payment: MixrPayPaymentResult) {
|
|
61
|
+
return NextResponse.json({ result: 'success', payer: payment.payer });
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
export const POST = withMixrPay({ priceUsd: 0.05 }, handler);
|
|
@@ -53,50 +68,98 @@ export const POST = withMixrPay({ priceUsd: 0.05 }, handler);
|
|
|
53
68
|
|
|
54
69
|
```typescript
|
|
55
70
|
import Fastify from 'fastify';
|
|
56
|
-
import {
|
|
71
|
+
import { x402Plugin, x402 } from '@mixrpay/merchant-sdk/fastify';
|
|
57
72
|
|
|
58
73
|
const app = Fastify();
|
|
59
|
-
app.register(
|
|
74
|
+
app.register(x402Plugin);
|
|
60
75
|
|
|
61
|
-
app.post('/api/generate', {
|
|
62
|
-
preHandler: mixrpay({ priceUsd: 0.05 })
|
|
63
|
-
}, async (req) => {
|
|
76
|
+
app.post('/api/generate', { preHandler: x402({ price: 0.05 }) }, async (req) => {
|
|
64
77
|
return { result: 'success' };
|
|
65
78
|
});
|
|
66
79
|
```
|
|
67
80
|
|
|
68
|
-
|
|
81
|
+
### Middleware Options
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
mixrpay({
|
|
85
|
+
priceUsd: 0.05, // Fixed price
|
|
86
|
+
getPrice: (req) => calculatePrice(req.body), // Dynamic pricing
|
|
87
|
+
feature: 'ai-chat', // Feature slug for tracking
|
|
88
|
+
onPayment: (payment) => log(payment), // Callback on success
|
|
89
|
+
skip: (req) => req.user?.isPremium, // Skip payment conditionally
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Frontend Widget
|
|
96
|
+
|
|
97
|
+
### HTML (Simple)
|
|
69
98
|
|
|
70
99
|
```html
|
|
71
100
|
<script
|
|
72
101
|
src="https://www.mixrpay.com/widget.js"
|
|
73
102
|
data-seller-public-key="pk_live_..."
|
|
74
|
-
data-user-token="{{
|
|
103
|
+
data-user-token="{{ serverGeneratedToken }}">
|
|
75
104
|
</script>
|
|
76
105
|
|
|
77
106
|
<mixr-balance></mixr-balance>
|
|
78
107
|
|
|
79
|
-
<button data-meter-feature="generate" data-meter-price-usd="0.
|
|
80
|
-
Generate ($0.
|
|
108
|
+
<button data-meter-feature="generate" data-meter-price-usd="0.05">
|
|
109
|
+
Generate ($0.05)
|
|
81
110
|
</button>
|
|
82
111
|
```
|
|
83
112
|
|
|
84
|
-
###
|
|
113
|
+
### Programmatic (SPA/React/Vue)
|
|
85
114
|
|
|
86
115
|
```typescript
|
|
87
|
-
import
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
import { injectWidget, isWidgetLoaded } from '@mixrpay/merchant-sdk/widget';
|
|
117
|
+
|
|
118
|
+
// Inject widget with config
|
|
119
|
+
await injectWidget({
|
|
120
|
+
publicKey: 'pk_live_...',
|
|
121
|
+
userToken: serverGeneratedToken,
|
|
122
|
+
theme: 'dark',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Use the widget API
|
|
126
|
+
if (isWidgetLoaded()) {
|
|
127
|
+
window.Mixr.openWallet();
|
|
128
|
+
window.Mixr.charge('feature', '0.05', buttonElement);
|
|
97
129
|
}
|
|
98
130
|
```
|
|
99
131
|
|
|
132
|
+
### Widget Events
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
window.addEventListener('mixr:charge-success', (e) => {
|
|
136
|
+
const { feature, price, txHash } = e.detail;
|
|
137
|
+
// Payment succeeded, unlock feature
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
window.addEventListener('mixr:low-balance', (e) => {
|
|
141
|
+
// User needs to add funds
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
window.addEventListener('mixr:session-updated', (e) => {
|
|
145
|
+
const { sessionId, remainingUsd } = e.detail;
|
|
146
|
+
// Session state changed
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### TypeScript Support
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// For custom element types in JSX
|
|
154
|
+
import '@mixrpay/merchant-sdk/widget-elements';
|
|
155
|
+
|
|
156
|
+
// Now TypeScript knows about:
|
|
157
|
+
<mixr-balance data-theme="dark" />
|
|
158
|
+
<mixr-wallet />
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
100
163
|
## Webhooks
|
|
101
164
|
|
|
102
165
|
```typescript
|
|
@@ -109,23 +172,20 @@ app.post('/webhooks/mixrpay', (req, res) => {
|
|
|
109
172
|
return res.status(401).json({ error: 'Invalid signature' });
|
|
110
173
|
}
|
|
111
174
|
|
|
112
|
-
|
|
175
|
+
const { event, amount_usd, user_wallet } = req.body;
|
|
176
|
+
// Handle: session.created, session.charged, session.revoked, session.expired
|
|
177
|
+
|
|
113
178
|
res.json({ received: true });
|
|
114
179
|
});
|
|
115
180
|
```
|
|
116
181
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
import type { MixrPayOptions, MixrPayment } from '@mixrpay/merchant-sdk';
|
|
121
|
-
|
|
122
|
-
// Widget element types
|
|
123
|
-
import '@mixrpay/merchant-sdk/widget-elements';
|
|
124
|
-
```
|
|
182
|
+
---
|
|
125
183
|
|
|
126
184
|
## Documentation
|
|
127
185
|
|
|
128
|
-
|
|
186
|
+
- [Integration Guide](https://www.mixrpay.com/seller/integrate)
|
|
187
|
+
- [API Reference](https://www.mixrpay.com/seller/api-reference)
|
|
188
|
+
- [Widget Docs](https://www.mixrpay.com/seller/widget)
|
|
129
189
|
|
|
130
190
|
## License
|
|
131
191
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { M as MixrPayOptions, a as MixrPayPaymentResult, b as PaymentMethod, c as PriceContext } from './types-BwiuIaOu.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* MixrPay Merchant SDK - Payment Receipt Verification
|
|
6
|
-
*
|
|
7
|
-
* Verify JWT payment receipts issued by MixrPay after successful x402 payments.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { verifyPaymentReceipt } from '@mixrpay/merchant-sdk';
|
|
12
|
-
*
|
|
13
|
-
* const receipt = req.headers['x-payment-receipt'];
|
|
14
|
-
* const payment = await verifyPaymentReceipt(receipt);
|
|
15
|
-
*
|
|
16
|
-
* console.log(`Payment received: $${payment.amountUsd} from ${payment.payer}`);
|
|
17
|
-
* console.log(`Transaction: ${payment.txHash}`);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Verify a JWT payment receipt from MixrPay.
|
|
23
|
-
*
|
|
24
|
-
* This function:
|
|
25
|
-
* 1. Fetches the JWKS from MixrPay (cached for 1 hour)
|
|
26
|
-
* 2. Verifies the JWT signature using RS256
|
|
27
|
-
* 3. Validates standard JWT claims (exp, iat)
|
|
28
|
-
* 4. Returns the typed payment receipt
|
|
29
|
-
*
|
|
30
|
-
* @param receipt - The JWT receipt string from X-Payment-Receipt header
|
|
31
|
-
* @param options - Optional configuration (custom JWKS URL, issuer validation)
|
|
32
|
-
* @returns Verified payment receipt
|
|
33
|
-
* @throws Error if verification fails
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // Basic usage
|
|
38
|
-
* const payment = await verifyPaymentReceipt(receipt);
|
|
39
|
-
*
|
|
40
|
-
* // With custom JWKS URL (for testing or self-hosted)
|
|
41
|
-
* const payment = await verifyPaymentReceipt(receipt, {
|
|
42
|
-
* jwksUrl: 'https://your-mixrpay.com/.well-known/jwks'
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function verifyPaymentReceipt(receipt: string, options?: VerifyReceiptOptions): Promise<PaymentReceipt>;
|
|
1
|
+
export { M as MixrPayOptions, a as MixrPayPaymentResult, P as PaymentMethod, b as PriceContext } from './types-BO8cImOi.mjs';
|
|
47
2
|
|
|
48
3
|
interface SessionGrant {
|
|
49
4
|
/** Session key ID */
|
|
@@ -343,6 +298,47 @@ interface MixrAPI {
|
|
|
343
298
|
* Make an authenticated fetch request with MixrPay headers
|
|
344
299
|
*/
|
|
345
300
|
fetch(url: string, options?: RequestInit & { autoPrompt?: boolean }): Promise<Response>;
|
|
301
|
+
|
|
302
|
+
/** Check and refresh session state from server */
|
|
303
|
+
checkSession(): Promise<void>;
|
|
304
|
+
|
|
305
|
+
/** Reset prompt limit counters (for auto-prompt functionality) */
|
|
306
|
+
resetPromptLimit(): void;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Get URL for wallet actions
|
|
310
|
+
* @param tab - Optional tab to open
|
|
311
|
+
*/
|
|
312
|
+
getActionUrl(tab?: string): string;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Open agent chat in a popup window
|
|
316
|
+
* @param agentId - The agent ID to chat with
|
|
317
|
+
* @returns The popup window reference, or null if config is invalid
|
|
318
|
+
*/
|
|
319
|
+
openAgent(agentId: string): Window | null;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get embeddable URL for agent chat
|
|
323
|
+
* @param agentId - The agent ID
|
|
324
|
+
* @param options - Embed options
|
|
325
|
+
*/
|
|
326
|
+
getAgentEmbedUrl(agentId: string, options?: { embed?: boolean }): string;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Verify widget credentials with MixrPay server.
|
|
330
|
+
* Useful for debugging HMAC or configuration issues.
|
|
331
|
+
* @param testUserId - Optional test user ID for signature verification
|
|
332
|
+
*/
|
|
333
|
+
verifyCredentials(testUserId?: string): Promise<{
|
|
334
|
+
valid: boolean;
|
|
335
|
+
error?: string;
|
|
336
|
+
merchant?: {
|
|
337
|
+
id: string;
|
|
338
|
+
name: string;
|
|
339
|
+
};
|
|
340
|
+
mode?: string;
|
|
341
|
+
}>;
|
|
346
342
|
}
|
|
347
343
|
|
|
348
344
|
// =============================================================================
|
|
@@ -356,6 +352,10 @@ interface MixrChargeSuccessDetail {
|
|
|
356
352
|
price: string;
|
|
357
353
|
/** Unique charge ID */
|
|
358
354
|
chargeId?: string;
|
|
355
|
+
/** Transaction hash if available */
|
|
356
|
+
txHash?: string;
|
|
357
|
+
/** New balance after charge in USD */
|
|
358
|
+
newBalance?: number;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
interface MixrChargeErrorDetail {
|
|
@@ -388,6 +388,58 @@ interface MixrTransactionDetail {
|
|
|
388
388
|
amount: number;
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
interface MixrReadyDetail {
|
|
392
|
+
/** Whether widget is ready for transactions */
|
|
393
|
+
ready: boolean;
|
|
394
|
+
/** List of issues preventing readiness */
|
|
395
|
+
issues: string[];
|
|
396
|
+
/** Current balance in USD */
|
|
397
|
+
balanceUsd: number;
|
|
398
|
+
/** Current session ID if any */
|
|
399
|
+
sessionId: string | null;
|
|
400
|
+
/** Remaining session spending limit */
|
|
401
|
+
sessionRemaining: number;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface MixrSessionAuthorizedDetail {
|
|
405
|
+
/** The newly authorized session ID */
|
|
406
|
+
sessionId: string;
|
|
407
|
+
/** Spending limit in USD */
|
|
408
|
+
spendingLimitUsd: number;
|
|
409
|
+
/** Session expiration timestamp */
|
|
410
|
+
expiresAt: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface MixrErrorDetail {
|
|
414
|
+
/** Error code (e.g., 'INVALID_WIDGET_TOKEN', 'NETWORK_ERROR') */
|
|
415
|
+
code: string;
|
|
416
|
+
/** Human-readable error message */
|
|
417
|
+
message?: string;
|
|
418
|
+
/** Server error message if from API */
|
|
419
|
+
serverError?: string;
|
|
420
|
+
/** Original error message if wrapped */
|
|
421
|
+
originalError?: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
interface MixrAuthenticatedDetail {
|
|
425
|
+
/** User's wallet address */
|
|
426
|
+
walletAddress: string;
|
|
427
|
+
/** Privy user ID if available */
|
|
428
|
+
privyUserId?: string;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
interface MixrSessionLimitDetail {
|
|
432
|
+
/** Remaining session spending limit */
|
|
433
|
+
remaining: number;
|
|
434
|
+
/** Required amount for the operation */
|
|
435
|
+
required: number;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
interface MixrThemeChangedDetail {
|
|
439
|
+
/** Current effective theme */
|
|
440
|
+
theme: 'dark' | 'light';
|
|
441
|
+
}
|
|
442
|
+
|
|
391
443
|
// =============================================================================
|
|
392
444
|
// Custom Events Map
|
|
393
445
|
// =============================================================================
|
|
@@ -403,12 +455,33 @@ interface MixrTransactionDetail {
|
|
|
403
455
|
* ```
|
|
404
456
|
*/
|
|
405
457
|
interface MixrEventMap {
|
|
458
|
+
// Charge events
|
|
406
459
|
'mixr:charge-success': CustomEvent<MixrChargeSuccessDetail>;
|
|
407
460
|
'mixr:charge-error': CustomEvent<MixrChargeErrorDetail>;
|
|
461
|
+
|
|
462
|
+
// Balance events
|
|
408
463
|
'mixr:low-balance': CustomEvent<MixrLowBalanceDetail>;
|
|
409
|
-
'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
|
|
410
464
|
'mixr:funding': CustomEvent<MixrFundingDetail>;
|
|
411
465
|
'mixr:transaction': CustomEvent<MixrTransactionDetail>;
|
|
466
|
+
|
|
467
|
+
// State events
|
|
468
|
+
'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
|
|
469
|
+
'mixr:ready': CustomEvent<MixrReadyDetail>;
|
|
470
|
+
'mixr:theme-changed': CustomEvent<MixrThemeChangedDetail>;
|
|
471
|
+
|
|
472
|
+
// Session events
|
|
473
|
+
'mixr:session-updated': CustomEvent<MixrSessionState>;
|
|
474
|
+
'mixr:session-authorized': CustomEvent<MixrSessionAuthorizedDetail>;
|
|
475
|
+
'mixr:session-error': CustomEvent<{ error: string }>;
|
|
476
|
+
'mixr:session-limit': CustomEvent<MixrSessionLimitDetail>;
|
|
477
|
+
|
|
478
|
+
// Authentication events
|
|
479
|
+
'mixr:authenticated': CustomEvent<MixrAuthenticatedDetail>;
|
|
480
|
+
'mixr:auth-cancelled': CustomEvent<void>;
|
|
481
|
+
'mixr:disconnected': CustomEvent<void>;
|
|
482
|
+
|
|
483
|
+
// Error events
|
|
484
|
+
'mixr:error': CustomEvent<MixrErrorDetail>;
|
|
412
485
|
}
|
|
413
486
|
|
|
414
487
|
// =============================================================================
|
|
@@ -454,4 +527,4 @@ declare global {
|
|
|
454
527
|
}
|
|
455
528
|
}
|
|
456
529
|
|
|
457
|
-
export { type EnvValidationResult, MIXRPAY_API_URL,
|
|
530
|
+
export { type EnvValidationResult, MIXRPAY_API_URL, type SessionGrant, WIDGET_SCRIPT_URL, getWidgetUrl, logEnvValidation, minorToUsd, usdToMinor, validateEnv, verifySessionWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { M as MixrPayOptions, a as MixrPayPaymentResult, b as PaymentMethod, c as PriceContext } from './types-BwiuIaOu.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* MixrPay Merchant SDK - Payment Receipt Verification
|
|
6
|
-
*
|
|
7
|
-
* Verify JWT payment receipts issued by MixrPay after successful x402 payments.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { verifyPaymentReceipt } from '@mixrpay/merchant-sdk';
|
|
12
|
-
*
|
|
13
|
-
* const receipt = req.headers['x-payment-receipt'];
|
|
14
|
-
* const payment = await verifyPaymentReceipt(receipt);
|
|
15
|
-
*
|
|
16
|
-
* console.log(`Payment received: $${payment.amountUsd} from ${payment.payer}`);
|
|
17
|
-
* console.log(`Transaction: ${payment.txHash}`);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Verify a JWT payment receipt from MixrPay.
|
|
23
|
-
*
|
|
24
|
-
* This function:
|
|
25
|
-
* 1. Fetches the JWKS from MixrPay (cached for 1 hour)
|
|
26
|
-
* 2. Verifies the JWT signature using RS256
|
|
27
|
-
* 3. Validates standard JWT claims (exp, iat)
|
|
28
|
-
* 4. Returns the typed payment receipt
|
|
29
|
-
*
|
|
30
|
-
* @param receipt - The JWT receipt string from X-Payment-Receipt header
|
|
31
|
-
* @param options - Optional configuration (custom JWKS URL, issuer validation)
|
|
32
|
-
* @returns Verified payment receipt
|
|
33
|
-
* @throws Error if verification fails
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // Basic usage
|
|
38
|
-
* const payment = await verifyPaymentReceipt(receipt);
|
|
39
|
-
*
|
|
40
|
-
* // With custom JWKS URL (for testing or self-hosted)
|
|
41
|
-
* const payment = await verifyPaymentReceipt(receipt, {
|
|
42
|
-
* jwksUrl: 'https://your-mixrpay.com/.well-known/jwks'
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function verifyPaymentReceipt(receipt: string, options?: VerifyReceiptOptions): Promise<PaymentReceipt>;
|
|
1
|
+
export { M as MixrPayOptions, a as MixrPayPaymentResult, P as PaymentMethod, b as PriceContext } from './types-BO8cImOi.js';
|
|
47
2
|
|
|
48
3
|
interface SessionGrant {
|
|
49
4
|
/** Session key ID */
|
|
@@ -343,6 +298,47 @@ interface MixrAPI {
|
|
|
343
298
|
* Make an authenticated fetch request with MixrPay headers
|
|
344
299
|
*/
|
|
345
300
|
fetch(url: string, options?: RequestInit & { autoPrompt?: boolean }): Promise<Response>;
|
|
301
|
+
|
|
302
|
+
/** Check and refresh session state from server */
|
|
303
|
+
checkSession(): Promise<void>;
|
|
304
|
+
|
|
305
|
+
/** Reset prompt limit counters (for auto-prompt functionality) */
|
|
306
|
+
resetPromptLimit(): void;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Get URL for wallet actions
|
|
310
|
+
* @param tab - Optional tab to open
|
|
311
|
+
*/
|
|
312
|
+
getActionUrl(tab?: string): string;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Open agent chat in a popup window
|
|
316
|
+
* @param agentId - The agent ID to chat with
|
|
317
|
+
* @returns The popup window reference, or null if config is invalid
|
|
318
|
+
*/
|
|
319
|
+
openAgent(agentId: string): Window | null;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get embeddable URL for agent chat
|
|
323
|
+
* @param agentId - The agent ID
|
|
324
|
+
* @param options - Embed options
|
|
325
|
+
*/
|
|
326
|
+
getAgentEmbedUrl(agentId: string, options?: { embed?: boolean }): string;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Verify widget credentials with MixrPay server.
|
|
330
|
+
* Useful for debugging HMAC or configuration issues.
|
|
331
|
+
* @param testUserId - Optional test user ID for signature verification
|
|
332
|
+
*/
|
|
333
|
+
verifyCredentials(testUserId?: string): Promise<{
|
|
334
|
+
valid: boolean;
|
|
335
|
+
error?: string;
|
|
336
|
+
merchant?: {
|
|
337
|
+
id: string;
|
|
338
|
+
name: string;
|
|
339
|
+
};
|
|
340
|
+
mode?: string;
|
|
341
|
+
}>;
|
|
346
342
|
}
|
|
347
343
|
|
|
348
344
|
// =============================================================================
|
|
@@ -356,6 +352,10 @@ interface MixrChargeSuccessDetail {
|
|
|
356
352
|
price: string;
|
|
357
353
|
/** Unique charge ID */
|
|
358
354
|
chargeId?: string;
|
|
355
|
+
/** Transaction hash if available */
|
|
356
|
+
txHash?: string;
|
|
357
|
+
/** New balance after charge in USD */
|
|
358
|
+
newBalance?: number;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
interface MixrChargeErrorDetail {
|
|
@@ -388,6 +388,58 @@ interface MixrTransactionDetail {
|
|
|
388
388
|
amount: number;
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
interface MixrReadyDetail {
|
|
392
|
+
/** Whether widget is ready for transactions */
|
|
393
|
+
ready: boolean;
|
|
394
|
+
/** List of issues preventing readiness */
|
|
395
|
+
issues: string[];
|
|
396
|
+
/** Current balance in USD */
|
|
397
|
+
balanceUsd: number;
|
|
398
|
+
/** Current session ID if any */
|
|
399
|
+
sessionId: string | null;
|
|
400
|
+
/** Remaining session spending limit */
|
|
401
|
+
sessionRemaining: number;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface MixrSessionAuthorizedDetail {
|
|
405
|
+
/** The newly authorized session ID */
|
|
406
|
+
sessionId: string;
|
|
407
|
+
/** Spending limit in USD */
|
|
408
|
+
spendingLimitUsd: number;
|
|
409
|
+
/** Session expiration timestamp */
|
|
410
|
+
expiresAt: string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface MixrErrorDetail {
|
|
414
|
+
/** Error code (e.g., 'INVALID_WIDGET_TOKEN', 'NETWORK_ERROR') */
|
|
415
|
+
code: string;
|
|
416
|
+
/** Human-readable error message */
|
|
417
|
+
message?: string;
|
|
418
|
+
/** Server error message if from API */
|
|
419
|
+
serverError?: string;
|
|
420
|
+
/** Original error message if wrapped */
|
|
421
|
+
originalError?: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
interface MixrAuthenticatedDetail {
|
|
425
|
+
/** User's wallet address */
|
|
426
|
+
walletAddress: string;
|
|
427
|
+
/** Privy user ID if available */
|
|
428
|
+
privyUserId?: string;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
interface MixrSessionLimitDetail {
|
|
432
|
+
/** Remaining session spending limit */
|
|
433
|
+
remaining: number;
|
|
434
|
+
/** Required amount for the operation */
|
|
435
|
+
required: number;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
interface MixrThemeChangedDetail {
|
|
439
|
+
/** Current effective theme */
|
|
440
|
+
theme: 'dark' | 'light';
|
|
441
|
+
}
|
|
442
|
+
|
|
391
443
|
// =============================================================================
|
|
392
444
|
// Custom Events Map
|
|
393
445
|
// =============================================================================
|
|
@@ -403,12 +455,33 @@ interface MixrTransactionDetail {
|
|
|
403
455
|
* ```
|
|
404
456
|
*/
|
|
405
457
|
interface MixrEventMap {
|
|
458
|
+
// Charge events
|
|
406
459
|
'mixr:charge-success': CustomEvent<MixrChargeSuccessDetail>;
|
|
407
460
|
'mixr:charge-error': CustomEvent<MixrChargeErrorDetail>;
|
|
461
|
+
|
|
462
|
+
// Balance events
|
|
408
463
|
'mixr:low-balance': CustomEvent<MixrLowBalanceDetail>;
|
|
409
|
-
'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
|
|
410
464
|
'mixr:funding': CustomEvent<MixrFundingDetail>;
|
|
411
465
|
'mixr:transaction': CustomEvent<MixrTransactionDetail>;
|
|
466
|
+
|
|
467
|
+
// State events
|
|
468
|
+
'mixr:state-updated': CustomEvent<MixrStateUpdatedDetail>;
|
|
469
|
+
'mixr:ready': CustomEvent<MixrReadyDetail>;
|
|
470
|
+
'mixr:theme-changed': CustomEvent<MixrThemeChangedDetail>;
|
|
471
|
+
|
|
472
|
+
// Session events
|
|
473
|
+
'mixr:session-updated': CustomEvent<MixrSessionState>;
|
|
474
|
+
'mixr:session-authorized': CustomEvent<MixrSessionAuthorizedDetail>;
|
|
475
|
+
'mixr:session-error': CustomEvent<{ error: string }>;
|
|
476
|
+
'mixr:session-limit': CustomEvent<MixrSessionLimitDetail>;
|
|
477
|
+
|
|
478
|
+
// Authentication events
|
|
479
|
+
'mixr:authenticated': CustomEvent<MixrAuthenticatedDetail>;
|
|
480
|
+
'mixr:auth-cancelled': CustomEvent<void>;
|
|
481
|
+
'mixr:disconnected': CustomEvent<void>;
|
|
482
|
+
|
|
483
|
+
// Error events
|
|
484
|
+
'mixr:error': CustomEvent<MixrErrorDetail>;
|
|
412
485
|
}
|
|
413
486
|
|
|
414
487
|
// =============================================================================
|
|
@@ -454,4 +527,4 @@ declare global {
|
|
|
454
527
|
}
|
|
455
528
|
}
|
|
456
529
|
|
|
457
|
-
export { type EnvValidationResult, MIXRPAY_API_URL,
|
|
530
|
+
export { type EnvValidationResult, MIXRPAY_API_URL, type SessionGrant, WIDGET_SCRIPT_URL, getWidgetUrl, logEnvValidation, minorToUsd, usdToMinor, validateEnv, verifySessionWebhook };
|