Skip to content

Commit

Permalink
refactor authorize flow and Payment status mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
prasunna09 committed Oct 1, 2023
1 parent c81d8e9 commit 60a2906
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions crates/router/src/connector/iatapay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ impl api::IncomingWebhook for Iatapay {
| iatapay::IatapayPaymentStatus::Tobeinvestigated
| iatapay::IatapayPaymentStatus::Blocked
| iatapay::IatapayPaymentStatus::Locked
| iatapay::IatapayPaymentStatus::Cancel
| iatapay::IatapayPaymentStatus::UnexpectedSettled => {
Ok(api::IncomingWebhookEvent::EventNotSupported)
}
Expand Down
22 changes: 12 additions & 10 deletions crates/router/src/connector/iatapay/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use api_models::enums::PaymentMethod;
use masking::{Secret, SwitchStrategy};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -83,11 +82,7 @@ pub struct IatapayPaymentsRequest {
impl TryFrom<&types::PaymentsAuthorizeRouterData> for IatapayPaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
let payment_method = item.payment_method;
let country = match payment_method {
PaymentMethod::Upi => "IN".to_string(),
_ => item.get_billing_country()?.to_string(),
};
let country = item.get_billing_country()?.to_string();
let return_url = item.get_return_url()?;
let payer_info = match item.request.payment_method_data.clone() {
api::PaymentMethodData::Upi(upi_data) => upi_data.vpa_id.map(|id| PayerInfo {
Expand Down Expand Up @@ -157,6 +152,7 @@ pub enum IatapayPaymentStatus {
Cleared,
Failed,
Locked,
Cancel,
#[serde(rename = "UNEXPECTED SETTLED")]
UnexpectedSettled,
#[serde(other)]
Expand All @@ -166,11 +162,17 @@ pub enum IatapayPaymentStatus {
impl From<IatapayPaymentStatus> for enums::AttemptStatus {
fn from(item: IatapayPaymentStatus) -> Self {
match item {
IatapayPaymentStatus::Authorized | IatapayPaymentStatus::Settled => Self::Charged,
IatapayPaymentStatus::Failed | IatapayPaymentStatus::UnexpectedSettled => Self::Failure,
IatapayPaymentStatus::Authorized => Self::Authorized,
IatapayPaymentStatus::Settled
| IatapayPaymentStatus::Cleared
| IatapayPaymentStatus::Tobeinvestigated
| IatapayPaymentStatus::Blocked => Self::Charged,
IatapayPaymentStatus::Failed
| IatapayPaymentStatus::UnexpectedSettled
| IatapayPaymentStatus::Unknown => Self::Failure,
IatapayPaymentStatus::Created => Self::AuthenticationPending,
IatapayPaymentStatus::Initiated => Self::Pending,
_ => Self::Voided,
IatapayPaymentStatus::Initiated | IatapayPaymentStatus::Locked => Self::Pending,
IatapayPaymentStatus::Cancel => Self::Voided,
}
}
}
Expand Down

0 comments on commit 60a2906

Please sign in to comment.