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

Refactor(core): make save_payment_method as post_update_tracker trait function #4307

Merged
merged 60 commits into from
Apr 25, 2024

Conversation

prajjwalkumar17
Copy link
Contributor

@prajjwalkumar17 prajjwalkumar17 commented Apr 4, 2024

Type of Change

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

Description

This PR aims to make the locker call async(again). Moreover the main problem this PR solves is to adding pm_id in payment_attempt even in an async locker call. This is achieved by adding up a new function in PostUpdateTracker trait named as save_pm_and_mandate.

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?

Curls for the test cases:

  1. Save Card payment
curl --location 'http://127.0.0.1:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Lhj81dmb5DH3dasSlnRy2LUAHIOc6LJDFSQxyLbrAS7HWS5Hxva2YOJTYea90wXw' \
--data-raw '

{
    "amount": 150,
    "currency": "USD",
    "confirm": true,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "capture_method": "automatic",
    "customer_id": "cus_ssOCYK1qRIjeBfMhEy6A",
    "amount_to_capture": 150,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "5555 5555 5555 4444",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "phone_country_code": "+65",
    "authentication_type": "no_three_ds",
    "description": "Its my first payment request",
    "return_url": "https://google.com",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "metadata": {},
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "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": "sundari",
            "last_name": "sundari"
        }
    }
}'

Response

{
    "payment_id": "pay_htNp37U15sOwsXZPZ9Br",
    "merchant_id": "merchant_1712724367",
    "status": "succeeded",
    "amount": 150,
    "net_amount": 150,
    "amount_capturable": 0,
    "amount_received": 150,
    "connector": "cybersource",
    "client_secret": "pay_htNp37U15sOwsXZPZ9Br_secret_I56SQnEKoGQGyHhcIarl",
    "created": "2024-04-11T05:07:46.740Z",
    "currency": "USD",
    "customer_id": "cus_ssOCYK1qRIjeBfMhEy6A",
    "customer": {
        "id": "cus_ssOCYK1qRIjeBfMhEy6A",
        "name": "John 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": "4444",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "555555",
            "card_extended_bin": "55555555",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_QD71AcirSSN1hroINifk",
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "sundari",
            "last_name": "sundari"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cus_ssOCYK1qRIjeBfMhEy6A",
        "created_at": 1712812066,
        "expires": 1712815666,
        "secret": "epk_9ea82157d50e457c8f0d56c88f13b117"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7128120679866152903954",
    "frm_message": null,
    "metadata": {},
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_htNp37U15sOwsXZPZ9Br_1",
    "payment_link": null,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_JGHsMWurht6srLkWsjO3",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-11T05:22:46.740Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null
}

Payment Retrieve

{
    "payment_id": "pay_htNp37U15sOwsXZPZ9Br",
    "merchant_id": "merchant_1712724367",
    "status": "succeeded",
    "amount": 150,
    "net_amount": 150,
    "amount_capturable": 0,
    "amount_received": 150,
    "connector": "cybersource",
    "client_secret": "pay_htNp37U15sOwsXZPZ9Br_secret_I56SQnEKoGQGyHhcIarl",
    "created": "2024-04-11T05:07:46.740Z",
    "currency": "USD",
    "customer_id": "cus_ssOCYK1qRIjeBfMhEy6A",
    "customer": {
        "id": "cus_ssOCYK1qRIjeBfMhEy6A",
        "name": "John 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": "4444",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "555555",
            "card_extended_bin": "55555555",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_QD71AcirSSN1hroINifk",
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "sundari",
            "last_name": "sundari"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "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": "7128120679866152903954",
    "frm_message": null,
    "metadata": {},
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_htNp37U15sOwsXZPZ9Br_1",
    "payment_link": null,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_JGHsMWurht6srLkWsjO3",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-11T05:22:46.740Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": "pm_2ERfpXUJ7vYzqYSk3hdE",
    "payment_method_status": "active"
}
  1. Setup Mandate
curl --location 'http://127.0.0.1:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Lhj81dmb5DH3dasSlnRy2LUAHIOc6LJDFSQxyLbrAS7HWS5Hxva2YOJTYea90wXw' \
--data-raw '
{
    "amount": 0,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "mandate_customer1",
    "email": "[email protected]",
    "setup_future_usage": "off_session",
    "customer_acceptance": {
        "acceptance_type": "online"
    },
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "Test Holder",
            "card_cvc": "737"
        }
    },
    "payment_type": "setup_mandate",
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "authentication_type": "three_ds"
}'

Response

{
    "payment_id": "pay_okrJvtehbXTDXcDydQnv",
    "merchant_id": "merchant_1712724367",
    "status": "succeeded",
    "amount": 0,
    "net_amount": 0,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": "cybersource",
    "client_secret": "pay_okrJvtehbXTDXcDydQnv_secret_Y0quTVIFHHwNV1fTLT2T",
    "created": "2024-04-11T05:36:27.333Z",
    "currency": "USD",
    "customer_id": "mandate_customer1",
    "customer": {
        "id": "mandate_customer1",
        "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": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "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": "42424242",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "Test Holder",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_Xh7IwDTEFet4MJ3XCyYz",
    "shipping": null,
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": null,
    "phone": null,
    "return_url": null,
    "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": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "mandate_customer1",
        "created_at": 1712813787,
        "expires": 1712817387,
        "secret": "epk_b75613967b7e4965bad88d90704f985e"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7128137892656606404953",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_okrJvtehbXTDXcDydQnv_1",
    "payment_link": null,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_JGHsMWurht6srLkWsjO3",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-11T05:51:27.333Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": "pm_WmIHJOFLVZYHH1GMSztb",
    "payment_method_status": null
}
  1. Recurring mandate
curl --location 'http://127.0.0.1:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Lhj81dmb5DH3dasSlnRy2LUAHIOc6LJDFSQxyLbrAS7HWS5Hxva2YOJTYea90wXw' \
--data-raw '
{
    "amount": 499,
    "currency": "USD",
    "confirm": true,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "capture_method": "automatic",
    "customer_id": "mandate_customer1",
    "email": "[email protected]",
    "off_session": true,
    "recurring_details": {
        "type": "payment_method_id",
        "data": "pm_WmIHJOFLVZYHH1GMSztb"
    },
    "payment_method": "card",
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "authentication_type": "three_ds"
}'

Response:

{
    "payment_id": "pay_mg9hJf7VjCYa50hpSrdG",
    "merchant_id": "merchant_1712724367",
    "status": "succeeded",
    "amount": 499,
    "net_amount": 499,
    "amount_capturable": 0,
    "amount_received": 499,
    "connector": "cybersource",
    "client_secret": "pay_mg9hJf7VjCYa50hpSrdG_secret_EcNG9aGozUOBzs2vZhXj",
    "created": "2024-04-11T05:39:34.990Z",
    "currency": "USD",
    "customer_id": "mandate_customer1",
    "customer": {
        "id": "mandate_customer1",
        "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": "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": "03",
            "card_exp_year": "2030",
            "card_holder_name": "Test Holder",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": null,
    "phone": null,
    "return_url": null,
    "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": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "mandate_customer1",
        "created_at": 1712813974,
        "expires": 1712817574,
        "secret": "epk_381d81dec1eb4219a7ac9a072fd4402e"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7128139751946727304953",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_mg9hJf7VjCYa50hpSrdG_1",
    "payment_link": null,
    "profile_id": "pro_I8QjDfpUKyQ0EBzKRWfp",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_JGHsMWurht6srLkWsjO3",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-11T05:54:34.990Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": "pm_WmIHJOFLVZYHH1GMSztb",
    "payment_method_status": "active"
}

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
  • I added a CHANGELOG entry if applicable

@prajjwalkumar17 prajjwalkumar17 self-assigned this Apr 4, 2024
@prajjwalkumar17 prajjwalkumar17 requested review from a team as code owners April 4, 2024 14:36
@prajjwalkumar17 prajjwalkumar17 marked this pull request as draft April 4, 2024 14:36
Aprabhat19
Aprabhat19 previously approved these changes Apr 22, 2024
Aprabhat19
Aprabhat19 previously approved these changes Apr 22, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 25, 2024
Merged via the queue into main with commit 5f40eee Apr 25, 2024
10 of 12 checks passed
@likhinbopanna likhinbopanna deleted the refac/domain_func_for_save_payment_method branch April 25, 2024 08:29
pixincreate added a commit that referenced this pull request Apr 25, 2024
…to-env

* 'main' of github.com:juspay/hyperswitch:
  ci(postman): Fix Adyen postman collection (#4459)
  docs(cypress): Update Cypress README Documentation (#4380)
  Refactor(core): make save_payment_method as post_update_tracker trait function (#4307)
  refactor(connector): pass optional browser_info to stripe for increased trust (#4374)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR]: Create a domain function for saving payment method and updating pm_id in attempt
6 participants