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(graph): refactor the Knowledge Graph to include configs check, while eligibility analysis #4687

Merged
merged 16 commits into from
May 21, 2024

Conversation

Aprabhat19
Copy link
Contributor

@Aprabhat19 Aprabhat19 commented May 17, 2024

Type of Change

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

Description

Refactor the Knowledge Graph to include configs(pm_filters) check, while eligibility analysis

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?

  • Wrote unit test

  • To test it,

  • You can create MCA for 2 connectors

  • Do a payment using BOA and with some currency that it doesn't support , for eg:INR

Create

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_ylNGvTk4tI1OQFRGQN1CzMZMANf1jFHzTZqOkD4Ha4L4ubnngKMp98C6puzz1XPr' \
--data-raw '{
    "amount": 6540,
    "currency": "INR",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "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"
        },
        "email": "example@example.com"
    },
    "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"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "routing": {
        "type": "single",
        "data": "bankofamerica"
    }
}'
  • The payment would go through Stripe , as the eligibility analysis would fail
Response
{
    "payment_id": "pay_dhTO36kNBB03SWsTvSKC",
    "merchant_id": "merchant_1716296468",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "stripe",
    "client_secret": "pay_dhTO36kNBB03SWsTvSKC_secret_siY75j9e6hsgwNuAC3rS",
    "created": "2024-05-21T13:04:21.786Z",
    "currency": "INR",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "name": "John Doe",
        "email": "guest@example.com",
        "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": 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": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "address_line1_check": "pass",
                "address_postal_code_check": "pass",
                "cvc_check": "pass"
            },
            "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": "example@example.com"
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "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": "StripeCustomer",
        "created_at": 1716296661,
        "expires": 1716300261,
        "secret": "epk_a404fe01e93d445da59f0a1d7346ad90"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3PIsMcD5R7gDAGff0O0dJvGC",
    "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_3PIsMcD5R7gDAGff0O0dJvGC",
    "payment_link": null,
    "profile_id": "pro_vucql9T54ccffbKNdOvw",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_41ElW94TenDAaISxhaVj",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-05-21T13:19:21.786Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-05-21T13:04:23.236Z",
    "frm_metadata": 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 requested a review from vspecky May 17, 2024 13:14
@Aprabhat19 Aprabhat19 self-assigned this May 17, 2024
@Aprabhat19 Aprabhat19 requested a review from a team as a code owner May 17, 2024 13:14
@Aprabhat19 Aprabhat19 requested a review from a team as a code owner May 21, 2024 04:08
crates/kgraph_utils/src/mca.rs Outdated Show resolved Hide resolved
crates/kgraph_utils/src/mca.rs Outdated Show resolved Hide resolved
.filter(|p| enabled_pmt.clone().into_iter().any(|d| &d != p))
.collect::<Vec<_>>();
global_vector
.clone()
Copy link
Member

Choose a reason for hiding this comment

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

redundant .clone()

cgraph::Relation::Positive,
cgraph::Strength::Normal,
));
if let Some(country) = config.country.clone() {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like the .clone() can be avoided.

))
}

if let Some(currency) = config.currency.clone() {
Copy link
Member

Choose a reason for hiding this comment

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

The .clone() here probably can be avoided too.

})
.transpose()?;

if let Some(_country_currency) = curr {
Copy link
Member

Choose a reason for hiding this comment

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

I'm kinda surprised clippy didn't suggest this.

Suggested change
if let Some(_country_currency) = curr {
if curr.is_some() {

Comment on lines 638 to 649
// PaymentMethodsEnabled {
// payment_method: api_enums::PaymentMethod::Wallet,
// payment_method_types: Some(vec![RequestPaymentMethodTypes {
// payment_method_type: api_enums::PaymentMethodType::GooglePay,
// payment_experience: None,
// card_networks: None,
// accepted_currencies: Some(AcceptedCurrencies::EnableOnly(vec![
// api_enums::Currency::USD,
// api_enums::Currency::INR,
// ])),
// accepted_countries: None,
// minimum_amount: Some(10),
Copy link
Member

Choose a reason for hiding this comment

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

remove commented code

Comment on lines 132 to 147
impl IntoDirValue for api_enums::PaymentMethodType {
fn into_dir_value(self) -> Result<dir::DirValue, KgraphError> {
match self {
Self::Credit => Ok(dirval!(CardType = Credit)),
Self::Debit => Ok(dirval!(CardType = Debit)),
Self::Giropay => Ok(dirval!(BankRedirectType = Giropay)),
Self::Ideal => Ok(dirval!(BankRedirectType = Ideal)),
Self::Sofort => Ok(dirval!(BankRedirectType = Sofort)),
Self::Eps => Ok(dirval!(BankRedirectType = Eps)),
Self::Klarna => Ok(dirval!(PayLaterType = Klarna)),
Self::Affirm => Ok(dirval!(PayLaterType = Affirm)),
Self::AfterpayClearpay => Ok(dirval!(PayLaterType = AfterpayClearpay)),
Self::GooglePay => Ok(dirval!(WalletType = GooglePay)),
Self::ApplePay => Ok(dirval!(WalletType = ApplePay)),
Self::Paypal => Ok(dirval!(WalletType = Paypal)),
Self::CryptoCurrency => Ok(dirval!(CryptoType = CryptoCurrency)),
Copy link
Member

Choose a reason for hiding this comment

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

Don't have this as an IntoDirValue impl. Instead have it as a private function in kgraph_utils::mca, since we don't want to encourage its usage.

Copy link
Member

Choose a reason for hiding this comment

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

I would argue naming the file types.rs is more appropriate. But utils.rs works too.

Copy link
Member

Choose a reason for hiding this comment

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

have empty lines between function definitions

crates/kgraph_utils/src/mca.rs Outdated Show resolved Hide resolved
crates/kgraph_utils/src/transformers.rs Outdated Show resolved Hide resolved
@@ -28,7 +28,7 @@ impl From<DomainId> for DomainIdOrIdentifier<'_> {
Self::DomainId(value)
}
}

#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible we can revert the added Derive implemetations.

@likhinbopanna likhinbopanna added this pull request to the merge queue May 21, 2024
Merged via the queue into main with commit a917776 May 21, 2024
13 checks passed
@likhinbopanna likhinbopanna deleted the refac-eligibity-analysis branch May 21, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants