Create subscription

Creates a new subscription for a customer

📘

API Refs

Pricing Note

The final subscription price includes the base amount (gross premium from stripePriceId) plus any additional fees like serviceFee and taxes. This works like invoice pricing

Request body

NameTypeDescriptionRequired
effectiveDatestringEffective date of the policy/subscription (ISO 8601)yes
expirationDatestringExpiration date of the policy/subscription (ISO 8601)yes
stripeCustomerIdstringStripe customer ID (must start with "cus_")yes
stripePriceIdstringStripe price ID (must start with "price_")yes
policyholderIdnumberThe policyholder ID from contact catalogyes
carrierIdnumberThe carrier ID from contact catalogyes
paymentMethodstringPayment method: "card" or "us_bank_account"yes
isAutoRemitPremiumsbooleanAuto-remit premiums for created invoicesno
serviceFeenumberService fee amount added to base priceno
taxesnumberTax amount added to base priceno
commissionnumberCommission amount for invoicesno
numDaysForAutoRemindnumberDays for auto-reminder notificationsno
memostringCustom memo prefix (max 200 chars)no
brokerCodestringBroker code (max 50 chars)no
shouldBeSignedbooleanWhether invoices should be signedno
isCommissionVisibleForPolicyholderbooleanShow commission to policyholderno
mgaIdnumberMGA IDno
policyIdstringExternal policy ID (max 50 chars)no
downPaymentnumberDown payment amountno
financeAmountnumberFinance amountno
billingPortalReturnUrlstringReturn URL for Stripe billing portal (when customer exits portal)no
checkoutSuccessUrlstringURL to redirect to after successful payment completion (automatically appends ?isPaymentCompleted=true)yes
checkoutCancelUrlstringURL to redirect to when customer cancels paymentno

Response

Success Response (201 Created)

FieldTypeDescription
stripeCustomerIdstringStripe customer ID
statusstringSubscription status (see enum values below)
invoiceIdnumberInternal invoice ID for reference (nullable)
planobjectPlan details
subscriptionPricingobjectSubscription pricing with fees breakdown
checkoutSessionUrlstringStripe Checkout Session URL with redirect support (nullable)
billingPortalUrlstringBilling portal URL for subscription management (nullable)

Subscription Status Values

  • incomplete
  • incomplete_expired
  • trialing
  • active
  • past_due
  • canceled
  • unpaid
  • paused
  • unpaid_paused

Plan Object Structure

FieldTypeDescription
stripePriceIdstringStripe price ID
amountnumberPre-fee price amount in cents (base price before any fees are added)
intervalstringBilling interval
intervalCountnumberFrequency multiplier

Subscription Pricing Object Structure

FieldTypeDescription
baseAmountnumberBase amount before fees (gross premium) in cents
totalFeesnumberTotal fees applied in cents
totalAmountnumberFinal total amount in cents
intervalstringBilling interval
intervalCountnumberFrequency multiplier
paymentMethodstringPayment method used

Example Request

{
  "effectiveDate": "2024-01-01T00:00:00.000Z",
  "expirationDate": "2025-01-01T00:00:00.000Z",
  "stripeCustomerId": "cus_ExampleCustomerID123",
  "stripePriceId": "price_ExamplePriceID456",
  "policyholderId": 12345,
  "carrierId": 678,
  "paymentMethod": "card",
  "isAutoRemitPremiums": true,
  "serviceFee": 25.00,
  "taxes": 8.50,
  "commission": 150.00,
  "memo": "Auto Insurance Policy",
  "brokerCode": "BRK-2024-001",
  "shouldBeSigned": true,
  "billingPortalReturnUrl": "https://example.com/billing-portal-return",
  "checkoutSuccessUrl": "https://example.com/payment-success",
  "checkoutCancelUrl": "https://example.com/payment-cancelled"
}

Example Response

{
  "stripeCustomerId": "cus_ExampleCustomerID123",
  "status": "active",
  "invoiceId": 98765,
  "plan": {
    "stripePriceId": "price_ExamplePriceID456",
    "amount": 4999,
    "interval": "month",
    "intervalCount": 1
  },
  "checkoutSessionUrl": "https://checkout.stripe.com/c/pay/cs_test_xxx",
  "billingPortalUrl": "https://billing.stripe.com/p/session/test_xxx",
}

Important Notes

  1. Payment Method Required: The paymentMethod field is now required and determines fee structures. Only "card" and "us_bank_account" are supported.

  2. Customer Prerequisites: The customer must already exist in Stripe with a valid payment method before creating a subscription.

  3. Payment URLs: The response includes multiple URL options:

    • checkoutSessionUrl: For initial payment completion with redirect support
    • billingPortalUrl: For ongoing subscription management
  4. URL Redirects:

    • checkoutSuccessUrl and checkoutCancelUrl control redirects during the checkout process
    • The success URL will automatically have ?isPaymentCompleted=true appended as a query parameter
    • billingPortalReturnUrl controls redirects when customers exit the billing portal
  5. Invoice Integration: Subscriptions automatically create invoices in the AgentSnap system with the specified configuration.

Error Responses

  • 400 Bad Request: Invalid subscription configuration or validation errors
  • 401 Unauthorized: Invalid or missing authorization token
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Customer or price not found