@lynq/stripe 0.1.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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.mjs +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hogekai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ToolContext, MCPServer, ToolMiddleware } from '@lynq/lynq';
|
|
2
|
+
|
|
3
|
+
interface StripeOptions {
|
|
4
|
+
/** Middleware name. Default: "stripe" */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Stripe secret key (server-side). */
|
|
7
|
+
secretKey: string;
|
|
8
|
+
/** Base URL of your server (for callback URLs). */
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/** Callback path. Default: "/payment/stripe/callback" */
|
|
11
|
+
callbackPath?: string;
|
|
12
|
+
/** Price in cents (USD). e.g., 100 = $1.00 */
|
|
13
|
+
amount: number;
|
|
14
|
+
/** Currency. Default: "usd" */
|
|
15
|
+
currency?: string;
|
|
16
|
+
/** Product description shown on Stripe Checkout. */
|
|
17
|
+
description?: string;
|
|
18
|
+
/** Session key for payment data. Default: "payment" */
|
|
19
|
+
sessionKey?: string;
|
|
20
|
+
/** If true, only charge once per session per tool. Default: false */
|
|
21
|
+
once?: boolean;
|
|
22
|
+
/** Message shown to user. */
|
|
23
|
+
message?: string;
|
|
24
|
+
/** Timeout in ms. Default: 300000 */
|
|
25
|
+
timeout?: number;
|
|
26
|
+
/** Custom skip condition. Takes priority over sessionKey check. */
|
|
27
|
+
skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
|
|
28
|
+
/** Called after payment completes successfully, before next(). */
|
|
29
|
+
onComplete?: (c: ToolContext) => void | Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** @deprecated Use `StripeOptions` instead. */
|
|
32
|
+
type StripePaymentOptions = StripeOptions;
|
|
33
|
+
declare function stripe(options: StripeOptions): ToolMiddleware;
|
|
34
|
+
/** @deprecated Use `stripe()` from `@lynq/stripe` instead. */
|
|
35
|
+
declare const stripePayment: typeof stripe;
|
|
36
|
+
interface HandleCallbackOptions {
|
|
37
|
+
/** Stripe secret key. */
|
|
38
|
+
secretKey: string;
|
|
39
|
+
/** Session key. Default: "payment" */
|
|
40
|
+
sessionKey?: string;
|
|
41
|
+
}
|
|
42
|
+
/** @deprecated Use `HandleCallbackOptions` instead. */
|
|
43
|
+
type HandleStripeCallbackOptions = HandleCallbackOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Handle Stripe Checkout callback. Call from your HTTP callback route.
|
|
46
|
+
* Retrieves the Checkout Session, verifies payment, stores in session, and completes elicitation.
|
|
47
|
+
*/
|
|
48
|
+
declare function handleCallback(server: MCPServer, params: {
|
|
49
|
+
checkoutSessionId: string;
|
|
50
|
+
state: string;
|
|
51
|
+
}, options: HandleCallbackOptions): Promise<{
|
|
52
|
+
success: boolean;
|
|
53
|
+
error?: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** @deprecated Use `handleCallback()` from `@lynq/stripe` instead. */
|
|
56
|
+
declare const handleStripeCallback: typeof handleCallback;
|
|
57
|
+
|
|
58
|
+
export { type HandleCallbackOptions, type HandleStripeCallbackOptions, type StripeOptions, type StripePaymentOptions, handleCallback, handleStripeCallback, stripe, stripePayment };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {verifyState,signState}from'@lynq/lynq/helpers';import {payment}from'@lynq/lynq/payment';var p=null;function I(){return p||(p=import('stripe').catch(()=>(p=null,null))),p}function _(e){let{secretKey:r,baseUrl:s,callbackPath:a="/payment/stripe/callback",amount:i,currency:u="usd",description:m,once:t=false}=e,d=e.name??"stripe",y=e.sessionKey??"payment",n=e.message??`Payment required ($${(i/100).toFixed(2)}).`,o={name:d,sessionKey:y,message:n,async buildUrl({sessionId:c,elicitationId:l}){let g=await I();if(!g)throw new Error("stripe package is required. Install it: pnpm add stripe");let S=g.default,b=new S(r),k=signState(c,l,r);return (await b.checkout.sessions.create({payment_method_types:["card"],line_items:[{price_data:{currency:u,product_data:{name:m??"Tool access"},unit_amount:i},quantity:1}],mode:"payment",success_url:`${s}${a}?session_id={CHECKOUT_SESSION_ID}&state=${k}`,cancel_url:`${s}${a}?cancelled=true&state=${k}`,metadata:{sessionId:c,elicitationId:l}})).url??""}};e.timeout!==void 0&&(o.timeout=e.timeout),e.skipIf&&(o.skipIf=e.skipIf),e.onComplete&&(o.onComplete=e.onComplete);let f=payment(o);return t?f:{...f,onResult(c,l){return l.session.set(y,void 0),c}}}var v=_;async function w(e,r,s){let a=s.sessionKey??"payment",i=verifyState(r.state,s.secretKey);if(!i)return {success:false,error:"Invalid state parameter"};let{sessionId:u,elicitationId:m}=i;try{let t;try{t=await import('stripe');}catch{return {success:!1,error:"stripe package is required. Install it: pnpm add stripe"}}let d=t.default,n=await new d(s.secretKey).checkout.sessions.retrieve(r.checkoutSessionId);return n.payment_status!=="paid"?{success:!1,error:"Payment not completed"}:(e.session(u).set(a,{provider:"stripe",checkoutSessionId:n.id,amount:n.amount_total,currency:n.currency,paidAt:new Date().toISOString()}),e.completeElicitation(m),{success:!0})}catch(t){return {success:false,error:t instanceof Error?t.message:String(t)}}}var $=w;export{w as handleCallback,$ as handleStripeCallback,_ as stripe,v as stripePayment};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lynq/stripe",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Stripe Checkout payment provider for lynq MCP framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lynq/lynq": "^0.8.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"stripe": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"stripe": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"stripe": "^20.4.1",
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.6.0",
|
|
31
|
+
"vitest": "^2.0.0",
|
|
32
|
+
"zod": "^3.24.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/hogekai/lynq",
|
|
40
|
+
"directory": "packages/stripe"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
}
|
|
51
|
+
}
|