@creem_io/nextjs
退站 客户门户 并验证了Next.js App路由器的Webhook助手.
完整文档: 文件:creem.io/code/sdks/nextjs
安装
pnpm add @creem_io/nextjs
要求 Next.js 13 或 更新 和 React 18 或 更新 .
最小设置
创建检出路径 :
// app/checkout/route.ts
import { Checkout } from "@creem_io/nextjs";
export const GET = Checkout({
apiKey: process.env.CREEM_API_KEY!,
testMode: true,
defaultSuccessUrl: "/billing/success",
});
绘制出账链接 :
import { CreemCheckout } from "@creem_io/nextjs";
export default function PricingPage() {
return <CreemCheckout productId="prod_...">Subscribe</CreemCheckout>;
}
处理网络呼号 :
// app/api/webhook/creem/route.ts
import { Webhook } from "@creem_io/nextjs";
export const POST = Webhook({
webhookSecret: process.env.CREEM_WEBHOOK_SECRET!,
onCheckoutCompleted: async ({ customer, product }) => {
console.log(`${customer.email} purchased ${product.name}`);
},
});
召回必须具有先验性,因为webhook的交付可以被重审. 给予或取消应用程序访问需要信任的用户ID; 遵循认证 在使用访问回调前在全指南中检查出模式 .
出口
| 导出 | 目的 |
|---|---|
CreemCheckout | 构建与您的退出路径的链接 . |
CreemPortal | 建立与您的客户端路径的链接 . |
Checkout | 创建取出会话并重定向到 Creem . |
Portal | 创建客户计费链接并重定向到门户网站. |
Webhook | 验证和发送克里姆网络新闻活动. |
见 Next.js 适配器指南 所有道具,路线设置, 访问回调 和安全指导. 见 常见的 用于 webhook 字段名称, 时间戳、取出金额和元数据.
实例与发展
从寄存器根 :
pnpm --filter @creem_io/nextjs build
pnpm --filter @creem_io/nextjs typecheck
pnpm --filter @creem_io/nextjs check:package