diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 208f68243ab0..ddb786d2d686 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -923,6 +923,7 @@ pub enum AcceptedCurrencies { content = "list", rename_all = "snake_case" )] +/// Object to filter the customer countries for which the payment method is displayed pub enum AcceptedCountries { #[schema(value_type = Vec)] EnableOnly(Vec), diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 67b5e34d6076..ba60782f8f7b 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -82,7 +82,7 @@ pub struct CustomerDetails { ToSchema, router_derive::PolymorphicSchema, )] -#[generate_schemas(PaymentsCreateRequest, PaymentsUpdateRequest)] +#[generate_schemas(PaymentsCreateRequest, PaymentsUpdateRequest, PaymentsConfirmRequest)] #[serde(deny_unknown_fields)] pub struct PaymentsRequest { /// 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 ¥100 since ¥ is a zero-decimal currency @@ -237,6 +237,7 @@ pub struct PaymentsRequest { /// A unique identifier to link the payment to a mandate. To do Recurring payments after a mandate has been created, pass the mandate_id instead of payment_method_data #[schema(max_length = 255, example = "mandate_iwer89rnjef349dni3")] + #[remove_in(PaymentsUpdateRequest)] pub mandate_id: Option, /// Additional details required by 3DS 2.0 @@ -264,11 +265,13 @@ pub struct PaymentsRequest { /// Business country of the merchant for this payment. /// To be deprecated soon. Pass the profile_id instead #[schema(value_type = Option, example = "US")] + #[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)] pub business_country: Option, /// Business label of the merchant for this payment. /// To be deprecated soon. Pass the profile_id instead #[schema(example = "food")] + #[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)] pub business_label: Option, /// Merchant connector details used to make payments. @@ -280,6 +283,7 @@ pub struct PaymentsRequest { pub allowed_payment_method_types: Option>, /// Business sub label for the payment + #[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest, PaymentsCreateRequest)] pub business_sub_label: Option, /// Denotes the retry action @@ -300,9 +304,11 @@ pub struct PaymentsRequest { /// The business profile to use for this payment, if not passed the default business profile /// associated with the merchant account will be used. + #[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)] pub profile_id: Option, /// surcharge_details for this payment + #[remove_in(PaymentsConfirmRequest)] #[schema(value_type = Option)] pub surcharge_details: Option, @@ -688,6 +694,7 @@ pub struct CustomerAcceptance { #[derive(Default, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, ToSchema)] #[serde(rename_all = "lowercase")] +/// This is used to indicate if the mandate was accepted online or offline pub enum AcceptanceType { Online, #[default] @@ -3118,7 +3125,7 @@ pub struct PaymentsCancelRequest { /// The reason for the payment cancel pub cancellation_reason: Option, /// Merchant connector details used to make payments. - #[schema(value_type = MerchantConnectorDetailsWrap)] + #[schema(value_type = Option)] pub merchant_connector_details: Option, } diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index ae9be820d6ae..b1d135a88a9f 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -269,6 +269,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payments::PaymentsRequest, api_models::payments::PaymentsCreateRequest, api_models::payments::PaymentsUpdateRequest, + api_models::payments::PaymentsConfirmRequest, api_models::payments::PaymentsResponse, api_models::payments::PaymentsStartRequest, api_models::payments::PaymentRetrieveBody, diff --git a/crates/openapi/src/routes/payments.rs b/crates/openapi/src/routes/payments.rs index d90ed15dbaf9..8d77790c9543 100644 --- a/crates/openapi/src/routes/payments.rs +++ b/crates/openapi/src/routes/payments.rs @@ -279,7 +279,7 @@ pub fn payments_update() {} ("payment_id" = String, Path, description = "The identifier for payment") ), request_body( - content = PaymentsRequest, + content = PaymentsConfirmRequest, examples( ( "Confirm a payment with payment method data" = ( @@ -320,7 +320,21 @@ pub fn payments_confirm() {} params( ("payment_id" = String, Path, description = "The identifier for payment") ), - request_body=PaymentsCaptureRequest, + request_body ( + content = PaymentsCaptureRequest, + examples( + ( + "Capture the full amount" = ( + value = json!({}) + ) + ), + ( + "Capture partial amount" = ( + value = json!({"amount_to_capture": 654}) + ) + ), + ) + ), responses( (status = 200, description = "Payment captured", body = PaymentsResponse), (status = 400, description = "Missing mandatory fields") @@ -333,7 +347,7 @@ pub fn payments_capture() {} /// Payments - Session token /// -/// To create the session object or to get *session token* for wallets +/// Creates a session object or a session token for wallets like Apple Pay, Google Pay, etc. These tokens are used by Hyperswitch's SDK to initiate these wallets' SDK. #[utoipa::path( post, path = "/payments/session_tokens", diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 9a63368fb113..9ddce51fe21e 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -2231,7 +2231,7 @@ "Payments" ], "summary": "Payments - Session token", - "description": "Payments - Session token\n\nTo create the session object or to get *session token* for wallets", + "description": "Payments - Session token\n\nCreates a session object or a session token for wallets like Apple Pay, Google Pay, etc. These tokens are used by Hyperswitch's SDK to initiate these wallets' SDK.", "operationId": "Create Session tokens for a Payment", "requestBody": { "content": { @@ -2477,6 +2477,16 @@ "application/json": { "schema": { "$ref": "#/components/schemas/PaymentsCaptureRequest" + }, + "examples": { + "Capture partial amount": { + "value": { + "amount_to_capture": 654 + } + }, + "Capture the full amount": { + "value": {} + } } } }, @@ -2527,7 +2537,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/PaymentsRequest" + "$ref": "#/components/schemas/PaymentsConfirmRequest" }, "examples": { "Confirm a payment with payment method data": { @@ -2777,6 +2787,7 @@ "schemas": { "AcceptanceType": { "type": "string", + "description": "This is used to indicate if the mandate was accepted online or offline", "enum": [ "online", "offline" @@ -2841,6 +2852,7 @@ } } ], + "description": "Object to filter the customer countries for which the payment method is displayed", "discriminator": { "propertyName": "type" } @@ -10187,9 +10199,6 @@ }, "PaymentsCancelRequest": { "type": "object", - "required": [ - "merchant_connector_details" - ], "properties": { "cancellation_reason": { "type": "string", @@ -10197,7 +10206,12 @@ "nullable": true }, "merchant_connector_details": { - "$ref": "#/components/schemas/MerchantConnectorDetailsWrap" + "allOf": [ + { + "$ref": "#/components/schemas/MerchantConnectorDetailsWrap" + } + ], + "nullable": true } } }, @@ -10240,6 +10254,351 @@ } } }, + "PaymentsConfirmRequest": { + "type": "object", + "properties": { + "amount": { + "type": "integer", + "format": "int64", + "description": "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 ¥100 since ¥ is a zero-decimal currency", + "example": 6540, + "nullable": true, + "minimum": 0 + }, + "currency": { + "allOf": [ + { + "$ref": "#/components/schemas/Currency" + } + ], + "nullable": true + }, + "amount_to_capture": { + "type": "integer", + "format": "int64", + "description": "The Amount to be captured / debited from the users payment method. It shall be in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc., If not provided, the default amount_to_capture will be the payment amount.", + "example": 6540, + "nullable": true + }, + "payment_id": { + "type": "string", + "description": "Unique identifier for the payment. This ensures idempotency for multiple payments\nthat have been done by a single merchant. This field is auto generated and is returned in the API response.", + "example": "pay_mbabizu24mvu3mela5njyhpit4", + "nullable": true, + "maxLength": 30, + "minLength": 30 + }, + "merchant_id": { + "type": "string", + "description": "This is an identifier for the merchant account. This is inferred from the API key\nprovided during the request", + "example": "merchant_1668273825", + "nullable": true, + "maxLength": 255 + }, + "routing": { + "allOf": [ + { + "$ref": "#/components/schemas/RoutingAlgorithm" + } + ], + "nullable": true + }, + "connector": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Connector" + }, + "description": "This allows to manually select a connector with which the payment can go through", + "example": [ + "stripe", + "adyen" + ], + "nullable": true + }, + "capture_method": { + "allOf": [ + { + "$ref": "#/components/schemas/CaptureMethod" + } + ], + "nullable": true + }, + "authentication_type": { + "allOf": [ + { + "$ref": "#/components/schemas/AuthenticationType" + } + ], + "default": "three_ds", + "nullable": true + }, + "billing": { + "allOf": [ + { + "$ref": "#/components/schemas/Address" + } + ], + "nullable": true + }, + "capture_on": { + "type": "string", + "format": "date-time", + "description": "A timestamp (ISO 8601 code) that determines when the payment should be captured.\nProviding this field will automatically set `capture` to true", + "example": "2022-09-10T10:11:12Z", + "nullable": true + }, + "confirm": { + "type": "boolean", + "description": "Whether to confirm the payment (if applicable)", + "default": false, + "example": true, + "nullable": true + }, + "customer": { + "allOf": [ + { + "$ref": "#/components/schemas/CustomerDetails" + } + ], + "nullable": true + }, + "customer_id": { + "type": "string", + "description": "The identifier for the customer object. This field will be deprecated soon, use the customer object instead", + "example": "cus_y3oqhf46pyzuxjbcn2giaqnb44", + "nullable": true, + "maxLength": 255 + }, + "email": { + "type": "string", + "description": "TThe customer's email address This field will be deprecated soon, use the customer object instead", + "example": "johntest@test.com", + "nullable": true, + "maxLength": 255 + }, + "name": { + "type": "string", + "description": "The customer's name\nThis field will be deprecated soon, use the customer object instead", + "example": "John Test", + "nullable": true, + "maxLength": 255 + }, + "phone": { + "type": "string", + "description": "The customer's phone number\nThis field will be deprecated soon, use the customer object instead", + "example": "3141592653", + "nullable": true, + "maxLength": 255 + }, + "phone_country_code": { + "type": "string", + "description": "The country code for the customer phone number\nThis field will be deprecated soon, use the customer object instead", + "example": "+1", + "nullable": true, + "maxLength": 255 + }, + "off_session": { + "type": "boolean", + "description": "Set to true to indicate that the customer is not in your checkout flow during this payment, and therefore is unable to authenticate. This parameter is intended for scenarios where you collect card details and charge them later. When making a recurring payment by passing a mandate_id, this parameter is mandatory", + "example": true, + "nullable": true + }, + "description": { + "type": "string", + "description": "A description for the payment", + "example": "It's my first payment request", + "nullable": true + }, + "return_url": { + "type": "string", + "description": "The URL to redirect after the completion of the operation", + "example": "https://hyperswitch.io", + "nullable": true + }, + "setup_future_usage": { + "allOf": [ + { + "$ref": "#/components/schemas/FutureUsage" + } + ], + "nullable": true + }, + "payment_method_data": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentMethodData" + } + ], + "nullable": true + }, + "payment_method": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentMethod" + } + ], + "nullable": true + }, + "payment_token": { + "type": "string", + "description": "Provide a reference to a stored payment method", + "example": "187282ab-40ef-47a9-9206-5099ba31e432", + "nullable": true + }, + "card_cvc": { + "type": "string", + "description": "This is used along with the payment_token field while collecting during saved card payments. This field will be deprecated soon, use the payment_method_data.card_token object instead", + "deprecated": true, + "nullable": true + }, + "shipping": { + "allOf": [ + { + "$ref": "#/components/schemas/Address" + } + ], + "nullable": true + }, + "statement_descriptor_name": { + "type": "string", + "description": "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.", + "example": "Hyperswitch Router", + "nullable": true, + "maxLength": 255 + }, + "statement_descriptor_suffix": { + "type": "string", + "description": "Provides information about a card payment that customers see on their statements. Concatenated with the prefix (shortened descriptor) or statement descriptor that’s set on the account to form the complete statement descriptor. Maximum 22 characters for the concatenated descriptor.", + "example": "Payment for shoes purchase", + "nullable": true, + "maxLength": 255 + }, + "order_details": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OrderDetailsWithAmount" + }, + "description": "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", + "example": "[{\n \"product_name\": \"Apple iPhone 16\",\n \"quantity\": 1,\n \"amount\" : 69000\n \"product_img_link\" : \"https://dummy-img-link.com\"\n }]", + "nullable": true + }, + "client_secret": { + "type": "string", + "description": "It's a token used for client side verification.", + "example": "pay_U42c409qyHwOkWo3vK60_secret_el9ksDkiB8hi6j9N78yo", + "nullable": true + }, + "mandate_data": { + "allOf": [ + { + "$ref": "#/components/schemas/MandateData" + } + ], + "nullable": true + }, + "mandate_id": { + "type": "string", + "description": "A unique identifier to link the payment to a mandate. To do Recurring payments after a mandate has been created, pass the mandate_id instead of payment_method_data", + "example": "mandate_iwer89rnjef349dni3", + "nullable": true, + "maxLength": 255 + }, + "browser_info": { + "allOf": [ + { + "$ref": "#/components/schemas/BrowserInformation" + } + ], + "nullable": true + }, + "payment_experience": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentExperience" + } + ], + "nullable": true + }, + "payment_method_type": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentMethodType" + } + ], + "nullable": true + }, + "merchant_connector_details": { + "allOf": [ + { + "$ref": "#/components/schemas/MerchantConnectorDetailsWrap" + } + ], + "nullable": true + }, + "allowed_payment_method_types": { + "type": "array", + "items": { + "$ref": "#/components/schemas/PaymentMethodType" + }, + "description": "Use this parameter to restrict the Payment Method Types to show for a given PaymentIntent", + "nullable": true + }, + "retry_action": { + "allOf": [ + { + "$ref": "#/components/schemas/RetryAction" + } + ], + "nullable": true + }, + "metadata": { + "type": "object", + "description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.", + "nullable": true + }, + "connector_metadata": { + "allOf": [ + { + "$ref": "#/components/schemas/ConnectorMetadata" + } + ], + "nullable": true + }, + "feature_metadata": { + "allOf": [ + { + "$ref": "#/components/schemas/FeatureMetadata" + } + ], + "nullable": true + }, + "payment_link_object": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentLinkObject" + } + ], + "nullable": true + }, + "payment_type": { + "allOf": [ + { + "$ref": "#/components/schemas/PaymentType" + } + ], + "nullable": true + }, + "request_incremental_authorization": { + "type": "boolean", + "description": "Request for an incremental authorization", + "nullable": true + }, + "frm_metadata": { + "description": "additional data related to some frm connectors", + "nullable": true + } + } + }, "PaymentsCreateRequest": { "type": "object", "required": [ @@ -10534,11 +10893,6 @@ "description": "Use this parameter to restrict the Payment Method Types to show for a given PaymentIntent", "nullable": true }, - "business_sub_label": { - "type": "string", - "description": "Business sub label for the payment", - "nullable": true - }, "retry_action": { "allOf": [ { @@ -11807,13 +12161,6 @@ ], "nullable": true }, - "mandate_id": { - "type": "string", - "description": "A unique identifier to link the payment to a mandate. To do Recurring payments after a mandate has been created, pass the mandate_id instead of payment_method_data", - "example": "mandate_iwer89rnjef349dni3", - "nullable": true, - "maxLength": 255 - }, "browser_info": { "allOf": [ { @@ -11838,20 +12185,6 @@ ], "nullable": true }, - "business_country": { - "allOf": [ - { - "$ref": "#/components/schemas/CountryAlpha2" - } - ], - "nullable": true - }, - "business_label": { - "type": "string", - "description": "Business label of the merchant for this payment.\nTo be deprecated soon. Pass the profile_id instead", - "example": "food", - "nullable": true - }, "merchant_connector_details": { "allOf": [ { @@ -11868,11 +12201,6 @@ "description": "Use this parameter to restrict the Payment Method Types to show for a given PaymentIntent", "nullable": true }, - "business_sub_label": { - "type": "string", - "description": "Business sub label for the payment", - "nullable": true - }, "retry_action": { "allOf": [ { @@ -11910,11 +12238,6 @@ ], "nullable": true }, - "profile_id": { - "type": "string", - "description": "The business profile to use for this payment, if not passed the default business profile\nassociated with the merchant account will be used.", - "nullable": true - }, "surcharge_details": { "allOf": [ {