mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
feat(payment_methods_v2): single use token implementation (#7485)
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in> Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Narayan Bhat <48803246+Narayanbhat166@users.noreply.github.com> Co-authored-by: Anurag Thakur <anurag.thakur@juspay.in> Co-authored-by: Pa1NarK <69745008+pixincreate@users.noreply.github.com> Co-authored-by: Shankar Singh C <83439957+ShankarSinghC@users.noreply.github.com> Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Co-authored-by: hrithikesh026 <hrithikesh.vm@juspay.in> Co-authored-by: Debarati Ghatak <88573135+cookieg13@users.noreply.github.com> Co-authored-by: awasthi21 <107559116+awasthi21@users.noreply.github.com> Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Arindam Sahoo <88739246+arindam-sahoo@users.noreply.github.com> Co-authored-by: Arindam Sahoo <arindam.sahoo@Arindam-Sahoo-F565040VFJ.local> Co-authored-by: Sakil Mostak <73734619+Sakilmostak@users.noreply.github.com> Co-authored-by: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Co-authored-by: Riddhiagrawal001 <50551695+Riddhiagrawal001@users.noreply.github.com> Co-authored-by: Suman Maji <77887221+sumanmaji4@users.noreply.github.com> Co-authored-by: Sandeep Kumar <83278309+tsdk02@users.noreply.github.com> Co-authored-by: Debarshi Gupta <debarshigupta47@gmail.com> Co-authored-by: Debarshi Gupta <debarshi.gupta@Debarshi-Gupta-CM92YWDXFD.local> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Co-authored-by: Swangi Kumari <85639103+swangi-kumari@users.noreply.github.com> Co-authored-by: pranav-arjunan <pranav.arjunan@juspay.in> Co-authored-by: Kashif <kashif.dev@protonmail.com> Co-authored-by: Sagnik Mitra <83326850+ImSagnik007@users.noreply.github.com> Co-authored-by: sweta-kumari-sharma <77436883+Sweta-Kumari-Sharma@users.noreply.github.com>
This commit is contained in:
@ -1343,3 +1343,68 @@ pub fn update_connector_mandate_details_status(
|
||||
payouts: None,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
pub async fn add_token_for_payment_method(
|
||||
router_data: &mut types::RouterData<
|
||||
api::PaymentMethodToken,
|
||||
types::PaymentMethodTokenizationData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
payment_method_data_request: types::PaymentMethodTokenizationData,
|
||||
state: SessionState,
|
||||
merchant_connector_account_details: &hyperswitch_domain_models::merchant_connector_account::MerchantConnectorAccount,
|
||||
) -> RouterResult<types::PspTokenResult> {
|
||||
let connector_id = merchant_connector_account_details.id.clone();
|
||||
let connector_data = api::ConnectorData::get_connector_by_name(
|
||||
&(state.conf.connectors),
|
||||
&merchant_connector_account_details
|
||||
.connector_name
|
||||
.to_string(),
|
||||
api::GetToken::Connector,
|
||||
Some(connector_id.clone()),
|
||||
)?;
|
||||
|
||||
let connector_integration: services::BoxedPaymentConnectorIntegrationInterface<
|
||||
api::PaymentMethodToken,
|
||||
types::PaymentMethodTokenizationData,
|
||||
types::PaymentsResponseData,
|
||||
> = connector_data.connector.get_connector_integration();
|
||||
|
||||
let payment_method_token_response_data_type: Result<
|
||||
types::PaymentsResponseData,
|
||||
types::ErrorResponse,
|
||||
> = Err(types::ErrorResponse::default());
|
||||
|
||||
let payment_method_token_router_data =
|
||||
helpers::router_data_type_conversion::<_, api::PaymentMethodToken, _, _, _, _>(
|
||||
router_data.clone(),
|
||||
payment_method_data_request.clone(),
|
||||
payment_method_token_response_data_type,
|
||||
);
|
||||
|
||||
let connector_integration_response = services::execute_connector_processing_step(
|
||||
&state,
|
||||
connector_integration,
|
||||
&payment_method_token_router_data,
|
||||
payments::CallConnectorAction::Trigger,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.to_payment_failed_response()?;
|
||||
let payment_token_response = connector_integration_response.response.map(|res| {
|
||||
if let types::PaymentsResponseData::TokenizationResponse { token } = res {
|
||||
Ok(token)
|
||||
} else {
|
||||
Err(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("Failed to get token from connector")
|
||||
}
|
||||
});
|
||||
|
||||
match payment_token_response {
|
||||
Ok(token) => Ok(types::PspTokenResult { token: Ok(token?) }),
|
||||
Err(error_response) => Ok(types::PspTokenResult {
|
||||
token: Err(error_response),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user