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

feat(connector): [Tsys] Currency Unit Conversion #2749

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

zakhaev26
Copy link

@zakhaev26 zakhaev26 commented Oct 31, 2023

Type of Change

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

Description

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?

Got to test it by paying using Tsys and test the currency unit.

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
  • I added a CHANGELOG entry if applicable

@zakhaev26 zakhaev26 marked this pull request as ready for review October 31, 2023 16:56
@zakhaev26 zakhaev26 requested a review from a team as a code owner October 31, 2023 16:56
@swangi-kumari swangi-kumari added A-connector-integration Area: Connector integration C-feature Category: Feature request or enhancement hacktoberfest Issues that are up for grabs for Hacktoberfest participants labels Oct 31, 2023
@swangi-kumari swangi-kumari self-requested a review October 31, 2023 18:05
@zakhaev26
Copy link
Author

My bad , got some issues due which CI is failing. I am working on it now.
Please suggest any changes if required.

@swangi-kumari
Copy link
Contributor

Please address the failing CI checks
Run cargo +nightly fmt for formatting.
Run cargo clippy and addressed lints thrown by it.

@swangi-kumari swangi-kumari linked an issue Oct 31, 2023 that may be closed by this pull request
2 tasks
@swangi-kumari
Copy link
Contributor

Hey @zakhaev26 ,
Thanks for your interest in contributing to hyperswitch.
Let us know if you need any assistance from our end.
Also, even if hacktoberfest is over, we should celebrate open source everyday and we are open for more contributions from you.
We would still be rewarding folks with goodies even if the PR gets merged post hacktoberfest.
May the Source be with you!

@AkshayaFoiger AkshayaFoiger added the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Nov 2, 2023
@zakhaev26
Copy link
Author

zakhaev26 commented Nov 4, 2023

I am getting some errors on running cargo clippy :

error: cannot find attribute `serde` in this scope
  --> crates/router/src/connector/tsys/transformers.rs:51:3
   |
51 | #[serde(rename_all = "camelCase")]
   |   ^^^^^
   |
   = note: `serde` is in scope, but it is a crate, not an attribute
   

and

error[E0412]: cannot find type `T` in this scope
--> crates/router/src/connector/tsys/transformers.rs:494:33
 |
494 | impl<F> TryFrom<&TsysRouterData<T>::RefundsRouterData<F>> for TsysRefundRequest {
 |      -                          ^
 |      |
 |      similarly named type parameter `F` defined here
 

can someone please guide me how to fix these issues ?

crates/router/src/connector/tsys.rs Outdated Show resolved Hide resolved
@zakhaev26
Copy link
Author

zakhaev26 commented Nov 8, 2023

and do adequate changes to the TryFrom of RefundsRouterData in transformer.rs file

Getting Errors at tsys/transformers.rs ..at TsysRefundRouter :

impl<F> TryFrom<&TsysRouterData<T>::RefundsRouterData<F>> for TsysRefundRequest {
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(item: &TsysRouterData<&types::RefundsRouterData<F>>) -> Result<Self, Self::Error> {
        let connector_auth: TsysAuthType = TsysAuthType::try_from(&item.connector_auth_type)?;
        let return_request = TsysReturnRequest {
            device_id: connector_auth.device_id,
            transaction_key: connector_auth.transaction_key,
            transaction_amount: item.request.refund_amount.to_string(),
            transaction_id: item.request.connector_transaction_id.clone(),
        };
        Ok(Self { return_request })
    }
}

These were my changes I made according to help messages after cargo clippy , but still fails. Please Help!

@AkshayaFoiger
Copy link
Contributor

AkshayaFoiger commented Nov 9, 2023

and do adequate changes to the TryFrom of RefundsRouterData in transformer.rs file

Getting Errors at tsys/transformers.rs ..at TsysRefundRouter :

impl<F> TryFrom<&TsysRouterData<T>::RefundsRouterData<F>> for TsysRefundRequest {
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(item: &TsysRouterData<&types::RefundsRouterData<F>>) -> Result<Self, Self::Error> {
        let connector_auth: TsysAuthType = TsysAuthType::try_from(&item.connector_auth_type)?;
        let return_request = TsysReturnRequest {
            device_id: connector_auth.device_id,
            transaction_key: connector_auth.transaction_key,
            transaction_amount: item.request.refund_amount.to_string(),
            transaction_id: item.request.connector_transaction_id.clone(),
        };
        Ok(Self { return_request })
    }
}

These were my changes I made according to help messages after cargo clippy , but still fails. Please Help!

Hey @zakhaev26,
I would suggest to replace the try_from implementation for RefundRouterData as provided bellow

impl<F> TryFrom<&TsysRouterData<&types::RefundsRouterData<F>>> for TsysRefundRequest {
    type Error = error_stack::Report<errors::ConnectorError>;
    fn try_from(item: &TsysRouterData<&types::RefundsRouterData<F>>) -> Result<Self, Self::Error> {
        let connector_auth: TsysAuthType = TsysAuthType::try_from(&item.router_data.connector_auth_type)?;
         let return_request = TsysReturnRequest {
             device_id: connector_auth.device_id,
             transaction_key: connector_auth.transaction_key,
             transaction_amount: item.router_data.request.refund_amount.to_string(),
             transaction_id: item.router_data.request.connector_transaction_id.clone(),
         };
         Ok(Self { return_request })
    }
}

Comment on lines +234 to +243

let connector_router_data = tsys::TsysRouterData::try_from((
&self.get_currency_unit(),
req.request.currency,
req.request.amount,
req,
))?;

let req_obj = tsys::TsysPaymentsRequest::try_from(&connector_router_data)?;

Copy link
Contributor

Choose a reason for hiding this comment

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

Undo these changes in PaymentsSync flow.
This implemented to be done for line 151 in the

impl ConnectorIntegration<api::Authorize , types::PaymentsAuthorizeData, types::PaymentsResponseData>
    for Tsys
{
         ...
       fn get_request_body(
        &self,
        req: &types::PaymentsAuthorizeRouterData,
    ) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
                    ...
       }
}

and similar change has to be implemented for Capture flow, line 322

impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData>
    for Tsys
{
         ....
        fn get_request_body(
        &self,
        req: &types::PaymentsCaptureRouterData,
    ) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
        //do your changes here
          ...
     }
}

fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
fn try_from(
item: &TsysRouterData<&types::PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instances where item.request is utilized should be substituted with item.router_data.request

In case you have any queries, you can ask them on this PR thread, or on slack whichever you are comfortable with

@swangi-kumari
Copy link
Contributor

Hey @zakhaev26
Are you still working on this issue?
Please let us know if you need any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-feature Category: Feature request or enhancement hacktoberfest Issues that are up for grabs for Hacktoberfest participants S-waiting-on-author Status: This PR is incomplete or needs to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: [Tsys] Currency Unit Conversion
3 participants