@awesomate/hosting-mcp
Version:
Awesomate MCP server — lets Claude manage your Awesomate WordPress hosting, plan, limits, n8n automations, and build Node/static apps + databases
217 lines (185 loc) • 10.6 kB
Markdown
# Stripe first: recipes
Every recipe here takes money into **the business's own Stripe account**, on a
page Stripe hosts. Read the SKILL.md rules first. Check Stripe's docs as
Markdown (https://docs.stripe.com/llms.txt, or any docs page plus `.md`) when a
parameter isn't shown here: Stripe changes faster than this file.
## A. No code: a Payment Link
For "a link I can send", "a buy button on my WordPress site", "a QR code at
the counter".
1. With Stripe's MCP signed in to the owner's account (SKILL.md section 2),
find or create the product and price, then create a Payment Link. Or walk
the owner through it in their Stripe Dashboard: Payment Links, New.
2. Ask what happens after payment: Stripe's own confirmation page, or a thank
you page on their site (set as the link's after-payment redirect).
3. Hand them the link. On a WordPress page it can be a plain button linking
to it; Stripe also gives a buy button snippet.
Nothing to host, no key to store. If an app or workflow must match a Payment
Link payment to its own order, add `?client_reference_id=<the order's id>` to
the link's address when handing it out: the webhook (C) finds the order by it,
and checks the amount, because anyone holding a link can edit its address. A
payment that comes without one is not one of the app's orders.
## B. A pay button in an app: Checkout Sessions
The app's server makes a Checkout Session and sends the customer to its `url`.
The key stays on the server; the browser never sees it.
```bash
npm view stripe version # use the current major
npm install stripe
```
Store the restricted key as `STRIPE_SECRET_KEY` through awesomate-credentials.
Its permissions: Checkout Sessions write, Products and Prices read, Customers
write if the app links payments to its own customers, and Customer portal
write if it uses recipe E. Nothing else.
```js
import Stripe from 'stripe';
import express from 'express';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();
app.post('/api/checkout', express.json(), async (req, res) => {
try {
// Work out what is being bought on the SERVER: never trust a price from the browser.
const order = await loadOrderForUser(req);
if (!order) return res.status(404).json({ error: 'That order was not found.' });
if (order.paidAt) return res.status(409).json({ error: 'This order is already paid.' });
const params = {
mode: 'payment',
line_items: [{ price: order.priceId, quantity: order.quantity }],
customer_email: order.email,
client_reference_id: order.id, // how the webhook finds the order
success_url: `${process.env.APP_URL}/thanks?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.APP_URL}/cart`,
};
// A payment page moves no money, so no idempotency key of our own: stripe-node retries a
// network failure with its own. A second click makes a second page; a second payment is caught
// by the webhook (C).
const session = await stripe.checkout.sessions.create(params);
res.json({ url: session.url });
} catch (err) {
console.error('checkout', err.message);
// Stripe refusing the request as made (a price that no longer exists, say) won't work on a retry.
if (err.type === 'StripeInvalidRequestError') {
return res.status(400).json({ error: "This order can't be paid online as it is. Please contact us." });
}
res.status(503).json({ error: "We couldn't open the payment page just now. Try again in a moment." });
}
});
```
The browser posts to `/api/checkout` and sets `window.location` to the `url`
it gets back. That's all the front end does.
**Never** mark the order paid on the success page: someone can open that
address without paying. Mark it paid from the webhook (C).
## C. The webhook: the only proof of payment
```js
// Mount BEFORE app.use(express.json()): the signature is over the raw bytes.
app.post('/api/stripe/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
let event;
try {
event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET);
} catch {
return res.status(400).send('bad signature');
}
try {
const session = event.data.object;
// One-off payments only (mode 'payment'): memberships are recipe D. 'no_payment_required' is
// an order a 100% discount covers. A bank debit (BECS) completes 'unpaid' and is paid when
// async_payment_succeeded arrives.
const paid =
session.mode === 'payment' &&
((event.type === 'checkout.session.completed' && ['paid', 'no_payment_required'].includes(session.payment_status)) ||
event.type === 'checkout.session.async_payment_succeeded');
// Set by our checkout (B), or on a Payment Link's address (A). None: not one of our orders.
const orderId = session.client_reference_id;
if (paid && orderId) {
const order = await loadOrder(orderId);
// A Payment Link's address can be edited by anyone holding it, so the reference alone proves
// nothing: the price before discounts and the currency (Stripe sends it in lower case) must
// be this order's.
const matches = order && session.amount_subtotal === order.subtotalCents && session.currency === (order.currency ?? '').toLowerCase();
if (!matches) {
await tellTheOwner(session.id, 'a payment that does not match its order');
} else if (!(await markOrderPaid(orderId, session.id))) {
// UPDATE orders SET paid_at = COALESCE(paid_at, NOW()), paid_session = ? WHERE id = ? AND (paid_at IS NULL OR
// paid_session = ?): safe to repeat, false only when ANOTHER payment already paid it (two
// tabs, a changed cart). Never refund by yourself. tellTheOwner tells once per session (a
// unique key on session.id), so a redelivered event never asks for a second refund.
await tellTheOwner(session.id, 'this order was paid twice: refund one, with your yes');
}
}
res.sendStatus(200);
} catch {
res.sendStatus(500); // Stripe retries a failed delivery
}
});
```
- The customer's receipt: let Stripe send it (the owner's Dashboard, Settings,
Business, Customer emails, Successful payments). Stripe sends it once, after the
payment, with the business's branding: no email code to get wrong.
- Add the endpoint in the owner's Stripe Dashboard (Developers, Webhooks), with
only the events the app uses. Its signing secret (`whsec_`) goes in as
`STRIPE_WEBHOOK_SECRET` through awesomate-credentials.
- Events can arrive twice, at once and out of order. Make each step happen once
in the database (a conditional update or a unique key), and re-read an object
from Stripe when its order matters.
- Locally: `stripe listen --forward-to localhost:<port>/api/stripe/webhook`
prints a test signing secret for the session.
- Bank debits (BECS) finish later: the handler above takes
`checkout.session.async_payment_succeeded`; on
`checkout.session.async_payment_failed` the order stays unpaid and the
customer can pay again. Subscribe the endpoint to both.
## D. Memberships and plans: Stripe Billing
- A recurring Price (monthly, yearly) on a product. Then either a Payment Link
for it (no code) or recipe B with `mode: 'subscription'`.
- Renewals, failed-card retries, reminder emails and receipts are Stripe's:
switch them on in the owner's Dashboard (Billing settings). Don't rebuild
them in the app.
- Keep access in step with the subscription's **status**, not with a payment,
from `customer.subscription.created`, `.updated` and `.deleted`: access while
the status is `active`, `trialing` (a free trial included) or `past_due`
(Stripe is still retrying the card), none for `incomplete` (card check or
bank debit not finished), `incomplete_expired`, `unpaid`, `paused` or
`canceled`, as Stripe's own guidance says. Use `invoice.payment_failed` to
warn.
## E. "Change my card or cancel": the customer portal
Set it up once in the owner's Dashboard (Billing, Customer portal). Then:
```js
const portal = await stripe.billingPortal.sessions.create({
customer: user.stripeCustomerId,
return_url: `${process.env.APP_URL}/account`,
});
res.redirect(303, portal.url);
```
## F. Invoices
For "send them an invoice they can pay online": Stripe Invoicing on the
owner's account. Stripe emails it, hosts the pay page, sends reminders and
marks it paid. Through Stripe's MCP or the Dashboard, no code needed. If the
business already invoices from Xero, ask before adding a second way to
invoice: nothing should be invoiced twice.
In Australia, a GST-registered business should show its ABN on invoices: in
the owner's Stripe settings, add it as the account's tax ID (Australian
Business Number).
## G. n8n
- Use n8n's Stripe node and Stripe Trigger node with a credential holding a
**restricted** key made for that workflow. No Awesomate tool creates a
Stripe credential on their n8n: the owner adds it themselves in n8n (Credentials,
Stripe API) and pastes the key there, never into the chat. A Stripe Trigger
registers its own webhook endpoint, so its key also needs Webhook Endpoints
write.
- A workflow that charges, refunds or cancels stops and asks a person first
(awesomate-n8n's decisions reference). A workflow that only reacts to a
payment (send a thank-you, book the job) needs no approval.
- Don't assume a trigger proves a payment. Before acting on one, read it back
from Stripe with the Stripe node (the payment or session by its id) and act
on what Stripe says, so a forged call to the workflow's address does nothing.
## H. An AI agent that works in Stripe
`/agent-toolkit` gives an agent Stripe tools (LangChain, Vercel's AI
SDK, MCP). Give it a **restricted key** with only what the agent needs, switch
on only the actions it should have, and keep money-moving actions (refunds,
charges) behind a person's yes. Follow its README for the current setup. It
calls Stripe's API with that key; the December 2026 key rule in SKILL.md
section 2 is for Stripe's own MCP server at mcp.stripe.com, where the owner
signs in with OAuth instead.
## What not to do
- No card fields of our own, anywhere.
- No Charges API, no Sources API, no legacy Card Element (Stripe says not for new builds: Sources is deprecated, the others legacy).
- No full secret key in any app, workflow or agent.
- No order marked paid from a redirect or a browser message.
- No retry of a money call whose outcome you don't know: look it up first.