Skip to content

Conversation

mrudulvajpayee4935
Copy link
Contributor

@mrudulvajpayee4935 mrudulvajpayee4935 commented Jan 10, 2025

Type of Change

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

Description

Using values in allowed_payment_method_types that were not configured during the creation of the connector results in breaking the SDK flow which shows something went wrong, as the PML call returned an empty payment method list. We need to apply this check during intent creation call.

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 manually by hitting payments create api.
Test cases-

  1. allowed_payment_method_types have only those PMT which are not enabled for connector. This will return error in payments create API.
  2. allowed_payment_method_types also have those PMT which are enabled for connector. This should be the successful payments flow.

Curl:

curl --location 'localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_bA6dXFz2dKBE4zqZKCpZBoE26BpZgCZpzfF9LKOHhCP0W7WZ0NyeIjpzfHAOw3tc' \
--data-raw '{
    "amount": 10000,
    "currency": "EUR",
    "allowed_payment_method_types": ["online_banking_czech_republic","multibanco"],
    "confirm": true,
    "payment_link": false,
    "capture_method": "manual",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 10000,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4000 0000 0000 1091",
            "card_exp_month": "12",
            "card_exp_year": "2026",
            "card_holder_name": "Max Mustermann",
            "card_cvc": "000"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "CA",
            "line3": "CA",
            "city": "Musterhausen",
            "state": "California",
            "zip": "12345",
            "country": "DE",
            "first_name": "Max",
            "last_name": "Mustermann"
        },
        "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,
        "ip_address": "103.77.139.95",
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

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

@mrudulvajpayee4935 mrudulvajpayee4935 added C-bug Category: Bug A-payment-methods Area: Payment Methods labels Jan 10, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 self-assigned this Jan 10, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 requested a review from a team as a code owner January 10, 2025 08:25
Copy link

semanticdiff-com bot commented Jan 10, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/helpers.rs  1% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/routes/metrics.rs  0% smaller

@mrudulvajpayee4935 mrudulvajpayee4935 changed the title check allowed payment method types in enabled options refactor: check allowed payment method types in enabled options Jan 10, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 force-pushed the handle-allowed-payment-method-types branch from a783ba7 to fad712c Compare January 10, 2025 12:47
);
}

if unsupported_payment_methods.len() == allowed_payment_method_types.len() {
Copy link
Contributor

Choose a reason for hiding this comment

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

use fp_utils::when

@@ -309,6 +311,93 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
)
.await?;

let allowed_payment_method_types = payment_intent_new
Copy link
Contributor

Choose a reason for hiding this comment

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

do this validation before we create any database entities. I see that shipping and billing address are already created, and the payment_intent as well.

common_enums::ConnectorType::PaymentProcessor,
);

let supporting_payment_method_types: HashSet<_> = filtered_connector_accounts
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this logic to an impl based on the MerchantConnectorAccount domain type and use it in both of the places?

@@ -863,3 +863,5 @@ pub trait ShouldCallConnector {
force_sync: Option<bool>,
) -> bool;
}

pub const MERCHANT_ID: &str = "merchant_id";
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this to constants, also name it appropriately so as to know where all this can be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing this as this const is not needed, we can directly use "merchant_id"

@mrudulvajpayee4935 mrudulvajpayee4935 force-pushed the handle-allowed-payment-method-types branch 3 times, most recently from f37301e to 1d1317c Compare January 16, 2025 09:53
@mrudulvajpayee4935 mrudulvajpayee4935 requested a review from a team as a code owner January 16, 2025 09:53
@mrudulvajpayee4935 mrudulvajpayee4935 force-pushed the handle-allowed-payment-method-types branch 2 times, most recently from 4ade2f6 to e409729 Compare January 16, 2025 09:56
@mrudulvajpayee4935 mrudulvajpayee4935 force-pushed the handle-allowed-payment-method-types branch 2 times, most recently from c9182ba to 9fbcc36 Compare January 16, 2025 11:01
Narayanbhat166
Narayanbhat166 previously approved these changes Jan 16, 2025
dgeee13
dgeee13 previously approved these changes Jan 16, 2025
ShankarSinghC
ShankarSinghC previously approved these changes Jan 16, 2025
dgeee13
dgeee13 previously approved these changes Jan 17, 2025
Narayanbhat166
Narayanbhat166 previously approved these changes Jan 17, 2025
ShankarSinghC
ShankarSinghC previously approved these changes Jan 17, 2025
@mrudulvajpayee4935 mrudulvajpayee4935 force-pushed the handle-allowed-payment-method-types branch from 5f72a83 to 147237d Compare January 21, 2025 07:55
@likhinbopanna likhinbopanna added this pull request to the merge queue Jan 21, 2025
Merged via the queue into main with commit 0eca55f Jan 21, 2025
19 of 20 checks passed
@likhinbopanna likhinbopanna deleted the handle-allowed-payment-method-types branch January 21, 2025 10:22
pixincreate added a commit that referenced this pull request Jan 24, 2025
…d-memory-cache

* 'main' of github.com:juspay/hyperswitch: (38 commits)
  fix(cypress): uncaught exceptions thrown by `hyperswitch.io` (#7092)
  ci(workflows): Add code coverage reporting for v2 (#6884)
  chore(version): 2025.01.23.0
  refactor: [CYBERSOURCE, BANKOFAMERICA, WELLSFARGO] Move code to crate hyperswitch_connectors (#6908)
  Documentation edits made through Mintlify web editor
  chore: enable 128-column-tables feature for diesel crate (#6857)
  feat(connector): [ADYEN ] Consume transaction id for PaymentsPreProcessing error (#7061)
  chore(version): 2025.01.22.0
  feat(routing): Integrate global success rates (#6950)
  feat(email): Add mailhog by default in docker-compose for local smtp server (#6869)
  refactor: check allowed payment method types in enabled options (#7019)
  feat(router): add payment method-specific features to connector feature list (#6963)
  Refactor: Customer email and browser Information (#7034)
  feat(connectors): fiuu,novalnet,worldpay - extend NTI flows (#6946)
  fix(cypress): address cybersource redirection inconsistency (#7057)
  chore(version): 2025.01.21.0
  refactor(payment-link): use shouldRemoveBeforeUnloadEvents flag for handling removal of beforeunload events through SDK (#7072)
  refactor(router): refactor ctp flow to fetch mca_id and get the connector creds instead of connector_name (#6859)
  chore(version): 2025.01.20.0
  fix(relay): populate connector metadata in the refunds flow (#7045)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants