From 2d09c268b011155572dc54973d82a51c0a819b41 Mon Sep 17 00:00:00 2001 From: Sayak Bhattacharya Date: Wed, 18 Dec 2024 16:38:33 +0530 Subject: [PATCH] chore: Resolve PR Comments --- .../src/connectors/jpmorgan/transformers.rs | 517 ++---------------- 1 file changed, 37 insertions(+), 480 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs index 79ce0d64068f..9e62e06cd381 100644 --- a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs @@ -109,8 +109,8 @@ pub struct Expiry { #[derive(Serialize, Debug, Default, Deserialize)] #[serde(rename_all = "camelCase")] pub struct JpmorganMerchantSoftware { - company_name: String, - product_name: String, + company_name: Secret, + product_name: Secret, } #[derive(Default, Debug, Serialize, Deserialize)] @@ -152,8 +152,8 @@ impl TryFrom<&JpmorganRouterData<&PaymentsAuthorizeRouterData>> for JpmorganPaym map_capture_method(item.router_data.request.capture_method.unwrap_or_default()); let merchant_software = JpmorganMerchantSoftware { - company_name: String::from("JPMC"), - product_name: String::from("Hyperswitch"), + company_name: String::from("JPMC").into(), + product_name: String::from("Hyperswitch").into(), }; let merchant = JpmorganMerchant { merchant_software }; @@ -243,29 +243,17 @@ pub enum JpmorganTransactionState { Error, } -#[derive(Default, Debug, Serialize, Deserialize)] +#[derive(Default, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct JpmorganPaymentsResponse { transaction_id: String, - request_id: Option, + request_id: String, transaction_state: JpmorganTransactionState, response_status: String, response_code: String, - response_message: Option, - payment_method_type: Option, + response_message: String, + payment_method_type: PaymentMethodType, capture_method: Option, - is_capture: Option, - initiator_type: Option, - account_on_file: Option, - transaction_date: Option, - approval_code: Option, - host_message: Option, - amount: Option, - currency: Option, - remaining_refundable_amount: Option, - remaining_auth_amount: Option, - host_reference_id: Option, - merchant: Option, } #[derive(Default, Debug, Serialize, Deserialize)] @@ -279,24 +267,24 @@ pub struct Merchant { #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MerchantSoftware { - company_name: String, - product_name: String, - version: Option, + company_name: Secret, + product_name: Secret, + version: Option>, } -#[derive(Default, Debug, Serialize, Deserialize)] +#[derive(Default, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct PaymentMethodType { card: Option, } -#[derive(Default, Debug, Serialize, Deserialize)] +#[derive(Default, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Card { expiry: Option, - card_type: Option, - card_type_name: Option, - masked_account_number: Option, + card_type: Option>, + card_type_name: Option>, + masked_account_number: Option>, card_type_indicators: Option, network_response: Option, } @@ -304,24 +292,24 @@ pub struct Card { #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct NetworkResponse { - address_verification_result: Option, - address_verification_result_code: Option, - card_verification_result_code: Option, + address_verification_result: Option>, + address_verification_result_code: Option>, + card_verification_result_code: Option>, } #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ExpiryResponse { - month: Option, - year: Option, + month: Option>, + year: Option>, } -#[derive(Default, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CardTypeIndicators { - issuance_country_code: Option, + issuance_country_code: Option>, is_durbin_regulated: Option, - card_product_types: Vec, + card_product_types: Secret>, } impl From for common_enums::AttemptStatus { @@ -387,420 +375,12 @@ impl TryFrom, - merchant: Option, - recurring: Option, - installment: Option, - payment_method_type: Option, - ship_to: Option, - initiator_type: Option, - account_on_file: Option, - original_transaction_id: Option, - is_amount_final: Option, amount: MinorUnit, currency: Option, - merchant_order_number: Option, - risk: Option, - retail_addenda: Option, - account_holder: Option, - statement_descriptor: Option, - partial_authorization_support: Option, - payment_request_id: Option, - multi_capture: Option, - sub_merchant_supplemental_data: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SubMerchantSupplementalData { - pub custom_data: Option, - pub service_address: Option, - pub business_information: Option, - pub partner_service: Option, - pub shipping_info: Option, - pub recurring_billing: Option, - pub merchant_reported_revenue: Option, - pub order_information: Option, - pub consumer_device: Option, - pub merchant_identification: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CustomData { - pub external_transaction_reference_number: Option, - pub external_transaction_type: Option, - pub external_merchant_id: Option, - pub merchant_order_reference_id: Option, - pub external_batch_id: Option, - pub merchant_expected_deposit_date: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ServiceAddress { - pub line1: Option, - pub line2: Option, - pub city: Option, - pub state: Option, - pub postal_code: Option, - pub country_code: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BusinessInformation { - pub organization_legal_name: Option, - pub client_business_description_text: Option, - pub organization_d_b_a_name: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct PartnerService { - pub external_vendor_product_name: Option, - pub currency: Option, - pub external_monthly_service_fee_amount: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ShippingInfo { - pub shipping_carrier_name: Option, - pub expected_merchant_product_delivery_date: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RecurringBilling { - pub billing_schedule_update_timestamp: Option, - pub payment_frequency_code: Option, - pub billing_cycle_sequence_number: Option, - pub initiator_type: Option, - pub billing_cycles_total_count: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MerchantReportedRevenue { - pub amount: Option, - pub start_date: Option, - pub end_date: Option, - pub currency: Option, - pub amount_type: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct OrderInformation { - pub order_items: Option>, - pub receipt_url: Option, - pub payment_notes: Option, - pub merchant_url: Option, - pub terms_url: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct OrderItem { - pub merchant_product_identifier: Option, - pub line_item_description_text: Option, - pub unit_price_amount: Option, - pub line_item_unit_quantity: Option, - pub item_comodity_code: Option, - pub chosen_shipping_option: Option, - pub merchant_campaign_name: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ConsumerDevice { - pub session_id: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MerchantIdentification { - pub sub_merchant_id: Option, - pub service_entitlement_number: Option, - pub seller_identifier: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MultiCapture { - multi_capture_sequence_number: Option, - multi_capture_record_count: Option, - is_final_capture: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct AccountHolderCapReq { - reference_id: Option, - consumer_id_creation_date: String, - full_name: Option, - email: Option, - mobile: Option, - phone: Option, - i_p_address: Option, - billing_address: Option, - national_id: Option, - first_name: Option, - last_name: Option, - middle_name: Option, - consumer_profile_info: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct PhoneNumber { - country_code: Option, - phone_number: String, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct BillingAddress { - line1: Option, - line2: Option, - city: Option, - state: Option, - postal_code: Option, - country_code: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -struct ConsumerProfileInfo { - consumer_profile_request_type: Option, - legacy_consumer_profile_id: Option, - external_consumer_profile_identifier: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RetailAddendaCapReq { - purchase_order_number: Option, - order_date: Option, - tax_amount: Option, - is_taxable: Option, - level3: Option, - gratuity_amount: Option, - surcharge_amount: Option, - health_care_data: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct HealthCareDataCapReq { - total_healthcare_amount: Option, - total_vision_amount: Option, - total_clinic_amount: Option, - total_dental_amount: Option, - total_prescription_amount: Option, - is_i_i_a_s: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Level3 { - total_shipping_amount: Option, - duty_amount: Option, - ship_to_address_postal_code: Option, - ship_to_address_country_code: Option, - ship_from_address_postal_code: Option, - total_transaction_discount_amount: Option, - value_added_tax_amount: Option, - value_added_tax_percent: Option, - shipping_value_added_tax_percent: Option, - order_discount_treatment_code: Option, - value_added_tax_invoice_reference_number: Option, - shipping_value_added_tax_amount: Option, - party_tax_government_issued_identifier: Option, - alternate_tax_amount: Option, - line_items: Option, - tax_treatment_code: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct LineItemsCapReq { - line_item_description_text: Option, - merchant_product_identifier: Option, - item_commodity_code: Option, - line_item_unit_quantity: Option, - line_item_unit_of_measure_code: Option, - unit_price_amount: Option, - tax_inclusive_line_item_total_amount: Option, - transaction_discount_amount: Option, - purchase_transaction_discount_percent: Option, - line_item_discount_treatment_code: Option, - line_item_detail_code: Option, - line_item_tax_indicator: Option, - line_item_discount_indicator: Option, - line_item_taxes: Option>, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct LineItemTaxesCapReq { - tax_type_code: Option, - line_item_tax_amount: Option, - tax_percent: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RiskCapReq { - request_fraud_score: Option, - transaction_risk_score: Option, - token_risk_score: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ShipToCapReq { - shipping_description: Option, - shipping_address: Option, - full_name: Option, - email: Option, - mobile: Option, - phone: Option, - first_name: Option, - last_name: Option, - middle_name: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct PhoneCapReq { - country_code: Option, - phone_number: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MobileCapReq { - country_code: Option, - phone_number: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ShippingAddressCapReq { - line1: Option, - line2: Option, - city: Option, - state: Option, - postal_code: Option, - country_code: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct PaymentMethodTypeCapReq { - card: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CardCapReq { - account_number_type: Option, - account_number: String, - expiry: Option, - wallet_provider: Option, - cvv: Option, - original_network_transaction_id: Option, - account_updater: Option, - authentication: Option, - encryption_integrity_check: Option, - preferred_payment_network_name_list: Vec, - merchant_sales_channel_name: Option, - merchant_preferred_routing: Option, - card_type_funding: Option, - pie_key_id: Option, - pie_phase_id: Option, - encrypted_payload: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct PaymentAuthenticationCapReq {} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct AuthenticationCapReq { - authentication_id: Option, - electronic_commerce_indicator: Option, - token_authentication_value: Option, - s_c_a_exemption_reason: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct AccountUpdaterCapReq { - request_account_updater: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ExpiryCapReq { - month: i32, - year: i32, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct InstallmentCapReq { - installment_count: Option, - total_installments: Option, - number_of_deferrals: Option, - plan_id: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RecurringCapReq { - recurring_sequence: Option, - agreement_id: Option, - payment_agreement_expiry_date: Option, - is_variable_amount: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MerchantCapReq { - merchant_software: MerchantSoftwareCapReq, - merchant_category_code: Option, - merchant_logo_url: Option, - soft_merchant: SoftMerchantCapReq, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MerchantSoftwareCapReq { - company_name: Option, - product_name: Option, - version: Option, - software_id: Option, -} - -#[derive(Default, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SoftMerchantCapReq { - name: Option, - phone: Option, - email: Option, - url: Option, - merchant_purchase_description: Option, - visa_merchant_verification_value_id: Option, - master_card_merchant_verification_value_id: Option, - merchant_incorporation_status: Option, - foreign_merchant_indicator: Option, } #[derive(Debug, Default, Copy, Serialize, Deserialize, Clone)] @@ -818,29 +398,11 @@ impl TryFrom<&JpmorganRouterData<&PaymentsCaptureRouterData>> for JpmorganCaptur item: &JpmorganRouterData<&PaymentsCaptureRouterData>, ) -> Result { let capture_method = - map_capture_method(item.router_data.request.capture_method.unwrap_or_default()); + Some(map_capture_method(item.router_data.request.capture_method.unwrap_or_default())?); Ok(Self { - capture_method: Some(capture_method?), - merchant: None, - recurring: None, - installment: None, - payment_method_type: None, - ship_to: None, - initiator_type: None, - account_on_file: None, - original_transaction_id: None, - is_amount_final: None, + capture_method, amount: item.amount, currency: Some(item.router_data.request.currency), - merchant_order_number: None, - risk: None, - retail_addenda: None, - account_holder: None, - statement_descriptor: None, - partial_authorization_support: None, - payment_request_id: None, - multi_capture: None, - sub_merchant_supplemental_data: None, }) } } @@ -866,9 +428,9 @@ pub struct PaymentMethodTypeCapRes { #[derive(Default, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CardCapRes { - pub card_type: Option, - pub card_type_name: Option, - unmasked_account_number: Option, + pub card_type: Option>, + pub card_type_name: Option>, + unmasked_account_number: Option>, } impl From for common_enums::AttemptStatus { @@ -910,16 +472,11 @@ impl TryFrom #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct TransactionData { - payment_type: Option, - status_code: i32, - txn_secret: Option, + payment_type: Option>, + status_code: Secret, + txn_secret: Option>, tid: Option>, - test_mode: Option, + test_mode: Option>, status: Option, } @@ -1137,8 +694,8 @@ pub struct JpmorganPaymentMethodTypeCancelResponse { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CardCancelResponse { - pub card_type: String, - pub card_type_name: String, + pub card_type: Secret, + pub card_type_name: Secret, } impl