Skip to content
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

refactor(address): change address to domain address in application #6608

Merged
merged 25 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
34206a8
feat(hyperswitch_domain_models): introduce `EncryptedJsonType` to han…
SanchithHegde Nov 12, 2024
4719740
feat: add domain address
Narayanbhat166 Nov 17, 2024
8b47104
refactor: add batch encryption to payment intent
Narayanbhat166 Nov 17, 2024
7464faa
refactor: fix operation macro and batch encrypt pa
Narayanbhat166 Nov 17, 2024
19462ae
chore: cargo clippy_v2
Narayanbhat166 Nov 17, 2024
487a682
refactor: change address to domain address
Narayanbhat166 Nov 17, 2024
73b5be9
refactor: change address to domain address fix v1 errors
Narayanbhat166 Nov 18, 2024
609f499
chore: fix errors in connector tests crate
Narayanbhat166 Nov 18, 2024
bb1b27c
chore: cargo clippy
Narayanbhat166 Nov 19, 2024
b3cf0c7
chore: cargo clippy_v2
Narayanbhat166 Nov 19, 2024
08aa130
Merge branch 'add_address_for_v2' into change_address_to_domain
Narayanbhat166 Nov 19, 2024
c3de460
chore: run formatter
hyperswitch-bot[bot] Nov 19, 2024
1eb84e5
refactor: add a method to sessiongetters to get payment_method_billing
Narayanbhat166 Nov 20, 2024
d2ad969
refactor: pass address to connector module
Narayanbhat166 Nov 21, 2024
4eafc74
chore: run formatter
hyperswitch-bot[bot] Nov 21, 2024
b3bac53
refactor: add address to payment_attempt
Narayanbhat166 Nov 21, 2024
f0d2559
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Nov 21, 2024
2b7921c
refactor: add shipping and billing to response
Narayanbhat166 Nov 21, 2024
8abb159
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Nov 21, 2024
e53d062
Merge branch 'main' into change_address_to_domain
Narayanbhat166 Nov 27, 2024
654abc7
chore: cargo clippy_v2
Narayanbhat166 Nov 27, 2024
288aa2d
Merge branch 'main' into change_address_to_domain
Narayanbhat166 Dec 2, 2024
9be1abf
Merge branch 'main' into change_address_to_domain
Narayanbhat166 Dec 2, 2024
126a6bc
Merge branch 'main' into change_address_to_domain
Narayanbhat166 Dec 3, 2024
1235ca0
Merge branch 'main' into change_address_to_domain
Narayanbhat166 Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2972,8 +2972,8 @@
"required": [
"order_amount",
"currency",
"skip_external_tax_calculation",
"skip_surcharge_calculation"
"external_tax_calculation",
"surcharge_calculation"
],
"properties": {
"order_amount": {
Expand Down Expand Up @@ -3002,10 +3002,10 @@
],
"nullable": true
},
"skip_external_tax_calculation": {
"external_tax_calculation": {
"$ref": "#/components/schemas/TaxCalculationOverride"
},
"skip_surcharge_calculation": {
"surcharge_calculation": {
"$ref": "#/components/schemas/SurchargeCalculationOverride"
},
"surcharge_amount": {
Expand Down Expand Up @@ -6125,8 +6125,8 @@
"type": "object",
"required": [
"currency",
"skip_external_tax_calculation",
"skip_surcharge_calculation",
"external_tax_calculation",
"surcharge_calculation",
"net_amount",
"amount_capturable"
],
Expand Down Expand Up @@ -6157,10 +6157,10 @@
],
"nullable": true
},
"skip_external_tax_calculation": {
"external_tax_calculation": {
"$ref": "#/components/schemas/TaxCalculationOverride"
},
"skip_surcharge_calculation": {
"surcharge_calculation": {
"$ref": "#/components/schemas/SurchargeCalculationOverride"
},
"surcharge_amount": {
Expand Down Expand Up @@ -14971,6 +14971,7 @@
"status",
"amount_details",
"client_secret",
"profile_id",
"capture_method",
"authentication_type",
"customer_present",
Expand All @@ -14997,6 +14998,10 @@
"description": "It's a token used for client side verification.",
"example": "pay_U42c409qyHwOkWo3vK60_secret_el9ksDkiB8hi6j9N78yo"
},
"profile_id": {
"type": "string",
"description": "The identifier for the profile. This is inferred from the `x-profile-id` header"
},
"merchant_reference_id": {
"type": "string",
"description": "Unique identifier for the payment. This ensures idempotency for multiple payments\nthat have been done by a single merchant.",
Expand Down Expand Up @@ -15816,6 +15821,22 @@
}
],
"nullable": true
},
"shipping": {
"allOf": [
{
"$ref": "#/components/schemas/Address"
}
],
"nullable": true
},
"billing": {
"allOf": [
{
"$ref": "#/components/schemas/Address"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -19661,8 +19682,8 @@
"SurchargeCalculationOverride": {
"type": "string",
"enum": [
"Skip",
"Calculate"
"skip",
"calculate"
]
},
"SurchargeDetailsResponse": {
Expand Down Expand Up @@ -19763,8 +19784,8 @@
"TaxCalculationOverride": {
"type": "string",
"enum": [
"Skip",
"Calculate"
"skip",
"calculate"
]
},
"ThirdPartySdkSessionResponse": {
Expand Down
18 changes: 14 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ pub struct PaymentsIntentResponse {
#[schema(value_type = String, example = "pay_U42c409qyHwOkWo3vK60_secret_el9ksDkiB8hi6j9N78yo")]
pub client_secret: common_utils::types::ClientSecret,

/// The identifier for the profile. This is inferred from the `x-profile-id` header
#[schema(value_type = String)]
pub profile_id: id_type::ProfileId,

/// Unique identifier for the payment. This ensures idempotency for multiple payments
/// that have been done by a single merchant.
#[schema(
Expand Down Expand Up @@ -476,10 +480,10 @@ pub struct AmountDetailsResponse {
pub order_tax_amount: Option<MinorUnit>,
/// The action to whether calculate tax by calling external tax provider or not
#[schema(value_type = TaxCalculationOverride)]
pub skip_external_tax_calculation: common_enums::TaxCalculationOverride,
pub external_tax_calculation: common_enums::TaxCalculationOverride,
/// The action to whether calculate surcharge or not
#[schema(value_type = SurchargeCalculationOverride)]
pub skip_surcharge_calculation: common_enums::SurchargeCalculationOverride,
pub surcharge_calculation: common_enums::SurchargeCalculationOverride,
/// The surcharge amount to be added to the order, collected from the merchant
pub surcharge_amount: Option<MinorUnit>,
/// tax on surcharge amount
Expand All @@ -502,10 +506,10 @@ pub struct ConfirmIntentAmountDetailsResponse {
pub order_tax_amount: Option<MinorUnit>,
/// The action to whether calculate tax by calling external tax provider or not
#[schema(value_type = TaxCalculationOverride)]
pub skip_external_tax_calculation: common_enums::TaxCalculationOverride,
pub external_tax_calculation: common_enums::TaxCalculationOverride,
/// The action to whether calculate surcharge or not
#[schema(value_type = SurchargeCalculationOverride)]
pub skip_surcharge_calculation: common_enums::SurchargeCalculationOverride,
pub surcharge_calculation: common_enums::SurchargeCalculationOverride,
/// The surcharge amount to be added to the order, collected from the merchant
pub surcharge_amount: Option<MinorUnit>,
/// tax on surcharge amount
Expand Down Expand Up @@ -4733,6 +4737,12 @@ pub struct PaymentsRetrieveResponse {

/// Error details for the payment if any
pub error: Option<ErrorDetails>,

/// The shipping address associated with the payment intent
pub shipping: Option<Address>,

/// The billing address associated with the payment intent
pub billing: Option<Address>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,7 @@ pub enum PresenceOfCustomerDuringPayment {
}

#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum TaxCalculationOverride {
/// Skip calling the external tax provider
#[default]
Expand All @@ -3337,6 +3338,7 @@ pub enum TaxCalculationOverride {
}

#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum SurchargeCalculationOverride {
/// Skip calculating surcharge
#[default]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use api_models::payments::AddressDetails;
use common_enums::enums;
use common_utils::{pii::Email, request::Method};
use error_stack::ResultExt;
Expand Down Expand Up @@ -182,7 +181,9 @@ impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalP
}
}

fn get_payer_name(address: &AddressDetails) -> Option<Secret<String>> {
fn get_payer_name(
address: &hyperswitch_domain_models::address::AddressDetails,
) -> Option<Secret<String>> {
let first_name = address
.first_name
.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn get_billing_details(
}

fn get_address_details(
address: Option<&api_models::payments::AddressDetails>,
address: Option<&hyperswitch_domain_models::address::AddressDetails>,
) -> Result<Option<Address>, Error> {
let address_details = match address {
Some(address) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use api_models::{payments::AddressDetails, webhooks::IncomingWebhookEvent};
use api_models::webhooks::IncomingWebhookEvent;
use cards::CardNumber;
use common_enums::enums;
use common_utils::{
Expand Down Expand Up @@ -555,7 +555,9 @@ where
}
}

fn get_address_details(address_details: Option<&AddressDetails>) -> Option<Address> {
fn get_address_details(
address_details: Option<&hyperswitch_domain_models::address::AddressDetails>,
) -> Option<Address> {
address_details.map(|address| Address {
line1: address.line1.clone(),
line2: address.line1.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use api_models::payments;
use common_enums::enums::{AttemptStatus, BankNames, CaptureMethod, CountryAlpha2, Currency};
use common_utils::{pii::Email, request::Method};
use hyperswitch_domain_models::{
Expand Down Expand Up @@ -418,15 +417,18 @@ fn make_bank_redirect_request(
}

fn get_address(
billing: &payments::Address,
) -> Option<(&payments::Address, &payments::AddressDetails)> {
billing: &hyperswitch_domain_models::address::Address,
) -> Option<(
&hyperswitch_domain_models::address::Address,
&hyperswitch_domain_models::address::AddressDetails,
)> {
let address = billing.address.as_ref()?;
address.country.as_ref()?;
Some((billing, address))
}

fn build_customer_info(
billing_address: &payments::Address,
billing_address: &hyperswitch_domain_models::address::Address,
email: &Option<Email>,
) -> Result<Customer, error_stack::Report<errors::ConnectorError>> {
let (billing, address) =
Expand Down Expand Up @@ -454,8 +456,8 @@ fn build_customer_info(
})
}

impl From<payments::AddressDetails> for BillingAddress {
fn from(value: payments::AddressDetails) -> Self {
impl From<hyperswitch_domain_models::address::AddressDetails> for BillingAddress {
fn from(value: hyperswitch_domain_models::address::AddressDetails) -> Self {
Self {
city: value.city,
country_code: value.country,
Expand All @@ -466,8 +468,8 @@ impl From<payments::AddressDetails> for BillingAddress {
}
}

impl From<payments::AddressDetails> for Shipping {
fn from(value: payments::AddressDetails) -> Self {
impl From<hyperswitch_domain_models::address::AddressDetails> for Shipping {
fn from(value: hyperswitch_domain_models::address::AddressDetails) -> Self {
Self {
city: value.city,
country_code: value.country,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::collections::HashMap;

use api_models::payments::{Address, MandateIds, MandateReferenceId};
use api_models::payments::{MandateIds, MandateReferenceId};
use base64::Engine;
use common_enums::enums;
use common_utils::{
consts::BASE64_ENGINE, errors::CustomResult, ext_traits::OptionExt, pii, types::MinorUnit,
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
address,
payment_method_data::{PaymentMethodData, WalletData},
router_data::{ConnectorAuthType, ErrorResponse, RouterData},
router_flow_types::{Authorize, SetupMandate},
Expand Down Expand Up @@ -70,7 +71,7 @@ impl TryFrom<Option<&pii::SecretSerdeValue>> for WorldpayConnectorMetadataObject

fn fetch_payment_instrument(
payment_method: PaymentMethodData,
billing_address: Option<&Address>,
billing_address: Option<&address::Address>,
mandate_ids: Option<MandateIds>,
) -> CustomResult<PaymentInstrument, errors::ConnectorError> {
match payment_method {
Expand Down Expand Up @@ -232,7 +233,7 @@ trait WorldpayPaymentsRequestData {
fn get_off_session(&self) -> Option<bool>;
fn get_mandate_id(&self) -> Option<MandateIds>;
fn get_currency(&self) -> enums::Currency;
fn get_optional_billing_address(&self) -> Option<&Address>;
fn get_optional_billing_address(&self) -> Option<&address::Address>;
fn get_connector_meta_data(&self) -> Option<&pii::SecretSerdeValue>;
fn get_payment_method(&self) -> enums::PaymentMethod;
fn get_payment_method_type(&self) -> Option<enums::PaymentMethodType>;
Expand Down Expand Up @@ -278,7 +279,7 @@ impl WorldpayPaymentsRequestData
self.request.currency
}

fn get_optional_billing_address(&self) -> Option<&Address> {
fn get_optional_billing_address(&self) -> Option<&address::Address> {
self.get_optional_billing()
}

Expand Down Expand Up @@ -338,7 +339,7 @@ impl WorldpayPaymentsRequestData
self.request.currency
}

fn get_optional_billing_address(&self) -> Option<&Address> {
fn get_optional_billing_address(&self) -> Option<&address::Address> {
self.get_optional_billing()
}

Expand Down
3 changes: 2 additions & 1 deletion crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};

use api_models::payments::{self, Address, AddressDetails, PhoneDetails};
use api_models::payments;
use base64::Engine;
use common_enums::{
enums,
Expand All @@ -16,6 +16,7 @@ use common_utils::{
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
address::{Address, AddressDetails, PhoneDetails},
payment_method_data::{Card, PaymentMethodData},
router_data::{
ApplePayPredecryptData, ErrorResponse, PaymentMethodToken, RecurringMandatePaymentData,
Expand Down
Loading
Loading