@riligar/agents-kit 1.12.0 → 1.13.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.
@@ -1,152 +1,257 @@
1
1
  ---
2
2
  name: riligar-dev-stripe
3
- type: development
4
- description: Stripe payment integration patterns. Use when implementing payments, subscriptions, webhooks, checkout flows, or billing in Elysia/Bun applications.
3
+ description: 'Interactive Stripe setup wizard. Use when implementing payments. The agent will ask for keys, products, and configure everything automatically.'
5
4
  ---
6
5
 
7
- # Stripe Integration Patterns
6
+ # Stripe Setup Wizard
8
7
 
9
- > Patterns for integrating Stripe payments in RiLiGar applications.
8
+ Esta skill configura a integração completa do Stripe no seu projeto. O agente vai guiar você através de um setup interativo.
10
9
 
11
10
  ---
12
11
 
13
- ## Mandatory Guidelines
12
+ ## Setup Workflow
14
13
 
15
- > [!IMPORTANT]
16
- > All work in this skill MUST adhere to:
14
+ Quando o usuário solicitar configurar o Stripe, siga este fluxo **OBRIGATÓRIO**:
15
+
16
+ ### Step 1: Coletar Chaves
17
+
18
+ Pergunte ao usuário:
19
+
20
+ > Para configurar o Stripe, preciso das suas chaves da API.
21
+ > Você pode encontrá-las em: https://dashboard.stripe.com/apikeys
17
22
  >
18
- > - @[.agent/skills/riligar-dev-backend] (API Standards)
19
- > - @[.agent/skills/riligar-dev-clean-code] (Clean Code Standards)
23
+ > Por favor, me forneça:
24
+ > 1. **Publishable Key** (pk_live_... ou pk_test_...)
25
+ > 2. **Secret Key** (sk_live_... ou sk_test_...)
20
26
 
21
- ---
27
+ Aguarde as chaves antes de prosseguir.
22
28
 
23
- ## 1. Core Concepts
29
+ ### Step 2: Identificar Produtos
24
30
 
25
- | Concept | Description |
26
- | --- | --- |
27
- | **Customer** | User identity in Stripe |
28
- | **Product** | What you're selling |
29
- | **Price** | How much and billing cycle |
30
- | **Subscription** | Recurring payment |
31
- | **PaymentIntent** | One-time payment |
32
- | **Webhook** | Event notifications |
31
+ Após receber as chaves, pergunte:
33
32
 
34
- ---
33
+ > Agora preciso entender seus produtos. Me diga:
34
+ >
35
+ > 1. **Tipo de cobrança**: Assinatura (recorrente) ou pagamento único?
36
+ > 2. **Quais planos/produtos** você quer oferecer?
37
+ >
38
+ > Exemplo de resposta:
39
+ > - Assinatura mensal
40
+ > - Plano Starter: R$ 29/mês (5 projetos, suporte email)
41
+ > - Plano Pro: R$ 99/mês (ilimitado, suporte prioritário)
42
+ > - Plano Enterprise: R$ 299/mês (tudo + SLA)
35
43
 
36
- ## 2. Environment Setup
44
+ ### Step 3: Criar Produtos no Stripe
37
45
 
38
- ```bash
39
- # .env
40
- STRIPE_SECRET_KEY=sk_live_...
41
- STRIPE_WEBHOOK_SECRET=whsec_...
42
- STRIPE_PUBLISHABLE_KEY=pk_live_...
46
+ Com as informações coletadas, gere o script para criar os produtos:
47
+
48
+ ```javascript
49
+ // scripts/setup-stripe-products.js
50
+ import Stripe from 'stripe'
51
+
52
+ const stripe = new Stripe('SK_KEY_AQUI')
53
+
54
+ async function setupProducts() {
55
+ const products = [
56
+ // Substituir com os produtos do usuário
57
+ {
58
+ name: 'Plano Starter',
59
+ description: '5 projetos, suporte email',
60
+ price: 2900, // R$ 29,00 em centavos
61
+ interval: 'month',
62
+ features: ['5 projetos', 'Suporte email', '1GB storage']
63
+ },
64
+ {
65
+ name: 'Plano Pro',
66
+ description: 'Ilimitado, suporte prioritário',
67
+ price: 9900, // R$ 99,00 em centavos
68
+ interval: 'month',
69
+ features: ['Projetos ilimitados', 'Suporte prioritário', '10GB storage']
70
+ }
71
+ ]
72
+
73
+ console.log('Criando produtos no Stripe...\n')
74
+
75
+ for (const product of products) {
76
+ const stripeProduct = await stripe.products.create({
77
+ name: product.name,
78
+ description: product.description,
79
+ metadata: { features: JSON.stringify(product.features) }
80
+ })
81
+
82
+ const stripePrice = await stripe.prices.create({
83
+ product: stripeProduct.id,
84
+ unit_amount: product.price,
85
+ currency: 'brl',
86
+ recurring: product.interval ? { interval: product.interval } : undefined
87
+ })
88
+
89
+ console.log(`✓ ${product.name}`)
90
+ console.log(` Product ID: ${stripeProduct.id}`)
91
+ console.log(` Price ID: ${stripePrice.id}\n`)
92
+ }
93
+
94
+ console.log('Produtos criados com sucesso!')
95
+ }
96
+
97
+ setupProducts().catch(console.error)
43
98
  ```
44
99
 
45
- > [!IMPORTANT]
46
- > Never expose `STRIPE_SECRET_KEY` in frontend code.
100
+ Instrua o usuário a executar: `bun run scripts/setup-stripe-products.js`
47
101
 
48
- ---
102
+ ### Step 4: Coletar Price IDs
49
103
 
50
- ## 3. Server-Side Patterns (Elysia)
104
+ Após executar o script, peça:
51
105
 
52
- ### Initialize Stripe
106
+ > O script gerou os Price IDs. Por favor, me envie os IDs gerados.
107
+ > Exemplo: price_1ABC123...
53
108
 
54
- ```javascript
55
- import Stripe from 'stripe'
109
+ ### Step 5: Configurar Ambiente
56
110
 
57
- const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)
111
+ Com as chaves e Price IDs, configure os arquivos de ambiente:
112
+
113
+ **Backend: `.env.development` e `.env.production`**
114
+ ```bash
115
+ # .env.development (chaves de teste)
116
+ STRIPE_SECRET_KEY=sk_test_...
117
+ STRIPE_WEBHOOK_SECRET=whsec_...
118
+
119
+ # .env.production (chaves de produção)
120
+ STRIPE_SECRET_KEY=sk_live_...
121
+ STRIPE_WEBHOOK_SECRET=whsec_...
58
122
  ```
59
123
 
60
- ### Create Checkout Session
124
+ **Frontend: `.env.development` e `.env.production`**
125
+ ```bash
126
+ # .env.development
127
+ VITE_STRIPE_PUBLISHABLE_KEY=pk_test_...
61
128
 
62
- ```javascript
63
- const session = await stripe.checkout.sessions.create({
64
- mode: 'subscription',
65
- customer_email: user.email,
66
- line_items: [{ price: priceId, quantity: 1 }],
67
- success_url: `${baseUrl}/success?session_id={CHECKOUT_SESSION_ID}`,
68
- cancel_url: `${baseUrl}/cancel`,
69
- })
129
+ # .env.production
130
+ VITE_STRIPE_PUBLISHABLE_KEY=pk_live_...
70
131
  ```
71
132
 
72
- ### Webhook Handler
133
+ ### Step 6: Configurar Database
73
134
 
74
- ```javascript
75
- app.post('/webhook/stripe', async ({ request, set }) => {
76
- const sig = request.headers.get('stripe-signature')
77
- const body = await request.text()
78
-
79
- const event = stripe.webhooks.constructEvent(
80
- body,
81
- sig,
82
- process.env.STRIPE_WEBHOOK_SECRET
83
- )
84
-
85
- switch (event.type) {
86
- case 'checkout.session.completed':
87
- await handleCheckoutComplete(event.data.object)
88
- break
89
- case 'customer.subscription.updated':
90
- await handleSubscriptionUpdate(event.data.object)
91
- break
92
- case 'customer.subscription.deleted':
93
- await handleSubscriptionCancel(event.data.object)
94
- break
95
- }
135
+ Gere a migration para adicionar campos do Stripe:
96
136
 
97
- return { received: true }
98
- })
137
+ ```javascript
138
+ // database/schema.js - adicionar aos users
139
+ stripeCustomerId: text('stripe_customer_id').unique(),
140
+ stripeSubscriptionId: text('stripe_subscription_id').unique(),
141
+ plan: text('plan').default('free'),
142
+ subscriptionStatus: text('subscription_status'),
143
+ currentPeriodEnd: integer('current_period_end', { mode: 'timestamp' }),
99
144
  ```
100
145
 
101
- ---
146
+ ### Step 7: Configurar Webhook
102
147
 
103
- ## 4. Essential Webhooks
148
+ Instrua o usuário:
104
149
 
105
- | Event | When to Handle |
150
+ > Configure o webhook no Stripe Dashboard:
151
+ >
152
+ > 1. Acesse https://dashboard.stripe.com/webhooks
153
+ > 2. Clique em "Add endpoint"
154
+ > 3. URL: `https://seu-dominio.com/webhook/stripe`
155
+ > 4. Selecione os eventos:
156
+ > - `checkout.session.completed`
157
+ > - `customer.subscription.updated`
158
+ > - `customer.subscription.deleted`
159
+ > - `invoice.paid`
160
+ > - `invoice.payment_failed`
161
+ > 5. Copie o "Signing secret" (whsec_...)
162
+ > 6. Adicione ao `.env.development` e `.env.production`
163
+
164
+ ### Step 8: Gerar Código
165
+
166
+ Gere todos os arquivos necessários usando os templates de [assets/](assets/):
167
+
168
+ | Arquivo | Baseado em |
106
169
  | --- | --- |
107
- | `checkout.session.completed` | Provision access after payment |
108
- | `customer.subscription.updated` | Plan changes, renewals |
109
- | `customer.subscription.deleted` | Cancellation |
110
- | `invoice.payment_failed` | Payment issues |
111
- | `invoice.paid` | Successful recurring payment |
170
+ | `plugins/stripe.js` | stripe-server.js (seção 1) |
171
+ | `routes/billing.js` | stripe-server.js (seção 2) |
172
+ | `routes/webhook.js` | stripe-server.js (seção 3) |
173
+ | `services/billing.js` | stripe-server.js (seção 4) |
174
+ | `config/stripe-prices.js` | Price IDs coletados |
175
+ | `pages/Pricing.jsx` | stripe-client.js (seção 3) |
176
+ | `components/BillingSettings.jsx` | stripe-client.js (seção 4) |
177
+ | `hooks/useSubscription.js` | stripe-client.js (seção 2) |
112
178
 
113
- ---
179
+ ### Step 9: Criar Config de Preços
114
180
 
115
- ## 5. Customer Portal
181
+ Gere o arquivo de configuração com os Price IDs:
116
182
 
117
183
  ```javascript
118
- const portalSession = await stripe.billingPortal.sessions.create({
119
- customer: customerId,
120
- return_url: `${baseUrl}/account`,
121
- })
184
+ // config/stripe-prices.js
185
+ export const STRIPE_PRICES = {
186
+ starter: {
187
+ priceId: 'price_COLETADO_STARTER',
188
+ name: 'Starter',
189
+ price: 29,
190
+ features: ['5 projetos', 'Suporte email', '1GB storage']
191
+ },
192
+ pro: {
193
+ priceId: 'price_COLETADO_PRO',
194
+ name: 'Pro',
195
+ price: 99,
196
+ features: ['Projetos ilimitados', 'Suporte prioritário', '10GB storage']
197
+ }
198
+ }
199
+
200
+ export const getPrice = (plan) => STRIPE_PRICES[plan]
201
+ export const getPriceId = (plan) => STRIPE_PRICES[plan]?.priceId
122
202
  ```
123
203
 
124
204
  ---
125
205
 
126
- ## 6. Security Checklist
206
+ ## Checklist Final
127
207
 
128
- - [ ] Verify webhook signatures
129
- - [ ] Use idempotency keys for retries
130
- - [ ] Store customer ID in database
131
- - [ ] Handle edge cases (expired cards, disputes)
132
- - [ ] Test with Stripe CLI locally
208
+ Ao completar o setup, confirme:
209
+
210
+ - [ ] Dependências instaladas (`bun add stripe @stripe/stripe-js @stripe/react-stripe-js`)
211
+ - [ ] Chaves no `.env.development` e `.env.production` (backend e frontend)
212
+ - [ ] Produtos criados no Stripe
213
+ - [ ] Price IDs configurados em `config/stripe-prices.js`
214
+ - [ ] Schema do database atualizado
215
+ - [ ] Webhook endpoint configurado no Stripe Dashboard
216
+ - [ ] Webhook secret nos arquivos de ambiente
217
+ - [ ] Rotas de billing funcionando
218
+ - [ ] Página de pricing criada
219
+ - [ ] Testado com cartão 4242 4242 4242 4242
133
220
 
134
221
  ---
135
222
 
136
- ## 7. Testing
223
+ ## Testing Local
137
224
 
138
225
  ```bash
139
- # Install Stripe CLI
226
+ # Instalar Stripe CLI
140
227
  brew install stripe/stripe-cli/stripe
141
228
 
142
- # Forward webhooks to local server
229
+ # Login
230
+ stripe login
231
+
232
+ # Forward webhooks
143
233
  stripe listen --forward-to localhost:3000/webhook/stripe
234
+
235
+ # Testar checkout
236
+ stripe trigger checkout.session.completed
144
237
  ```
145
238
 
146
239
  ---
147
240
 
241
+ ## Specialized Guides
242
+
243
+ | Guide | Content |
244
+ | --- | --- |
245
+ | [stripe-elysia.md](references/stripe-elysia.md) | Backend routes completas |
246
+ | [stripe-react.md](references/stripe-react.md) | Componentes React/Mantine |
247
+ | [stripe-webhooks.md](references/stripe-webhooks.md) | Handlers de eventos |
248
+ | [stripe-database.md](references/stripe-database.md) | Schema Drizzle |
249
+
250
+ ---
251
+
148
252
  ## Related Skills
149
253
 
150
254
  - @[.agent/skills/riligar-dev-backend]
255
+ - @[.agent/skills/riligar-dev-frontend]
151
256
  - @[.agent/skills/riligar-dev-auth-elysia]
152
257
  - @[.agent/skills/riligar-tech-stack]