Issue:
[FEATURE] Update worldpay connector's integration

# Storing long connector transaction IDs (\>128 characters)

## Aim

This issue describes the approach for efficiently storing long connector transaction IDs in HyperSwitch application.

## Context

HyperSwitch is integrated with multiple connectors, these underlying connectors generate their own resource IDs which are stored in HyperSwitch DB for future references and / or debugging.

For payments, this is stored in payment\_attempt table \- `connector_transaction_id`  
For refunds, this is stored in refunds table \- `connector_refund_id`  
For captures, this is stored in captures table \- `connector_capture_id`

Both these columns are of size 128 characters in length, giving ample amount of space for storing these resource identifiers.

Some connectors \- like Worldpay, use a different approach for their resource identifiers. Worldpay uses an encrypted token as its resource identifier whose length usually exceeds 450 characters.

HyperSwitch cannot keep increasing the length of these two columns for storing IDs with such large lengths due to performance impacts on both read and write, specifically during webhooks flows as `connector_transaction_id` is an indexed column.

## Solution

Includes a bug fix and basically migrates the API endpoints to consume the v7 endpoints.

Bug fix -`entity` is a param in their API spec for specifying the merchant's account. 

The solution requires making changes in two places \-

1. Convert `connector_transaction_id` to a typed enum with two variants in the application  
   1. `ConnectorTxnId`  
   2. `HashedConnectorData`  
2. Introduce a new column per table for storing such large resource identifiers.

### Pre-requisites

- Add a new column `connector_transaction_data`

### Storing large IDs

- If input string length \> 128 characters, store this data in `connector_transaction_data`  
- Create a one-way hash of this data and store it in `connector_transaction_id` with a prefix `hs_hash_`

### Consuming large IDs

- If input string length \> 128 characters, create a hash and query using the hashed value  
- Deserialize `connector_transaction_id` into a typed variant \- either `ConnectorTxnId` or `HashedConnectorData` based on the prefix (`hs_hash_`)  
- If it’s `HashedConnectorData`, use `connector_transaction_data` as resource ID

## Example

Let’s say we want to extend storage of such IDs to payment attempts table

1. Add a new column in the said table \- `connector_transaction_data`  
2. While receiving these IDs (assuming length \>128), store in `connector_transaction_data`  
3. Create a one-way hash and store in `connector_transaction_id`  
4. While querying using these IDs (webhooks flow), create a hash and query using the hashed value  
5. Use `connector_transaction_data` instead of `connector_transaction_id` in application and application responses

## Notes

- Never expose the hashed `connector_transaction_id’s` outside the system, i.e. in API responses or webhook responses  
- Deserialize into `HashedConnectorData` only when the `connector_transaction_id` is prefixed with `hs_hash_`

### Have you spent some time checking if this feature request has been raised before?

- [X] I checked and didn't find a similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

Yes, I am willing to submit a PR!

Resolution:
<think>
PR Context:
- Title: feat(worldpay): migrate to v7
- Merged: 2024-10-17T10:57:00Z
- Files changed: 30 files
- Commits: 25 commits

Implementation approach:
## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [x] Bugfix
- [ ] New feature
- [x] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD

## Description
Described in #6116 

### Additional Changes

- [ ] This PR modifies the API contract
- [ ] This PR modifies the database schema
- [ ] This PR modifies application configuration/environment variables

<!--
Provide links to the files with corresponding changes.

Following are
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat(worldpay): migrate to v7 (#6109)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bo
Files to modify:


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

**crates/common_utils/src/consts.rs**
  Modify existing code

**crates/common_utils/src/types.rs**
  Add:
    - function: pub::get_id
    - function: pub::form_id_and_data
    - function: pub::get_txn_id
    - function: private::from
    - function: private::build
    - function: private::from_sql
    - function: private::to_sql
    - function: private::get_optional_connector_transaction_id
    - function: private::get_connector_transaction_id
    - function: private::get_optional_connector_refund_id
    - enum: pub::ConnectorTransactionId
    - trait: pub::ConnectorTransactionIdTrait
    - impl: impl ConnectorTransactionId
    - impl: impl From<String> for ConnectorTransactionId
    - impl: impl Queryable<sql_types::Text, DB> for ConnectorTransactionId
    - impl: impl FromSql<sql_types::Text, DB> for ConnectorTransactionId
    - impl: impl ToSql<sql_types::Text, DB> for ConnectorTransactionId

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

**crates/diesel_models/src/capture.rs**
  Modify existing code

**crates/diesel_models/src/payment_attempt.rs**
  Add:
    - function: private::get_optional_connector_transaction_id
    - function: private::get_optional_connector_transaction_id
    - impl: impl ConnectorTransactionIdTrait for PaymentAttempt
    - impl: impl ConnectorTransactionIdTrait for PaymentAttempt

**crates/diesel_models/src/query/capture.rs**
  Add:
    - function: private::get_optional_connector_transaction_id
    - impl: impl ConnectorTransactionIdTrait for Capture

**crates/diesel_models/src/refund.rs**
  Add:
    - function: private::get_optional_connector_refund_id
    - function: private::get_connector_transaction_id
    - impl: impl ConnectorTransactionIdTrait for Refund

**crates/diesel_models/src/schema.rs**
  Modify existing code

**crates/diesel_models/src/schema_v2.rs**
  Modify existing code

**crates/diesel_models/src/user/sample_data.rs**
  Modify existing code

**crates/hyperswitch_domain_models/src/payments/payment_attempt.rs**
  Modify existing code

**crates/hyperswitch_domain_models/src/router_request_types.rs**
  Modify existing code

**crates/kgraph_utils/src/transformers.rs**
  Modify existing code

**crates/router/src/connector/worldpay.rs**
  Remove:
    - function: private::get_url
    - struct: pub::Worldpay
  Add:
    - function: pub::new
    - function: private::get_url
    - struct: pub::Worldpay
    - impl: impl Worldpay

**crates/router/src/connector/worldpay/requests.rs**
  Modify existing code

**crates/router/src/connector/worldpay/response.rs**
  Remove:
    - function: pub::new
    - function: pub::new
    - function: pub::new
    - function: pub::new
    - struct: pub::PaymentInstrumentCard
    - struct: pub::PaymentInstrumentCardExpiryDate
    - struct: pub::PaymentInstrumentCardIssuer
    - struct: pub::PaymentInstrumentCardNumber
    - enum: pub::Outcome
    - impl: impl Exemption
    - impl: impl PaymentsResPaymentInstrument
    - impl: impl PaymentInstrumentCardExpiryDate
    - impl: impl PaymentInstrumentCardIssuer
  Add:
    - enum: pub::PaymentOutcome
    - enum: pub::RefundOutcome

**crates/router/src/connector/worldpay/transformers.rs**
  Modify existing code

**crates/router/src/core/fraud_check/flows/transaction_flow.rs**
  Modify existing code

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

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

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

**crates/router/src/core/refunds.rs**
  Modify existing code

**crates/router/src/core/utils.rs**
  Modify existing code

**crates/router/src/core/webhooks/incoming.rs**
  Modify existing code

**crates/router/src/db/address.rs**
  Modify existing code

**crates/router/src/db/capture.rs**
  Modify existing code

**crates/router/src/db/customers.rs**
  Modify existing code

**crates/router/src/db/mandate.rs**
  Modify existing code

**crates/router/src/db/payment_method.rs**
  Modify existing code

**crates/router/src/db/refund.rs**
  Modify existing code

**crates/router/src/db/reverse_lookup.rs**
  Modify existing code

**crates/router/src/services/kafka/refund.rs**
  Modify existing code

**crates/router/src/services/kafka/refund_event.rs**
  Modify existing code

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

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

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

**crates/router/src/utils/user/sample_data.rs**
  Modify existing code

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

**crates/storage_impl/src/lookup.rs**
  Modify existing code

**crates/storage_impl/src/payments/payment_attempt.rs**
  Modify existing code

**crates/storage_impl/src/payments/payment_intent.rs**
  Modify existing code

**crates/storage_impl/src/payouts/payout_attempt.rs**
  Modify existing code

**crates/storage_impl/src/payouts/payouts.rs**
  Modify existing code

**crates/storage_impl/src/redis/kv_store.rs**
  Modify existing code