fix(connector): [Cryptopay] fix amount_captured population logic in response handling #9674
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
amount_capturedin router_data when payment status isCharged.PaymentsSyncData::get_captured_amountmethod was ignoring theamount_capturedparameter and only consulting stored payment data and getting total_amount. To fix this added.or(amount_captured.map(MinorUnit::new))to the chain inPaymentsSyncData::get_captured_amount, ensuring the method prioritizes amount_captured from router_data similar to PaymentsAuthorizeData before consulting payment_data for total_amount.Additional Changes
Motivation and Context
amount_capturedwas being set from theprice_amountfield for all payment statuses, including incomplete payments likerequires_customer_actioncaptured_amount > total_capturable_amountandis_overcapture_enabledwas falseHow did you test it?
Create Payment
{ "amount": 15, "currency": "USD", "confirm": true, "email": "[email protected]", "return_url": "https://google.com", "payment_method": "crypto", "payment_method_type": "crypto_currency", "payment_experience": "redirect_to_url", "capture_method": "automatic", "payment_method_data": { "crypto": { "pay_currency": "LTC" } } }Response
{ "payment_id": "pay_nmtnfFNgKIwgtmwwwfeZ", "merchant_id": "merchant_1759732916", "status": "requires_customer_action", "amount": 15, "net_amount": 15, "shipping_cost": null, "amount_capturable": 15, "amount_received": null, "connector": "cryptopay", "client_secret": "pay_nmtnfFNgKIwgtmwwwfeZ_secret_6Ga6ekLlDTUcJVKLE9xd", "created": "2025-10-06T06:46:16.209Z", "currency": "USD", "customer_id": null, "customer": { "id": null, "name": null, "email": "[email protected]", "phone": null, "phone_country_code": null }, "description": null, "refunds": null, "disputes": null, "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": "automatic", "payment_method": "crypto", "payment_method_data": { "crypto": { "pay_currency": "LTC", "network": null }, "billing": null }, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "https://google.com/", "authentication_type": "no_three_ds", "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": { "type": "redirect_to_url", "redirect_to_url": "http://localhost:8080/payments/redirect/pay_nmtnfFNgKIwgtmwwwfeZ/merchant_1759732916/pay_nmtnfFNgKIwgtmwwwfeZ_1" }, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": "782f2938-c41d-4be2-b93e-c22709654054", "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": { "redirect_response": null, "search_tags": null, "apple_pay_recurring_details": null, "gateway_system": "direct" }, "reference_id": "pay_nmtnfFNgKIwgtmwwwfeZ_1", "payment_link": null, "profile_id": "pro_idiFBCtfW7ACI2qZSLdk", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": "mca_LB9MXkHZW8HRFzhiyJvY", "incremental_authorization_allowed": false, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2025-10-06T07:01:16.209Z", "fingerprint": null, "browser_info": null, "payment_channel": null, "payment_method_id": null, "network_transaction_id": null, "payment_method_status": null, "updated": "2025-10-06T06:46:16.598Z", "split_payments": null, "frm_metadata": null, "extended_authorization_applied": null, "request_extended_authorization": null, "capture_before": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null, "card_discovery": null, "force_3ds_challenge": false, "force_3ds_challenge_trigger": false, "issuer_error_code": null, "issuer_error_message": null, "is_iframe_redirection_enabled": null, "whole_connector_response": null, "enable_partial_authorization": null, "enable_overcapture": null, "is_overcapture_enabled": null, "network_details": null, "is_stored_credential": null, "mit_category": null }Underpaid Payment Sync
Response
{ "payment_id": "pay_AQ3kBO4NEV65g4nzsI5H", "merchant_id": "merchant_1759732916", "status": "partially_captured", "amount": 15, "net_amount": 15, "shipping_cost": null, "amount_capturable": 0, "amount_received": 12, "connector": "cryptopay", "client_secret": "pay_AQ3kBO4NEV65g4nzsI5H_secret_ogakUxfaNRXMgwTm2Cx2", "created": "2025-10-06T10:31:46.564Z", "currency": "USD", "customer_id": null, "customer": { "id": null, "name": null, "email": "[email protected]", "phone": null, "phone_country_code": null }, "description": null, "refunds": null, "disputes": null, "attempts": [ { "attempt_id": "pay_AQ3kBO4NEV65g4nzsI5H_1", "status": "partial_charged", "amount": 15, "order_tax_amount": null, "currency": "USD", "connector": "cryptopay", "error_message": null, "payment_method": "crypto", "connector_transaction_id": "8157c59c-7ef1-4520-adc0-ff505d67c4c2", "capture_method": "automatic", "authentication_type": "no_three_ds", "created_at": "2025-10-06T10:31:46.567Z", "modified_at": "2025-10-06T10:41:51.594Z", "cancellation_reason": null, "mandate_id": null, "error_code": null, "payment_token": null, "connector_metadata": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "reference_id": "pay_AQ3kBO4NEV65g4nzsI5H_1", "unified_code": null, "unified_message": null, "client_source": null, "client_version": null } ], "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": "automatic", "payment_method": "crypto", "payment_method_data": { "crypto": { "pay_currency": "LTC", "network": null }, "billing": null }, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "https://google.com/", "authentication_type": "no_three_ds", "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": null, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": "8157c59c-7ef1-4520-adc0-ff505d67c4c2", "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": { "redirect_response": null, "search_tags": null, "apple_pay_recurring_details": null, "gateway_system": "direct" }, "reference_id": "pay_AQ3kBO4NEV65g4nzsI5H_1", "payment_link": null, "profile_id": "pro_idiFBCtfW7ACI2qZSLdk", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": "mca_LB9MXkHZW8HRFzhiyJvY", "incremental_authorization_allowed": false, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2025-10-06T10:46:46.564Z", "fingerprint": null, "browser_info": null, "payment_channel": null, "payment_method_id": null, "network_transaction_id": null, "payment_method_status": null, "updated": "2025-10-06T10:41:51.594Z", "split_payments": null, "frm_metadata": null, "extended_authorization_applied": null, "request_extended_authorization": null, "capture_before": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null, "card_discovery": null, "force_3ds_challenge": false, "force_3ds_challenge_trigger": false, "issuer_error_code": null, "issuer_error_message": null, "is_iframe_redirection_enabled": null, "whole_connector_response": null, "enable_partial_authorization": null, "enable_overcapture": null, "is_overcapture_enabled": null, "network_details": null, "is_stored_credential": null, "mit_category": null }Overpaid Payment sync
Response
{ "payment_id": "pay_GDtiguqwSEiybP9S2Pgc", "merchant_id": "merchant_1759732916", "status": "succeeded", "amount": 15, "net_amount": 15, "shipping_cost": null, "amount_capturable": 0, "amount_received": 17, "connector": "cryptopay", "client_secret": "pay_GDtiguqwSEiybP9S2Pgc_secret_yVeHrITuZPa434ZYDMN4", "created": "2025-10-06T06:42:08.937Z", "currency": "USD", "customer_id": null, "customer": { "id": null, "name": null, "email": "[email protected]", "phone": null, "phone_country_code": null }, "description": null, "refunds": null, "disputes": null, "attempts": [ { "attempt_id": "pay_GDtiguqwSEiybP9S2Pgc_1", "status": "charged", "amount": 15, "order_tax_amount": null, "currency": "USD", "connector": "cryptopay", "error_message": null, "payment_method": "crypto", "connector_transaction_id": "98c30587-0544-4c2f-949e-923965773a87", "capture_method": "automatic", "authentication_type": "no_three_ds", "created_at": "2025-10-06T06:42:08.940Z", "modified_at": "2025-10-06T06:45:42.581Z", "cancellation_reason": null, "mandate_id": null, "error_code": null, "payment_token": null, "connector_metadata": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "reference_id": "pay_GDtiguqwSEiybP9S2Pgc_1", "unified_code": null, "unified_message": null, "client_source": null, "client_version": null } ], "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": "automatic", "payment_method": "crypto", "payment_method_data": { "crypto": { "pay_currency": "LTC", "network": null }, "billing": null }, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "https://google.com/", "authentication_type": "no_three_ds", "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": null, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": "98c30587-0544-4c2f-949e-923965773a87", "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": { "redirect_response": null, "search_tags": null, "apple_pay_recurring_details": null, "gateway_system": "direct" }, "reference_id": "pay_GDtiguqwSEiybP9S2Pgc_1", "payment_link": null, "profile_id": "pro_idiFBCtfW7ACI2qZSLdk", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": "mca_LB9MXkHZW8HRFzhiyJvY", "incremental_authorization_allowed": false, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2025-10-06T06:57:08.936Z", "fingerprint": null, "browser_info": null, "payment_channel": null, "payment_method_id": null, "network_transaction_id": null, "payment_method_status": null, "updated": "2025-10-06T06:45:42.581Z", "split_payments": null, "frm_metadata": null, "extended_authorization_applied": null, "request_extended_authorization": null, "capture_before": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null, "card_discovery": null, "force_3ds_challenge": false, "force_3ds_challenge_trigger": false, "issuer_error_code": null, "issuer_error_message": null, "is_iframe_redirection_enabled": null, "whole_connector_response": null, "enable_partial_authorization": null, "enable_overcapture": null, "is_overcapture_enabled": null, "network_details": null, "is_stored_credential": null, "mit_category": null }Exact amount paid Payment Sync
Response
{ "payment_id": "pay_0yVxECTGSurN7u9hMe1j", "merchant_id": "merchant_1759732916", "status": "succeeded", "amount": 15, "net_amount": 15, "shipping_cost": null, "amount_capturable": 0, "amount_received": 15, "connector": "cryptopay", "client_secret": "pay_0yVxECTGSurN7u9hMe1j_secret_i3GfK1Km0iitrQx66IgF", "created": "2025-10-10T07:49:43.268Z", "currency": "USD", "customer_id": null, "customer": { "id": null, "name": null, "email": "[email protected]", "phone": null, "phone_country_code": null }, "description": null, "refunds": null, "disputes": null, "attempts": [ { "attempt_id": "pay_0yVxECTGSurN7u9hMe1j_1", "status": "charged", "amount": 15, "order_tax_amount": null, "currency": "USD", "connector": "cryptopay", "error_message": null, "payment_method": "crypto", "connector_transaction_id": "af24ef5c-f51c-43de-9c73-732ac3c4857d", "capture_method": "automatic", "authentication_type": "no_three_ds", "created_at": "2025-10-10T07:49:43.275Z", "modified_at": "2025-10-10T07:55:00.411Z", "cancellation_reason": null, "mandate_id": null, "error_code": null, "payment_token": null, "connector_metadata": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "reference_id": "pay_0yVxECTGSurN7u9hMe1j_1", "unified_code": null, "unified_message": null, "client_source": null, "client_version": null } ], "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": "automatic", "payment_method": "crypto", "payment_method_data": { "crypto": { "pay_currency": "LTC", "network": null }, "billing": null }, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "https://google.com/", "authentication_type": "no_three_ds", "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": null, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": "redirect_to_url", "payment_method_type": "crypto_currency", "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": "af24ef5c-f51c-43de-9c73-732ac3c4857d", "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": { "redirect_response": null, "search_tags": null, "apple_pay_recurring_details": null, "gateway_system": "direct" }, "reference_id": "pay_0yVxECTGSurN7u9hMe1j_1", "payment_link": null, "profile_id": "pro_idiFBCtfW7ACI2qZSLdk", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": "mca_LB9MXkHZW8HRFzhiyJvY", "incremental_authorization_allowed": false, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2025-10-10T08:04:43.267Z", "fingerprint": null, "browser_info": null, "payment_channel": null, "payment_method_id": null, "network_transaction_id": null, "payment_method_status": null, "updated": "2025-10-10T07:55:00.412Z", "split_payments": null, "frm_metadata": null, "extended_authorization_applied": null, "request_extended_authorization": null, "capture_before": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null, "card_discovery": null, "force_3ds_challenge": false, "force_3ds_challenge_trigger": false, "issuer_error_code": null, "issuer_error_message": null, "is_iframe_redirection_enabled": null, "whole_connector_response": null, "enable_partial_authorization": null, "enable_overcapture": null, "is_overcapture_enabled": null, "network_details": null, "is_stored_credential": null, "mit_category": null }Checklist
cargo +nightly fmt --allcargo clippy