-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(connector): [Bluesnap] Metadata to connector metadata mapping #3331
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e5627fb
send merchant metadata to bluesnap
AkshayaFoiger 3a5c6a7
Merge branch 'main' into metadata/bluesnap
AkshayaFoiger fc8f275
fix clippy error
AkshayaFoiger 6209e88
chore: run formatter
hyperswitch-bot[bot] d2fdd9c
remove logger
AkshayaFoiger c385a39
remove throwing error for metadata parsing
AkshayaFoiger 126d49b
fix cargo clippy
AkshayaFoiger e9f1101
fix RequestMetadata serialization
AkshayaFoiger 55f21d9
refactor bluesnap metadata
AkshayaFoiger 285442f
chore: run formatter
hyperswitch-bot[bot] e96c62a
fix(clippy): refactor transaction_metadata
AkshayaFoiger 535311f
resolve comment
AkshayaFoiger d95dbf6
update variable name
AkshayaFoiger ce55ce9
Merge branch 'main' into metadata/bluesnap
AkshayaFoiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use std::collections::HashMap; | ||
|
||
use api_models::{enums as api_enums, payments}; | ||
use base64::Engine; | ||
use common_utils::{ | ||
|
@@ -8,6 +10,7 @@ use common_utils::{ | |
use error_stack::{IntoReport, ResultExt}; | ||
use masking::{ExposeInterface, PeekInterface}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
use crate::{ | ||
connector::utils::{ | ||
|
@@ -17,7 +20,11 @@ use crate::{ | |
consts, | ||
core::errors, | ||
pii::Secret, | ||
types::{self, api, storage::enums, transformers::ForeignTryFrom}, | ||
types::{ | ||
self, api, | ||
storage::enums, | ||
transformers::{ForeignFrom, ForeignTryFrom}, | ||
}, | ||
utils::{Encode, OptionExt}, | ||
}; | ||
|
||
|
@@ -63,6 +70,21 @@ pub struct BluesnapPaymentsRequest { | |
transaction_fraud_info: Option<TransactionFraudInfo>, | ||
card_holder_info: Option<BluesnapCardHolderInfo>, | ||
merchant_transaction_id: Option<String>, | ||
transaction_meta_data: Option<BluesnapMetadata>, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct BluesnapMetadata { | ||
meta_data: Vec<RequestMetadata>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RequestMetadata { | ||
meta_key: Option<String>, | ||
meta_value: Option<String>, | ||
is_visible: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Serialize)] | ||
|
@@ -241,6 +263,15 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues | |
Some(enums::CaptureMethod::Manual) => BluesnapTxnType::AuthOnly, | ||
_ => BluesnapTxnType::AuthCapture, | ||
}; | ||
let transaction_meta_data = | ||
item.router_data | ||
.request | ||
.metadata | ||
.as_ref() | ||
.map(|metadata| BluesnapMetadata { | ||
meta_data: Vec::<RequestMetadata>::foreign_from(metadata.peek().to_owned()), | ||
}); | ||
|
||
let (payment_method, card_holder_info) = match item | ||
.router_data | ||
.request | ||
|
@@ -405,6 +436,7 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues | |
}), | ||
card_holder_info, | ||
merchant_transaction_id: Some(item.router_data.connector_request_reference_id.clone()), | ||
transaction_meta_data, | ||
}) | ||
} | ||
} | ||
|
@@ -569,6 +601,7 @@ pub struct BluesnapCompletePaymentsRequest { | |
transaction_fraud_info: Option<TransactionFraudInfo>, | ||
card_holder_info: Option<BluesnapCardHolderInfo>, | ||
merchant_transaction_id: Option<String>, | ||
transaction_meta_data: Option<BluesnapMetadata>, | ||
} | ||
|
||
impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> | ||
|
@@ -590,6 +623,15 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> | |
.parse_value("BluesnapRedirectionResponse") | ||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||
|
||
let transaction_meta_data = | ||
item.router_data | ||
.request | ||
.metadata | ||
.as_ref() | ||
.map(|metadata| BluesnapMetadata { | ||
meta_data: Vec::<RequestMetadata>::foreign_from(metadata.peek().to_owned()), | ||
}); | ||
|
||
let pf_token = item | ||
.router_data | ||
.request | ||
|
@@ -637,6 +679,7 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsCompleteAuthorizeRouterData>> | |
)?, | ||
merchant_transaction_id: Some(item.router_data.connector_request_reference_id.clone()), | ||
pf_token, | ||
transaction_meta_data, | ||
}) | ||
} | ||
} | ||
|
@@ -1021,7 +1064,7 @@ pub struct BluesnapWebhookObjectResource { | |
reversal_ref_num: Option<String>, | ||
} | ||
|
||
impl TryFrom<BluesnapWebhookObjectResource> for serde_json::Value { | ||
impl TryFrom<BluesnapWebhookObjectResource> for Value { | ||
type Error = error_stack::Report<errors::ConnectorError>; | ||
fn try_from(details: BluesnapWebhookObjectResource) -> Result<Self, Self::Error> { | ||
let (card_transaction_type, processing_status, transaction_id) = match details | ||
|
@@ -1118,3 +1161,19 @@ impl From<ErrorDetails> for utils::ErrorCodeAndMessage { | |
} | ||
} | ||
} | ||
|
||
impl ForeignFrom<Value> for Vec<RequestMetadata> { | ||
fn foreign_from(metadata: Value) -> Self { | ||
let hashmap: HashMap<Option<String>, Option<Value>> = | ||
serde_json::from_str(&metadata.to_string()).unwrap_or(HashMap::new()); | ||
let mut vector: Self = Self::new(); | ||
for (key, value) in hashmap { | ||
vector.push(RequestMetadata { | ||
meta_key: key, | ||
meta_value: value.map(|field_value| field_value.to_string()), | ||
is_visible: Some("Y".to_string()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please assign this to constant and use it here |
||
}); | ||
} | ||
vector | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to keep these fields as optional? RequestMetadata should be instructed only incase of payment metadata is present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fields are optional at the connector end. Hence made them optional in
RequestMetadata
struct