check_payment
Verify Lightning invoice payment status and retrieve spend tokens for pay-per-request AI model access. Use after generating an invoice to confirm payment completion.
Instructions
Check if a Lightning invoice has been paid and retrieve the spend token. Poll this after generate_invoice until the payment is confirmed.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| charge_id | Yes | Charge ID returned by generate_invoice |
Implementation Reference
- src/index.ts:168-176 (handler)The `checkPayment` function performs the HTTP request to verify the payment and fetch the spend token.
async function checkPayment(chargeId: string): Promise<any> { const res = await fetch(`${LIGHTNINGPROX_URL}/v1/tokens`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ charge_id: chargeId, duration_hours: 720 }), }); const data = await res.json() as any; return data; } - src/index.ts:91-105 (schema)The tool definition for `check_payment` including its description and input schema.
{ name: "check_payment", description: "Check if a Lightning invoice has been paid and retrieve the spend token. Poll this after generate_invoice until the payment is confirmed.", inputSchema: { type: "object", properties: { charge_id: { type: "string", description: "Charge ID returned by generate_invoice", }, }, required: ["charge_id"], }, }, - src/index.ts:294-326 (registration)The request handler in the `server.setRequestHandler` loop for `check_payment` that calls the `checkPayment` function and formats the response.
case "check_payment": { const { charge_id } = args as any; const data = await checkPayment(charge_id); if (data.spend_token) { return { content: [ { type: "text", text: [ `✅ Payment confirmed!`, ``, `Your spend token:`, data.spend_token, ``, `Expires: ${data.expires_at || "30 days"}`, ``, `Use this token in the spend_token field of the chat tool.`, ].join("\n"), }, ], }; } return { content: [ { type: "text", text: `⏳ Payment not yet confirmed for charge: ${charge_id}\n\nTry again in a few seconds after paying the Lightning invoice.`, }, ], }; }