Issue:
todo: Optimise encode process for signature based requests

### Feature Description

For a connector call, `get_request_body` is being called twice, Once in `get_headers`, other in `build_request`.

This is an expensive operation to call the same encoding function twice.

### Possible Implementation

Need to optimise it to a state from where it can be further implemented into the methods.

### Have you spent some time to check if this feature request has been raised before?

- [X] I checked and didn't find similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/contrib/CONTRIBUTING.md)

### Are you willing to submit a PR?

None

Resolution:
<think>
PR Context:
- Title: feat(connector): implement authorize and capture flows for Fiserv
- Merged: 2023-01-15T10:33:06Z
- Files changed: 18 files
- Commits: 16 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates

## Description
Authorize and capture flow
Todo: Issue for optimising the encoding process in header and body #370 

### Additional Changes

- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!-- 
Provide links to the files with corresponding changes.

Follow
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat(connector): implement authorize and capture flows for Fiserv (#266)
Files to modify:


**crates/api_models/src/enums.rs**
  Modify existing code

**crates/common_utils/src/lib.rs**
  Add:
    - function: pub::now_unix_timestamp

**crates/router/src/configs/settings.rs**
  Modify existing code

**crates/router/src/connector.rs**
  Add:
    - mod: pub::fiserv

**crates/router/src/connector/fiserv.rs**
  Add:
    - function: pub::generate_authorization_signature
    - function: private::id
    - function: private::common_get_content_type
    - function: private::base_url
    - function: private::get_headers
    - function: private::get_content_type
    - function: private::get_request_body
    - function: private::build_request
    - function: private::handle_response
    - function: private::get_url
    - function: private::get_error_response
    - function: private::get_headers
    - function: private::get_content_type
    - function: private::get_url
    - function: private::get_request_body
    - function: private::build_request
    - function: private::handle_response
    - function: private::get_error_response
    - function: private::get_webhook_object_reference_id
    - function: private::get_webhook_event_type
    - function: private::get_webhook_resource_object
    - function: private::get_flow_type
    - struct: pub::Fiserv
    - impl: impl Fiserv
    - impl: impl api::ConnectorCommon for Fiserv
    - impl: impl api::Payment for Fiserv
    - impl: impl api::PreVerify for Fiserv
    - impl: impl services::ConnectorIntegration<
        api::Verify,
        types::VerifyRequestData,
        types::PaymentsResponseData,
    > for Fiserv
    - impl: impl api::PaymentVoid for Fiserv
    - impl: impl services::ConnectorIntegration<
        api::Void,
        types::PaymentsCancelData,
        types::PaymentsResponseData,
    > for Fiserv
    - impl: impl api::PaymentSync for Fiserv
    - impl: impl services::ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData> for Fiserv
    - impl: impl api::PaymentCapture for Fiserv
    - impl: impl services::ConnectorIntegration<
        api::Capture,
        types::PaymentsCaptureData,
        types::PaymentsResponseData,
    > for Fiserv
    - impl: impl api::PaymentSession for Fiserv
    - impl: impl services::ConnectorIntegration<
        api::Session,
        types::PaymentsSessionData,
        types::PaymentsResponseData,
    > for Fiserv
    - impl: impl api::PaymentAuthorize for Fiserv
    - impl: impl services::ConnectorIntegration<
        api::Authorize,
        types::PaymentsAuthorizeData,
        types::PaymentsResponseData,
    > for Fiserv
    - impl: impl api::Refund for Fiserv
    - impl: impl api::RefundExecute for Fiserv
    - impl: impl api::RefundSync for Fiserv
    - impl: impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsResponseData> for Fiserv
    - impl: impl services::ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponseData> for Fiserv
    - impl: impl api::IncomingWebhook for Fiserv
    - impl: impl services::ConnectorRedirectResponse for Fiserv
    - mod: private::transformers

**crates/router/src/connector/fiserv/transformers.rs**
  Add:
    - function: private::try_from
    - function: private::try_from
    - function: private::from
    - function: private::try_from
    - function: private::try_from
    - function: private::try_from
    - function: private::from
    - function: private::try_from
    - function: private::try_from
    - struct: pub::FiservPaymentsRequest
    - struct: pub::Source
    - struct: pub::CardData
    - struct: pub::Amount
    - struct: pub::TransactionDetails
    - struct: pub::MerchantDetails
    - struct: pub::TransactionInteraction
    - struct: pub::FiservAuthType
    - struct: pub::ErrorResponse
    - struct: pub::ErrorDetails
    - struct: pub::FiservPaymentsResponse
    - struct: pub::GatewayResponse
    - struct: pub::TransactionProcessingDetails
    - struct: pub::FiservCaptureRequest
    - struct: pub::ReferenceTransactionDetails
    - struct: pub::SessionObject
    - struct: pub::FiservRefundRequest
    - struct: pub::RefundResponse
    - enum: pub::FiservPaymentStatus
    - enum: pub::RefundStatus
    - impl: impl TryFrom<&types::PaymentsAuthorizeRouterData> for FiservPaymentsRequest
    - impl: impl TryFrom<&types::ConnectorAuthType> for FiservAuthType
    - impl: impl From<FiservPaymentStatus> for enums::AttemptStatus
    - impl: impl TryFrom<types::ResponseRouterData<F, FiservPaymentsResponse, T, types::PaymentsResponseData>> for types::RouterData<F, T, types::PaymentsResponseData>
    - impl: impl TryFrom<&types::PaymentsCaptureRouterData> for FiservCaptureRequest
    - impl: impl TryFrom<&types::RefundsRouterData<F>> for FiservRefundRequest
    - impl: impl From<RefundStatus> for enums::RefundStatus
    - impl: impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>> for types::RefundsRouterData<api::Execute>
    - impl: impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>> for types::RefundsRouterData<api::RSync>

**crates/router/src/core/payments/transformers.rs**
  Modify existing code

**crates/router/src/types.rs**
  Modify existing code

**crates/router/src/types/api.rs**
  Modify existing code

**crates/router/tests/connectors/connector_auth.rs**
  Add:
    - function: private::from
    - struct: pub::SignatureKey
    - impl: impl From<SignatureKey> for ConnectorAuthType

**crates/router/tests/connectors/fiserv.rs**
  Add:
    - function: private::get_data
    - function: private::get_auth_token
    - function: private::get_name
    - function: private::get_connector_meta
    - function: private::should_only_authorize_payment
    - function: private::should_authorize_and_capture_payment
    - struct: private::Fiserv
    - impl: impl ConnectorActions for Fiserv
    - impl: impl utils::Connector for Fiserv

**crates/router/tests/connectors/main.rs**
  Add:
    - mod: private::fiserv

**crates/router/tests/connectors/utils.rs**
  Modify existing code