Bug: [FEATURE] [PLACETOPAY] Connector audit



### Feature Description

Connector placetopay needs to be audited.

### Possible Implementation

Connector placetopay needs to be audited.

### 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!
diff --git a/crates/router/src/connector/placetopay.rs b/crates/router/src/connector/placetopay.rs
index 81255f450e5..c28fed1fede 100644
--- a/crates/router/src/connector/placetopay.rs
+++ b/crates/router/src/connector/placetopay.rs
@@ -119,8 +119,8 @@ impl ConnectorValidation for Placetopay {
     ) -> CustomResult<(), errors::ConnectorError> {
         let capture_method = capture_method.unwrap_or_default();
         match capture_method {
-            enums::CaptureMethod::Manual => Ok(()),
-            enums::CaptureMethod::Automatic
+            enums::CaptureMethod::Automatic => Ok(()),
+            enums::CaptureMethod::Manual
             | enums::CaptureMethod::ManualMultiple
             | enums::CaptureMethod::Scheduled => Err(utils::construct_not_supported_error_report(
                 capture_method,
@@ -615,7 +615,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> {
         Ok(Some(
             services::RequestBuilder::new()
-                .method(services::Method::Get)
+                .method(services::Method::Post)
                 .url(&types::RefundSyncType::get_url(self, req, connectors)?)
                 .attach_default_headers()
                 .headers(types::RefundSyncType::get_headers(self, req, connectors)?)
diff --git a/crates/router/src/connector/placetopay/transformers.rs b/crates/router/src/connector/placetopay/transformers.rs
index f1c054b960b..e5dedf6ded0 100644
--- a/crates/router/src/connector/placetopay/transformers.rs
+++ b/crates/router/src/connector/placetopay/transformers.rs
@@ -206,30 +206,43 @@ impl TryFrom<&types::ConnectorAuthType> for PlacetopayAuthType {
 
 #[derive(Debug, Clone, Deserialize, Serialize)]
 #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
-pub enum PlacetopayStatus {
+pub enum PlacetopayTransactionStatus {
     Ok,
     Failed,
     Approved,
+    // ApprovedPartial,
+    // PartialExpired,
     Rejected,
     Pending,
     PendingValidation,
     PendingProcess,
+    // Refunded,
+    // Reversed,
+    Error,
+    // Unknown,
+    // Manual,
+    // Dispute,
+    //The statuses that are commented out are awaiting clarification on the connector.
 }
 
 #[derive(Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct PlacetopayStatusResponse {
-    status: PlacetopayStatus,
+    status: PlacetopayTransactionStatus,
 }
 
-impl From<PlacetopayStatus> for enums::AttemptStatus {
-    fn from(item: PlacetopayStatus) -> Self {
+impl From<PlacetopayTransactionStatus> for enums::AttemptStatus {
+    fn from(item: PlacetopayTransactionStatus) -> Self {
         match item {
-            PlacetopayStatus::Approved | PlacetopayStatus::Ok => Self::Authorized,
-            PlacetopayStatus::Failed | PlacetopayStatus::Rejected => Self::Failure,
-            PlacetopayStatus::Pending
-            | PlacetopayStatus::PendingValidation
-            | PlacetopayStatus::PendingProcess => Self::Authorizing,
+            PlacetopayTransactionStatus::Approved | PlacetopayTransactionStatus::Ok => {
+                Self::Charged
+            }
+            PlacetopayTransactionStatus::Failed
+            | PlacetopayTransactionStatus::Rejected
+            | PlacetopayTransactionStatus::Error => Self::Failure,
+            PlacetopayTransactionStatus::Pending
+            | PlacetopayTransactionStatus::PendingValidation
+            | PlacetopayTransactionStatus::PendingProcess => Self::Pending,
         }
     }
 }
@@ -239,6 +252,7 @@ impl From<PlacetopayStatus> for enums::AttemptStatus {
 pub struct PlacetopayPaymentsResponse {
     status: PlacetopayStatusResponse,
     internal_reference: u64,
+    authorization: Option<String>,
 }
 
 impl<F, T>
@@ -263,7 +277,11 @@ impl<F, T>
                 ),
                 redirection_data: None,
                 mandate_reference: None,
-                connector_metadata: None,
+                connector_metadata: item
+                    .response
+                    .authorization
+                    .clone()
+                    .map(|authorization| serde_json::json!(authorization)),
                 network_txn_id: None,
                 connector_response_reference_id: None,
                 incremental_authorization_allowed: None,
@@ -281,55 +299,90 @@ pub struct PlacetopayRefundRequest {
     auth: PlacetopayAuth,
     internal_reference: u64,
     action: PlacetopayNextAction,
+    authorization: Option<String>,
 }
 
 impl<F> TryFrom<&types::RefundsRouterData<F>> for PlacetopayRefundRequest {
     type Error = error_stack::Report<errors::ConnectorError>;
     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
-        let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?;
-        let internal_reference = item
-            .request
-            .connector_transaction_id
-            .parse::<u64>()
-            .into_report()
-            .change_context(errors::ConnectorError::RequestEncodingFailed)?;
-        let action = PlacetopayNextAction::Refund;
-
-        Ok(Self {
-            auth,
-            internal_reference,
-            action,
-        })
+        if item.request.refund_amount == item.request.payment_amount {
+            let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?;
+
+            let internal_reference = item
+                .request
+                .connector_transaction_id
+                .parse::<u64>()
+                .into_report()
+                .change_context(errors::ConnectorError::RequestEncodingFailed)?;
+            let action = PlacetopayNextAction::Reverse;
+            let authorization = match item.request.connector_metadata.clone() {
+                Some(metadata) => metadata.as_str().map(|auth| auth.to_string()),
+                None => None,
+            };
+            Ok(Self {
+                auth,
+                internal_reference,
+                action,
+                authorization,
+            })
+        } else {
+            Err(errors::ConnectorError::NotSupported {
+                message: "Partial Refund".to_string(),
+                connector: "placetopay",
+            }
+            .into())
+        }
     }
 }
 
 impl From<PlacetopayRefundStatus> for enums::RefundStatus {
     fn from(item: PlacetopayRefundStatus) -> Self {
         match item {
-            PlacetopayRefundStatus::Refunded => Self::Success,
-            PlacetopayRefundStatus::Failed | PlacetopayRefundStatus::Rejected => Self::Failure,
-            PlacetopayRefundStatus::Pending | PlacetopayRefundStatus::PendingProcess => {
-                Self::Pending
-            }
+            PlacetopayRefundStatus::Ok
+            | PlacetopayRefundStatus::Approved
+            | PlacetopayRefundStatus::Refunded => Self::Success,
+            PlacetopayRefundStatus::Failed
+            | PlacetopayRefundStatus::Rejected
+            | PlacetopayRefundStatus::Error => Self::Failure,
+            PlacetopayRefundStatus::Pending
+            | PlacetopayRefundStatus::PendingProcess
+            | PlacetopayRefundStatus::PendingValidation => Self::Pending,
         }
     }
 }
 
-#[derive(Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct PlacetopayRefundResponse {
-    status: PlacetopayRefundStatus,
-    internal_reference: u64,
-}
-
 #[derive(Debug, Deserialize, Serialize)]
 #[serde(rename_all = "SCREAMING_SNAKE_CASE")]
 pub enum PlacetopayRefundStatus {
-    Refunded,
-    Rejected,
+    Ok,
     Failed,
+    Approved,
+    // ApprovedPartial,
+    // PartialExpired,
+    Rejected,
     Pending,
+    PendingValidation,
     PendingProcess,
+    Refunded,
+    // Reversed,
+    Error,
+    // Unknown,
+    // Manual,
+    // Dispute,
+    //The statuses that are commented out are awaiting clarification on the connector.
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct PlacetopayRefundStatusResponse {
+    status: PlacetopayRefundStatus,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct PlacetopayRefundResponse {
+    status: PlacetopayRefundStatusResponse,
+    internal_reference: u64,
 }
 
 impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResponse>>
@@ -342,7 +395,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResp
         Ok(Self {
             response: Ok(types::RefundsResponseData {
                 connector_refund_id: item.response.internal_reference.to_string(),
-                refund_status: enums::RefundStatus::from(item.response.status),
+                refund_status: enums::RefundStatus::from(item.response.status.status),
             }),
             ..item.data
         })
@@ -383,7 +436,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, PlacetopayRefundRespon
         Ok(Self {
             response: Ok(types::RefundsResponseData {
                 connector_refund_id: item.response.internal_reference.to_string(),
-                refund_status: enums::RefundStatus::from(item.response.status),
+                refund_status: enums::RefundStatus::from(item.response.status.status),
             }),
             ..item.data
         })
@@ -447,6 +500,7 @@ pub struct PlacetopayNextActionRequest {
 #[serde(rename_all = "camelCase")]
 pub enum PlacetopayNextAction {
     Refund,
+    Reverse,
     Void,
     Process,
     Checkout,

## Type of Change
<!-- Put an `x` in the boxes that apply -->

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

## Description
<!-- Describe your changes in detail -->

- The authorization field retrieved during payments for Placetopay is now utilized in refund requests.

The following features have been removed as they are not supported by the connector:
- Manual authorization
- Partial refunds

### 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 the paths where you can find config files:
1. `config`
2. `crates/router/src/configs`
3. `loadtest/config`
-->


## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
https://github.com/juspay/hyperswitch/issues/3893

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
The following flows need to be tested for connector placetopay:

1. Authorization(Auto-capture)
Request: 
```curl
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{
    "amount":320320,
    "currency": "COP",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "deepanshu",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4110770010002837",
            "card_exp_month": "02",
            "card_exp_year": "26",
            "card_holder_name": "joseph",
            "card_cvc": "837"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36",
        "ip_address": "127.2.2.0"
    }
}'
```
Response: 
```json
{
    "payment_id": "pay_6Ra7qnW72e498RBrNgGs",
    "merchant_id": "merchant_1707896273",
    "status": "succeeded",
    "amount": 320320,
    "net_amount": 320320,
    "amount_capturable": 0,
    "amount_received": 320320,
    "connector": "placetopay",
    "client_secret": "pay_6Ra7qnW72e498RBrNgGs_secret_bqPRBHD9bFu6HzOzwkR1",
    "created": "2024-03-01T09:31:37.556Z",
    "currency": "COP",
    "customer_id": "deepanshu",
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "2837",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411077",
            "card_extended_bin": "41107700",
            "card_exp_month": "02",
            "card_exp_year": "26",
            "card_holder_name": "joseph"
        }
    },
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": null,
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "deepanshu",
        "created_at": 1709285497,
        "expires": 1709289097,
        "secret": "epk_f80f7b586ab64a1eae89501b68c09d00"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "1598433361",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_aAoX3JP7KaSPBqGXewox",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_UBdzUxzIT2eGEGnWq7wd",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "expires_on": "2024-03-01T09:46:37.556Z",
    "fingerprint": null
}
```
2. Authorization(Manual capture)
Request: 
```curl
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{
    "amount":320320,
    "currency": "COP",
    "confirm": true,
    "capture_method": "manual",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "deepanshu",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4110770010002837",
            "card_exp_month": "02",
            "card_exp_year": "26",
            "card_holder_name": "joseph",
            "card_cvc": "837"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36",
        "ip_address": "127.2.2.0"
    }
}'
```
Response: 
```json
{
    "error": {
        "type": "invalid_request",
        "message": "Payment method type not supported",
        "code": "HE_03",
        "reason": "manual is not supported by placetopay"
    }
}
```
3. Refunds
Request: 
```curl
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{
  "payment_id": "pay_6Ra7qnW72e498RBrNgGs",
  "refund_type": "instant"
}'
```
Response: 
```json
{
    "refund_id": "ref_dFvFk3gvAKMsWEyWq81d",
    "payment_id": "pay_6Ra7qnW72e498RBrNgGs",
    "amount": 320320,
    "currency": "COP",
    "status": "succeeded",
    "reason": null,
    "metadata": null,
    "error_message": null,
    "error_code": null,
    "created_at": "2024-03-01T09:31:45.539Z",
    "updated_at": "2024-03-01T09:31:45.539Z",
    "connector": "placetopay",
    "profile_id": "pro_aAoX3JP7KaSPBqGXewox",
    "merchant_connector_id": "mca_UBdzUxzIT2eGEGnWq7wd"
}
```
3. Partial Refunds
Request: 
```curl
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: API_KEY_HERE' \
--data '{
    "payment_id": "pay_T5RoR7gNvWAilXweIUOo",
    "amount": 600,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
```
Response: 
```json
{
    "error": {
        "type": "invalid_request",
        "message": "Refund failed while processing with connector. Retry refund",
        "code": "CE_06"
    }
}
```

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [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
- [ ] I added a [CHANGELOG](/CHANGELOG.md) entry if applicable
