Skip to content

Commit

Permalink
fix(connector): [Cryptopay]fix redirection for cryptopay (#4272)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
prasunna09 and hyperswitch-bot[bot] authored Apr 2, 2024
1 parent 2f304e6 commit 1023f46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/router/src/connector/cryptopay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use reqwest::Url;
use serde::{Deserialize, Serialize};

use crate::{
connector::utils::{self, is_payment_failure, CryptoData},
connector::utils::{self, is_payment_failure, CryptoData, PaymentsAuthorizeRequestData},
consts,
core::errors,
services,
Expand Down Expand Up @@ -70,7 +70,8 @@ impl TryFrom<&CryptopayRouterData<&types::PaymentsAuthorizeRouterData>>
pay_currency,
success_redirect_url: item.router_data.request.router_return_url.clone(),
unsuccess_redirect_url: item.router_data.request.router_return_url.clone(),
metadata: item.router_data.request.metadata.clone(),
//Cryptopay only accepts metadata as Object. If any other type, payment will fail with error.
metadata: item.router_data.request.get_metadata_as_object(),
custom_id: item.router_data.connector_request_reference_id.clone(),
})
}
Expand Down
14 changes: 14 additions & 0 deletions crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ pub trait PaymentsAuthorizeRequestData {
fn get_surcharge_amount(&self) -> Option<i64>;
fn get_tax_on_surcharge_amount(&self) -> Option<i64>;
fn get_total_surcharge_amount(&self) -> Option<i64>;
fn get_metadata_as_object(&self) -> Option<pii::SecretSerdeValue>;
}

pub trait PaymentMethodTokenizationRequestData {
Expand Down Expand Up @@ -632,6 +633,19 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData {
fn is_customer_initiated_mandate_payment(&self) -> bool {
self.setup_mandate_details.is_some()
}

fn get_metadata_as_object(&self) -> Option<pii::SecretSerdeValue> {
self.metadata
.clone()
.and_then(|meta_data| match meta_data.peek() {
serde_json::Value::Null
| serde_json::Value::Bool(_)
| serde_json::Value::Number(_)
| serde_json::Value::String(_)
| serde_json::Value::Array(_) => None,
serde_json::Value::Object(_) => Some(meta_data),
})
}
}

pub trait ConnectorCustomerData {
Expand Down

0 comments on commit 1023f46

Please sign in to comment.