@moneydevkit/replit 0.7.0-beta.1 → 0.7.0-beta.11
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 +55 -1
- package/dist/hooks/useProducts.d.ts +1 -0
- package/dist/hooks/useProducts.js +3 -0
- package/dist/hooks/useProducts.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/express.d.ts +3 -0
- package/dist/server/express.js +23 -1
- package/dist/server/express.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ export default function App() {
|
|
|
44
44
|
setError(null)
|
|
45
45
|
|
|
46
46
|
const result = await createCheckout({
|
|
47
|
+
type: 'AMOUNT', // or 'PRODUCTS' for product-based checkouts
|
|
47
48
|
title: 'Purchase title for the buyer',
|
|
48
49
|
description: 'Description of the purchase',
|
|
49
50
|
amount: 500,
|
|
@@ -86,6 +87,7 @@ Collect and store customer information with each checkout. Pass `customer` to pr
|
|
|
86
87
|
|
|
87
88
|
```tsx
|
|
88
89
|
const result = await createCheckout({
|
|
90
|
+
type: 'AMOUNT',
|
|
89
91
|
title: "Premium Plan",
|
|
90
92
|
description: 'Monthly subscription',
|
|
91
93
|
amount: 1000,
|
|
@@ -119,6 +121,7 @@ When your user is already authenticated in your app, pass `externalId` to link c
|
|
|
119
121
|
|
|
120
122
|
```tsx
|
|
121
123
|
const result = await createCheckout({
|
|
124
|
+
type: 'AMOUNT',
|
|
122
125
|
title: "Premium Plan",
|
|
123
126
|
description: 'Monthly subscription',
|
|
124
127
|
amount: 1000,
|
|
@@ -139,7 +142,58 @@ When `externalId` is provided:
|
|
|
139
142
|
- Only fields missing from the customer record are requested
|
|
140
143
|
- This prevents authenticated users from being asked for data you already have
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
## Product Checkouts
|
|
146
|
+
Sell products defined in your Money Dev Kit dashboard using `type: 'PRODUCTS'`:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { useCheckout, useProducts } from '@moneydevkit/replit'
|
|
150
|
+
|
|
151
|
+
function ProductPage() {
|
|
152
|
+
const { createCheckout, isLoading } = useCheckout()
|
|
153
|
+
const { products } = useProducts()
|
|
154
|
+
|
|
155
|
+
const handleBuyProduct = async (productId: string) => {
|
|
156
|
+
const result = await createCheckout({
|
|
157
|
+
type: 'PRODUCTS',
|
|
158
|
+
product: productId,
|
|
159
|
+
successUrl: '/checkout/success',
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
if (result.error) return
|
|
163
|
+
window.location.href = result.data.checkoutUrl
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div>
|
|
168
|
+
{products?.map(product => (
|
|
169
|
+
<button key={product.id} onClick={() => handleBuyProduct(product.id)}>
|
|
170
|
+
Buy {product.name} - ${(product.price?.priceAmount ?? 0) / 100}
|
|
171
|
+
</button>
|
|
172
|
+
))}
|
|
173
|
+
</div>
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Checkout Types
|
|
179
|
+
- **`type: 'AMOUNT'`** - For donations, tips, or custom amounts. Requires `amount` field.
|
|
180
|
+
- **`type: 'PRODUCTS'`** - For selling products. Requires `product` field with a product ID. Amount is calculated from product price.
|
|
181
|
+
|
|
182
|
+
### Pay What You Want (CUSTOM prices)
|
|
183
|
+
Products can have CUSTOM prices that let customers choose their own amount. When a checkout includes a product with a CUSTOM price, the checkout UI automatically shows an amount input field:
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// Create a checkout for a product with CUSTOM pricing
|
|
187
|
+
const result = await createCheckout({
|
|
188
|
+
type: 'PRODUCTS',
|
|
189
|
+
product: customPriceProductId, // Product configured with CUSTOM price in dashboard
|
|
190
|
+
successUrl: '/checkout/success',
|
|
191
|
+
})
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The customer enters their desired amount during checkout. For USD, amounts are in dollars (converted to cents internally). For SAT, amounts are in satoshis.
|
|
195
|
+
|
|
196
|
+
## Verify successful payments
|
|
143
197
|
```tsx
|
|
144
198
|
import { useCheckoutSuccess } from '@moneydevkit/replit'
|
|
145
199
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useProducts } from '@moneydevkit/core/client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProducts.js","sourceRoot":"","sources":["../../src/hooks/useProducts.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { Checkout } from './components/Checkout';
|
|
|
2
2
|
export type { CheckoutProps } from './components/Checkout';
|
|
3
3
|
export { useCheckout } from './hooks/useCheckout';
|
|
4
4
|
export { useCheckoutSuccess } from './hooks/useCheckoutSuccess';
|
|
5
|
+
export { useProducts } from './hooks/useProducts';
|
|
5
6
|
export type { MdkError, Result } from '@moneydevkit/core/client';
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/server/express.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { RequestHandler, Router } from 'express';
|
|
2
|
+
export { createCheckoutUrl } from '@moneydevkit/core/route';
|
|
3
|
+
export type { CreateCheckoutUrlOptions } from '@moneydevkit/core/route';
|
|
2
4
|
export declare const mdkExpressHandler: RequestHandler;
|
|
5
|
+
export declare const mdkExpressGetHandler: RequestHandler;
|
|
3
6
|
export declare function createMdkExpressRouter(): Router;
|
|
4
7
|
export default createMdkExpressRouter;
|
package/dist/server/express.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { createUnifiedHandler } from '@moneydevkit/core/route';
|
|
2
|
+
import { createUnifiedHandler, GET as getHandler } from '@moneydevkit/core/route';
|
|
3
|
+
// Re-export createCheckoutUrl for server-side URL generation
|
|
4
|
+
export { createCheckoutUrl } from '@moneydevkit/core/route';
|
|
3
5
|
const unifiedHandler = createUnifiedHandler();
|
|
4
6
|
function toFetchRequest(req) {
|
|
5
7
|
const protocol = req.protocol || 'http';
|
|
@@ -46,9 +48,29 @@ export const mdkExpressHandler = async (req, res) => {
|
|
|
46
48
|
res.status(500).send('Internal Server Error');
|
|
47
49
|
}
|
|
48
50
|
};
|
|
51
|
+
export const mdkExpressGetHandler = async (req, res) => {
|
|
52
|
+
try {
|
|
53
|
+
const request = toFetchRequest(req);
|
|
54
|
+
const response = await getHandler(request);
|
|
55
|
+
// Handle redirects specially for Express
|
|
56
|
+
if (response.status >= 300 && response.status < 400) {
|
|
57
|
+
const location = response.headers.get('location');
|
|
58
|
+
if (location) {
|
|
59
|
+
res.redirect(response.status, location);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await sendFetchResponse(res, response);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('MDK Express GET handler error', error);
|
|
67
|
+
res.status(500).send('Internal Server Error');
|
|
68
|
+
}
|
|
69
|
+
};
|
|
49
70
|
export function createMdkExpressRouter() {
|
|
50
71
|
const router = express.Router();
|
|
51
72
|
router.use(express.json());
|
|
73
|
+
router.get('/', mdkExpressGetHandler);
|
|
52
74
|
router.post('/', mdkExpressHandler);
|
|
53
75
|
return router;
|
|
54
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAG7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/server/express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAG7B,OAAO,EAAE,oBAAoB,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEjF,6DAA6D;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAG3D,MAAM,cAAc,GAAG,oBAAoB,EAAE,CAAA;AAE7C,SAAS,cAAc,CAAC,GAAoB;IAC1C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,MAAM,CAAA;IACvC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,WAAW,CAAA;IAC3C,MAAM,GAAG,GAAG,GAAG,QAAQ,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAA;IAEtE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,E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CAAC,CAAA;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAA;IAC/B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAA;IACrC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAA;IACnC,OAAO,MAAM,CAAA;AACf,CAAC;AAED,eAAe,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneydevkit/replit",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.11",
|
|
4
4
|
"description": "Money Dev Kit checkout package for Replit (Vite + Express).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"react-dom": "^18 || ^19"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@moneydevkit/core": "0.7.0-beta.
|
|
43
|
+
"@moneydevkit/core": "0.7.0-beta.11"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/express": "^4.17.21",
|