Bug: refactor(connector): [stripebilling] Change BillingConnectorPaymentSync from charges api to payment intents api.



Change the url from charge api to stripes payment intent api.
diff --git a/crates/hyperswitch_connectors/src/connectors/stripebilling.rs b/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
index 3fe121a1fc3..39a8e5a0dae 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripebilling.rs
@@ -599,7 +599,7 @@ impl
         connectors: &Connectors,
     ) -> CustomResult<String, errors::ConnectorError> {
         Ok(format!(
-            "{}v1/charges/{}",
+            "{}v1/payment_intents/{}?expand[0]=latest_charge",
             self.base_url(connectors),
             req.request.billing_connector_psync_id
         ))
@@ -632,10 +632,10 @@ impl
         recovery_router_data_types::BillingConnectorPaymentsSyncRouterData,
         errors::ConnectorError,
     > {
-        let response: stripebilling::StripebillingRecoveryDetailsData = res
+        let response: stripebilling::StripebillingBillingConnectorPaymentSyncResponseData = res
             .response
-            .parse_struct::<stripebilling::StripebillingRecoveryDetailsData>(
-                "StripebillingRecoveryDetailsData",
+            .parse_struct::<stripebilling::StripebillingBillingConnectorPaymentSyncResponseData>(
+                "StripebillingBillingConnectorPaymentSyncResponseData",
             )
             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
 
@@ -807,7 +807,9 @@ impl webhooks::IncomingWebhook for Stripebilling {
             stripebilling::StripebillingWebhookBody::get_webhook_object_from_body(request.body)
                 .change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
         Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
-            api_models::payments::PaymentIdType::ConnectorTransactionId(webhook.data.object.charge),
+            api_models::payments::PaymentIdType::ConnectorTransactionId(
+                webhook.data.object.payment_intent,
+            ),
         ))
     }
 
diff --git a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
index 3ff7d04fde6..1056006642f 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs
@@ -296,6 +296,7 @@ pub struct StripebillingWebhookObject {
     #[serde(rename = "amount_remaining")]
     pub amount: common_utils::types::MinorUnit,
     pub charge: String,
+    pub payment_intent: String,
 }
 
 #[derive(Debug, Serialize, Deserialize)]
@@ -346,7 +347,12 @@ impl TryFrom<StripebillingInvoiceBody> for revenue_recovery::RevenueRecoveryInvo
 }
 
 #[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct StripebillingRecoveryDetailsData {
+pub struct StripebillingBillingConnectorPaymentSyncResponseData {
+    pub latest_charge: StripebillingLatestChargeData,
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone)]
+pub struct StripebillingLatestChargeData {
     #[serde(rename = "id")]
     pub charge_id: String,
     pub status: StripebillingChargeStatus,
@@ -410,7 +416,7 @@ impl
     TryFrom<
         ResponseRouterData<
             recovery_router_flows::BillingConnectorPaymentsSync,
-            StripebillingRecoveryDetailsData,
+            StripebillingBillingConnectorPaymentSyncResponseData,
             recovery_request_types::BillingConnectorPaymentsSyncRequest,
             recovery_response_types::BillingConnectorPaymentsSyncResponse,
         >,
@@ -420,45 +426,45 @@ impl
     fn try_from(
         item: ResponseRouterData<
             recovery_router_flows::BillingConnectorPaymentsSync,
-            StripebillingRecoveryDetailsData,
+            StripebillingBillingConnectorPaymentSyncResponseData,
             recovery_request_types::BillingConnectorPaymentsSyncRequest,
             recovery_response_types::BillingConnectorPaymentsSyncResponse,
         >,
     ) -> Result<Self, Self::Error> {
-        let merchant_reference_id = id_type::PaymentReferenceId::from_str(
-            &item.response.invoice_id,
-        )
-        .change_context(errors::ConnectorError::MissingRequiredField {
-            field_name: "invoice_id",
-        })?;
+        let charge_details = item.response.latest_charge;
+        let merchant_reference_id =
+            id_type::PaymentReferenceId::from_str(charge_details.invoice_id.as_str())
+                .change_context(errors::ConnectorError::MissingRequiredField {
+                    field_name: "invoice_id",
+                })?;
         let connector_transaction_id = Some(common_utils::types::ConnectorTransactionId::from(
-            item.response.charge_id,
+            charge_details.charge_id,
         ));
 
         Ok(Self {
             response: Ok(
                 recovery_response_types::BillingConnectorPaymentsSyncResponse {
-                    status: item.response.status.into(),
-                    amount: item.response.amount,
-                    currency: item.response.currency,
+                    status: charge_details.status.into(),
+                    amount: charge_details.amount,
+                    currency: charge_details.currency,
                     merchant_reference_id,
                     connector_account_reference_id:
                         MCA_ID_IDENTIFIER_FOR_STRIPE_IN_STRIPEBILLING_MCA_FEAATURE_METADATA
                             .to_string(),
                     connector_transaction_id,
-                    error_code: item.response.failure_code,
-                    error_message: item.response.failure_message,
-                    processor_payment_method_token: item.response.payment_method,
-                    connector_customer_id: item.response.customer,
-                    transaction_created_at: Some(item.response.created),
+                    error_code: charge_details.failure_code,
+                    error_message: charge_details.failure_message,
+                    processor_payment_method_token: charge_details.payment_method,
+                    connector_customer_id: charge_details.customer,
+                    transaction_created_at: Some(charge_details.created),
                     payment_method_sub_type: common_enums::PaymentMethodType::from(
-                        item.response
+                        charge_details
                             .payment_method_details
                             .card_funding_type
                             .funding,
                     ),
                     payment_method_type: common_enums::PaymentMethod::from(
-                        item.response.payment_method_details.type_of_payment_method,
+                        charge_details.payment_method_details.type_of_payment_method,
                     ),
                 },
             ),


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

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

## Description
This PR changes the url of billing connector payment sync flow from using stripe charge api to stripe payment intents api. Because in Recovery Flow there is a chance to call stripe's psync flow to update the error codes and other details for an attempt. And psync flow accepts payment intent id rather than the charge id. To reuse the existing flow we need payment_intent id to propogate.


### 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



## 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)?
-->
To test this You can follow the steps of this PR: #7461
Tested it locally. And the logs are as following.
<img width="1290" alt="Screenshot 2025-04-24 at 6 10 52 PM" src="https://github.com/user-attachments/assets/7803e047-7ef5-4f58-85a5-f00313f3ab04" />
<img width="1296" alt="Screenshot 2025-04-24 at 6 11 02 PM" src="https://github.com/user-attachments/assets/80049b8e-17fc-40f3-b6ae-d5977ea3ab79" />
<img width="1288" alt="Screenshot 2025-04-24 at 6 10 25 PM" src="https://github.com/user-attachments/assets/cc252496-1924-4e9d-8daa-563c15e85979" />


## 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

