hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

Improve (Payment Templates): Complete, Default, and Resolve Variables

Open cestercian opened this issue 9 months ago • 3 comments

Type of Change

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

Description

This PR addresses several issues in the connector template files that could cause runtime errors or compilation failures when the templates are used to implement new payment connectors:

  1. In connector-template/mod.rs:

    • Replaced todo!() in get_currency_unit() with a default implementation to prevent runtime panics
    • Fixed template variable in base_url() method to properly include the downcase filter
    • Added implementations for empty AccessTokenAuth interface methods
  2. In connector-template/test.rs:

    • Implemented test helper functions that were previously returning None
    • Added realistic test data for payment methods and payment information
    • Added necessary imports for the new functionality
  3. In connector-template/transformers.rs:

    • Added missing import for the cards module which is used for the CardNumber type

Additional Changes

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

Motivation and Context

These template files serve as a starting point for implementing new payment connectors. The issues fixed in this PR would cause confusion or errors for developers trying to use these templates. By providing working defaults and fixing structural issues, we make the connector implementation process more straightforward and avoid the following problems:

  1. Runtime panics from todo!() calls
  2. Compilation errors due to missing imports
  3. Template rendering issues due to inconsistent variable formatting
  4. Test failures due to None values in test helpers

How did you test it?

The template files were manually reviewed to ensure consistent formatting and proper default implementations. Since these are template files, the changes ensure that when an actual connector is implemented using these templates, the resulting code will compile and run without immediate errors.

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [x] I addressed lints thrown by cargo clippy
  • [x] I reviewed the submitted code
  • [ ] I added unit tests for my changes where possible

cestercian avatar Mar 27 '25 17:03 cestercian

Review changes with  SemanticDiff

semanticdiff-com[bot] avatar Mar 27 '25 17:03 semanticdiff-com[bot]

Hey @deepanshu-iiitu, Thank you for your review and feedback! I've made the changes you requested:

  • Reverted the AccessToken implementation to keep it empty as in the original template
  • Removed the unnecessary cards import from transformers.rs.

Let me know if you'd like to see any other modifications to the PR!

cestercian avatar Mar 28 '25 09:03 cestercian

Hey @deepanshu-iiitu,

Could you take a look at this PR? It seems like it might have been missed. Thanks!

cestercian avatar Apr 03 '25 14:04 cestercian