BOB Docs
APIApplicationPayment

StripeProvider

Key Features

  • Customer Management:
    • Create, update, and manage customer records in Stripe.
    • Support for tax-related data, including VAT numbers.
  • Subscription Handling:
    • Create, update, and cancel customer subscriptions.
    • Adjust pricing dynamically based on business requirements.
  • Product and Pricing Management:
    • Create or retrieve products and pricing data in Stripe.
    • Support multi-currency configurations and pricing modifications.
  • Checkout Sessions:
    • Generate checkout sessions for one-time payments or subscriptions.
    • Handle metadata and custom configurations for tailored payment flows.
  • Webhook Processing:
    • Decode and validate Stripe webhooks to handle real-time events.
  • Customer Portal:
    • Generate self-service billing management links via Stripe's customer portal.

Methods

  1. Customer Management:

    • create_customer: Creates a new customer in Stripe.
    • update_customer: Updates existing customer details, including tax exemptions.
    • create_customer_tax: Adds a tax ID (e.g., VAT) to a Stripe customer.
  2. Subscription Management:

    • create_subscription: Creates a new subscription for a customer.
    • cancel_subscription: Cancels an existing subscription in Stripe.
    • modify_subscription_pricing: Updates subscription pricing dynamically.
  3. Checkout Management:

    • create_checkout_session: Generates a checkout session for subscriptions or one-time payments.
    • decode_webhook: Validates and decodes webhook events from Stripe.
  4. Product and Pricing Management:

    • get_or_create_product: Retrieves or creates a product in Stripe.
    • create_pricing: Defines product pricing, supporting multiple currencies.
    • modify_pricing: Updates existing pricing details, including adjustments for different currencies.
  5. Country and Tax Management:

    • get_all_countries_in_iso_2_format: Retrieves all supported countries in ISO-2 format.
    • create_tax_rate: Creates a tax rate for products or subscriptions.
  6. Customer Portal:

    • create_customer_portal_link: Generates a link to Stripe's customer portal for self-service billing management.

Example Workflows

  1. Create a Customer:

    customer_id = await stripe_provider.create_customer(
        email="john.doe@example.com",
        name="John Doe",
        city="Warsaw",
        country="PL",
        line1="Main Street 1",
        postal_code="00-001"
    )
  2. Set Up a Subscription:

subscription_url = await stripe_provider.create_checkout_session(
    line_items=[StripeLineItem(price="price_id", quantity=1)],
    mode=CheckoutModes.SUBSCRIPTION,
    checkout_session_external_id="checkout123",
    customer_id="customer123"
)
  1. Modify Pricing:
new_pricing_id = await stripe_provider.modify_pricing(
    pricing_external_id="price123",
    unit_amount=2000,
    currency="usd",
    interval="month"
)
  1. Cancel a Subscription:
success = await stripe_provider.cancel_subscription(subscription_id="sub_123")

Dependencies

  • External Libraries:
  • Stripe Python SDK: Directly communicates with the Stripe API.
  • Application Settings:
  • STRIPE_API_KEY: API key for authenticating with Stripe.
  • STRIPE_ENDPOINT_SECRET: Secret key for validating Stripe webhooks.
  • HOST_ADDRESS: Base URL for redirecting users back to the application.

Purpose

This service abstracts all Stripe-specific logic, ensuring that business operations are decoupled from the payment provider's API. It simplifies future enhancements, supports scalability, and ensures secure and reliable payment management within the application.

On this page