Skip to content

feat: add profile_id authentication for business profile update and list#5673

Merged
Gnanasundari24 merged 17 commits intomainfrom
profile-authentication-for-business-profile-endpoints
Sep 3, 2024
Merged

feat: add profile_id authentication for business profile update and list#5673
Gnanasundari24 merged 17 commits intomainfrom
profile-authentication-for-business-profile-endpoints

Conversation

@hrithikesh026
Copy link
Contributor

@hrithikesh026 hrithikesh026 commented Aug 22, 2024

Type of Change

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

Description

Add profile_id validation for business profile update and list apis.

  • In case of business profile update, validate the profile_id from auth layer and path param in auth layer itself
  • In case of business profile list, filter out the Business profile based on list of profile_ids from auth layer in core function.

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?

  1. Do profile list.
curl --location 'http://localhost:8080/account/merchant_1723462533/profile' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiN2M4MWM1MGUtNzExMC00YWQwLTgwMGEtOGVjYmJhNzhhNmQ2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIzNDYyNTMzIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyNDU2MzkxNiwib3JnX2lkIjoib3JnX1B4QXlPWHllZmZOSlJIUThGeXhCIiwicHJvZmlsZV9pZCI6bnVsbH0.FdzGUsmN7i9uR-SK8SA3tTZq5kU38SBiEpmsWwYYGG0'

Response:

[
    {
        "merchant_id": "merchant_1723462533",
        "profile_id": "pro_kHHimqwPAxpaBCMbtQpY",
        "profile_name": "default",
        "return_url": "https://www.google.com/",
        "enable_payment_response_hash": true,
        "payment_response_hash_key": "PALT9CVJZ3hrJ0cm8QoZVYTGukjclu9rey3B5lt14E1e8xtWk4r05uN7oLHOdjZu",
        "redirect_to_merchant_with_http_post": false,
        "webhook_details": null,
        "metadata": null,
        "routing_algorithm": null,
        "intent_fulfillment_time": 900,
        "frm_routing_algorithm": null,
        "payout_routing_algorithm": null,
        "applepay_verified_domains": null,
        "session_expiry": 900,
        "payment_link_config": null,
        "authentication_connector_details": null,
        "use_billing_as_payment_method_billing": true,
        "extended_card_info_config": null,
        "collect_shipping_details_from_wallet_connector": false,
        "collect_billing_details_from_wallet_connector": false,
        "is_connector_agnostic_mit_enabled": false,
        "payout_link_config": null,
        "outgoing_webhook_custom_http_headers": null
    }
]
  1. Do profile update.
curl --location 'http://localhost:8080/account/merchant_1723462533/business_profile/pro_kHHimqwPAxpaBCMbtQpY' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiN2M4MWM1MGUtNzExMC00YWQwLTgwMGEtOGVjYmJhNzhhNmQ2IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzIzNDYyNTMzIiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcyNDU2MzkxNiwib3JnX2lkIjoib3JnX1B4QXlPWHllZmZOSlJIUThGeXhCIiwicHJvZmlsZV9pZCI6bnVsbH0.FdzGUsmN7i9uR-SK8SA3tTZq5kU38SBiEpmsWwYYGG0' \
--data '{
    "return_url": "https://www.google.com"
}'

Response:

{
    "merchant_id": "merchant_1723462533",
    "profile_id": "pro_kHHimqwPAxpaBCMbtQpY",
    "profile_name": "default",
    "return_url": "https://www.google.com/",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "PALT9CVJZ3hrJ0cm8QoZVYTGukjclu9rey3B5lt14E1e8xtWk4r05uN7oLHOdjZu",
    "redirect_to_merchant_with_http_post": false,
    "webhook_details": null,
    "metadata": null,
    "routing_algorithm": null,
    "intent_fulfillment_time": 900,
    "frm_routing_algorithm": null,
    "payout_routing_algorithm": null,
    "applepay_verified_domains": null,
    "session_expiry": 900,
    "payment_link_config": null,
    "authentication_connector_details": null,
    "use_billing_as_payment_method_billing": true,
    "extended_card_info_config": null,
    "collect_shipping_details_from_wallet_connector": false,
    "collect_billing_details_from_wallet_connector": false,
    "is_connector_agnostic_mit_enabled": false,
    "payout_link_config": null,
    "outgoing_webhook_custom_http_headers": 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

@hrithikesh026 hrithikesh026 self-assigned this Aug 22, 2024
@hrithikesh026 hrithikesh026 requested review from a team as code owners August 22, 2024 12:33
@semanticdiff-com
Copy link

semanticdiff-com bot commented Aug 22, 2024

Review changes with SemanticDiff.

Analyzed 7 of 7 files.

Overall, the semantic diff is 5% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/lib.rs 80.22% smaller
✔️ crates/router/src/routes.rs 81.89% smaller
✔️ crates/router/src/services/authentication.rs Analyzed
✔️ crates/router/src/routes/admin.rs 5.22% smaller
✔️ crates/router/src/routes/app.rs Analyzed
✔️ crates/router/src/core/admin.rs Analyzed
✔️ crates/router/src/core/utils.rs Analyzed

@hrithikesh026 hrithikesh026 added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Aug 23, 2024
@hrithikesh026 hrithikesh026 added this to the August 2024 Release milestone Aug 23, 2024
Comment on lines +1124 to +1130
|state, auth, merchant_id, _| {
list_business_profile(
state,
merchant_id,
auth.profile_id.map(|profile_id| vec![profile_id]),
)
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't filter on profile_id in this route.

There should be a new route which filters on profile level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

list business profile endpoint looks like this currently. {base_url}/account/${merchantId}/business_profile

Should the new endpoint be {base_url}/account/${merchantId}/business_profile/profile

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check with @jarnura.

Copy link
Member

@jarnura jarnura Aug 28, 2024

Choose a reason for hiding this comment

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

{base_url}/account/${merchantId}/profile

We should use this route to list profiles since in resource is named as profiles.

In the list we can do the filter too by the access

MerchantJwtWithProfileId {
merchant_id: id_type::MerchantId,
profile_id: Option<id_type::ProfileId>,
user_id: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Option is needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ProfileId should come from JWT token right?
ProfileId is optional in JWT.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to user_id. Sorry for the confusion.

Comment on lines +1385 to +1391
#[derive(Debug)]
pub struct ProfileIdWrapper(pub common_utils::id_type::ProfileId);
impl GetProfileId for ProfileIdWrapper {
fn get_profile_id(&self) -> Option<&common_utils::id_type::ProfileId> {
Some(&self.0)
}
}
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 remove this, if this is not being used.

.route(web::get().to(business_profile_retrieve))
.route(web::post().to(business_profile_update))
.route(web::delete().to(business_profile_delete)),
web::scope("/account/{merchant_id}").service(
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 check this again. This is wrong. Merchant id will be there 2 times in the path.

Comment on lines +1647 to +1649
web::scope("/account/{account_id}/profile")
.app_data(web::Data::new(state))
.service(
Copy link
Contributor

Choose a reason for hiding this comment

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

We can combine this with the original BusinessProfile routes right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. I tried doing that, {base_url}/account/{merchant_id}/connectors was returning 404 not found.

ThisIsMani
ThisIsMani previously approved these changes Sep 2, 2024
jarnura
jarnura previously approved these changes Sep 2, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Sep 2, 2024
@likhinbopanna likhinbopanna removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Sep 2, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 2, 2024
@hrithikesh026 hrithikesh026 dismissed stale reviews from ThisIsMani and jarnura via 06e0306 September 2, 2024 14:33
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Sep 3, 2024
Merged via the queue into main with commit e3a9fb1 Sep 3, 2024
@Gnanasundari24 Gnanasundari24 deleted the profile-authentication-for-business-profile-endpoints branch September 3, 2024 06:31
pixincreate added a commit that referenced this pull request Sep 3, 2024
…config-fix

* 'main' of github.com:juspay/hyperswitch:
  feat: add profile_id authentication for business profile update and list (#5673)
  chore(version): 2024.09.03.0
  feat(user): implement invitations api (#5769)
  feat(connector): [Adyenplatform] add webhooks for payout (#5749)
  refactor(v2_migrations): re-organize v2 migrations (#5760)
  chore: add wasm support for connector additional details (#5712)
  refactor(connector): Move globepay, powertranz, tsys, worldline to hyperswitch_connectors (#5758)
  fix(cypress): fix cypress throwing error when `connectorId` is not passed and miscellaneous fixes (#5746)
  chore: fix typos (#5766)
  refactor(business_profile): change id for business profile (#5748)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: Core flows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants