fix(core): store payment token in payment attempt (#146)

This commit is contained in:
Narayan Bhat
2022-12-16 12:10:09 +05:30
committed by GitHub
parent bf7f24125f
commit aaa1901c5d
10 changed files with 49 additions and 11 deletions

View File

@ -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(),

View File

@ -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

View File

@ -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,

View File

@ -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,
)

View File

@ -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(

View File

@ -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(),
};

View File

@ -36,6 +36,7 @@ pub struct PaymentAttempt {
pub amount_to_capture: Option<i64>,
pub mandate_id: Option<String>,
pub browser_info: Option<serde_json::Value>,
pub payment_token: Option<String>,
pub error_code: Option<String>,
}
@ -71,6 +72,7 @@ pub struct PaymentAttemptNew {
pub amount_to_capture: Option<i64>,
pub mandate_id: Option<String>,
pub browser_info: Option<serde_json::Value>,
pub payment_token: Option<String>,
pub error_code: Option<String>,
}
@ -83,6 +85,10 @@ pub enum PaymentAttemptUpdate {
authentication_type: Option<storage_enums::AuthenticationType>,
payment_method: Option<storage_enums::PaymentMethodType>,
},
UpdateTrackers {
payment_token: Option<String>,
connector: Option<String>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
},
@ -91,6 +97,7 @@ pub enum PaymentAttemptUpdate {
payment_method: Option<storage_enums::PaymentMethodType>,
browser_info: Option<serde_json::Value>,
connector: Option<String>,
payment_token: Option<String>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
@ -133,6 +140,7 @@ pub struct PaymentAttemptUpdateInternal {
redirect: Option<bool>,
mandate_id: Option<String>,
browser_info: Option<serde_json::Value>,
payment_token: Option<String>,
error_code: Option<String>,
}
@ -155,6 +163,7 @@ impl PaymentAttemptUpdate {
.unwrap_or(source.payment_method_id),
browser_info: pa_update.browser_info,
modified_at: common_utils::date_time::now(),
payment_token: pa_update.payment_token,
..source
}
}
@ -192,12 +201,14 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
payment_method,
browser_info,
connector,
payment_token,
} => Self {
status: Some(status),
payment_method,
modified_at: Some(common_utils::date_time::now()),
browser_info,
connector,
payment_token,
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
@ -244,6 +255,14 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
status: Some(status),
..Default::default()
},
PaymentAttemptUpdate::UpdateTrackers {
payment_token,
connector,
} => Self {
payment_token,
connector,
..Default::default()
},
}
}
}

View File

@ -214,6 +214,7 @@ diesel::table! {
mandate_id -> Nullable<Varchar>,
browser_info -> Nullable<Jsonb>,
error_code -> Nullable<Varchar>,
payment_token -> Nullable<Varchar>,
}
}

View File

@ -0,0 +1 @@
ALTER TABLE payment_attempt DROP COLUMN payment_token;

View File

@ -0,0 +1 @@
ALTER TABLE payment_attempt ADD COLUMN payment_token VARCHAR(255);