Summary
Stripe 決済の導入・テスト・運用ガイド。新規プロジェクトへの Stripe 導入、本番/テストモード切替、決済テスト、返金処理などを行う。「Stripe を導入したい」「決済機能を追加」「返金したい」「Stripe のテスト」などのリクエストで使用する。
schroneko/skills
Stripe 決済の導?
npx skills add schroneko/skills --skill stripe
Stripe 決済の導入・テスト・運用ガイド。新規プロジェクトへの Stripe 導入、本番/テストモード切替、決済テスト、返金処理などを行う。「Stripe を導入したい」「決済機能を追加」「返金したい」「Stripe のテスト」などのリクエストで使用する。
Related neighbors and high-traction skills in the same topics — useful to compare before installing.
>- Guides Stripe integration decisions across API selection (Checkout Sessions vs PaymentIntent…
82.9K installsGuide for upgrading Stripe API versions and SDKs
64.9K installsUse when the user wants to provision infrastructure or third-party services using Stripe Projec…
62.4K installs>- Identifies external providers, merchants, nonprofits, platforms, APIs, and software services…
3.5K installs>- Use when the user or agent needs to read, search, or look up Stripe documentation or API ref…
1.8K installsBest practices for building Stripe integrations. Use when implementing payment processing, chec…
1.4K installsOther skills from schroneko/skills · top by installs.
npx skills add schroneko/skills
Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.
main
Files included with this skill beyond the listing page.
SKILL.md
6,297 B
SUMMARY.md
344 B
Stripe 決済の導入から運用までをカバーする。
| キー | 形式 | 用途 |
|---|---|---|
| Publishable Key | pktest / pklive |
クライアント側(公開可) |
| Secret Key | sktest / sklive |
サーバー側(秘匿必須) |
| Webhook Secret | whsec_* |
Webhook 署名検証用 |
ローカル開発用の値は既存の 1Password Environment に保存する。vault item は作らない。
STRIPEPUBLISHABLEKEYSTRIPESECRETKEYSTRIPEWEBHOOKSECRET追加・更新には $onepassword-environment-secrets を使い、実行時は op run --environment "$OPENVIRONMENTID" -- <command> で注入する。
公開キーは wrangler.toml の [vars] に、秘匿キーは Worker secret に設定する。Cloudflare 操作には 1Password を使わず、Wrangler の OAuth セッションを使う。
[vars]
STRIPE_PUBLISHABLE_KEY = "pk_live_xxx"
wrangler whoami
wrangler secret put STRIPE_SECRET_KEY
wrangler secret put STRIPE_WEBHOOK_SECRET
https://example.com/api/webhookcheckout.session.completed を選択whsec_*)をコピーして保存import Stripe from "stripe";
webhookRoutes.post("/", async (c) => {
const stripe = new Stripe(c.env.STRIPE_SECRET_KEY, {
httpClient: Stripe.createFetchHttpClient(),
});
const signature = c.req.header("stripe-signature");
if (!signature) {
return c.json({ error: "Missing signature" }, 400);
}
const body = await c.req.text();
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(
body,
signature,
c.env.STRIPE_WEBHOOK_SECRET,
undefined,
Stripe.createSubtleCryptoProvider(),
);
} catch {
return c.json({ error: "Invalid signature" }, 400);
}
if (event.type === "checkout.session.completed") {
const session = event.data.object as Stripe.Checkout.Session;
// 注文処理
}
return c.json({ received: true });
});
const stripe = new Stripe(c.env.STRIPE_SECRET_KEY, {
httpClient: Stripe.createFetchHttpClient(),
});
const session = await stripe.checkout.sessions.create({
mode: "payment",
line_items: [
{
price_data: {
currency: "jpy",
product_data: { name: "商品名" },
unit_amount: 1000,
},
quantity: 1,
},
],
success_url: `${c.env.SITE_URL}/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${c.env.SITE_URL}/cancel`,
metadata: {
userId: "xxx",
// カスタムデータ
},
});
return c.json({ url: session.url });
| 通貨 | 最低額 |
|---|---|
| JPY | 50円 |
| USD | $0.50 |
テスト用商品は最低額で作成する。
| カード番号 | 結果 |
|---|---|
| 4242 4242 4242 4242 | 成功 |
| 4000 0000 0000 0002 | 拒否 |
| 4000 0000 0000 3220 | 3D セキュア必須 |
有効期限: 将来の任意の日付、CVC: 任意の 3 桁
# 1. Stripe セッション ID から payment_intent を取得
curl -s -u "sk_live_xxx:" "https://api.stripe.com/v1/checkout/sessions/cs_live_xxx" | jq -r '.payment_intent'
# 2. 返金実行
curl -s -X POST "https://api.stripe.com/v1/refunds" \
-H "Authorization: Bearer sk_live_xxx" \
-d "payment_intent=pi_xxx" | jq '{id, status, amount}'
curl -s -X POST "https://api.stripe.com/v1/refunds" \
-H "Authorization: Bearer sk_live_xxx" \
-d "payment_intent=pi_xxx" \
-d "amount=500" | jq '{id, status, amount}'
pktest / sktest → テストモードpklive / sklive → 本番モードwrangler.toml の STRIPEPUBLISHABLEKEY を更新wrangler secret put で Worker secret を更新wrangler whoami
wrangler secret put STRIPE_SECRET_KEY
wrangler secret put STRIPE_WEBHOOK_SECRET
npm run build
wrangler deploy
Stripe SDK は Node.js の util モジュールを使用するため、wrangler.toml に以下が必要:
compatibility_flags = ["nodejs_compat"]
Webhook 署名検証には Stripe.createSubtleCryptoProvider() を使用する(Workers 環境では Node.js の crypto が使えないため)。
compatibilityflags = ["nodejscompat"] を追加してビルドし直す。
STRIPEWEBHOOKSECRET が正しいか確認c.req.text() で body を取得しているか確認(c.req.json() は NG)Webhook エンドポイントが正しく設定されているか確認:
wrangler tail --format=pretty