mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
fix(stripe): add setup intent sync for stripe (#953)
Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
@ -334,13 +334,22 @@ impl
|
||||
connectors: &settings::Connectors,
|
||||
) -> CustomResult<String, errors::ConnectorError> {
|
||||
let id = req.request.connector_transaction_id.clone();
|
||||
Ok(format!(
|
||||
"{}{}/{}",
|
||||
self.base_url(connectors),
|
||||
"v1/payment_intents",
|
||||
id.get_connector_transaction_id()
|
||||
.change_context(errors::ConnectorError::MissingConnectorTransactionID)?
|
||||
))
|
||||
|
||||
match id.get_connector_transaction_id() {
|
||||
Ok(x) if x.starts_with("set") => Ok(format!(
|
||||
"{}{}/{}",
|
||||
self.base_url(connectors),
|
||||
"v1/setup_intents",
|
||||
x
|
||||
)),
|
||||
Ok(x) => Ok(format!(
|
||||
"{}{}/{}",
|
||||
self.base_url(connectors),
|
||||
"v1/payment_intents",
|
||||
x
|
||||
)),
|
||||
x => x.change_context(errors::ConnectorError::MissingConnectorTransactionID),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_request(
|
||||
@ -368,10 +377,22 @@ impl
|
||||
types::PaymentsAuthorizeData: Clone,
|
||||
types::PaymentsResponseData: Clone,
|
||||
{
|
||||
let response: stripe::PaymentIntentSyncResponse = res
|
||||
.response
|
||||
.parse_struct("PaymentIntentSyncResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
let id = data.request.connector_transaction_id.clone();
|
||||
let response: transformers::PaymentIntentSyncResponse =
|
||||
match id.get_connector_transaction_id() {
|
||||
Ok(x) if x.starts_with("set") => res
|
||||
.response
|
||||
.parse_struct("SetupIntentSyncResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed),
|
||||
Ok(_) => res
|
||||
.response
|
||||
.parse_struct("PaymentIntentSyncResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed),
|
||||
Err(err) => {
|
||||
Err(err).change_context(errors::ConnectorError::MissingConnectorTransactionID)
|
||||
}
|
||||
}?;
|
||||
|
||||
types::RouterData::try_from(types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
|
||||
@ -116,6 +116,7 @@ pub struct SetupIntentRequest {
|
||||
pub confirm: bool,
|
||||
pub usage: Option<enums::FutureUsage>,
|
||||
pub off_session: Option<bool>,
|
||||
pub return_url: Option<String>,
|
||||
#[serde(flatten)]
|
||||
pub payment_data: StripePaymentMethodData,
|
||||
}
|
||||
@ -920,6 +921,7 @@ impl TryFrom<&types::VerifyRouterData> for SetupIntentRequest {
|
||||
metadata_txn_id,
|
||||
metadata_txn_uuid,
|
||||
payment_data,
|
||||
return_url: item.return_url.clone(),
|
||||
off_session: item.request.off_session,
|
||||
usage: item.request.setup_future_usage,
|
||||
})
|
||||
@ -1039,6 +1041,50 @@ impl std::ops::Deref for PaymentIntentSyncResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SetupIntentSyncResponse {
|
||||
#[serde(flatten)]
|
||||
setup_intent_fields: SetupIntentResponse,
|
||||
pub last_payment_error: Option<LastPaymentError>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for SetupIntentSyncResponse {
|
||||
type Target = SetupIntentResponse;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.setup_intent_fields
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SetupIntentSyncResponse> for PaymentIntentSyncResponse {
|
||||
fn from(value: SetupIntentSyncResponse) -> Self {
|
||||
Self {
|
||||
payment_intent_fields: value.setup_intent_fields.into(),
|
||||
last_payment_error: value.last_payment_error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SetupIntentResponse> for PaymentIntentResponse {
|
||||
fn from(value: SetupIntentResponse) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
object: value.object,
|
||||
status: value.status,
|
||||
client_secret: value.client_secret,
|
||||
customer: value.customer,
|
||||
description: None,
|
||||
statement_descriptor: value.statement_descriptor,
|
||||
statement_descriptor_suffix: value.statement_descriptor_suffix,
|
||||
metadata: value.metadata,
|
||||
next_action: value.next_action,
|
||||
payment_method_options: value.payment_method_options,
|
||||
last_payment_error: None,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize)]
|
||||
pub struct SetupIntentResponse {
|
||||
pub id: String,
|
||||
|
||||
Reference in New Issue
Block a user