Skip to content

Commit a161f24

Browse files
Debarshi-GuptaDebarshi Guptadebarshi.guptahyperswitch-bot[bot]
authored
fix(connector): [BRAINTREE] Added fix for Braintree Creds Identifier (#7501)
Co-authored-by: Debarshi Gupta <[email protected]> Co-authored-by: debarshi.gupta <[email protected]> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent f8a8d2a commit a161f24

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

Diff for: crates/router/src/core/payments.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,12 @@ impl PaymentRedirectFlow for PaymentRedirectCompleteAuthorize {
23282328
let payment_confirm_req = api::PaymentsRequest {
23292329
payment_id: Some(req.resource_id.clone()),
23302330
merchant_id: req.merchant_id.clone(),
2331+
merchant_connector_details: req.creds_identifier.map(|creds_id| {
2332+
api::MerchantConnectorDetailsWrap {
2333+
creds_identifier: creds_id,
2334+
encoded_data: None,
2335+
}
2336+
}),
23312337
feature_metadata: Some(api_models::payments::FeatureMetadata {
23322338
redirect_response: Some(api_models::payments::RedirectResponse {
23332339
param: req.param.map(Secret::new),

Diff for: crates/router/src/core/payments/helpers.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,18 @@ pub fn create_complete_authorize_url(
12621262
router_base_url: &String,
12631263
payment_attempt: &PaymentAttempt,
12641264
connector_name: impl std::fmt::Display,
1265+
creds_identifier: Option<&str>,
12651266
) -> String {
1267+
let creds_identifier = creds_identifier.map_or_else(String::new, |creds_identifier| {
1268+
format!("/{}", creds_identifier)
1269+
});
12661270
format!(
1267-
"{}/payments/{}/{}/redirect/complete/{}",
1271+
"{}/payments/{}/{}/redirect/complete/{}{}",
12681272
router_base_url,
12691273
payment_attempt.payment_id.get_string_repr(),
12701274
payment_attempt.merchant_id.get_string_repr(),
1271-
connector_name
1275+
connector_name,
1276+
creds_identifier
12721277
)
12731278
}
12741279

Diff for: crates/router/src/core/payments/operations/payment_complete_authorize.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
305305
id: profile_id.get_string_repr().to_owned(),
306306
})?;
307307

308+
let creds_identifier =
309+
request
310+
.merchant_connector_details
311+
.as_ref()
312+
.map(|merchant_connector_details| {
313+
merchant_connector_details.creds_identifier.to_owned()
314+
});
315+
308316
let payment_data = PaymentData {
309317
flow: PhantomData,
310318
payment_intent,
@@ -336,7 +344,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
336344
attempts: None,
337345
sessions_token: vec![],
338346
card_cvc: request.card_cvc.clone(),
339-
creds_identifier: None,
347+
creds_identifier,
340348
pm_token: None,
341349
connector_customer_id: None,
342350
recurring_mandate_payment_data,

Diff for: crates/router/src/core/payments/transformers.rs

+6
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
223223
router_base_url,
224224
attempt,
225225
connector_id,
226+
None,
226227
));
227228

228229
let webhook_url = Some(helpers::create_webhook_url(
@@ -888,6 +889,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
888889
router_base_url,
889890
attempt,
890891
connector_id,
892+
None,
891893
));
892894

893895
let webhook_url = Some(helpers::create_webhook_url(
@@ -3120,7 +3122,9 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
31203122
router_base_url,
31213123
attempt,
31223124
connector_name,
3125+
payment_data.creds_identifier.as_deref(),
31233126
));
3127+
31243128
let merchant_connector_account_id_or_connector_name = payment_data
31253129
.payment_attempt
31263130
.merchant_connector_id
@@ -4120,6 +4124,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
41204124
router_base_url,
41214125
attempt,
41224126
connector_name,
4127+
payment_data.creds_identifier.as_deref(),
41234128
));
41244129
let braintree_metadata = payment_data
41254130
.payment_intent
@@ -4234,6 +4239,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
42344239
router_base_url,
42354240
attempt,
42364241
connector_name,
4242+
payment_data.creds_identifier.as_deref(),
42374243
));
42384244
let browser_info: Option<types::BrowserInformation> = payment_data
42394245
.payment_attempt

Diff for: crates/router/src/routes/app.rs

+5
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ impl Payments {
748748
.route(web::get().to(payments::payments_redirect_response))
749749
.route(web::post().to(payments::payments_redirect_response))
750750
)
751+
.service(
752+
web::resource("/{payment_id}/{merchant_id}/redirect/complete/{connector}/{creds_identifier}")
753+
.route(web::get().to(payments::payments_complete_authorize_redirect_with_creds_identifier))
754+
.route(web::post().to(payments::payments_complete_authorize_redirect_with_creds_identifier))
755+
)
751756
.service(
752757
web::resource("/{payment_id}/{merchant_id}/redirect/complete/{connector}")
753758
.route(web::get().to(payments::payments_complete_authorize_redirect))

Diff for: crates/router/src/routes/payments.rs

+52
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,58 @@ pub async fn payments_complete_authorize_redirect(
10861086
.await
10871087
}
10881088

1089+
#[cfg(feature = "v1")]
1090+
#[instrument(skip_all, fields(flow =? Flow::PaymentsRedirect, payment_id))]
1091+
pub async fn payments_complete_authorize_redirect_with_creds_identifier(
1092+
state: web::Data<app::AppState>,
1093+
req: actix_web::HttpRequest,
1094+
json_payload: Option<web::Form<serde_json::Value>>,
1095+
path: web::Path<(
1096+
common_utils::id_type::PaymentId,
1097+
common_utils::id_type::MerchantId,
1098+
String,
1099+
String,
1100+
)>,
1101+
) -> impl Responder {
1102+
let flow = Flow::PaymentsRedirect;
1103+
let (payment_id, merchant_id, connector, creds_identifier) = path.into_inner();
1104+
let param_string = req.query_string();
1105+
1106+
tracing::Span::current().record("payment_id", payment_id.get_string_repr());
1107+
1108+
let payload = payments::PaymentsRedirectResponseData {
1109+
resource_id: payment_types::PaymentIdType::PaymentIntentId(payment_id),
1110+
merchant_id: Some(merchant_id.clone()),
1111+
param: Some(param_string.to_string()),
1112+
json_payload: json_payload.map(|s| s.0),
1113+
force_sync: false,
1114+
connector: Some(connector),
1115+
creds_identifier: Some(creds_identifier),
1116+
};
1117+
let locking_action = payload.get_locking_input(flow.clone());
1118+
Box::pin(api::server_wrap(
1119+
flow,
1120+
state,
1121+
&req,
1122+
payload,
1123+
|state, auth: auth::AuthenticationData, req, req_state| {
1124+
1125+
<payments::PaymentRedirectCompleteAuthorize as PaymentRedirectFlow>::handle_payments_redirect_response(
1126+
&payments::PaymentRedirectCompleteAuthorize {},
1127+
state,
1128+
req_state,
1129+
auth.merchant_account,
1130+
auth.key_store,
1131+
req,
1132+
auth.platform_merchant_account,
1133+
)
1134+
},
1135+
&auth::MerchantIdAuth(merchant_id),
1136+
locking_action,
1137+
))
1138+
.await
1139+
}
1140+
10891141
#[cfg(feature = "v1")]
10901142
#[instrument(skip_all, fields(flow =? Flow::PaymentsCompleteAuthorize, payment_id))]
10911143
pub async fn payments_complete_authorize(

0 commit comments

Comments
 (0)