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(core): payments overcapture support for V1 #6824

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

Conversation

AkshayaFoiger
Copy link
Contributor

@AkshayaFoiger AkshayaFoiger commented Dec 12, 2024

Note: Implementation of this feature is supported only via manual capture
-> Cypress test not added because it cannot be tested, via stripe. As this functionality has to be enabled by stripe.
-> Integrated only for stripe card flow

Type of Change

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

Description

Overcapture allows you to capture with an amount that’s higher than the authorised amount for a card payment. Unlike incremental authorisations, overcapture doesn’t result in additional authorisations with the card networks.

Additional Changes

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

API contract changes:

a) /payments create request to include request_overcapture boolean

b) /payments response to include

overcapture_status (applicable/ not_applicable)
amount_capturable will be updated

c) Profile create request and response to include always_request_overcapture (boolean)

d) Profile update request and response to include always_request_overcapture (boolean)

DB changes:

a) request_overcapture enum(Enable/Skip) field to be introduced in payment_intent

b)ovecapture_status enum(Applicable/NotApplicable) to be introduced in payment_attempt

d) always_request_overcapture boolean field to be introduced in business_profiles table

Not Handled (These changes will be taken as a phase 2 change )

a) Error is not thrown, when overcapture is not supported by the connector/capture_type

b) List of supported connector and payment method not maintained.

c) Extend this feature for multiple manual capture

How did you test it?

  1. Create/ Update a business_profile with "always_request_overcapture": true
curl --location 'http://localhost:8080/account/postman_merchant_GHAction_358cf835-2879-4d90-8475-ef0e1a246611/business_profile/pro_bzfd1zHHxs30uUyc2TQg' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
  "profile_name": "US_default",
  "always_request_overcapture": true
}'

Response

{
    "merchant_id": "postman_merchant_GHAction_358cf835-2879-4d90-8475-ef0e1a246611",
    "profile_id": "pro_bzfd1zHHxs30uUyc2TQg",
    "profile_name": "US_default",
    "return_url": "https://duck.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "83d4dikvQDLVgKR2jQDWYODswS1Tw6R2IP40rBatKGBEJwX6LhNeuNQbLzQIrX7T",
    "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
    },
    "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,
    "is_click_to_pay_enabled": false,
    "authentication_product_ids": null,
    "always_request_overcapture": true
}

DB - business_profile will have a field called always_request_overcapture , marked as true
Screenshot 2024-12-23 at 3 07 37 PM

  1. Do a payment via stripe, without sending request_overcapture in the payment request
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_oqtfJBx4JGn0Pmr3ZLtDMyUEzRZQ0IBeqnvImk4W1lbRHnh07rqLSXNTv8JKYk9L' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "manual",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "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"
        }
    },
    "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": "9123456789",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "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": "9123456789",
            "country_code": "+91"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "routing": {
        "type": "single",
        "data": {
            "connector": "stripe",
            "merchant_connector_id": "mca_5SMXtr84AcZ8zhBefG8d"
        }
    }
    
}'

Cannot be tested because, this feature needs to be enabled at stripe
Response

{
    "payment_id": "pay_AmT397cniDgIldfJbugG",
    "merchant_id": "postman_merchant_GHAction_77b1a97f-001b-458d-b185-67998995c880",
    "status": "failed",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 6540,
    "amount_received": null,
    "connector": "stripe",
    "client_secret": "pay_AmT397cniDgIldfJbugG_secret_KTnMJZjgrKg9ABMSZ4hP",
    "created": "2024-12-23T09:51:43.572Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "9123456789",
            "country_code": "+91"
        },
        "email": null
    },
    "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"
        },
        "phone": {
            "number": "9123456789",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": "payment_intent_invalid_parameter",
    "error_message": "This account is not eligible for the requested card features. See https://stripe.com/docs/payments/flexible-payments for more details.",
    "unified_code": "UE_9000",
    "unified_message": "Something went wrong",
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "StripeCustomer",
        "created_at": 1734947503,
        "expires": 1734951103,
        "secret": "epk_2fc47b302b284925926a5e8ad5e658c5"
    },
    "manual_retry_allowed": true,
    "connector_transaction_id": "pi_3QZ8IdIVaesDjvMP001jsdN2",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_ZzurAEZrSqx46L8gNMk5",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_5SMXtr84AcZ8zhBefG8d",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-23T10:06:43.572Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-23T09:51:44.486Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null,
    "overcapture_applied": null,               // Because connector sends an error msg
    "maximum_capturable_amount": null. // Because connector sends an error msg
}
  1. Create a update the business account "always_request_overcapture": false
curl --location 'http://localhost:8080/account/postman_merchant_GHAction_77b1a97f-001b-458d-b185-67998995c880/business_profile/pro_ZzurAEZrSqx46L8gNMk5' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
  "profile_name": "US_default",
  "always_request_overcapture": false
}'

Response

{
    "merchant_id": "postman_merchant_GHAction_77b1a97f-001b-458d-b185-67998995c880",
    "profile_id": "pro_ZzurAEZrSqx46L8gNMk5",
    "profile_name": "US_default",
    "return_url": "https://duck.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "iJLfkEZljBCu2mNKSoAp2fOOh84X4WJPBAtkAJE4s4Tqjne78DrKkJUjWcv01PEG",
    "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
    },
    "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,
    "is_click_to_pay_enabled": false,
    "authentication_product_ids": null,
    "always_request_overcapture": false
}
  1. Create an overcapture payment with stripe
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_oqtfJBx4JGn0Pmr3ZLtDMyUEzRZQ0IBeqnvImk4W1lbRHnh07rqLSXNTv8JKYk9L' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "manual",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "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"
        }
    },
    "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": "9123456789",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "shipping": {
        "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": "9123456789",
            "country_code": "+91"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "routing": {
        "type": "single",
        "data": {
            "connector": "stripe",
            "merchant_connector_id": "mca_5SMXtr84AcZ8zhBefG8d"
        }
    }
    ,"request_overcapture": false
}'

Response

{
    "payment_id": "pay_FKzjYUzqpSigIfzoXolG",
    "merchant_id": "postman_merchant_GHAction_77b1a97f-001b-458d-b185-67998995c880",
    "status": "requires_capture",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 6540,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_FKzjYUzqpSigIfzoXolG_secret_sB7pumP3GJcc4ZnSvCxX",
    "created": "2024-12-23T09:57:04.620Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "9123456789",
            "country_code": "+91"
        },
        "email": null
    },
    "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"
        },
        "phone": {
            "number": "9123456789",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "StripeCustomer",
        "created_at": 1734947824,
        "expires": 1734951424,
        "secret": "epk_54c122be30324503a3199e33d42fff0f"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QZ8NpIVaesDjvMP1f6ANdO7",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QZ8NpIVaesDjvMP1f6ANdO7",
    "payment_link": null,
    "profile_id": "pro_ZzurAEZrSqx46L8gNMk5",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_5SMXtr84AcZ8zhBefG8d",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-23T10:12:04.620Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-23T09:57:06.130Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null,
    "overcapture_applied": false,
    "maximum_capturable_amount": 6540
}

Screenshot 2024-12-24 at 3 05 48 PM

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

@AkshayaFoiger AkshayaFoiger requested review from a team as code owners December 12, 2024 07:09
Copy link

semanticdiff-com bot commented Dec 12, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/connector/utils.rs  56% smaller
  crates/diesel_models/src/user/sample_data.rs  30% smaller
  crates/router/src/types.rs  25% smaller
  crates/router/src/connector/stripe/transformers.rs  11% smaller
  crates/openapi/src/openapi_v2.rs  11% smaller
  crates/openapi/src/openapi.rs  10% smaller
  crates/router/src/core/payments/helpers.rs  8% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/admin.rs  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/common_enums/Cargo.toml Unsupported file format
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_enums/src/transformers.rs  0% smaller
  crates/diesel_models/Cargo.toml Unsupported file format
  crates/diesel_models/src/business_profile.rs  0% smaller
  crates/diesel_models/src/payment_attempt.rs  0% smaller
  crates/diesel_models/src/payment_intent.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/business_profile.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_data.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  0% smaller
  crates/router/src/core/admin.rs  0% smaller
  crates/router/src/core/payments/operations/payment_capture.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/core/payments/operations/payment_response.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/core/payments/retry.rs  0% smaller
  crates/router/src/core/payments/transformers.rs  0% smaller
  crates/router/src/core/utils.rs  0% smaller
  crates/router/src/types/api/admin.rs  0% smaller
  crates/router/src/types/api/verify_connector.rs  0% smaller
  crates/router/src/types/storage/payment_attempt.rs  0% smaller
  crates/router/src/utils/user/sample_data.rs  0% smaller
  crates/router/tests/connectors/utils.rs  0% smaller
  crates/router/tests/payments.rs  0% smaller
  crates/router/tests/payments2.rs  0% smaller
  crates/storage_impl/src/mock_db/payment_attempt.rs  0% smaller
  crates/storage_impl/src/payments/payment_attempt.rs  0% smaller
  migrations/2024-12-24-072648_add_always_request_overcapture/down.sql Unsupported file format
  migrations/2024-12-24-072648_add_always_request_overcapture/up.sql Unsupported file format
  migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql Unsupported file format
  migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql Unsupported file format
  migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/down.sql Unsupported file format
  migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql Unsupported file format

@AkshayaFoiger AkshayaFoiger marked this pull request as draft December 12, 2024 07:10
@hyperswitch-bot hyperswitch-bot bot added M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Dec 12, 2024
@AkshayaFoiger AkshayaFoiger added the C-feature Category: Feature request or enhancement label Dec 12, 2024
@AkshayaFoiger AkshayaFoiger self-assigned this Dec 12, 2024
@AkshayaFoiger AkshayaFoiger changed the title feat(core): Core changes for support overcapture feat(core): Core changes to support overcapture Dec 16, 2024
@AkshayaFoiger AkshayaFoiger marked this pull request as ready for review December 17, 2024 06:47
@AkshayaFoiger AkshayaFoiger requested a review from a team as a code owner December 17, 2024 06:47
@AkshayaFoiger AkshayaFoiger marked this pull request as draft December 19, 2024 11:06
@AkshayaFoiger AkshayaFoiger marked this pull request as ready for review December 20, 2024 05:47
crates/api_models/src/admin.rs Outdated Show resolved Hide resolved
crates/router/src/connector/utils.rs Outdated Show resolved Hide resolved
Comment on lines 409 to 412
payment_attempt.request_overcapture = request
.request_overcapture
.or(payment_attempt.request_overcapture);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot consider request_overcapture from request body in confirm flow, since it is a client call. request_overcapture must only be taken from either payment create or update request.

Copy link
Contributor Author

@AkshayaFoiger AkshayaFoiger Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did corresponding changes but during confirm call, if the capture method is changed
manual to other_capture_methods -> an error is thown
other_capture_methods to manual -> request_overcapture gets updated, according to profile config

Comment on lines 2609 to +2612
pub(crate) fn validate_amount_to_capture(
amount: i64,
amount_to_capture: Option<i64>,
is_overcapture_applied: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount_to_capture must be validated against amount_capturable if it is some. If it is None, then we will validate with net amount.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As amount_capturable is not a nullable value, we are not validating the amount with net_amount

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But amount_to_capture must not be greater than amount_capturable right?

crates/router/src/services/api.rs Outdated Show resolved Hide resolved
crates/router/src/types.rs Outdated Show resolved Hide resolved
crates/router/src/types.rs Outdated Show resolved Hide resolved
@@ -1289,6 +1309,7 @@ impl PaymentCreate {
organization_id: organization_id.clone(),
profile_id,
connector_mandate_detail: None,
request_overcapture,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets update this only in update_trackers of confirm flow.

@@ -819,6 +830,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
surcharge_amount,
tax_amount,
),
request_overcapture,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request_overcapture in attempt must only be updated before calling connector in confirm flow.

@@ -4286,6 +4293,7 @@ impl AttemptType {
organization_id: old_payment_attempt.organization_id,
profile_id: old_payment_attempt.profile_id,
connector_mandate_detail: None,
request_overcapture: old_payment_attempt.request_overcapture,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be None. In smart retries, connector will change. we need to figure out if the new connector supports overcapture and then update in attempt.

Comment on lines 2609 to +2612
pub(crate) fn validate_amount_to_capture(
amount: i64,
amount_to_capture: Option<i64>,
is_overcapture_applied: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But amount_to_capture must not be greater than amount_capturable right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants