Skip to content

Conversation

swetasharma03
Copy link
Contributor

@swetasharma03 swetasharma03 commented Jun 2, 2025

Type of Change

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

Description

  • Removed the unwanted changes (like addition of conector_name in RoutableConnectors enum, etc)
  • Amount convertor code is generated in the template
  • Connector Specification is also added in the template
  • Network error codes added
  • validate_mandate_payment, validate_psync_reference_id, toml files doesn't directly implements cards as supported payment method
  • The unit test file now generated directly to crates/router/tests/connectors etc
  • Derive macro copy added for all unit types like enums which only have 1 type of data (eg payment status, refund status) and structs which only have primitive types like i64, u64 , bool, char or unit structs.
  • Connector getting added in all the files in alphabetical order
  • In default_implmentation.rs, if connector previous to the new connector doesn't exist in any default_imp list, the new_connector will be added on the top of the list, else it will be in alphabetically sorted.
  • Code getting compiled directly after template generation.
Screenshot 2025-06-12 at 8 10 59 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

How did you test it?

This PR only updates the script to generate template code for a connector, hence no API testing required.

Script used to test the template generation.
sh scripts/add_connector.sh testConnector https://www.google.com/

Screenshot 2025-06-27 at 4 40 33 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

@swetasharma03 swetasharma03 self-assigned this Jun 2, 2025
@swetasharma03 swetasharma03 requested review from a team as code owners June 2, 2025 20:25
@swetasharma03 swetasharma03 added C-feature Category: Feature request or enhancement C-refactor Category: Refactor labels Jun 2, 2025
Copy link

semanticdiff-com bot commented Jun 2, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/hyperswitch_connectors/src/default_implementations.rs  2% smaller
  connector-template/mod.rs Unsupported file format
  connector-template/test.rs Unsupported file format
  connector-template/transformers.rs Unsupported file format
  scripts/add_connector.sh Unsupported file format

@swetasharma03 swetasharma03 changed the title [FEATURE] : Update new connector features in add connector script feat(connector): [SCRIPT] Update add connector script with new connector features Jun 2, 2025
@swetasharma03 swetasharma03 force-pushed the add-connector-script-refactor branch 9 times, most recently from e2162f9 to b9aa52c Compare June 3, 2025 09:23
@swetasharma03 swetasharma03 force-pushed the add-connector-script-refactor branch from b9aa52c to 0095cc5 Compare June 3, 2025 09:38
@swetasharma03 swetasharma03 force-pushed the add-connector-script-refactor branch from 8d820fc to 0195f2b Compare June 12, 2025 14:16
@swetasharma03 swetasharma03 force-pushed the add-connector-script-refactor branch from 0195f2b to 5f8ceb1 Compare June 12, 2025 14:37
awasthi21
awasthi21 previously approved these changes Jun 17, 2025
for file in "${default_impl_files[@]}"; do
tmpfile="${file}.tmp"

awk -v prev="$previous_connector_camelcase" -v new="$payment_gateway_camelcase" '
Copy link
Member

Choose a reason for hiding this comment

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

Could we at least have some comments as to what is happening 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.

Previously, in default_implementations.rs,default_implementations_v2.rs, the new connector was always added at the top of the macro list, without maintaining alphabetical order.

Also using a single sed command to insert the new connector depends on the presence of the previous_connector in the macro block. This approach fails when the previous_connector is missing from one or more lists, leading to skipped insertions.

To handle this correctly, the current logic does the following:

  • If the previous_connector exists in the macro, the new_connector is added after it, preserving alphabetical order.
  • If the previous_connector is not found, the new_connector is inserted at the top of the macro list.

I've also added comments in the code.



# Remove temporary files created in above step
rm $conn.rs-e $src/types/api.rs-e $src/configs/settings.rs-e config/development.toml-e config/docker_compose.toml-e config/config.example.toml-e loadtest/config/development.toml-e crates/api_models/src/connector_enums.rs-e crates/euclid/src/enums.rs-e crates/api_models/src/routing.rs-e $src/core/payments/flows.rs-e crates/common_enums/src/connector_enums.rs-e $src/types/transformers.rs-e $src/core/admin.rs-e crates/hyperswitch_connectors/src/default_implementations.rs-e crates/hyperswitch_connectors/src/default_implementations_v2.rs-e crates/hyperswitch_interfaces/src/configs.rs-e $src/connector.rs-e config/deployments/integration_test.toml-e config/deployments/production.toml-e config/deployments/sandbox.toml-e temp crates/connector_configs/src/connector.rs-e crates/router/tests/connectors/main.rs-e crates/router/src/core/payments/connector_integration_v2_impls.rs-e

sed -i'' -e "/pub ${previous_connector}: ConnectorParams,/a\\
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this going to generate more temporary files, but we' have a step before this which says "Remove temporary files created in above step".

Can we move this line above the rm command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We’re already running the rm command immediately after the sed edit for crates/hyperswitch_domain_models/src/configs.rs, so the temp file (.rs-e) is cleaned up right away. I’ve tested the script multiple times, and no temporary files are left behind.

sed -i'' -e "/pub ${previous_connector}: ConnectorParams,/a\\
    pub ${payment_gateway}: ConnectorParams,
" crates/hyperswitch_domain_models/src/configs.rs
rm crates/hyperswitch_domain_models/src/configs.rs-e

What are your thoughts? Do we still need to move this code above, or is the current placement okay?

Copy link
Member

Choose a reason for hiding this comment

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

Can we then group all the sed commands together, followed by one rm command? So move this sed command before the big rm command?

@swetasharma03 swetasharma03 dismissed stale reviews from deepanshu-iiitu and awasthi21 via 7a8c0ad June 27, 2025 12:16
awasthi21
awasthi21 previously approved these changes Jun 30, 2025
@swetasharma03 swetasharma03 dismissed stale reviews from awasthi21 and deepanshu-iiitu via f5190dd June 30, 2025 10:31
@SanchithHegde SanchithHegde changed the title feat(connector): [SCRIPT] Update add connector script with new connector features refactor(connector): update add connector script with new connector features Jun 30, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 1, 2025
Merged via the queue into main with commit 2ff93ff Jul 1, 2025
29 of 32 checks passed
@likhinbopanna likhinbopanna deleted the add-connector-script-refactor branch July 1, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants