Skip to content

Commit

Permalink
refactor(router): encrypted the merchant identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
prajjwalkumar17 committed Aug 31, 2023
1 parent 7c750b6 commit 78d613d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ recon_admin_api_key = "recon_test_admin"
[applepay_merchant_configs]
merchant_cert_key = "MERCHANT CERTIFICATE KEY"
merchant_cert = "MERCHANT CERTIFICATE"
common_merchant_identifier = "COMMON MERCHANT IDENTIFIER"

[locker]
host = ""
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/configs/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct Settings {
pub struct ApplepayMerchantConfigs {
pub merchant_cert: String,
pub merchant_cert_key: String,
pub common_merchant_identifier: String,
}

#[derive(Debug, Deserialize, Clone, Default)]
Expand Down
13 changes: 10 additions & 3 deletions crates/router/src/utils/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{

const APPLEPAY_MERCHANT_VERIFICATION_URL: &str =
"https://apple-pay-gateway.apple.com/paymentservices/registerMerchant";
const APPLEPAY_INTERNAL_MERCHANT_IDENTIFIER: &str = "merchant.com.noon.juspay";
const APPLEPAY_INTERNAL_MERCHANT_NAME: &str = "Applepay_merchant";

pub async fn verify_merchant_creds_for_applepay(
Expand All @@ -26,9 +25,16 @@ pub async fn verify_merchant_creds_for_applepay(
services::ApplicationResponse<ApplepayMerchantResponse>,
api_error_response::ApiErrorResponse,
> {
let encrypted_merchant_identifier = &state.conf.applepay_merchant_configs.common_merchant_identifier;
let encrypted_cert = &state.conf.applepay_merchant_configs.merchant_cert;
let encrypted_key = &state.conf.applepay_merchant_configs.merchant_cert_key;

let applepay_internal_merchant_identifier = kms::get_kms_client(kms_config)
.await
.decrypt(encrypted_cert)
.await
.change_context(api_error_response::ApiErrorResponse::InternalServerError)?;

let cert_data = kms::get_kms_client(kms_config)
.await
.decrypt(encrypted_cert)
Expand All @@ -43,8 +49,8 @@ pub async fn verify_merchant_creds_for_applepay(

let request_body = verifications::ApplepayMerchantVerificationConfigs {
domain_names: body.domain_names.clone(),
encrypt_to: APPLEPAY_INTERNAL_MERCHANT_IDENTIFIER.to_string(),
partner_internal_merchant_identifier: APPLEPAY_INTERNAL_MERCHANT_IDENTIFIER.to_string(),
encrypt_to: applepay_internal_merchant_identifier.to_string(),
partner_internal_merchant_identifier: applepay_internal_merchant_identifier.to_string(),
partner_merchant_name: APPLEPAY_INTERNAL_MERCHANT_NAME.to_string(),
};

Expand Down Expand Up @@ -73,6 +79,7 @@ pub async fn verify_merchant_creds_for_applepay(

let applepay_response =
response.change_context(api_error_response::ApiErrorResponse::InternalServerError)?;

// Error is already logged
Ok(match applepay_response {
Ok(_) => services::api::ApplicationResponse::Json(ApplepayMerchantResponse {
Expand Down

0 comments on commit 78d613d

Please sign in to comment.