feat(business_profile_v2): business profile v2 create and retrieve endpoint (#5606)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <sanchith.hegde@juspay.in>
This commit is contained in:
Narayan Bhat
2024-08-20 14:50:58 +05:30
committed by GitHub
parent ac7d8c572c
commit 6e7b38a622
28 changed files with 756 additions and 248 deletions

View File

@ -26,7 +26,10 @@ use super::payments::AddressDetails;
not(feature = "merchant_account_v2")
))]
use crate::routing;
use crate::{enums as api_enums, payment_methods};
use crate::{
consts::{MAX_ORDER_FULFILLMENT_EXPIRY, MIN_ORDER_FULFILLMENT_EXPIRY},
enums as api_enums, payment_methods,
};
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
pub struct MerchantAccountListRequest {
@ -80,7 +83,7 @@ pub struct MerchantAccountCreate {
#[schema(default = false, example = true)]
pub enable_payment_response_hash: Option<bool>,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a value is automatically generated.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled.
@ -300,7 +303,7 @@ pub struct MerchantAccountUpdate {
#[schema(default = false, example = true)]
pub enable_payment_response_hash: Option<bool>,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
@ -462,7 +465,7 @@ pub struct MerchantAccountResponse {
#[schema(default = false, example = true)]
pub enable_payment_response_hash: bool,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a value is automatically generated.
#[schema(max_length = 255, example = "xkkdf909012sdjki2dkh5sdf")]
pub payment_response_hash_key: Option<String>,
@ -1851,6 +1854,10 @@ pub struct MerchantConnectorDetails {
pub metadata: Option<pii::SecretSerdeValue>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
#[derive(Clone, Debug, Deserialize, ToSchema, Default, Serialize)]
#[serde(deny_unknown_fields)]
pub struct BusinessProfileCreate {
@ -1866,7 +1873,7 @@ pub struct BusinessProfileCreate {
#[schema(default = true, example = true)]
pub enable_payment_response_hash: Option<bool>,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a value is automatically generated.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
@ -1897,7 +1904,7 @@ pub struct BusinessProfileCreate {
#[schema(value_type = Option<RoutingAlgorithm>,example = json!({"type": "single", "data": "wise"}))]
pub payout_routing_algorithm: Option<serde_json::Value>,
/// Verified applepay domains for a particular profile
/// Verified Apple Pay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,
/// Client Secret Default expiry for all payments created under this business profile
@ -1936,6 +1943,93 @@ pub struct BusinessProfileCreate {
pub outgoing_webhook_custom_http_headers: Option<HashMap<String, String>>,
}
#[nutype::nutype(
validate(greater_or_equal = MIN_ORDER_FULFILLMENT_EXPIRY, less_or_equal = MAX_ORDER_FULFILLMENT_EXPIRY),
derive(Clone, Debug, Deserialize,Serialize)
)]
pub struct OrderFulfillmentTime(i64);
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, Deserialize, ToSchema, Default, Serialize)]
#[serde(deny_unknown_fields)]
pub struct BusinessProfileCreate {
/// The name of business profile
#[schema(max_length = 64)]
pub profile_name: String,
/// The URL to redirect after the completion of the operation
#[schema(value_type = Option<String>, max_length = 255, example = "https://www.example.com/success")]
pub return_url: Option<url::Url>,
/// A boolean value to indicate if payment response hash needs to be enabled
#[schema(default = true, example = true)]
pub enable_payment_response_hash: Option<bool>,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a value is automatically generated.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
#[schema(default = false, example = true)]
pub redirect_to_merchant_with_http_post: Option<bool>,
/// Webhook related details
pub webhook_details: Option<WebhookDetails>,
/// Metadata is useful for storing additional, unstructured information on an object.
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
pub metadata: Option<pii::SecretSerdeValue>,
/// Will be used to determine the time till which your payment will be active once the payment session starts
#[schema(value_type = u32, example = 900)]
pub order_fulfillment_time: Option<OrderFulfillmentTime>,
/// Whether the order fulfillment time is calculated from the origin or the time of creating the payment, or confirming the payment
#[schema(value_type = Option<OrderFulfillmentTimeOrigin>, example = "create")]
pub order_fulfillment_time_origin: Option<api_enums::OrderFulfillmentTimeOrigin>,
/// Verified Apple Pay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,
/// Client Secret Default expiry for all payments created under this business profile
#[schema(example = 900)]
pub session_expiry: Option<u32>,
/// Default Payment Link config for all payment links created under this business profile
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
/// External 3DS authentication details
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
/// Whether to use the billing details passed when creating the intent as payment method billing
pub use_billing_as_payment_method_billing: Option<bool>,
/// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
#[schema(default = false, example = false)]
pub collect_shipping_details_from_wallet_connector: Option<bool>,
/// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
#[schema(default = false, example = false)]
pub collect_billing_details_from_wallet_connector: Option<bool>,
/// Indicates if the MIT (merchant initiated transaction) payments can be made connector
/// agnostic, i.e., MITs may be processed through different connector than CIT (customer
/// initiated transaction) based on the routing rules.
/// If set to `false`, MIT will go through the same connector as the CIT.
pub is_connector_agnostic_mit_enabled: Option<bool>,
/// Default payout link config
#[schema(value_type = Option<BusinessPayoutLinkConfig>)]
pub payout_link_config: Option<BusinessPayoutLinkConfig>,
/// These key-value pairs are sent as additional custom headers in the outgoing webhook request. It is recommended not to use more than four key-value pairs.
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub outgoing_webhook_custom_http_headers: Option<HashMap<String, String>>,
}
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
#[derive(Clone, Debug, ToSchema, Serialize)]
pub struct BusinessProfileResponse {
/// The identifier for Merchant Account
@ -1958,7 +2052,7 @@ pub struct BusinessProfileResponse {
#[schema(default = true, example = true)]
pub enable_payment_response_hash: bool,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
@ -1989,7 +2083,7 @@ pub struct BusinessProfileResponse {
#[schema(value_type = Option<RoutingAlgorithm>,example = json!({"type": "single", "data": "wise"}))]
pub payout_routing_algorithm: Option<serde_json::Value>,
/// Verified applepay domains for a particular profile
/// Verified Apple Pay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,
/// Client Secret Default expiry for all payments created under this business profile
@ -2032,6 +2126,94 @@ pub struct BusinessProfileResponse {
pub outgoing_webhook_custom_http_headers: Option<HashMap<String, Secret<String>>>,
}
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, ToSchema, Serialize)]
pub struct BusinessProfileResponse {
/// The identifier for Merchant Account
#[schema(max_length = 64, example = "y3oqhf46pyzuxjbcn2giaqnb44", value_type = String)]
pub merchant_id: id_type::MerchantId,
/// The identifier for business profile. This must be used for creating merchant accounts, payments and payouts
#[schema(max_length = 64, example = "pro_abcdefghijklmnopqrstuvwxyz")]
pub id: String,
/// Name of the business profile
#[schema(max_length = 64)]
pub profile_name: String,
/// The URL to redirect after the completion of the operation
#[schema(value_type = Option<String>, max_length = 255, example = "https://www.example.com/success")]
pub return_url: Option<String>,
/// A boolean value to indicate if payment response hash needs to be enabled
#[schema(default = true, example = true)]
pub enable_payment_response_hash: bool,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
#[schema(default = false, example = true)]
pub redirect_to_merchant_with_http_post: bool,
/// Webhook related details
pub webhook_details: Option<WebhookDetails>,
/// Metadata is useful for storing additional, unstructured information on an object.
#[schema(value_type = Option<Object>, example = r#"{ "city": "NY", "unit": "245" }"#)]
pub metadata: Option<pii::SecretSerdeValue>,
/// Verified Apple Pay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,
/// Client Secret Default expiry for all payments created under this business profile
#[schema(example = 900)]
pub session_expiry: Option<i64>,
/// Default Payment Link config for all payment links created under this business profile
#[schema(value_type = Option<BusinessPaymentLinkConfig>)]
pub payment_link_config: Option<BusinessPaymentLinkConfig>,
/// External 3DS authentication details
pub authentication_connector_details: Option<AuthenticationConnectorDetails>,
// Whether to use the billing details passed when creating the intent as payment method billing
pub use_billing_as_payment_method_billing: Option<bool>,
/// Merchant's config to support extended card info feature
pub extended_card_info_config: Option<ExtendedCardInfoConfig>,
/// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
#[schema(default = false, example = false)]
pub collect_shipping_details_from_wallet_connector: Option<bool>,
/// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
#[schema(default = false, example = false)]
pub collect_billing_details_from_wallet_connector: Option<bool>,
/// Indicates if the MIT (merchant initiated transaction) payments can be made connector
/// agnostic, i.e., MITs may be processed through different connector than CIT (customer
/// initiated transaction) based on the routing rules.
/// If set to `false`, MIT will go through the same connector as the CIT.
pub is_connector_agnostic_mit_enabled: Option<bool>,
/// Default payout link config
#[schema(value_type = Option<BusinessPayoutLinkConfig>)]
pub payout_link_config: Option<BusinessPayoutLinkConfig>,
/// These key-value pairs are sent as additional custom headers in the outgoing webhook request.
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub outgoing_webhook_custom_http_headers: Option<HashMap<String, Secret<String>>>,
/// Will be used to determine the time till which your payment will be active once the payment session starts
#[schema(value_type = u32, example = 900)]
pub order_fulfillment_time: Option<OrderFulfillmentTime>,
/// Whether the order fulfillment time is calculated from the origin or the time of creating the payment, or confirming the payment
#[schema(value_type = Option<OrderFulfillmentTimeOrigin>, example = "create")]
pub order_fulfillment_time_origin: Option<api_enums::OrderFulfillmentTimeOrigin>,
}
#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
#[serde(deny_unknown_fields)]
pub struct BusinessProfileUpdate {
@ -2047,7 +2229,7 @@ pub struct BusinessProfileUpdate {
#[schema(default = true, example = true)]
pub enable_payment_response_hash: Option<bool>,
/// Refers to the hash key used for calculating the signature for webhooks and redirect response. If the value is not provided, a default value is used.
/// Refers to the hash key used for calculating the signature for webhooks and redirect response.
pub payment_response_hash_key: Option<String>,
/// A boolean value to indicate if redirect to merchant with http post needs to be enabled
@ -2078,7 +2260,7 @@ pub struct BusinessProfileUpdate {
#[schema(value_type = Option<RoutingAlgorithm>,example = json!({"type": "single", "data": "wise"}))]
pub payout_routing_algorithm: Option<serde_json::Value>,
/// Verified applepay domains for a particular profile
/// Verified Apple Pay domains for a particular profile
pub applepay_verified_domains: Option<Vec<String>>,
/// Client Secret Default expiry for all payments created under this business profile
@ -2097,11 +2279,11 @@ pub struct BusinessProfileUpdate {
// Whether to use the billing details passed when creating the intent as payment method billing
pub use_billing_as_payment_method_billing: Option<bool>,
/// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
/// A boolean value to indicate if customer shipping details needs to be collected from wallet connector (Eg. Apple Pay, Google Pay, etc.)
#[schema(default = false, example = false)]
pub collect_shipping_details_from_wallet_connector: Option<bool>,
/// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple pay, Google pay etc)
/// A boolean value to indicate if customer billing details needs to be collected from wallet connector (Eg. Apple Pay, Google Pay, etc.)
#[schema(default = false, example = false)]
pub collect_billing_details_from_wallet_connector: Option<bool>,

View File

@ -0,0 +1,5 @@
/// Max payment intent fulfillment expiry
pub const MAX_ORDER_FULFILLMENT_EXPIRY: i64 = 1800;
/// Min payment intent fulfillment expiry
pub const MIN_ORDER_FULFILLMENT_EXPIRY: i64 = 60;

View File

@ -6,6 +6,7 @@ pub mod blocklist;
pub mod cards_info;
pub mod conditional_configs;
pub mod connector_onboarding;
pub mod consts;
pub mod currency;
pub mod customers;
pub mod disputes;