Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .cursor/rules/convex_rules.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Note: `paginationOpts` is an object with the following properties:

## Schema guidelines
- Always define your schema in `convex/schema.ts`.
- Always import the schema definition functions from `convex/server`:
- Always import the schema definition functions from `convex/server`.
- System fields are automatically added to all documents and are prefixed with an underscore. The two system fields that are automatically added to all documents are `_creationTime` which has the validator `v.number()` and `_id` which has the validator `v.id(tableName)`.
- Always include all index fields in the index name. For example, if an index is defined as `["field1", "field2"]`, the index name should be "by_field1_and_field2".
- Index fields must be queried in the same order they are defined. If you want to be able to query by "field1" then "field2" and by "field2" then "field1", you must create separate indexes.
Expand Down Expand Up @@ -480,8 +480,8 @@ import OpenAI from "openai";
import { internal } from "./_generated/api";

/**
* Create a user with a given name.
*/
* Create a user with a given name.
*/
export const createUser = mutation({
args: {
name: v.string(),
Expand All @@ -493,8 +493,8 @@ export const createUser = mutation({
});

/**
* Create a channel with a given name.
*/
* Create a channel with a given name.
*/
export const createChannel = mutation({
args: {
name: v.string(),
Expand All @@ -506,8 +506,8 @@ export const createChannel = mutation({
});

/**
* List the 10 most recent messages from a channel in descending creation order.
*/
* List the 10 most recent messages from a channel in descending creation order.
*/
export const listMessages = query({
args: {
channelId: v.id("channels"),
Expand All @@ -532,8 +532,8 @@ export const listMessages = query({
});

/**
* Send a message to a channel and schedule a response from the AI.
*/
* Send a message to a channel and schedule a response from the AI.
*/
export const sendMessage = mutation({
args: {
channelId: v.id("channels"),
Expand Down Expand Up @@ -672,5 +672,4 @@ export default defineSchema({
export default function App() {
return <div>Hello World</div>;
}
```

```
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.1.2

- Fix updateSubscriptionQuantity: we now pass in STRIPE_SECRET_KEY explicitly.
component context did not have access to process.env

## 0.1.1

- Update docs
Expand Down
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": {
"url": "https://github.com/get-convex/stripe/issues"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "Apache-2.0",
"keywords": [
"convex",
Expand Down
3 changes: 2 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export class StripeSubscriptions {
quantity: number;
},
) {
// Delegate to the component's public action
// Delegate to the component's public action, passing the API key
await ctx.runAction(this.component.public.updateSubscriptionQuantity, {
stripeSubscriptionId: args.stripeSubscriptionId,
quantity: args.quantity,
apiKey: this.apiKey,
});

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/component/_generated/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
updateSubscriptionQuantity: FunctionReference<
"action",
"internal",
{ quantity: number; stripeSubscriptionId: string },
{ apiKey: string; quantity: number; stripeSubscriptionId: string },
null,
Name
>;
Expand Down
12 changes: 3 additions & 9 deletions src/component/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,17 @@ export const updateSubscriptionMetadata = mutation({
/**
* Update subscription quantity (for seat-based pricing).
* This will update both Stripe and the local database.
* STRIPE_SECRET_KEY must be set as an environment variable.
* STRIPE_SECRET_KEY must be provided as a parameter.
*/
export const updateSubscriptionQuantity = action({
args: {
stripeSubscriptionId: v.string(),
quantity: v.number(),
apiKey: v.string(),
},
returns: v.null(),
handler: async (ctx, args) => {
const apiKey = process.env.STRIPE_SECRET_KEY;
if (!apiKey) {
throw new Error(
"STRIPE_SECRET_KEY must be provided as an environment variable",
);
}

const stripe = new StripeSDK(apiKey);
const stripe = new StripeSDK(args.apiKey);

// Get the subscription from Stripe to find the subscription item ID
const subscription = await stripe.subscriptions.retrieve(
Expand Down
Loading