Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove client_secret from payment_intent and update related code #7648

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

GauravRawat369
Copy link
Contributor

@GauravRawat369 GauravRawat369 commented Mar 26, 2025

Your PR Description## Type of Change

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

Description

This commit changes how the client secret is generated in Payment Intent

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?

For /v2/payments/create-intent

Request

curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_REbCm9NzneE8vUBmgWWZ' \
--header 'Authorization: ••••••' \
--data-raw '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method":"manual",
    "authentication_type": "no_three_ds",
    "billing": {
        "address": {
            "first_name": "John",
            "last_name": "Dough"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "first_name": "John",
            "last_name": "Dough",
            "city": "Karwar",
            "zip": "581301",
            "state": "Karnataka"
        },
        "email": "[email protected]"
    }
}'

Response

{
    "id": "12345_pay_0195d5b7ff767ac094321057ddd9f2eb",
    "status": "requires_payment_method",
    "amount_details": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null
    },
    "client_secret": "cs_0195d5b7ffaf700397ea3e418d0835f6",
    "profile_id": "pro_EhW92OOmycGn3j0clrbm",
    "merchant_reference_id": null,
    "routing_algorithm_id": null,
    "capture_method": "manual",
    "authentication_type": "no_three_ds",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "shipping": {
        "address": {
            "city": "Karwar",
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": "581301",
            "state": "Karnataka",
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "customer_id": null,
    "customer_present": "present",
    "description": null,
    "return_url": null,
    "setup_future_usage": "on_session",
    "apply_mit_exemption": "Skip",
    "statement_descriptor": null,
    "order_details": null,
    "allowed_payment_method_types": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "payment_link_enabled": "Skip",
    "payment_link_config": null,
    "request_incremental_authorization": "default",
    "expires_on": "2025-03-27T04:04:20.409Z",
    "frm_metadata": null,
    "request_external_three_ds_authentication": "Skip"
}

For /v2/payments/:id/payment-methods

Request

curl --location 'http://localhost:8080/v2/payments/12345_pay_0195d65b6a2c7931ad28b04dba1be6c9/payment-methods' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_XTzqP0yNw5ndliWtB9MJ' \
--header 'Authorization: publishable-key=pk_dev_266ddc923fa940c8a97240b9e690756e,client-secret=cs_0195d65b6a7b7072acf186a4529ae9ad '

Response

{
    "payment_methods_enabled": [
        {
            "payment_method_type": "card_redirect",
            "payment_method_subtype": "card_redirect",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "card",
            "payment_method_subtype": "credit",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "card",
            "payment_method_subtype": "debit",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "google_pay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "apple_pay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "we_chat_pay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "ali_pay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "paypal",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "mb_way",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "klarna",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "affirm",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "afterpay_clearpay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "walley",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "giropay",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "ideal",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "eps",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "bancontact_card",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "przelewy24",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "sofort",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "blik",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "trustly",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "online_banking_finland",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "online_banking_poland",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "ach",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "sepa",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "bacs",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "ach",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "sepa",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "bacs",
            "required_fields": null,
            "surcharge_details": null
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "becs",
            "required_fields": null,
            "surcharge_details": null
        }
    ],
    "customer_payment_methods": null
}

For /v2/payments/:id/confirm-intent
Request

curl --location 'http://localhost:8080/v2/payments/12345_pay_0195d65b6a2c7931ad28b04dba1be6c9/confirm-intent' \
--header 'x-profile-id: pro_XTzqP0yNw5ndliWtB9MJ' \
--header 'Authorization: publishable-key=pk_dev_266ddc923fa940c8a97240b9e690756e,client-secret=cs_0195d65b6a7b7072acf186a4529ae9ad ' \
--header 'Content-Type: application/json' \
--data '{
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "01",
            "card_exp_year": "26",
            "card_holder_name": "John Doe",
            "card_cvc": "100"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit"
}

Response

{
    "id": "12345_pay_0195d65b6a2c7931ad28b04dba1be6c9",
    "status": "failed",
    "amount": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": null
    },
    "customer_id": null,
    "connector": "stripe",
    "client_secret": null,
    "created": "2025-03-27T06:47:50.083Z",
    "payment_method_data": {
        "billing": null
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "connector_transaction_id": null,
    "connector_reference_id": null,
    "merchant_connector_id": "mca_qB5no08zJFDBYPZBZdFR",
    "browser_info": null,
    "error": {
        "code": "No error code",
        "message": "No error message",
        "unified_code": null,
        "unified_message": null
    },
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": null,
    "payment_method_id": null,
    "next_action": null,
    "return_url": "https://google.com/success",
    "authentication_type": "no_three_ds",
    "authentication_type_applied": "no_three_ds"
}

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 March 26, 2025 14:11
Copy link

semanticdiff-com bot commented Mar 26, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/services/authentication.rs  50% smaller
  crates/diesel_models/src/schema_v2.rs  15% smaller
  Cargo.lock Unsupported file format
  api-reference-v2/openapi_spec.json  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/diesel_models/src/payment_intent.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  0% smaller
  crates/router/src/core/payments.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/operations/payment_complete_authorize.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_get_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_post_session_tokens.rs  0% smaller
  crates/router/src/core/payments/operations/payment_session.rs  0% smaller
  crates/router/src/core/payments/operations/payment_session_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_start.rs  0% smaller
  crates/router/src/core/payments/operations/payment_status.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update_intent.rs  0% smaller
  crates/router/src/core/payments/operations/tax_calculation.rs  0% smaller
  crates/router/src/core/payments/payment_methods.rs  0% smaller
  crates/router/src/core/payments/transformers.rs  0% smaller
  crates/router/src/types/transformers.rs  0% smaller
  v2_migrations/2025-03-25-090538_remove_client_secret_from_payment_intents/down.sql Unsupported file format
  v2_migrations/2025-03-25-090538_remove_client_secret_from_payment_intents/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Mar 26, 2025
@juspay juspay deleted a comment from mytag77 Mar 26, 2025
@GauravRawat369
Copy link
Contributor Author

response should only have secret , right?
Right now it's ClientSecretType

@GauravRawat369 GauravRawat369 self-assigned this Mar 27, 2025
@GauravRawat369 GauravRawat369 requested a review from a team as a code owner March 28, 2025 07:53
@GauravRawat369 GauravRawat369 changed the title feat: remove client_secret from payment_intents and update related code feat: remove client_secret from payment_intent and update related code Mar 28, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 28, 2025
@GauravRawat369 GauravRawat369 requested a review from AnuthaDev April 1, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-v2 M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
2 participants