|
1 | 1 | import { StripeIcon } from '@/components/icons' |
2 | 2 | import type { BlockConfig, BlockMeta } from '@/blocks/types' |
3 | 3 | import { AuthMode, IntegrationType } from '@/blocks/types' |
| 4 | +import { |
| 5 | + parseOptionalBooleanInput, |
| 6 | + parseOptionalJsonInput, |
| 7 | + parseOptionalNumberInput, |
| 8 | +} from '@/blocks/utils' |
4 | 9 | import type { StripeResponse } from '@/tools/stripe/types' |
5 | 10 | import { getTrigger } from '@/triggers' |
6 | 11 |
|
@@ -457,7 +462,7 @@ export const StripeBlock: BlockConfig<StripeResponse> = { |
457 | 462 | id: 'items', |
458 | 463 | title: 'Items (JSON Array)', |
459 | 464 | type: 'code', |
460 | | - placeholder: '[{"price": "price_1234567890", "quantity": 1}]', |
| 465 | + placeholder: '[{"id": "si_1234567890", "price": "price_1234567890", "quantity": 1}]', |
461 | 466 | condition: { |
462 | 467 | field: 'operation', |
463 | 468 | value: ['update_subscription'], |
@@ -898,62 +903,30 @@ export const StripeBlock: BlockConfig<StripeResponse> = { |
898 | 903 | return `stripe_${params.operation}` |
899 | 904 | }, |
900 | 905 | params: (params) => { |
901 | | - const { |
902 | | - operation, |
903 | | - apiKey, |
904 | | - address, |
905 | | - metadata, |
906 | | - items, |
907 | | - images, |
908 | | - recurring, |
909 | | - cancel_at_period_end, |
910 | | - auto_advance, |
911 | | - capture, |
912 | | - active, |
913 | | - prorate, |
914 | | - invoice_now, |
915 | | - paid_out_of_band, |
916 | | - ...rest |
917 | | - } = params |
918 | | - |
919 | | - // Parse JSON fields |
920 | | - let parsedAddress: any | undefined |
921 | | - let parsedMetadata: any | undefined |
922 | | - let parsedItems: any | undefined |
923 | | - let parsedImages: any | undefined |
924 | | - let parsedRecurring: any | undefined |
925 | | - |
926 | | - try { |
927 | | - if (address) parsedAddress = JSON.parse(address) |
928 | | - if (metadata) parsedMetadata = JSON.parse(metadata) |
929 | | - if (items) parsedItems = JSON.parse(items) |
930 | | - if (images) parsedImages = JSON.parse(images) |
931 | | - if (recurring) parsedRecurring = JSON.parse(recurring) |
932 | | - } catch (error: any) { |
933 | | - throw new Error(`Invalid JSON input: ${error.message}`) |
934 | | - } |
935 | | - |
936 | | - // Convert string booleans to actual booleans |
937 | | - const parsedBooleans: Record<string, boolean | undefined> = {} |
938 | | - if (cancel_at_period_end !== undefined) |
939 | | - parsedBooleans.cancel_at_period_end = cancel_at_period_end === 'true' |
940 | | - if (auto_advance !== undefined) parsedBooleans.auto_advance = auto_advance === 'true' |
941 | | - if (capture !== undefined) parsedBooleans.capture = capture === 'true' |
942 | | - if (active !== undefined) parsedBooleans.active = active === 'true' |
943 | | - if (prorate !== undefined) parsedBooleans.prorate = prorate === 'true' |
944 | | - if (invoice_now !== undefined) parsedBooleans.invoice_now = invoice_now === 'true' |
945 | | - if (paid_out_of_band !== undefined) |
946 | | - parsedBooleans.paid_out_of_band = paid_out_of_band === 'true' |
| 906 | + const { operation, ...rest } = params |
947 | 907 |
|
948 | 908 | return { |
949 | | - apiKey, |
950 | 909 | ...rest, |
951 | | - ...(parsedAddress && { address: parsedAddress }), |
952 | | - ...(parsedMetadata && { metadata: parsedMetadata }), |
953 | | - ...(parsedItems && { items: parsedItems }), |
954 | | - ...(parsedImages && { images: parsedImages }), |
955 | | - ...(parsedRecurring && { recurring: parsedRecurring }), |
956 | | - ...parsedBooleans, |
| 910 | + ...(operation === 'capture_payment_intent' && { |
| 911 | + amount_to_capture: |
| 912 | + parseOptionalNumberInput(params.amount_to_capture, 'Amount to capture') ?? |
| 913 | + parseOptionalNumberInput(params.amount, 'Amount'), |
| 914 | + }), |
| 915 | + ...(operation === 'capture_charge' && { |
| 916 | + amount: parseOptionalNumberInput(params.amount, 'Amount'), |
| 917 | + }), |
| 918 | + address: parseOptionalJsonInput(params.address, 'Address'), |
| 919 | + metadata: parseOptionalJsonInput(params.metadata, 'Metadata'), |
| 920 | + items: parseOptionalJsonInput(params.items, 'Items'), |
| 921 | + images: parseOptionalJsonInput(params.images, 'Images'), |
| 922 | + recurring: parseOptionalJsonInput(params.recurring, 'Recurring'), |
| 923 | + cancel_at_period_end: parseOptionalBooleanInput(params.cancel_at_period_end), |
| 924 | + auto_advance: parseOptionalBooleanInput(params.auto_advance), |
| 925 | + capture: parseOptionalBooleanInput(params.capture), |
| 926 | + active: parseOptionalBooleanInput(params.active), |
| 927 | + prorate: parseOptionalBooleanInput(params.prorate), |
| 928 | + invoice_now: parseOptionalBooleanInput(params.invoice_now), |
| 929 | + paid_out_of_band: parseOptionalBooleanInput(params.paid_out_of_band), |
957 | 930 | } |
958 | 931 | }, |
959 | 932 | }, |
@@ -1127,15 +1100,15 @@ export const StripeBlockMeta = { |
1127 | 1100 | }, |
1128 | 1101 | { |
1129 | 1102 | name: 'manage-subscription', |
1130 | | - description: 'Create, update, pause, or cancel a Stripe subscription for a customer.', |
| 1103 | + description: 'Create, update, cancel, or resume a paused Stripe subscription for a customer.', |
1131 | 1104 | content: |
1132 | | - '# Manage Subscription\n\nHandle the lifecycle of a recurring subscription.\n\n## Steps\n1. To start a subscription, run Create Subscription with the customer and price items.\n2. To change a plan, run Update Subscription with the new items. To pause and later restart, use Cancel Subscription or Resume Subscription as appropriate.\n3. Confirm the current state with Retrieve Subscription.\n\n## Output\nReturn the subscription ID, its status, current period end, and the plan items, and note exactly what changed.', |
| 1105 | + '# Manage Subscription\n\nHandle the lifecycle of a recurring subscription.\n\n## Steps\n1. To start a subscription, run Create Subscription with the customer and price items.\n2. To change a plan, run Update Subscription with the existing subscription item ID and replacement price. Omitting the item ID adds another item.\n3. To schedule cancellation, use Update Subscription with cancel_at_period_end=true; set it to false before the period ends to undo that schedule. Cancel Subscription ends the subscription immediately and cannot be undone. Resume Subscription applies only to paused subscriptions, not canceled ones.\n4. Confirm the current state with Retrieve Subscription.\n\n## Output\nReturn the subscription ID, status, and plan items, and note exactly what changed.', |
1133 | 1106 | }, |
1134 | 1107 | { |
1135 | 1108 | name: 'issue-invoice', |
1136 | 1109 | description: 'Create, finalize, and send a Stripe invoice to a customer, then track payment.', |
1137 | 1110 | content: |
1138 | | - '# Issue Invoice\n\nBill a customer with a Stripe invoice.\n\n## Steps\n1. Run Create Invoice for the customer with the line items.\n2. Run Finalize Invoice to lock it, then Send Invoice to deliver it to the customer.\n3. Track payment with Retrieve Invoice, or run Pay Invoice to charge a saved payment method. Use Void Invoice to cancel an unpaid invoice.\n\n## Output\nReturn the invoice ID, its status (draft, open, paid, or void), the amount due, and the hosted invoice URL when available.', |
| 1111 | + '# Issue Invoice\n\nBill a customer with a Stripe invoice.\n\n## Steps\n1. Run Create Invoice for the customer. This tool does not create line items; inspect the draft and any existing pending items with Retrieve Invoice.\n2. After verifying the amount and items, run Finalize Invoice to lock it, then Send Invoice to deliver it to the customer.\n3. Track payment with Retrieve Invoice, or run Pay Invoice to charge a saved payment method. Use Void Invoice to cancel an unpaid invoice.\n\n## Output\nReturn the invoice ID, its status (draft, open, paid, or void), the amount due, and the hosted invoice URL when available.', |
1139 | 1112 | }, |
1140 | 1113 | { |
1141 | 1114 | name: 'find-customer-activity', |
|
0 commit comments