mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-04 05:59:48 +08:00
feat(connector): (checkout_dot_com) add support for multiple partial captures (#1977)
This commit is contained in:
@ -138,8 +138,10 @@ impl ConnectorValidation for Checkout {
|
|||||||
) -> CustomResult<(), errors::ConnectorError> {
|
) -> CustomResult<(), errors::ConnectorError> {
|
||||||
let capture_method = capture_method.unwrap_or_default();
|
let capture_method = capture_method.unwrap_or_default();
|
||||||
match capture_method {
|
match capture_method {
|
||||||
enums::CaptureMethod::Automatic | enums::CaptureMethod::Manual => Ok(()),
|
enums::CaptureMethod::Automatic
|
||||||
enums::CaptureMethod::ManualMultiple | enums::CaptureMethod::Scheduled => Err(
|
| enums::CaptureMethod::Manual
|
||||||
|
| enums::CaptureMethod::ManualMultiple => Ok(()),
|
||||||
|
enums::CaptureMethod::Scheduled => Err(
|
||||||
connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
|
connector_utils::construct_not_implemented_error_report(capture_method, self.id()),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ use time::PrimitiveDateTime;
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connector::utils::{self, RouterData, WalletData},
|
connector::utils::{self, PaymentsCaptureRequestData, RouterData, WalletData},
|
||||||
consts,
|
consts,
|
||||||
core::errors,
|
core::errors,
|
||||||
services,
|
services,
|
||||||
@ -573,6 +573,7 @@ pub struct PaymentCaptureRequest {
|
|||||||
pub amount: Option<i64>,
|
pub amount: Option<i64>,
|
||||||
pub capture_type: Option<CaptureType>,
|
pub capture_type: Option<CaptureType>,
|
||||||
pub processing_channel_id: Secret<String>,
|
pub processing_channel_id: Secret<String>,
|
||||||
|
pub reference: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&types::PaymentsCaptureRouterData> for PaymentCaptureRequest {
|
impl TryFrom<&types::PaymentsCaptureRouterData> for PaymentCaptureRequest {
|
||||||
@ -581,10 +582,21 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for PaymentCaptureRequest {
|
|||||||
let connector_auth = &item.connector_auth_type;
|
let connector_auth = &item.connector_auth_type;
|
||||||
let auth_type: CheckoutAuthType = connector_auth.try_into()?;
|
let auth_type: CheckoutAuthType = connector_auth.try_into()?;
|
||||||
let processing_channel_id = auth_type.processing_channel_id;
|
let processing_channel_id = auth_type.processing_channel_id;
|
||||||
|
let capture_type = if item.request.is_multiple_capture() {
|
||||||
|
CaptureType::NonFinal
|
||||||
|
} else {
|
||||||
|
CaptureType::Final
|
||||||
|
};
|
||||||
|
let reference = item
|
||||||
|
.request
|
||||||
|
.multiple_capture_data
|
||||||
|
.as_ref()
|
||||||
|
.map(|multiple_capture_data| multiple_capture_data.capture_reference.clone());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
amount: Some(item.request.amount_to_capture),
|
amount: Some(item.request.amount_to_capture),
|
||||||
capture_type: Some(CaptureType::Final),
|
capture_type: Some(capture_type),
|
||||||
processing_channel_id,
|
processing_channel_id,
|
||||||
|
reference, // hyperswitch's reference for this capture
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,6 +604,7 @@ impl TryFrom<&types::PaymentsCaptureRouterData> for PaymentCaptureRequest {
|
|||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct PaymentCaptureResponse {
|
pub struct PaymentCaptureResponse {
|
||||||
pub action_id: String,
|
pub action_id: String,
|
||||||
|
pub reference: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<types::PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
|
impl TryFrom<types::PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
|
||||||
@ -609,16 +622,23 @@ impl TryFrom<types::PaymentsCaptureResponseRouterData<PaymentCaptureResponse>>
|
|||||||
} else {
|
} else {
|
||||||
(enums::AttemptStatus::Pending, None)
|
(enums::AttemptStatus::Pending, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if multiple capture request, return capture action_id so that it will be updated in the captures table.
|
||||||
|
// else return previous connector_transaction_id.
|
||||||
|
let resource_id = if item.data.request.is_multiple_capture() {
|
||||||
|
item.response.action_id
|
||||||
|
} else {
|
||||||
|
item.data.request.connector_transaction_id.to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(
|
resource_id: types::ResponseId::ConnectorTransactionId(resource_id),
|
||||||
item.data.request.connector_transaction_id.to_owned(),
|
|
||||||
),
|
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
mandate_reference: None,
|
mandate_reference: None,
|
||||||
connector_metadata: None,
|
connector_metadata: None,
|
||||||
network_txn_id: None,
|
network_txn_id: None,
|
||||||
connector_response_reference_id: None,
|
connector_response_reference_id: item.response.reference,
|
||||||
}),
|
}),
|
||||||
status,
|
status,
|
||||||
amount_captured,
|
amount_captured,
|
||||||
|
|||||||
@ -239,6 +239,16 @@ impl PaymentsPreProcessingData for types::PaymentsPreProcessingData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait PaymentsCaptureRequestData {
|
||||||
|
fn is_multiple_capture(&self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PaymentsCaptureRequestData for types::PaymentsCaptureData {
|
||||||
|
fn is_multiple_capture(&self) -> bool {
|
||||||
|
self.multiple_capture_data.is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait PaymentsAuthorizeRequestData {
|
pub trait PaymentsAuthorizeRequestData {
|
||||||
fn is_auto_capture(&self) -> Result<bool, Error>;
|
fn is_auto_capture(&self) -> Result<bool, Error>;
|
||||||
fn get_email(&self) -> Result<Email, Error>;
|
fn get_email(&self) -> Result<Email, Error>;
|
||||||
|
|||||||
@ -199,10 +199,7 @@ pub trait ConnectorIntegration<T, Req, Resp>: ConnectorIntegrationAny<T, Req, Re
|
|||||||
fn get_multiple_capture_sync_method(
|
fn get_multiple_capture_sync_method(
|
||||||
&self,
|
&self,
|
||||||
) -> CustomResult<CaptureSyncMethod, errors::ConnectorError> {
|
) -> CustomResult<CaptureSyncMethod, errors::ConnectorError> {
|
||||||
Err(
|
Err(errors::ConnectorError::NotImplemented("multiple capture sync".into()).into())
|
||||||
errors::ConnectorError::NotImplemented("multiple capture sync not implemented".into())
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_certificate(
|
fn get_certificate(
|
||||||
|
|||||||
Reference in New Issue
Block a user