Skip to content

Commit

Permalink
feat(core): conditionally return captures list during payment sync. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikesh026 committed Aug 29, 2023
1 parent 63d92c0 commit c2aa014
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,8 @@ pub struct PaymentsRetrieveRequest {
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
pub client_secret: Option<String>,
/// If enabled provides list of captures linked to latest attempt
pub expand_captures: Option<bool>,
/// If enabled provides list of attempts linked to payment intent
pub expand_attempts: Option<bool>,
}
Expand Down Expand Up @@ -2597,6 +2599,8 @@ pub struct PaymentRetrieveBody {
pub force_sync: Option<bool>,
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
pub client_secret: Option<String>,
/// If enabled provides list of captures linked to latest attempt
pub expand_captures: Option<bool>,
/// If enabled provides list of attempts linked to payment intent
pub expand_attempts: Option<bool>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe/payment_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub async fn payment_intents_retrieve(
merchant_connector_details: None,
client_secret: query_payload.client_secret.clone(),
expand_attempts: None,
expand_captures: None,
};

let (auth_type, auth_flow) =
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/compatibility/stripe/setup_intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub async fn setup_intents_retrieve(
merchant_connector_details: None,
client_secret: query_payload.client_secret.clone(),
expand_attempts: None,
expand_captures: None,
};

let (auth_type, auth_flow) =
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
}),
client_secret: None,
expand_attempts: None,
expand_captures: None,
};
payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
state,
Expand Down
5 changes: 4 additions & 1 deletion crates/router/src/core/payments/operations/payment_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ async fn get_tracker_for_sync<
.attach_printable_lazy(|| {
format!("Error while retrieving capture list for, merchant_id: {}, payment_id: {payment_id_str}", merchant_account.merchant_id)
})?;
Some(types::MultipleCaptureData::new_for_sync(captures)?)
Some(types::MultipleCaptureData::new_for_sync(
captures,
request.expand_captures,
)?)
} else {
None
};
Expand Down
25 changes: 16 additions & 9 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,29 @@ where
connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
connector_http_status_code: Option<u16>,
) -> RouterResponse<Self> {
let captures = payment_data
.multiple_capture_data
.and_then(|multiple_capture_data| {
multiple_capture_data
.expand_captures
.and_then(|should_expand| {
should_expand.then_some(
multiple_capture_data
.get_all_captures()
.into_iter()
.cloned()
.collect(),
)
})
});
payments_to_payments_response(
req,
payment_data.payment_attempt,
payment_data.payment_intent,
payment_data.refunds,
payment_data.disputes,
payment_data.attempts,
payment_data
.multiple_capture_data
.map(|multiple_capture_data| {
multiple_capture_data
.get_all_captures()
.into_iter()
.cloned()
.collect()
}),
captures,
payment_data.payment_method_data,
customer,
auth_flow,
Expand Down
8 changes: 7 additions & 1 deletion crates/router/src/core/payments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ pub struct MultipleCaptureData {
// key -> capture_id, value -> Capture
all_captures: HashMap<String, storage::Capture>,
latest_capture: storage::Capture,
pub expand_captures: Option<bool>,
_private: Private, // to restrict direct construction of MultipleCaptureData
}
#[derive(Clone, Debug)]
struct Private {}

impl MultipleCaptureData {
pub fn new_for_sync(captures: Vec<storage::Capture>) -> RouterResult<Self> {
pub fn new_for_sync(
captures: Vec<storage::Capture>,
expand_captures: Option<bool>,
) -> RouterResult<Self> {
let latest_capture = captures
.last()
.ok_or(errors::ApiErrorResponse::InternalServerError)
Expand All @@ -32,6 +36,7 @@ impl MultipleCaptureData {
.collect(),
latest_capture,
_private: Private {},
expand_captures,
};
Ok(multiple_capture_data)
}
Expand All @@ -48,6 +53,7 @@ impl MultipleCaptureData {
.collect(),
latest_capture: new_capture,
_private: Private {},
expand_captures: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
merchant_connector_details: None,
client_secret: None,
expand_attempts: None,
expand_captures: None,
},
services::AuthFlow::Merchant,
consume_or_trigger_flow,
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/routes/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ pub async fn payments_retrieve(
force_sync: json_payload.force_sync.unwrap_or(false),
client_secret: json_payload.client_secret.clone(),
expand_attempts: json_payload.expand_attempts,
expand_captures: json_payload.expand_captures,
..Default::default()
};
let (auth_type, auth_flow) =
Expand Down
10 changes: 10 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8269,6 +8269,11 @@
"description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK",
"nullable": true
},
"expand_captures": {
"type": "boolean",
"description": "If enabled provides list of captures linked to latest attempt",
"nullable": true
},
"expand_attempts": {
"type": "boolean",
"description": "If enabled provides list of attempts linked to payment intent",
Expand Down Expand Up @@ -9447,6 +9452,11 @@
"description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK",
"nullable": true
},
"expand_captures": {
"type": "boolean",
"description": "If enabled provides list of captures linked to latest attempt",
"nullable": true
},
"expand_attempts": {
"type": "boolean",
"description": "If enabled provides list of attempts linked to payment intent",
Expand Down

0 comments on commit c2aa014

Please sign in to comment.