Skip to content

feat(subscription): Add estimate to subscriptions flow and remove amount and currency#9835

Merged
Gnanasundari24 merged 3 commits intomainfrom
remove-amt-and-curr
Oct 16, 2025
Merged

feat(subscription): Add estimate to subscriptions flow and remove amount and currency#9835
Gnanasundari24 merged 3 commits intomainfrom
remove-amt-and-curr

Conversation

@GauravRawat369
Copy link
Contributor

@GauravRawat369 GauravRawat369 commented Oct 14, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

Currently, subscription/create, /subscription, and /subscription/:id/update accept amount and currency as input parameters(this pr removes that).
Retrieved the amount and currency from the get_subscription_estimate from item_price_id.

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?

Create customer

curl --location 'http://localhost:8080/customers' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_ihB1dFGcaW8dbAHI3gXtuWPErJXbUrHqt0vYTvWpT70n6yzUhbClhncYEVz4QvLr' \
--data-raw '{
    "email": "guest@example.com",
    "name": "Gauarv",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response

{
    "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
    "name": "Gauarv",
    "email": "guest@example.com",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "address": null,
    "created_at": "2025-10-14T12:40:19.251Z",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "default_payment_method_id": null,
    "tax_registration_id": null
}

subscription create and confirm

curl --location 'http://localhost:8080/subscriptions' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_Y83W2MtvQkrqcMJ4xPnE' \
--header 'api-key: dev_ihB1dFGcaW8dbAHI3gXtuWPErJXbUrHqt0vYTvWpT70n6yzUhbClhncYEVz4QvLr' \
--data '{
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "customer_id": "cus_SDD7vSsXqQxZ2S4f7K6Y",
    "description": "Hello this is description",
    "merchant_reference_id": "mer_ref_1759334677",
    "shipping": {
        "address": {
            "state": "zsaasdas",
            "city": "Banglore",
            "country": "US",
            "line1": "sdsdfsdf",
            "line2": "hsgdbhd",
            "line3": "alsksoe",
            "zip": "571201",
            "first_name": "joseph",
            "last_name": "doe"
        },
        "phone": {
            "number": "123456789",
            "country_code": "+1"
        }
    },
    "billing": {
        "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": "123456789",
            "country_code": "+1"
        }
    },
    "payment_details": {
        "payment_method": "card",
        "payment_method_type": "credit",
        "payment_method_data": {
            "card": {
                "card_number": "4111111111111111",
                "card_exp_month": "03",
                "card_exp_year": "2030",
                "card_holder_name": "CLBRW dffdg",
                "card_cvc": "737"
            }
        },
        "authentication_type": "no_three_ds",
        "setup_future_usage": "off_session",
        "capture_method": "automatic",
        "return_url": "https://google.com",
        "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": "sub_yAVIFT8qYHapAXwj6pQy",
    "merchant_reference_id": "mer_ref_1759334677",
    "status": "active",
    "plan_id": null,
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "coupon": null,
    "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
    "payment": {
        "payment_id": "pay_MZey8c4E4b1gJr94LLAN",
        "status": "succeeded",
        "amount": 14100,
        "currency": "INR",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "connector": "stripe",
        "payment_method_id": "pm_ts9XJdSnlujF7QRzwowE",
        "return_url": "https://google.com/",
        "next_action": null,
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": "credit",
        "client_secret": "pay_MZey8c4E4b1gJr94LLAN_secret_UnbqBbhcjFkNw1XIQM97",
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "US",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "joseph",
                "last_name": "Doe",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "shipping": {
            "address": {
                "city": "Banglore",
                "country": "US",
                "line1": "sdsdfsdf",
                "line2": "hsgdbhd",
                "line3": "alsksoe",
                "zip": "571201",
                "state": "zsaasdas",
                "first_name": "joseph",
                "last_name": "doe",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "payment_type": null
    },
    "customer_id": "cus_SDD7vSsXqQxZ2S4f7K6Y",
    "invoice": {
        "id": "invoice_8NTGYqKJmqJFuZo7CzY0",
        "subscription_id": "sub_yAVIFT8qYHapAXwj6pQy",
        "merchant_id": "merchant_1760132209",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "merchant_connector_id": "mca_nh1mc6KDDpo6xpSnMwzy",
        "payment_intent_id": "pay_MZey8c4E4b1gJr94LLAN",
        "payment_method_id": null,
        "customer_id": "cus_SDD7vSsXqQxZ2S4f7K6Y",
        "amount": 14100,
        "currency": "INR",
        "status": "payment_pending"
    },
    "billing_processor_subscription_id": "sub_yAVIFT8qYHapAXwj6pQy"
}

Subscription create

curl --location 'http://localhost:8080/subscriptions/create' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_Y83W2MtvQkrqcMJ4xPnE' \
--header 'api-key: dev_ihB1dFGcaW8dbAHI3gXtuWPErJXbUrHqt0vYTvWpT70n6yzUhbClhncYEVz4QvLr' \
--data '{
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "plan_id": "cbdemo_enterprise-suite",
    "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
    "payment_details": {
        "authentication_type": "no_three_ds",
        "setup_future_usage": "off_session",
        "capture_method": "automatic",
        "return_url": "https://google.com"
    }
}'

Response

{
    "id": "sub_pQJmsFqhaqhe69MP2rdh",
    "merchant_reference_id": null,
    "status": "created",
    "plan_id": "cbdemo_enterprise-suite",
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
    "client_secret": "sub_pQJmsFqhaqhe69MP2rdh_secret_ZV8W1UDL8HLTPfQhjbqf",
    "merchant_id": "merchant_1760132209",
    "coupon_code": null,
    "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
    "payment": {
        "payment_id": "pay_F4UtZneFoU2VLUMwOX8W",
        "status": "requires_payment_method",
        "amount": 14100,
        "currency": "INR",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "connector": null,
        "payment_method_id": null,
        "return_url": "https://google.com/",
        "next_action": null,
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": null,
        "client_secret": "pay_F4UtZneFoU2VLUMwOX8W_secret_kNStCQ5sdP0ffrrp0Vs1",
        "billing": null,
        "shipping": null,
        "payment_type": null
    },
    "invoice": {
        "id": "invoice_q6gxyDf9PlCCE87o7Jzu",
        "subscription_id": "sub_pQJmsFqhaqhe69MP2rdh",
        "merchant_id": "merchant_1760132209",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "merchant_connector_id": "mca_nh1mc6KDDpo6xpSnMwzy",
        "payment_intent_id": "pay_F4UtZneFoU2VLUMwOX8W",
        "payment_method_id": null,
        "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
        "amount": 14100,
        "currency": "INR",
        "status": "invoice_created"
    }
}

Subscription update

curl --location --request PUT 'http://localhost:8080/subscriptions/sub_pQJmsFqhaqhe69MP2rdh/update' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_Y83W2MtvQkrqcMJ4xPnE' \
--header 'api-key: dev_ihB1dFGcaW8dbAHI3gXtuWPErJXbUrHqt0vYTvWpT70n6yzUhbClhncYEVz4QvLr' \
--data '{
    "plan_id":"cbdemo_enterprise-suite",
    "item_price_id":"cbdemo_enterprise-suite-monthly"
}'

Response

{
    "id": "sub_pQJmsFqhaqhe69MP2rdh",
    "merchant_reference_id": null,
    "status": "created",
    "plan_id": "cbdemo_enterprise-suite",
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
    "client_secret": "sub_pQJmsFqhaqhe69MP2rdh_secret_ZV8W1UDL8HLTPfQhjbqf",
    "merchant_id": "merchant_1760132209",
    "coupon_code": null,
    "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
    "payment": null,
    "invoice": null
}

Subscription confirm

curl --location 'http://localhost:8080/subscriptions/sub_pQJmsFqhaqhe69MP2rdh/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_Y83W2MtvQkrqcMJ4xPnE' \
--header 'api-key: pk_dev_70bbe854c72a45ac9ac643d1d559c395' \
--data '{
    "client_secret": "sub_pQJmsFqhaqhe69MP2rdh_secret_ZV8W1UDL8HLTPfQhjbqf",
    "payment_details": {
        "shipping": {
            "address": {
                "state": "zsaasdas",
                "city": "Banglore",
                "country": "US",
                "line1": "sdsdfsdf",
                "line2": "hsgdbhd",
                "line3": "alsksoe",
                "zip": "571201",
                "first_name": "joseph",
                "last_name": "doe"
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            }
        },
        "payment_method": "card",
        "payment_method_type": "credit",
        "payment_method_data": {
            "card": {
                "card_number": "4111111111111111",
                "card_exp_month": "03",
                "card_exp_year": "2030",
                "card_holder_name": "CLBRW dffdg",
                "card_cvc": "737"
            },
            "billing": {
                "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": "123456789",
                    "country_code": "+1"
                }
            }
        },
        "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": "sub_pQJmsFqhaqhe69MP2rdh",
    "merchant_reference_id": null,
    "status": "active",
    "plan_id": "cbdemo_enterprise-suite",
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "coupon": null,
    "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
    "payment": {
        "payment_id": "pay_F4UtZneFoU2VLUMwOX8W",
        "status": "succeeded",
        "amount": 14100,
        "currency": "INR",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "connector": "stripe",
        "payment_method_id": "pm_PX92DQnxZm7nGAwSNkmx",
        "return_url": "https://google.com/",
        "next_action": null,
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": "credit",
        "client_secret": "pay_F4UtZneFoU2VLUMwOX8W_secret_kNStCQ5sdP0ffrrp0Vs1",
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "US",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "joseph",
                "last_name": "Doe",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "shipping": {
            "address": {
                "city": "Banglore",
                "country": "US",
                "line1": "sdsdfsdf",
                "line2": "hsgdbhd",
                "line3": "alsksoe",
                "zip": "571201",
                "state": "zsaasdas",
                "first_name": "joseph",
                "last_name": "doe",
                "origin_zip": null
            },
            "phone": {
                "number": "123456789",
                "country_code": "+1"
            },
            "email": null
        },
        "payment_type": null
    },
    "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
    "invoice": {
        "id": "invoice_q6gxyDf9PlCCE87o7Jzu",
        "subscription_id": "sub_pQJmsFqhaqhe69MP2rdh",
        "merchant_id": "merchant_1760132209",
        "profile_id": "pro_Y83W2MtvQkrqcMJ4xPnE",
        "merchant_connector_id": "mca_nh1mc6KDDpo6xpSnMwzy",
        "payment_intent_id": "pay_F4UtZneFoU2VLUMwOX8W",
        "payment_method_id": "pm_PX92DQnxZm7nGAwSNkmx",
        "customer_id": "cus_sP3ouUy0J01OSngw2Q3G",
        "amount": 14100,
        "currency": "INR",
        "status": "payment_pending"
    },
    "billing_processor_subscription_id": "sub_pQJmsFqhaqhe69MP2rdh"
}

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

@GauravRawat369 GauravRawat369 requested review from a team as code owners October 14, 2025 12:31
@semanticdiff-com
Copy link

semanticdiff-com bot commented Oct 14, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/subscription.rs  25% smaller
  crates/api_models/src/subscription.rs  6% smaller
  crates/router/src/core/subscription/invoice_handler.rs  0% smaller

jagan-jaya
jagan-jaya previously approved these changes Oct 15, 2025
@GauravRawat369 GauravRawat369 self-assigned this Oct 15, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Oct 16, 2025
Merged via the queue into main with commit c2c4894 Oct 16, 2025
25 of 29 checks passed
@Gnanasundari24 Gnanasundari24 deleted the remove-amt-and-curr branch October 16, 2025 10:36
chaitak-gorai pushed a commit that referenced this pull request Oct 16, 2025
drdholu pushed a commit to drdholu/hyperswitch that referenced this pull request Oct 30, 2025
aadityaguptaa pushed a commit that referenced this pull request Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(subscription): Add estimate to subscriptions flow and remove amount and currency

4 participants