( userId: string, subscriptionId: string )
| 266 | RETURNING microdollars_used |
| 267 | `); |
| 268 | if (chargedUsers.length === 0) { |
| 269 | throw new Error('Insufficient credit balance for this coding plan purchase.'); |
| 270 | } |
| 271 | |
| 272 | await tx.insert(credit_transactions).values({ |
| 273 | id: transactionId, |
| 274 | kilo_user_id: userId, |
| 275 | amount_microdollars: -plan.costMicrodollars, |
| 276 | is_free: false, |
| 277 | description: `Coding plan: ${plan.providerName} ${plan.name}`, |
| 278 | credit_category: `coding-plan:${plan.planId}:${requestKey}`, |
| 279 | check_category_uniqueness: true, |
| 280 | original_baseline_microdollars_used: lockedUser.microdollars_used, |
| 281 | created_at: periodStartIso, |
| 282 | }); |
| 283 | const { rows: inventoryRows } = await tx.execute<{ |
| 284 | id: string; |
| 285 | encrypted_api_key: { iv: string; data: string; authTag: string } | null; |
| 286 | }>(sql` |
| 287 | UPDATE coding_plan_key_inventory |
| 288 | SET status = 'assigned', |
| 289 | assigned_to_user_id = ${userId}, |
no test coverage detected