Skip to content

Commit af5e56e

Browse files
NISHANTH1221Nishanth Challa
andauthored
refactor(connector): [Stripebilling] change Billing Connector Payment Sync url from charges to payment intents api (#7893)
Co-authored-by: Nishanth Challa <[email protected]>
1 parent bbec7a4 commit af5e56e

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

crates/hyperswitch_connectors/src/connectors/stripebilling.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl
599599
connectors: &Connectors,
600600
) -> CustomResult<String, errors::ConnectorError> {
601601
Ok(format!(
602-
"{}v1/charges/{}",
602+
"{}v1/payment_intents/{}?expand[0]=latest_charge",
603603
self.base_url(connectors),
604604
req.request.billing_connector_psync_id
605605
))
@@ -632,10 +632,10 @@ impl
632632
recovery_router_data_types::BillingConnectorPaymentsSyncRouterData,
633633
errors::ConnectorError,
634634
> {
635-
let response: stripebilling::StripebillingRecoveryDetailsData = res
635+
let response: stripebilling::StripebillingBillingConnectorPaymentSyncResponseData = res
636636
.response
637-
.parse_struct::<stripebilling::StripebillingRecoveryDetailsData>(
638-
"StripebillingRecoveryDetailsData",
637+
.parse_struct::<stripebilling::StripebillingBillingConnectorPaymentSyncResponseData>(
638+
"StripebillingBillingConnectorPaymentSyncResponseData",
639639
)
640640
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
641641

@@ -807,7 +807,9 @@ impl webhooks::IncomingWebhook for Stripebilling {
807807
stripebilling::StripebillingWebhookBody::get_webhook_object_from_body(request.body)
808808
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
809809
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
810-
api_models::payments::PaymentIdType::ConnectorTransactionId(webhook.data.object.charge),
810+
api_models::payments::PaymentIdType::ConnectorTransactionId(
811+
webhook.data.object.payment_intent,
812+
),
811813
))
812814
}
813815

crates/hyperswitch_connectors/src/connectors/stripebilling/transformers.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ pub struct StripebillingWebhookObject {
296296
#[serde(rename = "amount_remaining")]
297297
pub amount: common_utils::types::MinorUnit,
298298
pub charge: String,
299+
pub payment_intent: String,
299300
}
300301

301302
#[derive(Debug, Serialize, Deserialize)]
@@ -346,7 +347,12 @@ impl TryFrom<StripebillingInvoiceBody> for revenue_recovery::RevenueRecoveryInvo
346347
}
347348

348349
#[derive(Serialize, Deserialize, Debug, Clone)]
349-
pub struct StripebillingRecoveryDetailsData {
350+
pub struct StripebillingBillingConnectorPaymentSyncResponseData {
351+
pub latest_charge: StripebillingLatestChargeData,
352+
}
353+
354+
#[derive(Serialize, Deserialize, Debug, Clone)]
355+
pub struct StripebillingLatestChargeData {
350356
#[serde(rename = "id")]
351357
pub charge_id: String,
352358
pub status: StripebillingChargeStatus,
@@ -410,7 +416,7 @@ impl
410416
TryFrom<
411417
ResponseRouterData<
412418
recovery_router_flows::BillingConnectorPaymentsSync,
413-
StripebillingRecoveryDetailsData,
419+
StripebillingBillingConnectorPaymentSyncResponseData,
414420
recovery_request_types::BillingConnectorPaymentsSyncRequest,
415421
recovery_response_types::BillingConnectorPaymentsSyncResponse,
416422
>,
@@ -420,45 +426,45 @@ impl
420426
fn try_from(
421427
item: ResponseRouterData<
422428
recovery_router_flows::BillingConnectorPaymentsSync,
423-
StripebillingRecoveryDetailsData,
429+
StripebillingBillingConnectorPaymentSyncResponseData,
424430
recovery_request_types::BillingConnectorPaymentsSyncRequest,
425431
recovery_response_types::BillingConnectorPaymentsSyncResponse,
426432
>,
427433
) -> Result<Self, Self::Error> {
428-
let merchant_reference_id = id_type::PaymentReferenceId::from_str(
429-
&item.response.invoice_id,
430-
)
431-
.change_context(errors::ConnectorError::MissingRequiredField {
432-
field_name: "invoice_id",
433-
})?;
434+
let charge_details = item.response.latest_charge;
435+
let merchant_reference_id =
436+
id_type::PaymentReferenceId::from_str(charge_details.invoice_id.as_str())
437+
.change_context(errors::ConnectorError::MissingRequiredField {
438+
field_name: "invoice_id",
439+
})?;
434440
let connector_transaction_id = Some(common_utils::types::ConnectorTransactionId::from(
435-
item.response.charge_id,
441+
charge_details.charge_id,
436442
));
437443

438444
Ok(Self {
439445
response: Ok(
440446
recovery_response_types::BillingConnectorPaymentsSyncResponse {
441-
status: item.response.status.into(),
442-
amount: item.response.amount,
443-
currency: item.response.currency,
447+
status: charge_details.status.into(),
448+
amount: charge_details.amount,
449+
currency: charge_details.currency,
444450
merchant_reference_id,
445451
connector_account_reference_id:
446452
MCA_ID_IDENTIFIER_FOR_STRIPE_IN_STRIPEBILLING_MCA_FEAATURE_METADATA
447453
.to_string(),
448454
connector_transaction_id,
449-
error_code: item.response.failure_code,
450-
error_message: item.response.failure_message,
451-
processor_payment_method_token: item.response.payment_method,
452-
connector_customer_id: item.response.customer,
453-
transaction_created_at: Some(item.response.created),
455+
error_code: charge_details.failure_code,
456+
error_message: charge_details.failure_message,
457+
processor_payment_method_token: charge_details.payment_method,
458+
connector_customer_id: charge_details.customer,
459+
transaction_created_at: Some(charge_details.created),
454460
payment_method_sub_type: common_enums::PaymentMethodType::from(
455-
item.response
461+
charge_details
456462
.payment_method_details
457463
.card_funding_type
458464
.funding,
459465
),
460466
payment_method_type: common_enums::PaymentMethod::from(
461-
item.response.payment_method_details.type_of_payment_method,
467+
charge_details.payment_method_details.type_of_payment_method,
462468
),
463469
},
464470
),

0 commit comments

Comments
 (0)