@mixrpay/merchant-sdk 0.1.1 → 0.2.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.
@@ -1,56 +0,0 @@
1
- import { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
- import { X as X402PaymentResult, b as X402Options } from '../types-BJNy6Hhb.mjs';
3
-
4
- /**
5
- * MixrPay Merchant SDK - Fastify Plugin
6
- *
7
- * Add x402 payment requirement to Fastify routes.
8
- *
9
- * @example
10
- * ```typescript
11
- * import Fastify from 'fastify';
12
- * import { x402Plugin, x402 } from '@mixrpay/merchant-sdk/fastify';
13
- *
14
- * const app = Fastify();
15
- *
16
- * // Register the plugin
17
- * app.register(x402Plugin, {
18
- * recipient: '0x...', // or use MIXRPAY_MERCHANT_ADDRESS env var
19
- * });
20
- *
21
- * // Use on routes
22
- * app.post('/api/query', { preHandler: x402({ price: 0.05 }) }, async (req, reply) => {
23
- * return { result: 'success', payer: req.x402Payment?.payer };
24
- * });
25
- *
26
- * // With JWT receipts
27
- * app.post('/api/premium', { preHandler: x402({ price: 0.10, receiptMode: 'jwt' }) }, handler);
28
- * ```
29
- */
30
-
31
- declare module 'fastify' {
32
- interface FastifyRequest {
33
- x402Payment?: X402PaymentResult;
34
- }
35
- }
36
- interface X402PluginOptions {
37
- /** Default recipient address (can be overridden per route) */
38
- recipient?: string;
39
- /** Default chain ID */
40
- chainId?: number;
41
- /** Default facilitator URL */
42
- facilitator?: string;
43
- }
44
- /**
45
- * Fastify plugin that adds x402 payment support.
46
- */
47
- declare const x402Plugin: FastifyPluginCallback<X402PluginOptions>;
48
- /**
49
- * Create a preHandler hook that requires x402 payment.
50
- *
51
- * @param options - x402 configuration options
52
- * @returns Fastify preHandler function
53
- */
54
- declare function x402(options: X402Options): (request: FastifyRequest, reply: FastifyReply) => Promise<undefined>;
55
-
56
- export { X402Options, X402PaymentResult, type X402PluginOptions, x402, x402Plugin };
@@ -1,56 +0,0 @@
1
- import { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
- import { X as X402PaymentResult, b as X402Options } from '../types-BJNy6Hhb.js';
3
-
4
- /**
5
- * MixrPay Merchant SDK - Fastify Plugin
6
- *
7
- * Add x402 payment requirement to Fastify routes.
8
- *
9
- * @example
10
- * ```typescript
11
- * import Fastify from 'fastify';
12
- * import { x402Plugin, x402 } from '@mixrpay/merchant-sdk/fastify';
13
- *
14
- * const app = Fastify();
15
- *
16
- * // Register the plugin
17
- * app.register(x402Plugin, {
18
- * recipient: '0x...', // or use MIXRPAY_MERCHANT_ADDRESS env var
19
- * });
20
- *
21
- * // Use on routes
22
- * app.post('/api/query', { preHandler: x402({ price: 0.05 }) }, async (req, reply) => {
23
- * return { result: 'success', payer: req.x402Payment?.payer };
24
- * });
25
- *
26
- * // With JWT receipts
27
- * app.post('/api/premium', { preHandler: x402({ price: 0.10, receiptMode: 'jwt' }) }, handler);
28
- * ```
29
- */
30
-
31
- declare module 'fastify' {
32
- interface FastifyRequest {
33
- x402Payment?: X402PaymentResult;
34
- }
35
- }
36
- interface X402PluginOptions {
37
- /** Default recipient address (can be overridden per route) */
38
- recipient?: string;
39
- /** Default chain ID */
40
- chainId?: number;
41
- /** Default facilitator URL */
42
- facilitator?: string;
43
- }
44
- /**
45
- * Fastify plugin that adds x402 payment support.
46
- */
47
- declare const x402Plugin: FastifyPluginCallback<X402PluginOptions>;
48
- /**
49
- * Create a preHandler hook that requires x402 payment.
50
- *
51
- * @param options - x402 configuration options
52
- * @returns Fastify preHandler function
53
- */
54
- declare function x402(options: X402Options): (request: FastifyRequest, reply: FastifyReply) => Promise<undefined>;
55
-
56
- export { X402Options, X402PaymentResult, type X402PluginOptions, x402, x402Plugin };
@@ -1,78 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { X as X402PaymentResult, R as ReceiptMode } from '../types-BJNy6Hhb.mjs';
3
-
4
- /**
5
- * MixrPay Merchant SDK - Next.js Integration
6
- *
7
- * Add x402 payment requirement to Next.js API routes.
8
- *
9
- * @example
10
- * ```typescript
11
- * // app/api/query/route.ts
12
- * import { withX402 } from '@mixrpay/merchant-sdk/nextjs';
13
- *
14
- * async function handler(req: NextRequest, payment: X402PaymentResult) {
15
- * // This handler only runs after payment is verified
16
- * return NextResponse.json({
17
- * result: 'success',
18
- * payer: payment.payer,
19
- * amount: payment.amount,
20
- * });
21
- * }
22
- *
23
- * export const POST = withX402({ price: 0.05 }, handler);
24
- *
25
- * // With JWT receipts
26
- * export const POST = withX402({ price: 0.10, receiptMode: 'jwt' }, handler);
27
- * ```
28
- */
29
-
30
- interface X402Config {
31
- /** Price in USD (e.g., 0.05 for 5 cents) */
32
- price: number;
33
- /** Your merchant wallet address to receive payments */
34
- recipient?: string;
35
- /** Chain ID (default: 8453 for Base) */
36
- chainId?: number;
37
- /** Facilitator URL */
38
- facilitator?: string;
39
- /** Description of what the payment is for */
40
- description?: string;
41
- /** Skip payment verification (for testing) */
42
- testMode?: boolean;
43
- /** Custom function to determine price dynamically */
44
- getPrice?: (req: NextRequest) => number | Promise<number>;
45
- /** Called after successful payment */
46
- onPayment?: (payment: X402PaymentResult, req: NextRequest) => void | Promise<void>;
47
- /**
48
- * Receipt mode for payment verification responses.
49
- * - 'jwt': Set X-Payment-Receipt header with JWT (no webhook)
50
- * - 'webhook': Send webhook only (default, backwards compatible)
51
- * - 'both': Set JWT header AND send webhook
52
- */
53
- receiptMode?: ReceiptMode;
54
- /** MixrPay API URL for fetching JWT receipts (default: production) */
55
- mixrpayApiUrl?: string;
56
- }
57
- type X402Handler = (req: NextRequest, payment: X402PaymentResult) => Promise<NextResponse> | NextResponse;
58
- /**
59
- * Wrap a Next.js API route handler with x402 payment requirement.
60
- *
61
- * @param config - x402 configuration
62
- * @param handler - The handler to wrap (receives req and payment result)
63
- * @returns Wrapped handler function
64
- */
65
- declare function withX402(config: X402Config, handler: X402Handler): (req: NextRequest) => Promise<NextResponse>;
66
- /**
67
- * Create a x402 payment requirements response.
68
- * Useful for building custom payment flows.
69
- */
70
- declare function createPaymentRequired(options: {
71
- recipient: string;
72
- amount: number;
73
- chainId?: number;
74
- facilitator?: string;
75
- description?: string;
76
- }): NextResponse;
77
-
78
- export { type X402Config, X402PaymentResult, createPaymentRequired, withX402 };
@@ -1,78 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
- import { X as X402PaymentResult, R as ReceiptMode } from '../types-BJNy6Hhb.js';
3
-
4
- /**
5
- * MixrPay Merchant SDK - Next.js Integration
6
- *
7
- * Add x402 payment requirement to Next.js API routes.
8
- *
9
- * @example
10
- * ```typescript
11
- * // app/api/query/route.ts
12
- * import { withX402 } from '@mixrpay/merchant-sdk/nextjs';
13
- *
14
- * async function handler(req: NextRequest, payment: X402PaymentResult) {
15
- * // This handler only runs after payment is verified
16
- * return NextResponse.json({
17
- * result: 'success',
18
- * payer: payment.payer,
19
- * amount: payment.amount,
20
- * });
21
- * }
22
- *
23
- * export const POST = withX402({ price: 0.05 }, handler);
24
- *
25
- * // With JWT receipts
26
- * export const POST = withX402({ price: 0.10, receiptMode: 'jwt' }, handler);
27
- * ```
28
- */
29
-
30
- interface X402Config {
31
- /** Price in USD (e.g., 0.05 for 5 cents) */
32
- price: number;
33
- /** Your merchant wallet address to receive payments */
34
- recipient?: string;
35
- /** Chain ID (default: 8453 for Base) */
36
- chainId?: number;
37
- /** Facilitator URL */
38
- facilitator?: string;
39
- /** Description of what the payment is for */
40
- description?: string;
41
- /** Skip payment verification (for testing) */
42
- testMode?: boolean;
43
- /** Custom function to determine price dynamically */
44
- getPrice?: (req: NextRequest) => number | Promise<number>;
45
- /** Called after successful payment */
46
- onPayment?: (payment: X402PaymentResult, req: NextRequest) => void | Promise<void>;
47
- /**
48
- * Receipt mode for payment verification responses.
49
- * - 'jwt': Set X-Payment-Receipt header with JWT (no webhook)
50
- * - 'webhook': Send webhook only (default, backwards compatible)
51
- * - 'both': Set JWT header AND send webhook
52
- */
53
- receiptMode?: ReceiptMode;
54
- /** MixrPay API URL for fetching JWT receipts (default: production) */
55
- mixrpayApiUrl?: string;
56
- }
57
- type X402Handler = (req: NextRequest, payment: X402PaymentResult) => Promise<NextResponse> | NextResponse;
58
- /**
59
- * Wrap a Next.js API route handler with x402 payment requirement.
60
- *
61
- * @param config - x402 configuration
62
- * @param handler - The handler to wrap (receives req and payment result)
63
- * @returns Wrapped handler function
64
- */
65
- declare function withX402(config: X402Config, handler: X402Handler): (req: NextRequest) => Promise<NextResponse>;
66
- /**
67
- * Create a x402 payment requirements response.
68
- * Useful for building custom payment flows.
69
- */
70
- declare function createPaymentRequired(options: {
71
- recipient: string;
72
- amount: number;
73
- chainId?: number;
74
- facilitator?: string;
75
- description?: string;
76
- }): NextResponse;
77
-
78
- export { type X402Config, X402PaymentResult, createPaymentRequired, withX402 };
@@ -1,166 +0,0 @@
1
- /**
2
- * MixrPay Merchant SDK - Type definitions
3
- */
4
- interface X402Options {
5
- /** Price in USD (e.g., 0.05 for 5 cents) */
6
- price: number;
7
- /** Your merchant wallet address to receive payments */
8
- recipient?: string;
9
- /** Chain ID (default: 8453 for Base) */
10
- chainId?: number;
11
- /** Facilitator URL for payment settlement */
12
- facilitator?: string;
13
- /** Description of what the payment is for */
14
- description?: string;
15
- /** Custom function to determine price dynamically */
16
- getPrice?: (context: PriceContext) => number | Promise<number>;
17
- /** Called after successful payment verification */
18
- onPayment?: (payment: X402PaymentResult) => void | Promise<void>;
19
- /** Skip payment for certain requests (return true to skip) */
20
- skip?: (context: SkipContext) => boolean | Promise<boolean>;
21
- /** Allow test payments (for development) */
22
- testMode?: boolean;
23
- /**
24
- * Receipt mode for payment verification responses.
25
- * - 'jwt': Set X-Payment-Receipt header with JWT (no webhook)
26
- * - 'webhook': Send webhook only (default, backwards compatible)
27
- * - 'both': Set JWT header AND send webhook
28
- */
29
- receiptMode?: ReceiptMode;
30
- /** MixrPay API URL for fetching JWT receipts (default: production) */
31
- mixrpayApiUrl?: string;
32
- }
33
- interface PriceContext {
34
- /** Request path */
35
- path: string;
36
- /** Request method */
37
- method: string;
38
- /** Request headers */
39
- headers: Record<string, string | string[] | undefined>;
40
- /** Request body (if parsed) */
41
- body?: unknown;
42
- }
43
- type SkipContext = PriceContext;
44
- interface X402PaymentResult {
45
- /** Whether the payment is valid */
46
- valid: boolean;
47
- /** Error message if invalid */
48
- error?: string;
49
- /** Address that paid (if valid) */
50
- payer?: string;
51
- /** Amount in USDC (major units, e.g., 0.05) */
52
- amount?: number;
53
- /** Amount in USDC minor units (e.g., 50000) */
54
- amountMinor?: bigint;
55
- /** Settlement transaction hash */
56
- txHash?: string;
57
- /** When the payment was settled */
58
- settledAt?: Date;
59
- /** The nonce used for this payment */
60
- nonce?: string;
61
- /** JWT payment receipt (when receiptMode is 'jwt' or 'both') */
62
- receipt?: string;
63
- }
64
- interface X402PaymentRequired {
65
- /** Recipient wallet address */
66
- recipient: string;
67
- /** Amount in USDC minor units (6 decimals) as string */
68
- amount: string;
69
- /** Currency code */
70
- currency: string;
71
- /** Chain ID */
72
- chainId: number;
73
- /** Facilitator URL */
74
- facilitator: string;
75
- /** Unique nonce for this payment request */
76
- nonce: string;
77
- /** Unix timestamp when payment requirements expire */
78
- expiresAt: number;
79
- /** Description of the payment */
80
- description?: string;
81
- }
82
- interface X402PaymentPayload {
83
- x402Version: number;
84
- scheme: 'exact';
85
- network: 'base' | 'base-sepolia';
86
- payload: {
87
- signature: string;
88
- authorization: {
89
- from: string;
90
- to: string;
91
- value: string;
92
- validAfter: string;
93
- validBefore: string;
94
- nonce: string;
95
- };
96
- };
97
- }
98
- interface EIP712Domain {
99
- name: string;
100
- version: string;
101
- chainId: number;
102
- verifyingContract: `0x${string}`;
103
- }
104
- interface TransferWithAuthorizationMessage {
105
- from: `0x${string}`;
106
- to: `0x${string}`;
107
- value: bigint;
108
- validAfter: bigint;
109
- validBefore: bigint;
110
- nonce: `0x${string}`;
111
- }
112
- interface VerifyOptions {
113
- /** Expected amount in USDC minor units */
114
- expectedAmount: bigint;
115
- /** Expected recipient address */
116
- expectedRecipient: string;
117
- /** Chain ID (default: 8453 for Base) */
118
- chainId?: number;
119
- /** Facilitator URL */
120
- facilitator?: string;
121
- /** Skip on-chain settlement (for testing) */
122
- skipSettlement?: boolean;
123
- }
124
- /**
125
- * Verified payment receipt from MixrPay.
126
- */
127
- interface PaymentReceipt {
128
- /** Unique payment ID */
129
- paymentId: string;
130
- /** Amount in USDC minor units (6 decimals) as string */
131
- amount: string;
132
- /** Amount in USD */
133
- amountUsd: number;
134
- /** Payer wallet address */
135
- payer: string;
136
- /** Recipient wallet address */
137
- recipient: string;
138
- /** Blockchain chain ID */
139
- chainId: number;
140
- /** Settlement transaction hash */
141
- txHash: string;
142
- /** When the payment was settled (ISO string) */
143
- settledAt: string;
144
- /** When the receipt was issued */
145
- issuedAt?: Date;
146
- /** When the receipt expires */
147
- expiresAt?: Date;
148
- }
149
- /**
150
- * Options for verifying a payment receipt.
151
- */
152
- interface VerifyReceiptOptions {
153
- /** Custom JWKS URL (default: MixrPay production JWKS) */
154
- jwksUrl?: string;
155
- /** Expected issuer (for additional validation) */
156
- issuer?: string;
157
- }
158
- /**
159
- * Receipt mode for x402 middleware.
160
- * - 'jwt': Only generate JWT receipt (no webhook)
161
- * - 'webhook': Only send webhook (default, backwards compatible)
162
- * - 'both': Generate JWT receipt AND send webhook
163
- */
164
- type ReceiptMode = 'jwt' | 'webhook' | 'both';
165
-
166
- export type { EIP712Domain as E, PaymentReceipt as P, ReceiptMode as R, SkipContext as S, TransferWithAuthorizationMessage as T, VerifyOptions as V, X402PaymentResult as X, VerifyReceiptOptions as a, X402Options as b, X402PaymentRequired as c, X402PaymentPayload as d, PriceContext as e };
@@ -1,166 +0,0 @@
1
- /**
2
- * MixrPay Merchant SDK - Type definitions
3
- */
4
- interface X402Options {
5
- /** Price in USD (e.g., 0.05 for 5 cents) */
6
- price: number;
7
- /** Your merchant wallet address to receive payments */
8
- recipient?: string;
9
- /** Chain ID (default: 8453 for Base) */
10
- chainId?: number;
11
- /** Facilitator URL for payment settlement */
12
- facilitator?: string;
13
- /** Description of what the payment is for */
14
- description?: string;
15
- /** Custom function to determine price dynamically */
16
- getPrice?: (context: PriceContext) => number | Promise<number>;
17
- /** Called after successful payment verification */
18
- onPayment?: (payment: X402PaymentResult) => void | Promise<void>;
19
- /** Skip payment for certain requests (return true to skip) */
20
- skip?: (context: SkipContext) => boolean | Promise<boolean>;
21
- /** Allow test payments (for development) */
22
- testMode?: boolean;
23
- /**
24
- * Receipt mode for payment verification responses.
25
- * - 'jwt': Set X-Payment-Receipt header with JWT (no webhook)
26
- * - 'webhook': Send webhook only (default, backwards compatible)
27
- * - 'both': Set JWT header AND send webhook
28
- */
29
- receiptMode?: ReceiptMode;
30
- /** MixrPay API URL for fetching JWT receipts (default: production) */
31
- mixrpayApiUrl?: string;
32
- }
33
- interface PriceContext {
34
- /** Request path */
35
- path: string;
36
- /** Request method */
37
- method: string;
38
- /** Request headers */
39
- headers: Record<string, string | string[] | undefined>;
40
- /** Request body (if parsed) */
41
- body?: unknown;
42
- }
43
- type SkipContext = PriceContext;
44
- interface X402PaymentResult {
45
- /** Whether the payment is valid */
46
- valid: boolean;
47
- /** Error message if invalid */
48
- error?: string;
49
- /** Address that paid (if valid) */
50
- payer?: string;
51
- /** Amount in USDC (major units, e.g., 0.05) */
52
- amount?: number;
53
- /** Amount in USDC minor units (e.g., 50000) */
54
- amountMinor?: bigint;
55
- /** Settlement transaction hash */
56
- txHash?: string;
57
- /** When the payment was settled */
58
- settledAt?: Date;
59
- /** The nonce used for this payment */
60
- nonce?: string;
61
- /** JWT payment receipt (when receiptMode is 'jwt' or 'both') */
62
- receipt?: string;
63
- }
64
- interface X402PaymentRequired {
65
- /** Recipient wallet address */
66
- recipient: string;
67
- /** Amount in USDC minor units (6 decimals) as string */
68
- amount: string;
69
- /** Currency code */
70
- currency: string;
71
- /** Chain ID */
72
- chainId: number;
73
- /** Facilitator URL */
74
- facilitator: string;
75
- /** Unique nonce for this payment request */
76
- nonce: string;
77
- /** Unix timestamp when payment requirements expire */
78
- expiresAt: number;
79
- /** Description of the payment */
80
- description?: string;
81
- }
82
- interface X402PaymentPayload {
83
- x402Version: number;
84
- scheme: 'exact';
85
- network: 'base' | 'base-sepolia';
86
- payload: {
87
- signature: string;
88
- authorization: {
89
- from: string;
90
- to: string;
91
- value: string;
92
- validAfter: string;
93
- validBefore: string;
94
- nonce: string;
95
- };
96
- };
97
- }
98
- interface EIP712Domain {
99
- name: string;
100
- version: string;
101
- chainId: number;
102
- verifyingContract: `0x${string}`;
103
- }
104
- interface TransferWithAuthorizationMessage {
105
- from: `0x${string}`;
106
- to: `0x${string}`;
107
- value: bigint;
108
- validAfter: bigint;
109
- validBefore: bigint;
110
- nonce: `0x${string}`;
111
- }
112
- interface VerifyOptions {
113
- /** Expected amount in USDC minor units */
114
- expectedAmount: bigint;
115
- /** Expected recipient address */
116
- expectedRecipient: string;
117
- /** Chain ID (default: 8453 for Base) */
118
- chainId?: number;
119
- /** Facilitator URL */
120
- facilitator?: string;
121
- /** Skip on-chain settlement (for testing) */
122
- skipSettlement?: boolean;
123
- }
124
- /**
125
- * Verified payment receipt from MixrPay.
126
- */
127
- interface PaymentReceipt {
128
- /** Unique payment ID */
129
- paymentId: string;
130
- /** Amount in USDC minor units (6 decimals) as string */
131
- amount: string;
132
- /** Amount in USD */
133
- amountUsd: number;
134
- /** Payer wallet address */
135
- payer: string;
136
- /** Recipient wallet address */
137
- recipient: string;
138
- /** Blockchain chain ID */
139
- chainId: number;
140
- /** Settlement transaction hash */
141
- txHash: string;
142
- /** When the payment was settled (ISO string) */
143
- settledAt: string;
144
- /** When the receipt was issued */
145
- issuedAt?: Date;
146
- /** When the receipt expires */
147
- expiresAt?: Date;
148
- }
149
- /**
150
- * Options for verifying a payment receipt.
151
- */
152
- interface VerifyReceiptOptions {
153
- /** Custom JWKS URL (default: MixrPay production JWKS) */
154
- jwksUrl?: string;
155
- /** Expected issuer (for additional validation) */
156
- issuer?: string;
157
- }
158
- /**
159
- * Receipt mode for x402 middleware.
160
- * - 'jwt': Only generate JWT receipt (no webhook)
161
- * - 'webhook': Only send webhook (default, backwards compatible)
162
- * - 'both': Generate JWT receipt AND send webhook
163
- */
164
- type ReceiptMode = 'jwt' | 'webhook' | 'both';
165
-
166
- export type { EIP712Domain as E, PaymentReceipt as P, ReceiptMode as R, SkipContext as S, TransferWithAuthorizationMessage as T, VerifyOptions as V, X402PaymentResult as X, VerifyReceiptOptions as a, X402Options as b, X402PaymentRequired as c, X402PaymentPayload as d, PriceContext as e };