Skip to content

feat(injector): add support for new crate - injector for external vault proxy#8959

Merged
bernard-eugine merged 88 commits intomainfrom
addition_injector_crate
Aug 25, 2025
Merged

feat(injector): add support for new crate - injector for external vault proxy#8959
bernard-eugine merged 88 commits intomainfrom
addition_injector_crate

Conversation

@su-shivanshmathur
Copy link
Contributor

Type of Change

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

Description

This is the injector crate which would be used for External Vault proxy usage

Screenshot 2025-07-09 at 12 03 03 PM Screenshot 2025-07-09 at 12 15 08 PM

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Needed a generic way of passing on text as card number which would be swaped on vaults's end for not having PCI compliant data in router.

How did you test it?

Have added a test case in the crate itself

Screenshot 2025-08-05 at 5 48 40 PM Screenshot 2025-08-05 at 5 49 22 PM

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

@su-shivanshmathur su-shivanshmathur self-assigned this Aug 14, 2025
@su-shivanshmathur su-shivanshmathur requested a review from a team as a code owner August 14, 2025 10:54
@semanticdiff-com
Copy link

semanticdiff-com bot commented Aug 14, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  Cargo.lock Unsupported file format
  crates/injector/Cargo.toml Unsupported file format
  crates/injector/src/injector.rs  0% smaller
  crates/injector/src/lib.rs  0% smaller
  crates/injector/src/types.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format

@su-shivanshmathur su-shivanshmathur linked an issue Aug 14, 2025 that may be closed by this pull request
2 tasks
@su-shivanshmathur su-shivanshmathur changed the title feature(router): addition injector crate feat(router): addition injector crate Aug 14, 2025
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 22, 2025
Comment on lines +924 to +936

// #[cfg(feature = "v2")]
// fn generate_connector_request_reference_id(
// &self,
// payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,
// _payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,
// ) -> String {
// payment_intent
// .merchant_reference_id
// .as_ref()
// .map(|id| id.get_string_repr().to_owned())
// .unwrap_or_else(|| connector_utils::generate_12_digit_number().to_string())
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert this change. seems like this is irrelevant change

}

#[cfg(not(feature = "v2"))]
#[cfg(feature = "v1")]
Copy link
Contributor

Choose a reason for hiding this comment

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

if not required, please revert this

let tokens = find_all_tokens(&template);
let mut result = template;

for token_ref in tokens {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can use into_iter

@prasunna09 prasunna09 changed the title feat(router): addition injector crate feat(injector): add support for new crate - injector for external vault proxy Aug 25, 2025
Comment on lines +14 to +20
pub enum ContentType {
ApplicationJson,
ApplicationXWwwFormUrlencoded,
ApplicationXml,
TextXml,
TextPlain,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

good that we moved to this crate.
cargo hack has been failing due to this particular structure is in hyperswitch interfaces which indirectly uses domain models and others.

but what of maintenance part? for the similar structures as well?
ps. not a blocker currently
CC: @jarnura

Comment on lines +403 to +409
let method = match config.http_method {
injector_types::HttpMethod::GET => Method::Get,
injector_types::HttpMethod::POST => Method::Post,
injector_types::HttpMethod::PUT => Method::Put,
injector_types::HttpMethod::PATCH => Method::Patch,
injector_types::HttpMethod::DELETE => Method::Delete,
};
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 write a from impl for this

Comment on lines +518 to +523
if response_text.len() > 10_000_000 {
// 10MB limit
logger::error!(
response_length = response_text.len(),
"Response from connector is too large, potential DoS or memory exhaustion"
);
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we checking the response length? do we do this for normal connector call as well??

Comment on lines +94 to +100
let method = match request.method {
Method::Get => reqwest::Method::GET,
Method::Post => reqwest::Method::POST,
Method::Put => reqwest::Method::PUT,
Method::Patch => reqwest::Method::PATCH,
Method::Delete => reqwest::Method::DELETE,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

can be a from impl

req_builder = req_builder.body(payload);
}
_ => {
logger::warn!("Unsupported request content type, using raw bytes");
Copy link
Contributor

Choose a reason for hiding this comment

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

throw an error instead of warning

}

#[derive(Error, Debug)]
pub enum InjectorError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this HttpRequestFailed should be API error, and injector errors are different which would include TokenReplacementFailed.

Comment on lines +440 to +445
ContentType::ApplicationXml | ContentType::TextXml => {
Some(RequestContent::RawBytes(payload.as_bytes().to_vec()))
}
ContentType::TextPlain => {
Some(RequestContent::RawBytes(payload.as_bytes().to_vec()))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ContentType::ApplicationXml | ContentType::TextXml => {
Some(RequestContent::RawBytes(payload.as_bytes().to_vec()))
}
ContentType::TextPlain => {
Some(RequestContent::RawBytes(payload.as_bytes().to_vec()))
}
ContentType::ApplicationXml | ContentType::TextXml |
ContentType::TextPlain => {
Some(RequestContent::RawBytes(payload.as_bytes().to_vec()))
}

@bernard-eugine bernard-eugine added this pull request to the merge queue Aug 25, 2025
Merged via the queue into main with commit d18a941 Aug 25, 2025
20 of 25 checks passed
@bernard-eugine bernard-eugine deleted the addition_injector_crate branch August 25, 2025 13:24
Pradesh-S pushed a commit that referenced this pull request Aug 26, 2025
…lt proxy (#8959)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
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.

[FEATURE] Payments V2 supporting External vault

4 participants