mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
fix(core): store payment token in payment attempt (#146)
This commit is contained in:
@ -349,11 +349,12 @@ impl
|
||||
data: &types::PaymentsAuthorizeRouterData,
|
||||
res: Response,
|
||||
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
|
||||
logger::debug!(stripe_payments_create_response=?res);
|
||||
let response: stripe::PaymentIntentResponse = res
|
||||
.response
|
||||
.parse_struct("PaymentIntentResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
logger::debug!(payments_create_response=?response);
|
||||
|
||||
types::RouterData::try_from(types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
|
||||
@ -373,6 +373,7 @@ impl<F, T>
|
||||
StripePaymentMethodOptions::Card {
|
||||
mandate_options, ..
|
||||
} => mandate_options.map(|mandate_options| mandate_options.reference),
|
||||
StripePaymentMethodOptions::Klarna {} => None,
|
||||
});
|
||||
|
||||
Ok(types::RouterData {
|
||||
@ -424,6 +425,7 @@ impl<F, T>
|
||||
StripePaymentMethodOptions::Card {
|
||||
mandate_options, ..
|
||||
} => mandate_options.map(|mandate_option| mandate_option.reference),
|
||||
StripePaymentMethodOptions::Klarna {} => None,
|
||||
});
|
||||
|
||||
Ok(types::RouterData {
|
||||
@ -662,6 +664,7 @@ pub enum StripePaymentMethodOptions {
|
||||
Card {
|
||||
mandate_options: Option<StripeMandateOptions>,
|
||||
},
|
||||
Klarna {},
|
||||
}
|
||||
// #[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
|
||||
// pub struct Card
|
||||
|
||||
@ -356,7 +356,6 @@ where
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn call_multiple_connectors_service<F, Op, Req>(
|
||||
state: &AppState,
|
||||
merchant_account: &storage::MerchantAccount,
|
||||
@ -521,15 +520,7 @@ pub fn should_call_connector<Op: Debug, F: Clone>(
|
||||
payment_data: &PaymentData<F>,
|
||||
) -> bool {
|
||||
match format!("{:?}", operation).as_str() {
|
||||
"PaymentConfirm" => {
|
||||
payment_data
|
||||
.payment_attempt
|
||||
.authentication_type
|
||||
.unwrap_or_default()
|
||||
== enums::AuthenticationType::NoThreeDs
|
||||
|| payment_data.payment_attempt.payment_method
|
||||
== Some(enums::PaymentMethodType::PayLater)
|
||||
}
|
||||
"PaymentConfirm" => true,
|
||||
"PaymentStart" => {
|
||||
!matches!(
|
||||
payment_data.payment_intent.status,
|
||||
|
||||
@ -197,6 +197,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
};
|
||||
|
||||
let connector = payment_data.payment_attempt.connector.clone();
|
||||
let payment_token = payment_data.token.clone();
|
||||
|
||||
payment_data.payment_attempt = db
|
||||
.update_payment_attempt(
|
||||
@ -206,6 +207,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
payment_method,
|
||||
browser_info,
|
||||
connector,
|
||||
payment_token,
|
||||
},
|
||||
storage_scheme,
|
||||
)
|
||||
|
||||
@ -250,6 +250,23 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let payment_token = payment_data.token.clone();
|
||||
let connector = payment_data.payment_attempt.connector.clone();
|
||||
|
||||
payment_data.payment_attempt = db
|
||||
.update_payment_attempt(
|
||||
payment_data.payment_attempt,
|
||||
storage::PaymentAttemptUpdate::UpdateTrackers {
|
||||
payment_token,
|
||||
connector,
|
||||
},
|
||||
storage_scheme,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
|
||||
})?;
|
||||
|
||||
let customer_id = payment_data.payment_intent.customer_id.clone();
|
||||
payment_data.payment_intent = db
|
||||
.update_payment_intent(
|
||||
|
||||
@ -240,6 +240,7 @@ impl PaymentAttemptInterface for MockDb {
|
||||
amount_to_capture: payment_attempt.amount_to_capture,
|
||||
mandate_id: None,
|
||||
browser_info: None,
|
||||
payment_token: None,
|
||||
error_code: payment_attempt.error_code,
|
||||
};
|
||||
payment_attempts.push(payment_attempt.clone());
|
||||
@ -371,6 +372,7 @@ mod storage {
|
||||
cancellation_reason: payment_attempt.cancellation_reason.clone(),
|
||||
mandate_id: payment_attempt.mandate_id.clone(),
|
||||
browser_info: payment_attempt.browser_info.clone(),
|
||||
payment_token: payment_attempt.payment_token.clone(),
|
||||
error_code: payment_attempt.error_code.clone(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user