Skip to content

feat(subscriptions): Add Subscription confirm handler#9353

Merged
Gnanasundari24 merged 145 commits intomainfrom
subscription-confirm-handler
Sep 25, 2025
Merged

feat(subscriptions): Add Subscription confirm handler#9353
Gnanasundari24 merged 145 commits intomainfrom
subscription-confirm-handler

Conversation

@Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Sep 10, 2025

This pull request introduces a new subscription feature to the codebase, adding comprehensive support for subscription management via new API models, endpoints, and supporting logic. The changes include new data models, API routes, core business logic for creating and confirming subscriptions, and integration with customer management. The implementation is gated behind the v1 and olap feature flags.

New Subscription Feature

  • Added subscription module to api_models, including request and response types, core data structures (Subscription, Invoice), and helper functions for mapping customer data.
  • Introduced a new Subscription resource to the global Resource enum for system-wide referencing.

Core Logic and Utilities

  • Implemented core business logic in core/subscription.rs for creating and confirming subscriptions, including customer handling, client secret generation, and placeholder billing processor integration.
  • Added utility functions in core/subscription/utils.rs for customer retrieval/creation and extracting customer details from subscription requests.
  • Updated customer helper function signature in payouts to allow broader usage in subscription flows.

Database and Model Changes

  • Added client secret generation to the SubscriptionNew model in diesel_models, supporting secure subscription creation. [1] [2]

API Routing and Integration

  • Registered new subscription endpoints in the API routes and application server, enabling /subscription and /subscription/{subscription_id}/confirm endpoints for managing subscriptions. [1] [2] [3] [4] [5]
  • Added subscription module references to core and feature-gated module lists for proper compilation and integration. [1] [2]
  • Updated API identifier enums to include Subscription for locking and routing utilities.] New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

  1. create a customer
curl --location 'http://localhost:8080/customers' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Ske75Nx2J7qtHsP8cc7pFx5k4dccYBedM6UAExaLOdHCkji3uVWSqfmZ0Qz0Tnyj' \
--data-raw '{
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
  1. create a subscription
curl --location 'http://localhost:8080/subscription/create' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_X16mQSHipgRuWbTEMkMp' \
--header 'api-key: dev_Ske75Nx2J7qtHsP8cc7pFx5k4dccYBedM6UAExaLOdHCkji3uVWSqfmZ0Qz0Tnyj' \
--data '{
    "customer_id": "cus_NdHhw4wwWyYXSldO9oYE"
}'

response -

{"id":"subscription_wBV1G9dhh6EBhTOTXRBA","merchant_reference_id":null,"status":"Created","plan_id":null,"profile_id":"pro_X16mQSHipgRuWbTEMkMp","client_secret":"subscription_wBV1G9dhh6EBhTOTXRBA_secret_6W89VL1bl5C3esgbxpJp","merchant_id":"merchant_1758626894","coupon_code":null,"customer_id":"cus_NdHhw4wwWyYXSldO9oYE"}
  1. Confirm subscription
curl --location 'http://localhost:8080/subscription/subscription_wBV1G9dhh6EBhTOTXRBA/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_2WzEeiNyj8fSCObXqo36' \
--header 'api-key: dev_Ske75Nx2J7qtHsP8cc7pFx5k4dccYBedM6UAExaLOdHCkji3uVWSqfmZ0Qz0Tnyj' \
--data '{
    "amount": 14100,
    "currency": "INR",
    "item_price_id": "cbdemo_enterprise-suite-INR-Daily",
    "customer_id": "cus_NdHhw4wwWyYXSldO9oYE",
    "billing_address": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "payment_details": {
        "payment_method": "card",
        "payment_method_type": "credit",
        "payment_method_data": {
            "card": {
                "card_number": "4242424242424242",
                "card_exp_month": "10",
                "card_exp_year": "25",
                "card_holder_name": "joseph Doe",
                "card_cvc": "123"
            }
        },
        "setup_future_usage": "off_session",
        "customer_acceptance": {
            "acceptance_type": "online",
            "accepted_at": "1963-05-03T04:07:52.723Z",
            "online": {
                "ip_address": "127.0.0.1",
                "user_agent": "amet irure esse"
            }
        }
    }
}'

Response -

{"id":"subscription_wBV1G9dhh6EBhTOTXRBA","merchant_reference_id":null,"status":"Active","plan_id":null,"price_id":null,"coupon":null,"profile_id":"pro_X16mQSHipgRuWbTEMkMp","payment":null,"customer_id":"cus_NdHhw4wwWyYXSldO9oYE","invoice":{"id":"invoice_0XANlbhMp2V7wUvWRhhJ","subscription_id":"subscription_wBV1G9dhh6EBhTOTXRBA","merchant_id":"merchant_1758626894","profile_id":"pro_X16mQSHipgRuWbTEMkMp","merchant_connector_id":"mca_eN6JxSK2NkuT0wSYAH5s","payment_intent_id":null,"payment_method_id":null,"customer_id":"cus_NdHhw4wwWyYXSldO9oYE","amount":14100,"currency":"INR","status":"InvoiceCreated"}}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

prajjwalkumar17 and others added 30 commits August 25, 2025 19:14
@Sarthak1799 Sarthak1799 removed the request for review from a team September 24, 2025 11:05
jarnura
jarnura previously approved these changes Sep 24, 2025
jagan-jaya
jagan-jaya previously approved these changes Sep 24, 2025
@ThisIsMani ThisIsMani removed the request for review from a team September 24, 2025 15:06
@Sarthak1799 Sarthak1799 removed the request for review from a team September 24, 2025 15:07
@Sarthak1799 Sarthak1799 dismissed stale reviews from jagan-jaya and jarnura via f73add1 September 25, 2025 06:01
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Sep 25, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 25, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Sep 25, 2025
Merged via the queue into main with commit f02d180 Sep 25, 2025
21 of 25 checks passed
@Gnanasundari24 Gnanasundari24 deleted the subscription-confirm-handler branch September 25, 2025 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-database-changes Metadata: This PR involves database schema changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subscription confirm API

5 participants