Skip to content

Conversation

GauravRawat369
Copy link
Contributor

@GauravRawat369 GauravRawat369 commented Oct 9, 2025

Type of Change

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

Description

  1. This pr adds plan_id and price_id columns to the subscription table.
  2. Created the subscription update call, which takes plan_id, item_price_id, amount, and currency as input.
  3. Added payment update s2s call.
  4. This PR removes all subscription information from the subscription confirm API so that the SDK can use it.

Subscription Update call does 2 things

  • Takes plan_id, item_price_id and update subscription
  • Takes amount, and currency, and updates the invoice and makes an S2S call to the payment update so that the confirm call can use the new amount and currency

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_KPQB3szY5nQvoegkHrIXZYsWEhsnljhp0CXly5dZUWNPmXgwICqUMHcl1qKKg2kb' \
--data-raw '{
    "email": "[email protected]",
    "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_zxMLIuJnnIJHR0A3ku4M",
    "name": "Gauarv",
    "email": "[email protected]",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "address": null,
    "created_at": "2025-10-09T20:29:01.003Z",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "default_payment_method_id": null,
    "tax_registration_id": null
}

Create subscription without price_id and plan_id

curl --location 'http://localhost:8080/subscriptions/create' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_q2odjxxoYxhwy5tXZKU1' \
--header 'api-key: dev_KPQB3szY5nQvoegkHrIXZYsWEhsnljhp0CXly5dZUWNPmXgwICqUMHcl1qKKg2kb' \
--data '{
    "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
    "amount": 14100,
    "currency": "USD",
    "payment_details": {
        "authentication_type": "no_three_ds",
        "setup_future_usage": "off_session",
        "capture_method": "automatic",
        "return_url": "https://google.com"
    }
}'

Response

{
    "id": "sub_h33npFPFe6Ok81MWv4Tq",
    "merchant_reference_id": null,
    "status": "created",
    "plan_id": null,
    "price_id": null,
    "profile_id": "pro_q2odjxxoYxhwy5tXZKU1",
    "client_secret": "sub_h33npFPFe6Ok81MWv4Tq_secret_xzh9usiNTNxjxAqcPWtk",
    "merchant_id": "merchant_1760011611",
    "coupon_code": null,
    "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
    "payment": {
        "payment_id": "pay_vz8HWByS019g2YMwt1is",
        "status": "requires_payment_method",
        "amount": 14100,
        "currency": "USD",
        "connector": null,
        "payment_method_id": null,
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": null,
        "client_secret": "pay_vz8HWByS019g2YMwt1is_secret_iYCy8Ksl0Zs68VBDPNzq"
    },
    "invoice": {
        "id": "invoice_OYxNwCMfnZDjRgcAqFxg",
        "subscription_id": "sub_h33npFPFe6Ok81MWv4Tq",
        "merchant_id": "merchant_1760011611",
        "profile_id": "pro_q2odjxxoYxhwy5tXZKU1",
        "merchant_connector_id": "mca_okM9o35Qk3O0VE9XS5ux",
        "payment_intent_id": "pay_vz8HWByS019g2YMwt1is",
        "payment_method_id": null,
        "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
        "amount": 14100,
        "currency": "USD",
        "status": "invoice_created"
    }
}

Request to update subscription

curl --location 'http://localhost:8080/subscriptions/update/sub_h33npFPFe6Ok81MWv4Tq' \
--header 'Content-Type: application/json' \
--header 'X-Profile-Id: pro_q2odjxxoYxhwy5tXZKU1' \
--header 'api-key: dev_KPQB3szY5nQvoegkHrIXZYsWEhsnljhp0CXly5dZUWNPmXgwICqUMHcl1qKKg2kb' \
--data '{
    "plan_id":"cbdemo_enterprise-suite",
    "item_price_id":"cbdemo_enterprise-suite-monthly",
    "amount": 15100,
    "currency": "USD"
}'

Response

{
    "id": "sub_h33npFPFe6Ok81MWv4Tq",
    "merchant_reference_id": null,
    "status": "created",
    "plan_id": "cbdemo_enterprise-suite",
    "price_id": "cbdemo_enterprise-suite-monthly",
    "profile_id": "pro_q2odjxxoYxhwy5tXZKU1",
    "client_secret": "sub_h33npFPFe6Ok81MWv4Tq_secret_xzh9usiNTNxjxAqcPWtk",
    "merchant_id": "merchant_1760011611",
    "coupon_code": null,
    "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
    "payment": null,
    "invoice": null
}

confirm subscription

curl --location 'http://localhost:8080/subscriptions/sub_h33npFPFe6Ok81MWv4Tq/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_q2odjxxoYxhwy5tXZKU1' \
--header 'api-key: pk_dev_13728cd3e3454df58262ffb8d10ce8c5' \
--data '{
    "client_secret": "sub_h33npFPFe6Ok81MWv4Tq_secret_xzh9usiNTNxjxAqcPWtk",
    "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_h33npFPFe6Ok81MWv4Tq",
    "merchant_reference_id": null,
    "status": "active",
    "plan_id": "sub_h33npFPFe6Ok81MWv4Tq",
    "price_id": "cbdemo_enterprise-suite",
    "coupon": null,
    "profile_id": "pro_q2odjxxoYxhwy5tXZKU1",
    "payment": {
        "payment_id": "pay_vz8HWByS019g2YMwt1is",
        "status": "succeeded",
        "amount": 15100,
        "currency": "USD",
        "connector": "stripe",
        "payment_method_id": "pm_BPUrH5VzG88jktYbihGO",
        "payment_experience": null,
        "error_code": null,
        "error_message": null,
        "payment_method_type": "credit",
        "client_secret": "pay_vz8HWByS019g2YMwt1is_secret_iYCy8Ksl0Zs68VBDPNzq"
    },
    "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
    "invoice": {
        "id": "invoice_OYxNwCMfnZDjRgcAqFxg",
        "subscription_id": "sub_h33npFPFe6Ok81MWv4Tq",
        "merchant_id": "merchant_1760011611",
        "profile_id": "pro_q2odjxxoYxhwy5tXZKU1",
        "merchant_connector_id": "mca_okM9o35Qk3O0VE9XS5ux",
        "payment_intent_id": "pay_vz8HWByS019g2YMwt1is",
        "payment_method_id": "pm_BPUrH5VzG88jktYbihGO",
        "customer_id": "cus_zxMLIuJnnIJHR0A3ku4M",
        "amount": 15100,
        "currency": "USD",
        "status": "payment_pending"
    },
    "billing_processor_subscription_id": "cbdemo_enterprise-suite-monthly"
}

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 9, 2025 19:54
Copy link

semanticdiff-com bot commented Oct 9, 2025

@GauravRawat369 GauravRawat369 self-assigned this Oct 9, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Oct 9, 2025
jagan-jaya
jagan-jaya previously approved these changes Oct 13, 2025
jarnura
jarnura previously approved these changes Oct 13, 2025
@GauravRawat369 GauravRawat369 dismissed stale reviews from jarnura and jagan-jaya via 2de817a October 13, 2025 13:54
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.

feat(subscriptions): Add update subscriptions APIs with payments update call

3 participants