Skip to content

Commit

Permalink
feat(connector): [HELCIM] Add connector_request_reference_id in invoi…
Browse files Browse the repository at this point in the history
…ce_number (#3087)
  • Loading branch information
deepanshu-iiitu authored Dec 13, 2023
1 parent bca7cdb commit 3cc9642
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 9 deletions.
4 changes: 4 additions & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ ach = { currency = "USD" }
[pm_filters.prophetpay]
card_redirect = { currency = "USD" }

[pm_filters.helcim]
credit = { currency = "USD" }
debit = { currency = "USD" }

[connector_customer]
connector_list = "gocardless,stax,stripe"
payout_connector_list = "wise"
Expand Down
4 changes: 4 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ paypal = { currency = "AUD,BRL,CAD,CNY,CZK,DKK,EUR,HKD,HUF,ILS,JPY,MYR,MXN,TWD,N
credit = { not_available_flows = { capture_method = "manual" } }
debit = { not_available_flows = { capture_method = "manual" } }

[pm_filters.helcim]
credit = { currency = "USD" }
debit = { currency = "USD" }

[pm_filters.klarna]
klarna = { country = "AU,AT,BE,CA,CZ,DK,FI,FR,DE,GR,IE,IT,NL,NZ,NO,PL,PT,ES,SE,CH,GB,US", currency = "AUD,EUR,EUR,CAD,CZK,DKK,EUR,EUR,EUR,EUR,EUR,EUR,EUR,NZD,NOK,PLN,EUR,EUR,SEK,CHF,GBP,USD" }
credit = { not_available_flows = { capture_method = "manual" } }
Expand Down
4 changes: 4 additions & 0 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ cashapp = {country = "US", currency = "USD"}
[pm_filters.prophetpay]
card_redirect = { currency = "USD" }

[pm_filters.helcim]
credit = { currency = "USD" }
debit = { currency = "USD" }

[pm_filters.stax]
credit = { currency = "USD" }
debit = { currency = "USD" }
Expand Down
166 changes: 166 additions & 0 deletions crates/router/src/configs/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,89 @@ impl Default for super::settings::RequiredFields {
]),
}
),
(
enums::Connector::Helcim,
RequiredFieldFinal {
mandate: HashMap::new(),
non_mandate: HashMap::from(
[
(
"payment_method_data.card.card_number".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_number".to_string(),
display_name: "card_number".to_string(),
field_type: enums::FieldType::UserCardNumber,
value: None,
}
),
(
"payment_method_data.card.card_exp_month".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_exp_month".to_string(),
display_name: "card_exp_month".to_string(),
field_type: enums::FieldType::UserCardExpiryMonth,
value: None,
}
),
(
"payment_method_data.card.card_exp_year".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_exp_year".to_string(),
display_name: "card_exp_year".to_string(),
field_type: enums::FieldType::UserCardExpiryYear,
value: None,
}
),
(
"payment_method_data.card.card_cvc".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_cvc".to_string(),
display_name: "card_cvc".to_string(),
field_type: enums::FieldType::UserCardCvc,
value: None,
}
),
(
"billing.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "billing.address.first_name".to_string(),
display_name: "billing_first_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "billing.address.last_name".to_string(),
display_name: "billing_last_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
}
),
(
"billing.address.zip".to_string(),
RequiredFieldInfo {
required_field: "billing.address.zip".to_string(),
display_name: "zip".to_string(),
field_type: enums::FieldType::UserAddressPincode,
value: None,
}
),
(
"billing.address.line1".to_string(),
RequiredFieldInfo {
required_field: "billing.address.line1".to_string(),
display_name: "line1".to_string(),
field_type: enums::FieldType::UserAddressLine1,
value: None,
}
),
]
),
common: HashMap::new(),
}
),
(
enums::Connector::Iatapay,
RequiredFieldFinal {
Expand Down Expand Up @@ -3049,6 +3132,89 @@ impl Default for super::settings::RequiredFields {
]),
}
),
(
enums::Connector::Helcim,
RequiredFieldFinal {
mandate: HashMap::new(),
non_mandate: HashMap::from(
[
(
"payment_method_data.card.card_number".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_number".to_string(),
display_name: "card_number".to_string(),
field_type: enums::FieldType::UserCardNumber,
value: None,
}
),
(
"payment_method_data.card.card_exp_month".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_exp_month".to_string(),
display_name: "card_exp_month".to_string(),
field_type: enums::FieldType::UserCardExpiryMonth,
value: None,
}
),
(
"payment_method_data.card.card_exp_year".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_exp_year".to_string(),
display_name: "card_exp_year".to_string(),
field_type: enums::FieldType::UserCardExpiryYear,
value: None,
}
),
(
"payment_method_data.card.card_cvc".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.card.card_cvc".to_string(),
display_name: "card_cvc".to_string(),
field_type: enums::FieldType::UserCardCvc,
value: None,
}
),
(
"billing.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "billing.address.first_name".to_string(),
display_name: "billing_first_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "billing.address.last_name".to_string(),
display_name: "billing_last_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
}
),
(
"billing.address.zip".to_string(),
RequiredFieldInfo {
required_field: "billing.address.zip".to_string(),
display_name: "zip".to_string(),
field_type: enums::FieldType::UserAddressPincode,
value: None,
}
),
(
"billing.address.line1".to_string(),
RequiredFieldInfo {
required_field: "billing.address.line1".to_string(),
display_name: "line1".to_string(),
field_type: enums::FieldType::UserAddressLine1,
value: None,
}
),
]
),
common: HashMap::new(),
}
),
(
enums::Connector::Iatapay,
RequiredFieldFinal {
Expand Down
68 changes: 59 additions & 9 deletions crates/router/src/connector/helcim/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ impl<T>
}
}

pub fn check_currency(
currency: types::storage::enums::Currency,
) -> Result<types::storage::enums::Currency, errors::ConnectorError> {
if currency == types::storage::enums::Currency::USD {
Ok(currency)
} else {
Err(errors::ConnectorError::NotSupported {
message: format!("currency {currency} is not supported for this merchant account"),
connector: "Helcim",
})?
}
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HelcimVerifyRequest {
Expand All @@ -62,6 +75,7 @@ pub struct HelcimPaymentsRequest {
currency: enums::Currency,
ip_address: Secret<String, IpAddress>,
card_data: HelcimCard,
invoice: HelcimInvoice,
billing_address: HelcimBillingAddress,
//The ecommerce field is an optional field in Connector Helcim.
//Setting the ecommerce field to true activates the Helcim Fraud Defender.
Expand All @@ -83,6 +97,22 @@ pub struct HelcimBillingAddress {
email: Option<Email>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HelcimInvoice {
invoice_number: String,
line_items: Vec<HelcimLineItems>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HelcimLineItems {
description: String,
quantity: u8,
price: f64,
total: f64,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HelcimCard {
Expand Down Expand Up @@ -111,9 +141,9 @@ impl TryFrom<(&types::SetupMandateRouterData, &api::Card)> for HelcimVerifyReque
email: item.request.email.clone(),
};
let ip_address = item.request.get_browser_info()?.get_ip_address()?;

let currency = check_currency(item.request.currency)?;
Ok(Self {
currency: item.request.currency,
currency,
ip_address,
card_data,
billing_address,
Expand Down Expand Up @@ -192,11 +222,30 @@ impl
.request
.get_browser_info()?
.get_ip_address()?;
let line_items = vec![
(HelcimLineItems {
description: item
.router_data
.description
.clone()
.unwrap_or("No Description".to_string()),
// By default quantity is set to 1 and price and total is set to amount because these three fields are required to generate an invoice.
quantity: 1,
price: item.amount,
total: item.amount,
}),
];
let invoice = HelcimInvoice {
invoice_number: item.router_data.connector_request_reference_id.clone(),
line_items,
};
let currency = check_currency(item.router_data.request.currency)?;
Ok(Self {
amount: item.amount.to_owned(),
currency: item.router_data.request.currency,
amount: item.amount,
currency,
ip_address,
card_data,
invoice,
billing_address,
ecommerce: None,
})
Expand Down Expand Up @@ -295,6 +344,7 @@ impl From<HelcimPaymentsResponse> for enums::AttemptStatus {
pub struct HelcimPaymentsResponse {
status: HelcimPaymentStatus,
transaction_id: u64,
invoice_number: Option<String>,
#[serde(rename = "type")]
transaction_type: HelcimTransactionType,
}
Expand Down Expand Up @@ -327,7 +377,7 @@ impl<F>
mandate_reference: None,
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
connector_response_reference_id: item.response.invoice_number.clone(),
incremental_authorization_allowed: None,
}),
status: enums::AttemptStatus::from(item.response),
Expand Down Expand Up @@ -382,7 +432,7 @@ impl<F>
mandate_reference: None,
connector_metadata,
network_txn_id: None,
connector_response_reference_id: None,
connector_response_reference_id: item.response.invoice_number.clone(),
incremental_authorization_allowed: None,
}),
status: enums::AttemptStatus::from(item.response),
Expand Down Expand Up @@ -441,7 +491,7 @@ impl<F>
mandate_reference: None,
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
connector_response_reference_id: item.response.invoice_number.clone(),
incremental_authorization_allowed: None,
}),
status: enums::AttemptStatus::from(item.response),
Expand Down Expand Up @@ -528,7 +578,7 @@ impl<F>
mandate_reference: None,
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
connector_response_reference_id: item.response.invoice_number.clone(),
incremental_authorization_allowed: None,
}),
status: enums::AttemptStatus::from(item.response),
Expand Down Expand Up @@ -591,7 +641,7 @@ impl<F>
mandate_reference: None,
connector_metadata: None,
network_txn_id: None,
connector_response_reference_id: None,
connector_response_reference_id: item.response.invoice_number.clone(),
incremental_authorization_allowed: None,
}),
status: enums::AttemptStatus::from(item.response),
Expand Down

0 comments on commit 3cc9642

Please sign in to comment.