Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(connector): [PLACETOPAY] Fix refund request and status mapping (#3894)
DEEPANSHU BANSAL5eff9d47d3e5
diff --git a/crates/router/src/connector/placetopay.rs b/crates/router/src/connector/placetopay.rsindex 81255f450e..c28fed1fed 100644--- a/crates/router/src/connector/placetopay.rs+++ b/crates/router/src/connector/placetopay.rs@@ -119,8 +119,8 @@ impl ConnectorValidation for Placetopay {) -> CustomResult<(), errors::ConnectorError> {let capture_method = capture_method.unwrap_or_default();match capture_method {- enums::CaptureMethod::Manual => Ok(()),- enums::CaptureMethod::Automatic+ enums::CaptureMethod::Automatic => Ok(()),+ enums::CaptureMethod::Manual| enums::CaptureMethod::ManualMultiple| enums::CaptureMethod::Scheduled => Err(utils::construct_not_supported_error_report(capture_method,@@ -615,7 +615,7 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse) -> CustomResult<Option<services::Request>, errors::ConnectorError> {Ok(Some(services::RequestBuilder::new()- .method(services::Method::Get)+ .method(services::Method::Post).url(&types::RefundSyncType::get_url(self, req, connectors)?).attach_default_headers().headers(types::RefundSyncType::get_headers(self, req, connectors)?)diff --git a/crates/router/src/connector/placetopay/transformers.rs b/crates/router/src/connector/placetopay/transformers.rsindex f1c054b960..e5dedf6ded 100644--- a/crates/router/src/connector/placetopay/transformers.rs+++ b/crates/router/src/connector/placetopay/transformers.rs@@ -206,30 +206,43 @@ impl TryFrom<&types::ConnectorAuthType> for PlacetopayAuthType {#[derive(Debug, Clone, Deserialize, Serialize)]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]-pub enum PlacetopayStatus {+pub enum PlacetopayTransactionStatus {Ok,Failed,Approved,+ // ApprovedPartial,+ // PartialExpired,Rejected,Pending,PendingValidation,PendingProcess,+ // Refunded,+ // Reversed,+ Error,+ // Unknown,+ // Manual,+ // Dispute,+ //The statuses that are commented out are awaiting clarification on the connector.}#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "camelCase")]pub struct PlacetopayStatusResponse {- status: PlacetopayStatus,+ status: PlacetopayTransactionStatus,}-impl From<PlacetopayStatus> for enums::AttemptStatus {- fn from(item: PlacetopayStatus) -> Self {+impl From<PlacetopayTransactionStatus> for enums::AttemptStatus {+ fn from(item: PlacetopayTransactionStatus) -> Self {match item {- PlacetopayStatus::Approved | PlacetopayStatus::Ok => Self::Authorized,- PlacetopayStatus::Failed | PlacetopayStatus::Rejected => Self::Failure,- PlacetopayStatus::Pending- | PlacetopayStatus::PendingValidation- | PlacetopayStatus::PendingProcess => Self::Authorizing,+ PlacetopayTransactionStatus::Approved | PlacetopayTransactionStatus::Ok => {+ Self::Charged+ }+ PlacetopayTransactionStatus::Failed+ | PlacetopayTransactionStatus::Rejected+ | PlacetopayTransactionStatus::Error => Self::Failure,+ PlacetopayTransactionStatus::Pending+ | PlacetopayTransactionStatus::PendingValidation+ | PlacetopayTransactionStatus::PendingProcess => Self::Pending,}}}@@ -239,6 +252,7 @@ impl From<PlacetopayStatus> for enums::AttemptStatus {pub struct PlacetopayPaymentsResponse {status: PlacetopayStatusResponse,internal_reference: u64,+ authorization: Option<String>,}impl<F, T>@@ -263,7 +277,11 @@ impl<F, T>),redirection_data: None,mandate_reference: None,- connector_metadata: None,+ connector_metadata: item+ .response+ .authorization+ .clone()+ .map(|authorization| serde_json::json!(authorization)),network_txn_id: None,connector_response_reference_id: None,incremental_authorization_allowed: None,@@ -281,55 +299,90 @@ pub struct PlacetopayRefundRequest {auth: PlacetopayAuth,internal_reference: u64,action: PlacetopayNextAction,+ authorization: Option<String>,}impl<F> TryFrom<&types::RefundsRouterData<F>> for PlacetopayRefundRequest {type Error = error_stack::Report<errors::ConnectorError>;fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {- let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?;- let internal_reference = item- .request- .connector_transaction_id- .parse::<u64>()- .into_report()- .change_context(errors::ConnectorError::RequestEncodingFailed)?;- let action = PlacetopayNextAction::Refund;-- Ok(Self {- auth,- internal_reference,- action,- })+ if item.request.refund_amount == item.request.payment_amount {+ let auth = PlacetopayAuth::try_from(&item.connector_auth_type)?;++ let internal_reference = item+ .request+ .connector_transaction_id+ .parse::<u64>()+ .into_report()+ .change_context(errors::ConnectorError::RequestEncodingFailed)?;+ let action = PlacetopayNextAction::Reverse;+ let authorization = match item.request.connector_metadata.clone() {+ Some(metadata) => metadata.as_str().map(|auth| auth.to_string()),+ None => None,+ };+ Ok(Self {+ auth,+ internal_reference,+ action,+ authorization,+ })+ } else {+ Err(errors::ConnectorError::NotSupported {+ message: "Partial Refund".to_string(),+ connector: "placetopay",+ }+ .into())+ }}}impl From<PlacetopayRefundStatus> for enums::RefundStatus {fn from(item: PlacetopayRefundStatus) -> Self {match item {- PlacetopayRefundStatus::Refunded => Self::Success,- PlacetopayRefundStatus::Failed | PlacetopayRefundStatus::Rejected => Self::Failure,- PlacetopayRefundStatus::Pending | PlacetopayRefundStatus::PendingProcess => {- Self::Pending- }+ PlacetopayRefundStatus::Ok+ | PlacetopayRefundStatus::Approved+ | PlacetopayRefundStatus::Refunded => Self::Success,+ PlacetopayRefundStatus::Failed+ | PlacetopayRefundStatus::Rejected+ | PlacetopayRefundStatus::Error => Self::Failure,+ PlacetopayRefundStatus::Pending+ | PlacetopayRefundStatus::PendingProcess+ | PlacetopayRefundStatus::PendingValidation => Self::Pending,}}}-#[derive(Debug, Deserialize, Serialize)]-#[serde(rename_all = "camelCase")]-pub struct PlacetopayRefundResponse {- status: PlacetopayRefundStatus,- internal_reference: u64,-}-#[derive(Debug, Deserialize, Serialize)]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]pub enum PlacetopayRefundStatus {- Refunded,- Rejected,+ Ok,Failed,+ Approved,+ // ApprovedPartial,+ // PartialExpired,+ Rejected,Pending,+ PendingValidation,PendingProcess,+ Refunded,+ // Reversed,+ Error,+ // Unknown,+ // Manual,+ // Dispute,+ //The statuses that are commented out are awaiting clarification on the connector.+}++#[derive(Debug, Deserialize, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct PlacetopayRefundStatusResponse {+ status: PlacetopayRefundStatus,+}++#[derive(Debug, Deserialize, Serialize)]+#[serde(rename_all = "camelCase")]+pub struct PlacetopayRefundResponse {+ status: PlacetopayRefundStatusResponse,+ internal_reference: u64,}impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundResponse>>@@ -342,7 +395,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, PlacetopayRefundRespOk(Self {response: Ok(types::RefundsResponseData {connector_refund_id: item.response.internal_reference.to_string(),- refund_status: enums::RefundStatus::from(item.response.status),+ refund_status: enums::RefundStatus::from(item.response.status.status),}),..item.data})@@ -383,7 +436,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, PlacetopayRefundResponOk(Self {response: Ok(types::RefundsResponseData {connector_refund_id: item.response.internal_reference.to_string(),- refund_status: enums::RefundStatus::from(item.response.status),+ refund_status: enums::RefundStatus::from(item.response.status.status),}),..item.data})@@ -447,6 +500,7 @@ pub struct PlacetopayNextActionRequest {#[serde(rename_all = "camelCase")]pub enum PlacetopayNextAction {Refund,+ Reverse,Void,Process,Checkout,