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(connectors): Amount received should be zero for pending and failed status #4331

Merged
merged 5 commits into from
Apr 10, 2024

Conversation

Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented Apr 8, 2024

Type of Change

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

Description

Amount received as well as amount capturable were both showing total amount during pending status but this breaks the convention i.e amount_received + amount_capturable = total amount .

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?

Tested through postman:
Create MCA (Adyen or Paypal): (eg. Paypal)

{
    "connector_type": "fiz_operations",
    "connector_name": "paypal",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "{{api_key}}",
        "key1": "{{key1}}"
    },
    "business_country": "US",
    "business_label": "default",
    "test_mode": false,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "paypal",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": false,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    }
}

Create a payment with Capture as Manual:

{
  "amount": 300,
  "currency": "USD",
  "confirm": true,
  "business_country": "US",
  "business_label": "default",
  "amount_to_capture": 300,
  "customer_id": "{{customer_id}}",
  "capture_method": "manual",
  "capture_on": "2022-09-10T10:11:12Z",
  "authentication_type": "no_three_ds",
  "return_url": "https://www.google.com",
  "email": "something@gmail.com",
  "name": "Joseph Doe",
  "phone": "999999999",
  "phone_country_code": "+65",
  "description": "Its my first payment request",
  "statement_descriptor_name": "Juspay",
  "statement_descriptor_suffix": "Router",
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_data": {
    "card": {
      "card_number": "4000000000001091",
      "card_exp_month": "01",
      "card_exp_year": "2026",
      "card_holder_name": "joseph Doe",
      "card_cvc": "100"
    }
  },
  "billing": {
    "address": {
      "line1": "1467",
      "line2": "CA",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "CA",
      "zip": "94122",
      "country": "PL",
      "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": "109.71.40.0"
  },
  "metadata": {
    "order_category": "applepay"
  },
  "order_details": [
    {
      "product_name": "Apple iphone 15",
      "quantity": 1,
      "amount": 300,
      "account_name": "transaction_processing"
    }
  ],
  "setup_future_usage": "off_session"
}

Retrieve the Payment: The status should be requires_capture
Capture the Payment: status should be processing and amount_received should be 0 (zero). Example Response is below

{
    "payment_id": "pay_Ix9SLSEcEb6hkLSxTS7g",
    "merchant_id": "merchant_1712583118",
    "status": "processing",
    "amount": 300,
    "net_amount": 300,
    "amount_capturable": 300,
    "amount_received": 0,
    "connector": "paypal",
    "client_secret": "pay_Ix9SLSEcEb6hkLSxTS7g_secret_xKILdtpMBeUPmaH1V2VL",
    "created": "2024-04-08T14:00:17.738Z",
    "currency": "USD",
    "customer_id": "cus_69Qz5OIKkVfjxgdlRX8L",
    "customer": {
        "id": "cus_69Qz5OIKkVfjxgdlRX8L",
        "name": "Joseph Doe",
        "email": "something@gmail.com",
        "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": "manual",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1091",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "400000",
            "card_extended_bin": "40000000",
            "card_exp_month": "01",
            "card_exp_year": "2026",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "PL",
            "line1": "1467",
            "line2": "CA",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "CA",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": [
        {
            "brand": null,
            "amount": 300,
            "category": null,
            "quantity": 1,
            "product_id": null,
            "product_name": "Apple iphone 15",
            "product_type": null,
            "product_img_link": null,
            "requires_shipping": null
        }
    ],
    "email": "something@gmail.com",
    "name": "Joseph Doe",
    "phone": "999999999",
    "return_url": "https://www.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": "credit",
    "connector_label": "paypal_US_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "8W030039AX010491J",
    "frm_message": null,
    "metadata": {
        "order_category": "applepay"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_Ix9SLSEcEb6hkLSxTS7g_1",
    "payment_link": null,
    "profile_id": "pro_k0JhxuX6vsJqtNXgNcr9",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_MzZlFWdMmr37qAvHgFQg",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-04-08T14:15:17.738Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "109.71.40.0",
        "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
}
Screenshot 2024-04-10 at 2 30 24 PM Note: This affect capture of Adyen and Paypal

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

@Sakilmostak Sakilmostak added A-connector-integration Area: Connector integration C-bug Category: Bug labels Apr 8, 2024
@Sakilmostak Sakilmostak self-assigned this Apr 8, 2024
@Sakilmostak Sakilmostak requested a review from a team as a code owner April 8, 2024 14:42
@Sakilmostak Sakilmostak changed the title bugfix(connectors): Amount received should be zero for pending and failed status fix(connectors): Amount received should be zero for pending and failed status Apr 8, 2024
| storage_enums::AttemptStatus::Failure
| storage_enums::AttemptStatus::CaptureFailed
| storage_enums::AttemptStatus::Voided => 0,
_ => item.data.request.amount_to_capture,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please mention all the statuses here, instead of using default case.

Copy link
Contributor

@srujanchikke srujanchikke left a comment

Choose a reason for hiding this comment

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

Please resolve given comments

Comment on lines 1550 to 1553
| storage_enums::AttemptStatus::Authorized
| storage_enums::AttemptStatus::Failure
| enums::AttemptStatus::RouterDeclined
| enums::AttemptStatus::AuthenticationFailed
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use either storage_enums or enums in the match arms. Not both.

@Sakilmostak Sakilmostak requested a review from a team as a code owner April 10, 2024 10:07
Copy link
Contributor

@hrithikesh026 hrithikesh026 left a comment

Choose a reason for hiding this comment

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

LGTM

@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 10, 2024
Merged via the queue into main with commit 6aa66c4 Apr 10, 2024
12 of 15 checks passed
@likhinbopanna likhinbopanna deleted the amount_received_bugfix branch April 10, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants