Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions crates/router/src/connector/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,30 +1242,43 @@ impl api::IncomingWebhook for Checkout {
.body
.parse_struct("CheckoutWebhookBody")
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;

if checkout::is_chargeback_event(&details.transaction_type) {
return Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
details
.data
.payment_id
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
),
));
}
if checkout::is_refund_event(&details.transaction_type) {
return Ok(api_models::webhooks::ObjectReferenceId::RefundId(
api_models::webhooks::RefundIdType::ConnectorRefundId(
details
.data
.action_id
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
),
));
}
Ok(api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(details.data.id),
))
let ref_id: api_models::webhooks::ObjectReferenceId =
if checkout::is_chargeback_event(&details.transaction_type) {
let reference = match details.data.reference {
Some(reference) => {
api_models::payments::PaymentIdType::PaymentAttemptId(reference)
}
None => api_models::payments::PaymentIdType::ConnectorTransactionId(
details
.data
.payment_id
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
),
};
api_models::webhooks::ObjectReferenceId::PaymentId(reference)
} else if checkout::is_refund_event(&details.transaction_type) {
let refund_reference = match details.data.reference {
Some(reference) => api_models::webhooks::RefundIdType::RefundId(reference),
None => api_models::webhooks::RefundIdType::ConnectorRefundId(
details
.data
.action_id
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?,
),
};
api_models::webhooks::ObjectReferenceId::RefundId(refund_reference)
} else {
let reference_id = match details.data.reference {
Some(reference) => {
api_models::payments::PaymentIdType::PaymentAttemptId(reference)
}
None => {
api_models::payments::PaymentIdType::ConnectorTransactionId(details.data.id)
}
};
api_models::webhooks::ObjectReferenceId::PaymentId(reference_id)
};
Ok(ref_id)
}

fn get_webhook_event_type(
Expand Down
92 changes: 80 additions & 12 deletions crates/router/src/connector/checkout/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub struct PaymentsRequest {
pub return_url: ReturnUrl,
pub capture: bool,
pub reference: String,
pub metadata: Option<Secret<serde_json::Value>>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -428,6 +429,7 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
let connector_auth = &item.router_data.connector_auth_type;
let auth_type: CheckoutAuthType = connector_auth.try_into()?;
let processing_channel_id = auth_type.processing_channel_id;
let metadata = item.router_data.request.metadata.clone();
Ok(Self {
source: source_var,
amount: item.amount.to_owned(),
Expand All @@ -437,6 +439,7 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
return_url,
capture,
reference: item.router_data.connector_request_reference_id.clone(),
metadata,
})
}
}
Expand All @@ -450,6 +453,16 @@ pub enum CheckoutPaymentStatus {
CardVerified,
Declined,
Captured,
#[serde(rename = "Retry Scheduled")]
RetryScheduled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please raise this with connector and get clarity on when do we get this status?

Voided,
#[serde(rename = "Partially Captured")]
PartiallyCaptured,
#[serde(rename = "Partially Refunded")]
PartiallyRefunded,
Refunded,
Canceled,
Expired,
}

impl TryFrom<CheckoutWebhookEventType> for CheckoutPaymentStatus {
Expand All @@ -460,7 +473,14 @@ impl TryFrom<CheckoutWebhookEventType> for CheckoutPaymentStatus {
CheckoutWebhookEventType::PaymentCaptured => Ok(Self::Captured),
CheckoutWebhookEventType::PaymentDeclined => Ok(Self::Declined),
CheckoutWebhookEventType::AuthenticationStarted
| CheckoutWebhookEventType::AuthenticationApproved => Ok(Self::Pending),
| CheckoutWebhookEventType::AuthenticationApproved
| CheckoutWebhookEventType::AuthenticationAttempted => Ok(Self::Pending),
CheckoutWebhookEventType::AuthenticationExpired
| CheckoutWebhookEventType::AuthenticationFailed
| CheckoutWebhookEventType::PaymentAuthenticationFailed
| CheckoutWebhookEventType::PaymentCaptureDeclined => Ok(Self::Declined),
CheckoutWebhookEventType::PaymentCanceled => Ok(Self::Canceled),
CheckoutWebhookEventType::PaymentVoided => Ok(Self::Voided),
CheckoutWebhookEventType::PaymentRefunded
| CheckoutWebhookEventType::PaymentRefundDeclined
| CheckoutWebhookEventType::DisputeReceived
Expand Down Expand Up @@ -494,10 +514,18 @@ impl ForeignFrom<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)> for enum
Self::Authorized
}
}
CheckoutPaymentStatus::Captured => Self::Charged,
CheckoutPaymentStatus::Declined => Self::Failure,
CheckoutPaymentStatus::Captured
| CheckoutPaymentStatus::PartiallyRefunded
| CheckoutPaymentStatus::Refunded => Self::Charged,
CheckoutPaymentStatus::PartiallyCaptured => Self::PartialCharged,
CheckoutPaymentStatus::Declined
| CheckoutPaymentStatus::Expired
| CheckoutPaymentStatus::Canceled => Self::Failure,
CheckoutPaymentStatus::Pending => Self::AuthenticationPending,
CheckoutPaymentStatus::CardVerified => Self::Pending,
CheckoutPaymentStatus::CardVerified | CheckoutPaymentStatus::RetryScheduled => {
Self::Pending
}
CheckoutPaymentStatus::Voided => Self::Voided,
}
}
}
Expand All @@ -514,10 +542,18 @@ impl ForeignFrom<(CheckoutPaymentStatus, CheckoutPaymentIntent)> for enums::Atte
Self::Authorized
}
}
CheckoutPaymentStatus::Captured => Self::Charged,
CheckoutPaymentStatus::Declined => Self::Failure,
CheckoutPaymentStatus::Captured
| CheckoutPaymentStatus::PartiallyRefunded
| CheckoutPaymentStatus::Refunded => Self::Charged,
CheckoutPaymentStatus::PartiallyCaptured => Self::PartialCharged,
CheckoutPaymentStatus::Declined
| CheckoutPaymentStatus::Expired
| CheckoutPaymentStatus::Canceled => Self::Failure,
CheckoutPaymentStatus::Pending => Self::AuthenticationPending,
CheckoutPaymentStatus::CardVerified => Self::Pending,
CheckoutPaymentStatus::CardVerified | CheckoutPaymentStatus::RetryScheduled => {
Self::Pending
}
CheckoutPaymentStatus::Voided => Self::Voided,
}
}
}
Expand All @@ -537,10 +573,18 @@ impl ForeignFrom<(CheckoutPaymentStatus, Option<Balances>)> for enums::AttemptSt
Self::Authorized
}
}
CheckoutPaymentStatus::Captured => Self::Charged,
CheckoutPaymentStatus::Declined => Self::Failure,
CheckoutPaymentStatus::Captured
| CheckoutPaymentStatus::PartiallyRefunded
| CheckoutPaymentStatus::Refunded => Self::Charged,
CheckoutPaymentStatus::PartiallyCaptured => Self::PartialCharged,
CheckoutPaymentStatus::Declined
| CheckoutPaymentStatus::Expired
| CheckoutPaymentStatus::Canceled => Self::Failure,
CheckoutPaymentStatus::Pending => Self::AuthenticationPending,
CheckoutPaymentStatus::CardVerified => Self::Pending,
CheckoutPaymentStatus::CardVerified | CheckoutPaymentStatus::RetryScheduled => {
Self::Pending
}
CheckoutPaymentStatus::Voided => Self::Voided,
}
}
}
Expand All @@ -559,6 +603,7 @@ pub struct Links {
pub struct PaymentsResponse {
id: String,
amount: Option<i32>,
currency: Option<String>,
action_id: Option<String>,
status: CheckoutPaymentStatus,
#[serde(rename = "_links")]
Expand All @@ -567,6 +612,8 @@ pub struct PaymentsResponse {
reference: Option<String>,
response_code: Option<String>,
response_summary: Option<String>,
approved: Option<bool>,
processed_on: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -1132,11 +1179,18 @@ pub fn is_chargeback_event(event_code: &CheckoutWebhookEventType) -> bool {
pub enum CheckoutWebhookEventType {
AuthenticationStarted,
AuthenticationApproved,
AuthenticationAttempted,
AuthenticationExpired,
AuthenticationFailed,
PaymentApproved,
PaymentCaptured,
PaymentDeclined,
PaymentRefunded,
PaymentRefundDeclined,
PaymentAuthenticationFailed,
PaymentCanceled,
PaymentCaptureDeclined,
PaymentVoided,
DisputeReceived,
DisputeExpired,
DisputeAccepted,
Expand Down Expand Up @@ -1169,6 +1223,8 @@ pub struct CheckoutWebhookData {
pub response_code: Option<String>,
pub response_summary: Option<String>,
pub currency: String,
pub processed_on: Option<String>,
pub approved: Option<bool>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -1220,13 +1276,22 @@ pub enum CheckoutDisputeTransactionType {
impl From<CheckoutWebhookEventType> for api::IncomingWebhookEvent {
fn from(transaction_type: CheckoutWebhookEventType) -> Self {
match transaction_type {
CheckoutWebhookEventType::AuthenticationStarted => Self::EventNotSupported,
CheckoutWebhookEventType::AuthenticationApproved => Self::EventNotSupported,
CheckoutWebhookEventType::AuthenticationStarted
| CheckoutWebhookEventType::AuthenticationApproved
| CheckoutWebhookEventType::AuthenticationAttempted => Self::EventNotSupported,
CheckoutWebhookEventType::AuthenticationExpired
| CheckoutWebhookEventType::AuthenticationFailed
| CheckoutWebhookEventType::PaymentAuthenticationFailed => {
Self::PaymentIntentAuthorizationFailure
}
CheckoutWebhookEventType::PaymentApproved => Self::EventNotSupported,
CheckoutWebhookEventType::PaymentCaptured => Self::PaymentIntentSuccess,
CheckoutWebhookEventType::PaymentDeclined => Self::PaymentIntentFailure,
CheckoutWebhookEventType::PaymentRefunded => Self::RefundSuccess,
CheckoutWebhookEventType::PaymentRefundDeclined => Self::RefundFailure,
CheckoutWebhookEventType::PaymentCanceled => Self::PaymentIntentCancelFailure,
CheckoutWebhookEventType::PaymentCaptureDeclined => Self::PaymentIntentCaptureFailure,
CheckoutWebhookEventType::PaymentVoided => Self::PaymentIntentCancelled,
CheckoutWebhookEventType::DisputeReceived
| CheckoutWebhookEventType::DisputeEvidenceRequired => Self::DisputeOpened,
CheckoutWebhookEventType::DisputeExpired => Self::DisputeExpired,
Expand Down Expand Up @@ -1329,6 +1394,9 @@ impl TryFrom<&api::IncomingWebhookRequestDetails<'_>> for PaymentsResponse {
response_code: data.response_code,
response_summary: data.response_summary,
action_id: data.action_id,
currency: Some(data.currency),
processed_on: data.processed_on,
approved: data.approved,
};

Ok(psync_struct)
Expand Down