mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(core): Add payments update-intent API for v2 (#6490)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -156,8 +156,8 @@ pub struct PaymentsCreateIntentRequest {
|
||||
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
|
||||
/// Set to true to indicate that the customer is in your checkout flow during this payment, and therefore is able to authenticate. This parameter should be false when merchant's doing merchant initiated payments and customer is not present while doing the payment.
|
||||
#[schema(example = true, value_type = Option<PresenceOfCustomerDuringPayment>)]
|
||||
/// Set to `present` to indicate that the customer is in your checkout flow during this payment, and therefore is able to authenticate. This parameter should be `absent` when merchant's doing merchant initiated payments and customer is not present while doing the payment.
|
||||
#[schema(example = "present", value_type = Option<PresenceOfCustomerDuringPayment>)]
|
||||
pub customer_present: Option<common_enums::PresenceOfCustomerDuringPayment>,
|
||||
|
||||
/// A description for the payment
|
||||
@ -297,6 +297,99 @@ pub struct PaymentsGetIntentRequest {
|
||||
pub id: id_type::GlobalPaymentId,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[cfg(feature = "v2")]
|
||||
pub struct PaymentsUpdateIntentRequest {
|
||||
pub amount_details: Option<AmountDetailsUpdate>,
|
||||
|
||||
/// The routing algorithm id to be used for the payment
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub routing_algorithm_id: Option<id_type::RoutingId>,
|
||||
|
||||
#[schema(value_type = Option<CaptureMethod>, example = "automatic")]
|
||||
pub capture_method: Option<api_enums::CaptureMethod>,
|
||||
|
||||
#[schema(value_type = Option<AuthenticationType>, example = "no_three_ds", default = "no_three_ds")]
|
||||
pub authentication_type: Option<api_enums::AuthenticationType>,
|
||||
|
||||
/// The billing details of the payment. This address will be used for invoicing.
|
||||
pub billing: Option<Address>,
|
||||
|
||||
/// The shipping address for the payment
|
||||
pub shipping: Option<Address>,
|
||||
|
||||
/// Set to `present` to indicate that the customer is in your checkout flow during this payment, and therefore is able to authenticate. This parameter should be `absent` when merchant's doing merchant initiated payments and customer is not present while doing the payment.
|
||||
#[schema(example = "present", value_type = Option<PresenceOfCustomerDuringPayment>)]
|
||||
pub customer_present: Option<common_enums::PresenceOfCustomerDuringPayment>,
|
||||
|
||||
/// A description for the payment
|
||||
#[schema(example = "It's my first payment request", value_type = Option<String>)]
|
||||
pub description: Option<common_utils::types::Description>,
|
||||
|
||||
/// The URL to which you want the user to be redirected after the completion of the payment operation
|
||||
#[schema(value_type = Option<String>, example = "https://hyperswitch.io")]
|
||||
pub return_url: Option<common_utils::types::Url>,
|
||||
|
||||
#[schema(value_type = Option<FutureUsage>, example = "off_session")]
|
||||
pub setup_future_usage: Option<api_enums::FutureUsage>,
|
||||
|
||||
/// Apply MIT exemption for a payment
|
||||
#[schema(value_type = Option<MitExemptionRequest>)]
|
||||
pub apply_mit_exemption: Option<common_enums::MitExemptionRequest>,
|
||||
|
||||
/// For non-card charges, you can use this value as the complete description that appears on your customers’ statements. Must contain at least one letter, maximum 22 characters.
|
||||
#[schema(max_length = 22, example = "Hyperswitch Router", value_type = Option<String>)]
|
||||
pub statement_descriptor: Option<common_utils::types::StatementDescriptor>,
|
||||
|
||||
/// Use this object to capture the details about the different products for which the payment is being made. The sum of amount across different products here should be equal to the overall payment amount
|
||||
#[schema(value_type = Option<Vec<OrderDetailsWithAmount>>, example = r#"[{
|
||||
"product_name": "Apple iPhone 16",
|
||||
"quantity": 1,
|
||||
"amount" : 69000
|
||||
"product_img_link" : "https://dummy-img-link.com"
|
||||
}]"#)]
|
||||
pub order_details: Option<Vec<OrderDetailsWithAmount>>,
|
||||
|
||||
/// Use this parameter to restrict the Payment Method Types to show for a given PaymentIntent
|
||||
#[schema(value_type = Option<Vec<PaymentMethodType>>)]
|
||||
pub allowed_payment_method_types: Option<Vec<api_enums::PaymentMethodType>>,
|
||||
|
||||
/// Metadata is useful for storing additional, unstructured information on an object. This metadata will override the metadata that was passed in payments
|
||||
#[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)]
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
|
||||
/// Some connectors like Apple pay, Airwallex and Noon might require some additional information, find specific details in the child attributes below.
|
||||
#[schema(value_type = Option<ConnectorMetadata>)]
|
||||
pub connector_metadata: Option<pii::SecretSerdeValue>,
|
||||
|
||||
/// Additional data that might be required by hyperswitch based on the requested features by the merchants.
|
||||
#[schema(value_type = Option<FeatureMetadata>)]
|
||||
pub feature_metadata: Option<FeatureMetadata>,
|
||||
|
||||
/// Configure a custom payment link for the particular payment
|
||||
#[schema(value_type = Option<PaymentLinkConfigRequest>)]
|
||||
pub payment_link_config: Option<admin::PaymentLinkConfigRequest>,
|
||||
|
||||
/// Request an incremental authorization, i.e., increase the authorized amount on a confirmed payment before you capture it.
|
||||
#[schema(value_type = Option<RequestIncrementalAuthorization>)]
|
||||
pub request_incremental_authorization: Option<common_enums::RequestIncrementalAuthorization>,
|
||||
|
||||
/// Will be used to expire client secret after certain amount of time to be supplied in seconds, if not sent it will be taken from profile config
|
||||
///(900) for 15 mins
|
||||
#[schema(value_type = Option<u32>, example = 900)]
|
||||
pub session_expiry: Option<u32>,
|
||||
|
||||
/// Additional data related to some frm(Fraud Risk Management) connectors
|
||||
#[schema(value_type = Option<Object>, example = r#"{ "coverage_request" : "fraud", "fulfillment_method" : "delivery" }"#)]
|
||||
pub frm_metadata: Option<pii::SecretSerdeValue>,
|
||||
|
||||
/// Whether to perform external authentication (if applicable)
|
||||
#[schema(value_type = Option<External3dsAuthenticationRequest>)]
|
||||
pub request_external_three_ds_authentication:
|
||||
Option<common_enums::External3dsAuthenticationRequest>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, Clone, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
#[cfg(feature = "v2")]
|
||||
@ -352,8 +445,8 @@ pub struct PaymentsIntentResponse {
|
||||
#[schema(value_type = Option<String>, max_length = 64, min_length = 1, example = "cus_y3oqhf46pyzuxjbcn2giaqnb44")]
|
||||
pub customer_id: Option<id_type::CustomerId>,
|
||||
|
||||
/// Set to true to indicate that the customer is in your checkout flow during this payment, and therefore is able to authenticate. This parameter should be false when merchant's doing merchant initiated payments and customer is not present while doing the payment.
|
||||
#[schema(example = true, value_type = PresenceOfCustomerDuringPayment)]
|
||||
/// Set to `present` to indicate that the customer is in your checkout flow during this payment, and therefore is able to authenticate. This parameter should be `absent` when merchant's doing merchant initiated payments and customer is not present while doing the payment.
|
||||
#[schema(example = "present", value_type = PresenceOfCustomerDuringPayment)]
|
||||
pub customer_present: common_enums::PresenceOfCustomerDuringPayment,
|
||||
|
||||
/// A description for the payment
|
||||
@ -453,6 +546,32 @@ pub struct AmountDetails {
|
||||
tax_on_surcharge: Option<MinorUnit>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct AmountDetailsUpdate {
|
||||
/// The payment amount. Amount for the payment in the lowest denomination of the currency, (i.e) in cents for USD denomination, in yen for JPY denomination etc. E.g., Pass 100 to charge $1.00 and 1 for 1¥ since ¥ is a zero-decimal currency. Read more about [the Decimal and Non-Decimal Currencies](https://github.com/juspay/hyperswitch/wiki/Decimal-and-Non%E2%80%90Decimal-Currencies)
|
||||
#[schema(value_type = Option<u64>, example = 6540)]
|
||||
#[serde(default, deserialize_with = "amount::deserialize_option")]
|
||||
order_amount: Option<Amount>,
|
||||
/// The currency of the order
|
||||
#[schema(example = "USD", value_type = Option<Currency>)]
|
||||
currency: Option<common_enums::Currency>,
|
||||
/// The shipping cost of the order. This has to be collected from the merchant
|
||||
shipping_cost: Option<MinorUnit>,
|
||||
/// Tax amount related to the order. This will be calculated by the external tax provider
|
||||
order_tax_amount: Option<MinorUnit>,
|
||||
/// The action to whether calculate tax by calling external tax provider or not
|
||||
#[schema(value_type = Option<TaxCalculationOverride>)]
|
||||
skip_external_tax_calculation: Option<common_enums::TaxCalculationOverride>,
|
||||
/// The action to whether calculate surcharge or not
|
||||
#[schema(value_type = Option<SurchargeCalculationOverride>)]
|
||||
skip_surcharge_calculation: Option<common_enums::SurchargeCalculationOverride>,
|
||||
/// The surcharge amount to be added to the order, collected from the merchant
|
||||
surcharge_amount: Option<MinorUnit>,
|
||||
/// tax on surcharge amount
|
||||
tax_on_surcharge: Option<MinorUnit>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
pub struct AmountDetailsSetter {
|
||||
pub order_amount: Amount,
|
||||
@ -552,10 +671,10 @@ impl AmountDetails {
|
||||
self.order_tax_amount
|
||||
}
|
||||
pub fn skip_external_tax_calculation(&self) -> common_enums::TaxCalculationOverride {
|
||||
self.skip_external_tax_calculation.clone()
|
||||
self.skip_external_tax_calculation
|
||||
}
|
||||
pub fn skip_surcharge_calculation(&self) -> common_enums::SurchargeCalculationOverride {
|
||||
self.skip_surcharge_calculation.clone()
|
||||
self.skip_surcharge_calculation
|
||||
}
|
||||
pub fn surcharge_amount(&self) -> Option<MinorUnit> {
|
||||
self.surcharge_amount
|
||||
@ -565,6 +684,33 @@ impl AmountDetails {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
impl AmountDetailsUpdate {
|
||||
pub fn order_amount(&self) -> Option<Amount> {
|
||||
self.order_amount
|
||||
}
|
||||
pub fn currency(&self) -> Option<common_enums::Currency> {
|
||||
self.currency
|
||||
}
|
||||
pub fn shipping_cost(&self) -> Option<MinorUnit> {
|
||||
self.shipping_cost
|
||||
}
|
||||
pub fn order_tax_amount(&self) -> Option<MinorUnit> {
|
||||
self.order_tax_amount
|
||||
}
|
||||
pub fn skip_external_tax_calculation(&self) -> Option<common_enums::TaxCalculationOverride> {
|
||||
self.skip_external_tax_calculation
|
||||
}
|
||||
pub fn skip_surcharge_calculation(&self) -> Option<common_enums::SurchargeCalculationOverride> {
|
||||
self.skip_surcharge_calculation
|
||||
}
|
||||
pub fn surcharge_amount(&self) -> Option<MinorUnit> {
|
||||
self.surcharge_amount
|
||||
}
|
||||
pub fn tax_on_surcharge(&self) -> Option<MinorUnit> {
|
||||
self.tax_on_surcharge
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "v1")]
|
||||
#[derive(
|
||||
Default,
|
||||
|
||||
Reference in New Issue
Block a user