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(core): Update pm_status accordingly for the respective attempt status #5560

Merged
merged 6 commits into from
Aug 7, 2024

Conversation

Aprabhat19
Copy link
Contributor

@Aprabhat19 Aprabhat19 commented Aug 7, 2024

Type of Change

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

Description

Update pm_status accordingly for the respective attempt status. Earlier we were mapping the AttemptStatus to Active in all the cases other than Failure. In this PR we must update the pm_status as Active only if it's charged / Authorised by the connector.

#5557

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?

  • Create a 3ds payment
Create
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_uaSNBro089ifFDTOyfoTqV6fEZOIkjtEUCDeHMDbwolILfq885p0xt0Nu9pwGLW9' \
--data-raw '{
    "amount": 10000,
    "currency": "USD",
    "confirm": false,
    
    "customer_id": "CustomerX7777",
    "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_u63AoTpv2Qca8c4RDaXe/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_fbebf112662d46a481bff6d83b0725d5' \
--data '{
  "confirm": true,
  
  "client_secret":"pay_u63AoTpv2Qca8c4RDaXe_secret_pz0luvr2gN831AW87IW7",
  "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_data": {
      "card": {
 "card_number":"4000003800000446",
                    
          "card_exp_month": "06",
          "card_exp_year": "2030",
          "card_holder_name": "John T",
          
          
          
          "card_cvc": "737"
      }
  }
}'
  • Until there's no redirection the pm_status is set to inactive, so if the redirection never happened and the payment reaches a failure state, the pmstatus would also be inactive
Screenshot 2024-08-07 at 7 31 39 PM
  • Once the redirection happens successfully we set the status to active
Screenshot 2024-08-07 at 7 31 47 PM

Test case for force_sync
-> Payment create with customer acceptance

{
    "amount": 100,
    "amount_to_capture": 100,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "cu_{{$timestamp}}",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "setup_future_usage": "on_session",
    "return_url": "http://127.0.0.1:4040/",
    "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_data": {
        "card": {
            "card_number": "4000000000000119",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "838"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX",
            "last_name": "ss"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "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"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}
{
    "payment_id": "pay_BDVr3lUHJT7pVczPcGWl",
    "merchant_id": "merchant_1723032662",
    "status": "requires_customer_action",
    "amount": 100,
    "net_amount": 100,
    "amount_capturable": 100,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_BDVr3lUHJT7pVczPcGWl_secret_Tfg8SRjvpZvFBJgFGpuD",
    "created": "2024-08-07T14:24:17.959Z",
    "currency": "USD",
    "customer_id": "cu_1723040658",
    "customer": {
        "id": "cu_1723040658",
        "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": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "0119",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "400000",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "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": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_BDVr3lUHJT7pVczPcGWl/merchant_1723032662/pay_BDVr3lUHJT7pVczPcGWl_1"
    },
    "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": "cu_1723040658",
        "created_at": 1723040657,
        "expires": 1723044257,
        "secret": "epk_654d3cf002e842baad449586be52a865"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "pi_3PlAmlD5R7gDAGff0RJuQdwe",
    "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_3PlAmlD5R7gDAGff0RJuQdwe",
    "payment_link": null,
    "profile_id": "pro_TqZuaiz7ejqVdbHtWzul",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_gmJhYjeHJvId2bDYFXyb",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-08-07T14:39:17.959Z",
    "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": null,
    "payment_method_status": null,
    "updated": "2024-08-07T14:24:19.862Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null
}

-> Delete payment method

curl --location --request DELETE 'http://localhost:8080/payment_methods/pm_aDl5RRooxS8pz82yyjA3' \
--header 'Accept: application/json' \
--header 'api-key: dev_uaSNBro089ifFDTOyfoTqV6fEZOIkjtEUCDeHMDbwolILfq885p0xt0Nu9pwGLW9'
{
    "payment_method_id": "pm_aDl5RRooxS8pz82yyjA3",
    "deleted": true
}

-> Force sync

curl --location 'http://localhost:8080/payments/pay_BDVr3lUHJT7pVczPcGWl?force_sync=true' \
--header 'Accept: application/json' \
--header 'api-key: dev_uaSNBro089ifFDTOyfoTqV6fEZOIkjtEUCDeHMDbwolILfq885p0xt0Nu9pwGLW9'
{
    "payment_id": "pay_BDVr3lUHJT7pVczPcGWl",
    "merchant_id": "merchant_1723032662",
    "status": "requires_customer_action",
    "amount": 100,
    "net_amount": 100,
    "amount_capturable": 100,
    "amount_received": 0,
    "connector": "stripe",
    "client_secret": "pay_BDVr3lUHJT7pVczPcGWl_secret_Tfg8SRjvpZvFBJgFGpuD",
    "created": "2024-08-07T14:24:17.959Z",
    "currency": "USD",
    "customer_id": "cu_1723040658",
    "customer": {
        "id": "cu_1723040658",
        "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": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "0119",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "400000",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "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": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_BDVr3lUHJT7pVczPcGWl/merchant_1723032662/pay_BDVr3lUHJT7pVczPcGWl_1"
    },
    "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": null,
    "connector_transaction_id": "pi_3PlAmlD5R7gDAGff0RJuQdwe",
    "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_3PlAmlD5R7gDAGff0RJuQdwe",
    "payment_link": null,
    "profile_id": "pro_TqZuaiz7ejqVdbHtWzul",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_gmJhYjeHJvId2bDYFXyb",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-08-07T14:39:17.959Z",
    "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_aDl5RRooxS8pz82yyjA3",
    "payment_method_status": null,
    "updated": "2024-08-07T14:25:29.945Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null
}

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 self-assigned this Aug 7, 2024
@Aprabhat19 Aprabhat19 requested review from a team as code owners August 7, 2024 14:16
@ShankarSinghC ShankarSinghC changed the base branch from main to hotfix-2024.08.02.0 August 7, 2024 14:17
@Aprabhat19 Aprabhat19 linked an issue Aug 7, 2024 that may be closed by this pull request
@ShankarSinghC ShankarSinghC removed the request for review from a team August 7, 2024 15:10
@likhinbopanna likhinbopanna merged commit 8b70aed into hotfix-2024.08.02.0 Aug 7, 2024
14 of 15 checks passed
@likhinbopanna likhinbopanna deleted the fix-status-and-fsync branch August 7, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Status handling for Payment Methods
6 participants