mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
fix(checkout): status mapping for payment (#442)
This commit is contained in:
@ -279,6 +279,7 @@ impl
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
logger::debug!(raw_response=?res);
|
||||
let response: checkout::ErrorResponse = res
|
||||
.response
|
||||
.parse_struct("ErrorResponse")
|
||||
@ -368,11 +369,11 @@ impl
|
||||
data: &types::PaymentsAuthorizeRouterData,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> {
|
||||
logger::debug!(payments_create_response=?res);
|
||||
let response: checkout::PaymentsResponse = 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(),
|
||||
@ -470,12 +471,13 @@ impl
|
||||
data: &types::PaymentsCancelRouterData,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::PaymentsCancelRouterData, errors::ConnectorError> {
|
||||
logger::debug!(payments_cancel_response=?res);
|
||||
|
||||
let mut response: checkout::PaymentVoidResponse = res
|
||||
.response
|
||||
.parse_struct("PaymentVoidResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
response.status = res.status_code;
|
||||
logger::debug!(payments_create_response=?response);
|
||||
types::RouterData::try_from(types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
|
||||
@ -140,6 +140,33 @@ pub enum CheckoutPaymentStatus {
|
||||
Captured,
|
||||
}
|
||||
|
||||
impl From<transformers::Foreign<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)>>
|
||||
for transformers::Foreign<enums::AttemptStatus>
|
||||
{
|
||||
fn from(
|
||||
item: transformers::Foreign<(CheckoutPaymentStatus, Option<enums::CaptureMethod>)>,
|
||||
) -> Self {
|
||||
let item = item.0;
|
||||
let (status, capture_method) = item;
|
||||
match status {
|
||||
CheckoutPaymentStatus::Authorized => {
|
||||
if capture_method == Some(enums::CaptureMethod::Automatic)
|
||||
|| capture_method.is_none()
|
||||
{
|
||||
enums::AttemptStatus::Charged
|
||||
} else {
|
||||
enums::AttemptStatus::Authorized
|
||||
}
|
||||
}
|
||||
CheckoutPaymentStatus::Captured => enums::AttemptStatus::Charged,
|
||||
CheckoutPaymentStatus::Declined => enums::AttemptStatus::Failure,
|
||||
CheckoutPaymentStatus::Pending => enums::AttemptStatus::AuthenticationPending,
|
||||
CheckoutPaymentStatus::CardVerified => enums::AttemptStatus::Pending,
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<transformers::Foreign<(CheckoutPaymentStatus, Balances)>>
|
||||
for transformers::Foreign<enums::AttemptStatus>
|
||||
{
|
||||
@ -215,7 +242,7 @@ impl TryFrom<types::PaymentsResponseRouterData<PaymentsResponse>>
|
||||
Ok(Self {
|
||||
status: enums::AttemptStatus::foreign_from((
|
||||
item.response.status,
|
||||
item.response.balances,
|
||||
item.data.request.capture_method,
|
||||
)),
|
||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
||||
|
||||
Reference in New Issue
Block a user