@mixrpay/merchant-sdk 0.3.5 → 0.3.6
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 +10 -41
- package/package.json +2 -14
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.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ npm install @mixrpay/merchant-sdk
|
|
|
15
15
|
MIXRPAY_PUBLIC_KEY=pk_live_...
|
|
16
16
|
MIXRPAY_SECRET_KEY=sk_live_...
|
|
17
17
|
MIXRPAY_WEBHOOK_SECRET=whsec_...
|
|
18
|
-
MIXRPAY_HMAC_SECRET=hmac_...
|
|
18
|
+
MIXRPAY_HMAC_SECRET=hmac_...
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Get credentials from [Developer Settings](https://www.mixrpay.com/seller/developers).
|
|
@@ -29,6 +29,7 @@ import express from 'express';
|
|
|
29
29
|
import { mixrpay } from '@mixrpay/merchant-sdk/express';
|
|
30
30
|
|
|
31
31
|
const app = express();
|
|
32
|
+
app.use(express.json());
|
|
32
33
|
|
|
33
34
|
app.post('/api/generate', mixrpay({ priceUsd: 0.05 }), (req, res) => {
|
|
34
35
|
const { payer, amountUsd } = req.mixrPayment!;
|
|
@@ -39,10 +40,10 @@ app.post('/api/generate', mixrpay({ priceUsd: 0.05 }), (req, res) => {
|
|
|
39
40
|
### Next.js
|
|
40
41
|
|
|
41
42
|
```typescript
|
|
42
|
-
import { withMixrPay } from '@mixrpay/merchant-sdk/nextjs';
|
|
43
|
+
import { withMixrPay, MixrPayment } from '@mixrpay/merchant-sdk/nextjs';
|
|
43
44
|
import { NextRequest, NextResponse } from 'next/server';
|
|
44
45
|
|
|
45
|
-
async function handler(req: NextRequest, payment) {
|
|
46
|
+
async function handler(req: NextRequest, payment: MixrPayment) {
|
|
46
47
|
return NextResponse.json({ result: 'success' });
|
|
47
48
|
}
|
|
48
49
|
|
|
@@ -58,44 +59,24 @@ import { mixrpayPlugin, mixrpay } from '@mixrpay/merchant-sdk/fastify';
|
|
|
58
59
|
const app = Fastify();
|
|
59
60
|
app.register(mixrpayPlugin);
|
|
60
61
|
|
|
61
|
-
app.post('/api/generate', {
|
|
62
|
-
preHandler: mixrpay({ priceUsd: 0.05 })
|
|
63
|
-
}, async (req) => {
|
|
62
|
+
app.post('/api/generate', { preHandler: mixrpay({ priceUsd: 0.05 }) }, async (req) => {
|
|
64
63
|
return { result: 'success' };
|
|
65
64
|
});
|
|
66
65
|
```
|
|
67
66
|
|
|
68
|
-
## Widget
|
|
67
|
+
## Widget
|
|
69
68
|
|
|
70
69
|
```html
|
|
71
70
|
<script
|
|
72
71
|
src="https://www.mixrpay.com/widget.js"
|
|
73
72
|
data-seller-public-key="pk_live_..."
|
|
74
|
-
data-user-token="{{
|
|
73
|
+
data-user-token="{{ userToken }}">
|
|
75
74
|
</script>
|
|
76
75
|
|
|
77
76
|
<mixr-balance></mixr-balance>
|
|
78
|
-
|
|
79
|
-
<button data-meter-feature="generate" data-meter-price-usd="0.10">
|
|
80
|
-
Generate ($0.10)
|
|
81
|
-
</button>
|
|
82
77
|
```
|
|
83
78
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import crypto from 'crypto';
|
|
88
|
-
|
|
89
|
-
function generateUserToken(userId: string): string {
|
|
90
|
-
const timestamp = Date.now();
|
|
91
|
-
const data = `${userId}:${timestamp}`;
|
|
92
|
-
const signature = crypto
|
|
93
|
-
.createHmac('sha256', process.env.MIXRPAY_HMAC_SECRET!)
|
|
94
|
-
.update(data)
|
|
95
|
-
.digest('hex');
|
|
96
|
-
return `${data}:${signature}`;
|
|
97
|
-
}
|
|
98
|
-
```
|
|
79
|
+
Generate user tokens server-side using your HMAC secret. See [Widget docs](https://www.mixrpay.com/seller/widget).
|
|
99
80
|
|
|
100
81
|
## Webhooks
|
|
101
82
|
|
|
@@ -104,28 +85,16 @@ import { verifySessionWebhook } from '@mixrpay/merchant-sdk';
|
|
|
104
85
|
|
|
105
86
|
app.post('/webhooks/mixrpay', (req, res) => {
|
|
106
87
|
const sig = req.headers['x-mixrpay-signature'] as string;
|
|
107
|
-
|
|
108
88
|
if (!verifySessionWebhook(JSON.stringify(req.body), sig, process.env.MIXRPAY_WEBHOOK_SECRET!)) {
|
|
109
89
|
return res.status(401).json({ error: 'Invalid signature' });
|
|
110
90
|
}
|
|
111
|
-
|
|
112
|
-
// Handle event
|
|
113
91
|
res.json({ received: true });
|
|
114
92
|
});
|
|
115
93
|
```
|
|
116
94
|
|
|
117
|
-
## TypeScript
|
|
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
|
-
```
|
|
125
|
-
|
|
126
95
|
## Documentation
|
|
127
96
|
|
|
128
|
-
|
|
97
|
+
[mixrpay.com/seller/docs](https://www.mixrpay.com/seller/docs)
|
|
129
98
|
|
|
130
99
|
## License
|
|
131
100
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mixrpay/merchant-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Add x402 payments to your API in minutes - middleware for Express, Next.js, and Fastify",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,19 +41,7 @@
|
|
|
41
41
|
"lint": "eslint src/",
|
|
42
42
|
"typecheck": "tsc --noEmit"
|
|
43
43
|
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"x402",
|
|
46
|
-
"payments",
|
|
47
|
-
"ai",
|
|
48
|
-
"agents",
|
|
49
|
-
"micropayments",
|
|
50
|
-
"middleware",
|
|
51
|
-
"express",
|
|
52
|
-
"nextjs",
|
|
53
|
-
"fastify",
|
|
54
|
-
"usdc",
|
|
55
|
-
"crypto"
|
|
56
|
-
],
|
|
44
|
+
"keywords": [],
|
|
57
45
|
"author": "MixrPay",
|
|
58
46
|
"license": "MIT",
|
|
59
47
|
"repository": {
|