Skip to content

feat(payments): Add MIT payment functionality and update invoice handler#9668

Merged
Gnanasundari24 merged 8 commits intomainfrom
add-record-back-to-mit
Oct 7, 2025
Merged

feat(payments): Add MIT payment functionality and update invoice handler#9668
Gnanasundari24 merged 8 commits intomainfrom
add-record-back-to-mit

Conversation

@GauravRawat369
Copy link
Contributor

@GauravRawat369 GauravRawat369 commented Oct 4, 2025

Type of Change

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

Description

This pr completes 9400

This pr adds support to do MIT payment for subscription and adds an invoice sync job
Created Mit payment handler in subscription invoice_handler.rs
and added create_invoice_sync_job after updating the invoice with the payment 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

Enable internal API key Auth by changing config/development.toml
[internal_merchant_id_profile_id_auth]
enabled = true
internal_api_key = "test_internal_api_key"
  1. Create Merchant, API key, Payment connector, Billing Connector
  2. Update profile to set the billing processor
    Request
curl --location 'http://localhost:8080/account/merchant_1759125756/business_profile/pro_71jcERFiZERp44d8fuSJ' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_0RJW0cwZDeGfSkod0eJWOkfZHK0PCoZtDYJJ1FxeHqhHky1VNPU6nkgFQiTFSDvA' \
--data '{
  "billing_processor_id": "mca_NLnCEvS2DfuHWHFVa09o"
}'

Response

{"merchant_id":"merchant_1759125756","profile_id":"pro_71jcERFiZERp44d8fuSJ","profile_name":"US_default","return_url":"https://google.com/success","enable_payment_response_hash":true,"payment_response_hash_key":"ZFjTKSE1EYiXaPcRhacrwlNh4wieUorlmP7r2uSHI8fyHigGmNCKY2hqVtzAq51m","redirect_to_merchant_with_http_post":false,"webhook_details":{"webhook_version":"1.0.1","webhook_username":"ekart_retail","webhook_password":"password_ekart@123","webhook_url":null,"payment_created_enabled":true,"payment_succeeded_enabled":true,"payment_failed_enabled":true,"payment_statuses_enabled":null,"refund_statuses_enabled":null,"payout_statuses_enabled":null},"metadata":null,"routing_algorithm":null,"intent_fulfillment_time":900,"frm_routing_algorithm":null,"payout_routing_algorithm":null,"applepay_verified_domains":null,"session_expiry":900,"payment_link_config":null,"authentication_connector_details":null,"use_billing_as_payment_method_billing":true,"extended_card_info_config":null,"collect_shipping_details_from_wallet_connector":false,"collect_billing_details_from_wallet_connector":false,"always_collect_shipping_details_from_wallet_connector":false,"always_collect_billing_details_from_wallet_connector":false,"is_connector_agnostic_mit_enabled":false,"payout_link_config":null,"outgoing_webhook_custom_http_headers":null,"tax_connector_id":null,"is_tax_connector_enabled":false,"is_network_tokenization_enabled":false,"is_auto_retries_enabled":false,"max_auto_retries_enabled":null,"always_request_extended_authorization":null,"is_click_to_pay_enabled":false,"authentication_product_ids":null,"card_testing_guard_config":{"card_ip_blocking_status":"disabled","card_ip_blocking_threshold":3,"guest_user_card_blocking_status":"disabled","guest_user_card_blocking_threshold":10,"customer_id_blocking_status":"disabled","customer_id_blocking_threshold":5,"card_testing_guard_expiry":3600},"is_clear_pan_retries_enabled":false,"force_3ds_challenge":false,"is_debit_routing_enabled":false,"merchant_business_country":null,"is_pre_network_tokenization_enabled":false,"acquirer_configs":null,"is_iframe_redirection_enabled":null,"merchant_category_code":null,"merchant_country_code":null,"dispute_polling_interval":null,"is_manual_retry_enabled":null,"always_enable_overcapture":null,"is_external_vault_enabled":"skip","external_vault_connector_details":null,"billing_processor_id":"mca_NLnCEvS2DfuHWHFVa09o"}
  1. Create Customer
    Request
curl --location 'http://localhost:8080/customers' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_0RJW0cwZDeGfSkod0eJWOkfZHK0PCoZtDYJJ1FxeHqhHky1VNPU6nkgFQiTFSDvA' \
--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"
    }
}'

Response

{
    "customer_id": "cus_OYy3hzTTt04Enegu3Go3",
    "name": "John Doe",
    "email": "guest@example.com",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "address": null,
    "created_at": "2025-09-29T14:45:14.430Z",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "default_payment_method_id": null,
    "tax_registration_id": null
}
  1. Subscription create and confirm
    Request
curl --location 'http://localhost:8080/subscriptions' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_MiKOgwbj84jJ095MoWdj' \
--header 'api-key: dev_I62cGvBVijteiN61aMcAOeYvXpO8s36gT8BFvPznYYDXF4GFtVtjzgiel9oIpvUK' \
--data '{
    "item_price_id": "cbdemo_enterprise-suite-monthly",
    "customer_id": "cus_efEv4nqfrYEo8wSKZ10C",
    "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_CkPzNaFAyxzX2WwdKFCr",
    "merchant_reference_id": "mer_ref_1759334529",
    "status": "active",
    "plan_id": null,
    "price_id": null,
    "coupon": null,
    "profile_id": "pro_MiKOgwbj84jJ095MoWdj",
    "payment": {
        "payment_id": "sub_pay_KXEtoTxvu0EsadB5wxNn",
        "status": "succeeded",
        "amount": 14100,
        "currency": "INR",
        "connector": "stripe",
        "payment_method_id": "pm_bDPHgNaP7UZGjtZ7QPrS",
        "payment_experience": null,
        "error_code": null,
        "error_message": null
    },
    "customer_id": "cus_uBtUJLSVSICr8ctmoL8i",
    "invoice": {
        "id": "invoice_Ht72m0Enqy4YOGRKAtbZ",
        "subscription_id": "sub_CkPzNaFAyxzX2WwdKFCr",
        "merchant_id": "merchant_1759157014",
        "profile_id": "pro_MiKOgwbj84jJ095MoWdj",
        "merchant_connector_id": "mca_oMyzcBFcpfISftwDDVuG",
        "payment_intent_id": "sub_pay_KXEtoTxvu0EsadB5wxNn",
        "payment_method_id": null,
        "customer_id": "cus_uBtUJLSVSICr8ctmoL8i",
        "amount": 14100,
        "currency": "INR",
        "status": "payment_pending"
    },
    "billing_processor_subscription_id": "sub_CkPzNaFAyxzX2WwdKFCr"
}

incoming webhook for chargebee

curl --location 'http://localhost:8080/webhooks/merchant_1758710612/mca_YH3XxYGMv6IbKD0icBie' \
--header 'api-key: dev_5LNrrMNqyyFle8hvMssLob9pFq6OIEh0Vl3DqZttFXiDe7wrrScUePEYrIiYfSKT' \
--header 'Content-Type: application/json' \
--header 'authorization: Basic aHlwZXJzd2l0Y2g6aHlwZXJzd2l0Y2g=' \
--data-raw '{
    "api_version": "v2",
    "content": {
        "invoice": {
            "adjustment_credit_notes": [],
            "amount_adjusted": 0,
            "amount_due": 14100,
            "amount_paid": 0,
            "amount_to_collect": 14100,
            "applied_credits": [],
            "base_currency_code": "INR",
            "channel": "web",
            "credits_applied": 0,
            "currency_code": "INR",
            "customer_id": "gaurav_test",
            "date": 1758711043,
            "deleted": false,
            "due_date": 1758711043,
            "dunning_attempts": [],
            "exchange_rate": 1.0,
            "first_invoice": false,
            "generated_at": 1758711043,
            "has_advance_charges": false,
            "id": "3",
            "is_gifted": false,
            "issued_credit_notes": [],
            "line_items": [
                {
                    "amount": 14100,
                    "customer_id": "gaurav_test",
                    "date_from": 1758711043,
                    "date_to": 1761303043,
                    "description": "Enterprise Suite Monthly",
                    "discount_amount": 0,
                    "entity_id": "cbdemo_enterprise-suite-monthly",
                    "entity_type": "plan_item_price",
                    "id": "li_169vD0Uxi8JBp46g",
                    "is_taxed": false,
                    "item_level_discount_amount": 0,
                    "object": "line_item",
                    "pricing_model": "flat_fee",
                    "quantity": 1,
                    "subscription_id": "169vD0Uxi8JB746e",
                    "tax_amount": 0,
                    "tax_exempt_reason": "tax_not_configured",
                    "unit_amount": 14100
                }
            ],
            "linked_orders": [],
            "linked_payments": [],
            "net_term_days": 0,
            "new_sales_amount": 14100,
            "object": "invoice",
            "price_type": "tax_exclusive",
            "recurring": true,
            "reference_transactions": [],
            "resource_version": 1758711043846,
            "round_off_amount": 0,
            "site_details_at_creation": {
                "timezone": "Asia/Calcutta"
            },
            "status": "payment_due",
            "sub_total": 14100,
            "subscription_id": "169vD0Uxi8JB746e",
            "tax": 0,
            "term_finalized": true,
            "total": 14100,
            "updated_at": 1758711043,
            "write_off_amount": 0
        }
    },
    "event_type": "invoice_generated",
    "id": "ev_169vD0Uxi8JDf46i",
    "object": "event",
    "occurred_at": 1758711043,
    "source": "admin_console",
    "user": "ankit.gupta.001@juspay.in",
    "webhook_status": "scheduled",
    "webhooks": [
        {
            "id": "whv2_169mYOUxi3nvkZ8v",
            "object": "webhook",
            "webhook_status": "scheduled"
        }
    ]
}'

response

200 ok

How did you test it?

invoice sync finished
image
Record back successful
image
invoice table entry
image

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 4, 2025 20:28
@semanticdiff-com
Copy link

semanticdiff-com bot commented Oct 4, 2025

@Javierm748
Copy link

I agree with these changes! Very insightful.

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Oct 7, 2025
Merged via the queue into main with commit f2c2bd6 Oct 7, 2025
21 of 25 checks passed
@Gnanasundari24 Gnanasundari24 deleted the add-record-back-to-mit branch October 7, 2025 13:03
UdayPandey01 pushed a commit to UdayPandey01/hyperswitch that referenced this pull request Oct 8, 2025
…ler (juspay#9668)

Co-authored-by: Jagan <jaganelavarasan@gmail.com>
aadityaguptaa pushed a commit that referenced this pull request Nov 10, 2025
…ler (#9668)

Co-authored-by: Jagan <jaganelavarasan@gmail.com>
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.

[feature] add mit payment s2s call and invoice sync job to subscription webhook

5 participants