BOB Docs
APIApplicationStore

ProductService

Key Features

  • Product Management: Handles creation, retrieval, and updates for products and their associated data (e.g., pricing, images, translations).
  • Pricing Models: Supports single-payment and subscription-based pricing models.
  • Multilingual Support: Allows product translations for multiple languages.
  • Image Management: Manages product images, including file handling and ordering.
  • Validation and Integrity: Ensures valid operations, such as checking product availability for subscription purchases.

Methods

  1. Product Retrieval:

    • get_products(page, page_size): Retrieves all products with pagination.
    • get_paginated_single_payment_products(page, page_size): Fetches products with a one-off payment pricing model.
  2. Product Creation:

    • create_product(key, tax_code, shippable): Creates a new product with basic attributes.
    • create_pricing(product_id, unit_amount, currency, interval): Defines pricing for a product, including payment intervals.
    • create_product_image(product_id, title, path, order): Adds an image to a product with file validation.
    • create_product_translation(product_id, language_code, name, checkout_description, description, statement_descriptor): Creates a product translation for a specified language.
  3. Product Validation:

    • product_for_subscription(pricing_id): Ensures a product is eligible for subscription-based purchases.
    • get_pricing(pricing_id): Retrieves a pricing object by ID.

Example Workflow

  1. Create a Product:

    product = await product_service.create_product(key="prod_123", tax_code="tax001", shippable=True)
  2. Add Pricing to a Product:

    pricing = await product_service.create_pricing(
        product_id=product.id,
        unit_amount=1000,
        currency="USD",
        interval=PriceInterval.MONTHLY
    )
  3. Add an Image to a Product:

    image = await product_service.create_product_image(
        product_id=product.id,
        title="Main Image",
        path="/path/to/image.jpg",
        order=1
    )
  4. Add a Translation:

    translation = await product_service.create_product_translation(
        product_id=product.id,
        language_code="en",
        name="Product Name",
        checkout_description="Short checkout description",
        description="Detailed product description",
        statement_descriptor="Statement Descriptor"
    )
  5. Retrieve Products with Single-Payment Pricing:

    single_payment_products, pagination = await product_service.get_paginated_single_payment_products(
        page=1,
        page_size=10
    )

Dependencies

  • Repositories Used:
    • ProductRepository: Handles product database operations.
    • PricingRepository: Manages pricing data for products.
    • ProductImageRepository: Handles storage and retrieval of product images.
    • ProductTranslationRepository: Manages translations for products.

Notes

This service ensures a robust and scalable approach to product management, accommodating multilingual support and flexible pricing models. It enforces integrity checks and provides clear APIs for product-related operations.

Benefits:

  • Flexibility: Supports diverse pricing models and multilingual capabilities.
  • Integrity: Ensures consistent product and pricing data through validation.
  • Efficiency: Streamlines the creation and management of product-related resources.

On this page