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

fix(mandates): handle the connector_mandate creation once and only if the payment is charged #6358

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

Aprabhat19
Copy link
Contributor

@Aprabhat19 Aprabhat19 commented Oct 17, 2024

Type of Change

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

Description

Earlier we used to store the connector mandate id irrespective of the payments status being charged or not for 3DS flows, now we would handle the connector_mandate_id updation in payment_method once and only if the payment has a status as charged.
This PR is a hot fix for the PR

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?

  • Configure a MA and a MCA
  • Make a 3ds mandate failed payment, it would be populated in the payment_attempt, but not in the payment_method table
Create
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'api-key: dev_5SpseUd7WAhIwgQeMpoCKwEeaPjmduquAv3Qu4VxdRkSBkilsq5arTZa6nXoPokw' \
--data-raw '{
    "amount": 8500,
    "currency": "USD",
    "confirm": false,
    
    "customer_id": "CustomerX777",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
     "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    
"setup_future_usage":"off_session",
    "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": "8056594427",
            "country_code": "+91"
        }
    },
    


    "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": "8056594427",
            "country_code": "+91"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    }
    
   
}'
Confirm

curl --location 'http://localhost:8080/payments/pay_v7bENZR0bgPe0g6ThobF/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'api-key: pk_dev_07feea3d36ed4f8da3cd844b07b8e3e9' \
--data '{
    "confirm": true,
    
    "client_secret":"pay_v7bENZR0bgPe0g6ThobF_secret_d792ajlpJ4z6XlS9esjK",
    "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": "8056594427",
            "country_code": "+91"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36",
        "accept_header": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "125.0.0.1"
    },
  
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    
     
    "payment_method": "card",


     "payment_method_type": "debit",
    "payment_method_data": {
        "card": {

 
            
                 "card_number": "4000008400001629",
            "card_exp_month": "06",
            "card_exp_year": "2030",
            "card_holder_name": "John T",
            
            
            
            "card_cvc": "737"
        }
    }
}'
Response

{
    "payment_id": "pay_v7bENZR0bgPe0g6ThobF",
    "merchant_id": "merchant_1729155606",
    "status": "requires_customer_action",
    "amount": 8500,
    "net_amount": 8500,
    "amount_capturable": 8500,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_v7bENZR0bgPe0g6ThobF_secret_d792ajlpJ4z6XlS9esjK",
    "created": "2024-10-17T09:01:29.364Z",
    "currency": "USD",
    "customer_id": "CustomerX777",
    "customer": {
        "id": "CustomerX777",
        "name": "Joseph Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1629",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "400000",
            "card_extended_bin": null,
            "card_exp_month": "06",
            "card_exp_year": "2030",
            "card_holder_name": null,
            "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": "8056594427",
            "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": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "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_v7bENZR0bgPe0g6ThobF/merchant_1729155606/pay_v7bENZR0bgPe0g6ThobF_1"
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "debit",
    "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": "pi_3QApaRD5R7gDAGff0khxOUA8",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": {
        "apple_pay": null,
        "airwallex": null,
        "noon": {
            "order_category": "pay"
        }
    },
    "feature_metadata": null,
    "reference_id": "pi_3QApaRD5R7gDAGff0khxOUA8",
    "payment_link": null,
    "profile_id": "pro_OYE7Iv9nauJb3HXYFB1u",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_LKJi6vdC2IEQwbEaVJQP",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-10-17T09:16:29.364Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.0.0.1",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": "pm_PxUXcAinbE62hBE1mAg2",
    "payment_method_status": "inactive",
    "updated": "2024-10-17T09:01:39.749Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "pm_1QApaRD5R7gDAGffKM5cG6sU"
}
The payment_method_table won't have connectir_mandate_details
Screenshot 2024-10-17 at 2 48 01 PM
  • Make a 3ds payment successful, then only it will be populated in the payment_method
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'api-key: dev_5SpseUd7WAhIwgQeMpoCKwEeaPjmduquAv3Qu4VxdRkSBkilsq5arTZa6nXoPokw' \
--data-raw '{
    "amount": 8500,
    "currency": "USD",
    "confirm": false,
    
    "customer_id": "CustomerX777",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
     "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",   
"setup_future_usage":"off_session",
    "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": "8056594427",
            "country_code": "+91"
        }
    },

    "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": "8056594427",
            "country_code": "+91"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    }
    
   
}'
Confirm

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'api-key: dev_5SpseUd7WAhIwgQeMpoCKwEeaPjmduquAv3Qu4VxdRkSBkilsq5arTZa6nXoPokw' \
--data-raw '{
    "amount": 8500,
    "currency": "USD",
    "confirm": false,
    
    "customer_id": "CustomerX777",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
     "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
"setup_future_usage":"off_session",
    "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": "8056594427",
            "country_code": "+91"
        }
    },
    
    "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": "8056594427",
            "country_code": "+91"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    }
    
   
}'
response
{
    "payment_id": "pay_m59xmko152RMgzTqgUeP",
    "merchant_id": "merchant_1729155606",
    "status": "succeeded",
    "amount": 8500,
    "net_amount": 8500,
    "amount_capturable": 0,
    "amount_received": 8500,
    "connector": "stripe",
    "client_secret": "pay_m59xmko152RMgzTqgUeP_secret_m8J1xt82aJYVaK4o4vNs",
    "created": "2024-10-17T09:18:18.049Z",
    "currency": "USD",
    "customer_id": "CustomerX777",
    "customer": {
        "id": "CustomerX777",
        "name": "Joseph Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "06",
            "card_exp_year": "2030",
            "card_holder_name": null,
            "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": "8056594427",
            "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": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "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": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QApqiD5R7gDAGff1ykvxYD0",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": {
        "apple_pay": null,
        "airwallex": null,
        "noon": {
            "order_category": "pay"
        }
    },
    "feature_metadata": null,
    "reference_id": "pi_3QApqiD5R7gDAGff1ykvxYD0",
    "payment_link": null,
    "profile_id": "pro_OYE7Iv9nauJb3HXYFB1u",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_LKJi6vdC2IEQwbEaVJQP",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-10-17T09:33:18.049Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.0.0.1",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": "pm_9ahIWQWjvWNTYCi1myPc",
    "payment_method_status": "active",
    "updated": "2024-10-17T09:18:35.865Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

The payment_method would have a connector_mandate_id with it

Screenshot 2024-10-17 at 2 54 03 PM
  • If another CIT mandate payment is made it wouldn't be populated anymore

  • Make a complete authorise mandate payment , it should be saved in the payment_method, for that mca_id

  • Make a external 3ds mandate payment , it should be saved in the payment_method, for that mca_id

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

@Aprabhat19 Aprabhat19 requested review from a team as code owners October 17, 2024 17:19
Copy link

semanticdiff-com bot commented Oct 17, 2024

Review changes with SemanticDiff.

Analyzed 32 of 34 files.

Overall, the semantic diff is 21% smaller than the GitHub diff.

File Information
Filename Status
migrations/2024-10-13-182546_add_connector_mandate_id_in_payment_attempt/down.sql Unsupported file format
migrations/2024-10-13-182546_add_connector_mandate_id_in_payment_attempt/up.sql Unsupported file format
✔️ crates/storage_impl/src/lookup.rs Analyzed
✔️ crates/storage_impl/src/redis/kv_store.rs 97.18% smaller
✔️ crates/storage_impl/src/payouts/payout_attempt.rs Analyzed
✔️ crates/storage_impl/src/payouts/payouts.rs 0.0% smaller
✔️ crates/storage_impl/src/payments/payment_attempt.rs 63.87% smaller
✔️ crates/storage_impl/src/payments/payment_intent.rs 0.0% smaller
✔️ crates/storage_impl/src/mock_db/payment_attempt.rs Analyzed
✔️ crates/router/src/utils/user/sample_data.rs Analyzed
✔️ crates/router/src/types/storage/payment_attempt.rs Analyzed
✔️ crates/router/src/types/storage/payment_method.rs Analyzed
✔️ crates/router/src/db/address.rs Analyzed
✔️ crates/router/src/db/customers.rs Analyzed
✔️ crates/router/src/db/mandate.rs Analyzed
✔️ crates/router/src/db/payment_method.rs 0.0% smaller
✔️ crates/router/src/db/refund.rs Analyzed
✔️ crates/router/src/db/reverse_lookup.rs Analyzed
✔️ crates/router/src/core/webhooks/incoming.rs Analyzed
✔️ crates/router/src/core/payments/helpers.rs Analyzed
✔️ crates/router/src/core/payments/retry.rs Analyzed
✔️ crates/router/src/core/payments/tokenization.rs 13.66% smaller
✔️ crates/router/src/core/payments/transformers.rs 15.92% smaller
✔️ crates/router/src/core/payments/operations/payment_complete_authorize.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_confirm.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_create.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_response.rs 21.25% smaller
✔️ crates/router/src/core/payments/operations/payment_update.rs Analyzed
✔️ crates/hyperswitch_domain_models/src/payments/payment_attempt.rs 18.65% smaller
✔️ crates/diesel_models/src/payment_attempt.rs 6.31% smaller
✔️ crates/diesel_models/src/schema.rs Analyzed
✔️ crates/diesel_models/src/schema_v2.rs Analyzed
✔️ crates/diesel_models/src/user/sample_data.rs 0.76% smaller
✔️ crates/common_enums/src/enums.rs Analyzed

@Aprabhat19 Aprabhat19 self-assigned this Oct 17, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Oct 17, 2024
@Aprabhat19 Aprabhat19 added C-bug Category: Bug M-database-changes Metadata: This PR involves database schema changes labels Oct 17, 2024
@Aprabhat19 Aprabhat19 changed the base branch from main to hotfix-2024.10.04.0-prod October 17, 2024 17:19
apoorvdixit88
apoorvdixit88 previously approved these changes Oct 17, 2024
@Sarthak1799
Copy link
Contributor

Checks are failing @Aprabhat19

@SanchithHegde SanchithHegde merged commit 66e8620 into hotfix-2024.10.04.0-prod Oct 17, 2024
17 of 18 checks passed
@SanchithHegde SanchithHegde deleted the fix-mandate branch October 17, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Bug M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix(mandates): handle the connector_mandate creation once and only if the payment is charged
5 participants