Docs: Api reference docs update for Payments - Create (#4955)

Co-authored-by: Gorakhnath Yadav <gorakhnath.yadav@Gorakhnath-Yadav-J9J2YJH1J2.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
GORAKHNATH YADAV
2024-06-28 17:02:38 +05:30
committed by GitHub
parent f03dc7a1c9
commit f55cae20af
9 changed files with 666 additions and 151 deletions

View File

@ -857,9 +857,11 @@ pub struct ToggleAllKVResponse {
#[schema(example = true)]
pub kv_enabled: bool,
}
/// Merchant connector details used to make payments.
#[derive(Debug, Clone, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct MerchantConnectorDetailsWrap {
/// Creds Identifier is to uniquely identify the credentials. Do not send any sensitive info in this field. And do not send the string "null".
/// Creds Identifier is to uniquely identify the credentials. Do not send any sensitive info, like encoded_data in this field. And do not send the string "null".
pub creds_identifier: String,
/// Merchant connector details type type. Base64 Encode the credentials and send it in this type and send as a string.
#[schema(value_type = Option<MerchantConnectorDetails>, example = r#"{

View File

@ -572,6 +572,7 @@ mod test {
}
}
/// Denotes the retry action
#[derive(
Debug,
serde::Deserialize,

View File

@ -2,6 +2,7 @@ use common_utils::id_type;
use serde;
use utoipa::ToSchema;
/// ephemeral_key for the customer_id mentioned
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, ToSchema)]
pub struct EphemeralKeyCreateResponse {
/// customer_id to which this ephemeral key belongs to

View File

@ -114,6 +114,7 @@ pub struct MandateListConstraints {
pub created_time_gte: Option<PrimitiveDateTime>,
}
/// Details required for recurring payment
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum RecurringDetails {

View File

@ -179,6 +179,7 @@ mod client_secret_tests {
}
}
/// Passing this object creates a new customer or attaches an existing customer to the payment
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema, PartialEq)]
pub struct CustomerDetails {
/// The identifier for the customer.
@ -202,6 +203,7 @@ pub struct CustomerDetails {
pub phone_country_code: Option<String>,
}
/// Details of customer attached to this payment
#[derive(Debug, Default, serde::Serialize, Clone, ToSchema, PartialEq, Setter)]
pub struct CustomerDetailsResponse {
/// The identifier for the customer.
@ -267,6 +269,7 @@ pub struct PaymentsRequest {
/// This is an identifier for the merchant account. This is inferred from the API key
/// provided during the request
#[schema(max_length = 255, example = "merchant_1668273825")]
#[remove_in(PaymentsUpdateRequest, PaymentsCreateRequest, PaymentsConfirmRequest)]
pub merchant_id: Option<String>,
#[schema(value_type = Option<StraightThroughAlgorithm>, example = json!({
@ -279,11 +282,9 @@ pub struct PaymentsRequest {
#[schema(value_type = Option<Vec<Connector>>, max_length = 255, example = json!(["stripe", "adyen"]))]
pub connector: Option<Vec<api_enums::Connector>>,
/// Default value if not passed is set to 'automatic' which results in Auth and Capture in one single API request. Pass 'manual' or 'manual_multiple' in case you want do a separate Auth and Capture by first authorizing and placing a hold on your customer's funds so that you can use the Payments/Capture endpoint later to capture the authorized amount. Pass 'manual' if you want to only capture the amount later once or 'manual_multiple' if you want to capture the funds multiple times later. Both 'manual' and 'manual_multiple' are only supported by a specific list of processors
#[schema(value_type = Option<CaptureMethod>, example = "automatic")]
pub capture_method: Option<api_enums::CaptureMethod>,
/// Pass this parameter to force 3DS or non 3DS auth for this payment. Some connectors will still force 3DS auth even in case of passing 'no_three_ds' here and vice versa. Default value is 'no_three_ds' if not set
#[schema(value_type = Option<AuthenticationType>, example = "no_three_ds", default = "three_ds")]
pub authentication_type: Option<api_enums::AuthenticationType>,
@ -294,6 +295,7 @@ pub struct PaymentsRequest {
/// Providing this field will automatically set `capture` to true
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
#[remove_in(PaymentsUpdateRequest, PaymentsCreateRequest, PaymentsConfirmRequest)]
pub capture_on: Option<PrimitiveDateTime>,
/// Whether to confirm the payment (if applicable)
@ -342,16 +344,14 @@ pub struct PaymentsRequest {
/// The URL to redirect after the completion of the operation
#[schema(value_type = Option<String>, example = "https://hyperswitch.io")]
pub return_url: Option<Url>,
/// Indicates that you intend to make future payments with this Payments payment method. Providing this parameter will attach the payment method to the Customer, if present, after the Payment is confirmed and any required actions from the user are complete.
#[schema(value_type = Option<FutureUsage>, example = "off_session")]
pub setup_future_usage: Option<api_enums::FutureUsage>,
/// The payment method information provided for making a payment
#[schema(example = "bank_transfer")]
#[serde(with = "payment_method_data_serde", default)]
pub payment_method_data: Option<PaymentMethodDataRequest>,
/// The payment method that is to be used
#[schema(value_type = Option<PaymentMethod>, example = "card")]
pub payment_method: Option<api_enums::PaymentMethod>,
@ -361,6 +361,7 @@ pub struct PaymentsRequest {
/// 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
#[schema(value_type = Option<String>, deprecated)]
#[remove_in(PaymentsUpdateRequest, PaymentsCreateRequest, PaymentsConfirmRequest)]
pub card_cvc: Option<Secret<String>>,
/// The shipping address for the payment
@ -391,7 +392,7 @@ pub struct PaymentsRequest {
/// Passing this object during payments creates a mandate. The mandate_type sub object is passed by the server.
pub mandate_data: Option<MandateData>,
/// Passing this object during payments confirm . The customer_acceptance sub object is usually passed by the SDK or client
/// We will be Passing this "CustomerAcceptance" object during Payments-Confirm. The customer_acceptance sub object is usually passed by the SDK or client
#[schema(value_type = Option<CustomerAcceptance>)]
pub customer_acceptance: Option<CustomerAcceptance>,
@ -418,7 +419,7 @@ pub struct PaymentsRequest {
#[schema(value_type = Option<PaymentExperience>, example = "redirect_to_url")]
pub payment_experience: Option<api_enums::PaymentExperience>,
/// Payment Method Type
/// Can be used to specify the Payment Method Type
#[schema(value_type = Option<PaymentMethodType>, example = "google_pay")]
pub payment_method_type: Option<api_enums::PaymentMethodType>,
@ -434,7 +435,6 @@ pub struct PaymentsRequest {
#[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)]
pub business_label: Option<String>,
/// Merchant connector details used to make payments.
#[schema(value_type = Option<MerchantConnectorDetailsWrap>)]
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
@ -448,23 +448,24 @@ pub struct PaymentsRequest {
/// Denotes the retry action
#[schema(value_type = Option<RetryAction>)]
#[remove_in(PaymentsCreateRequest)]
pub retry_action: Option<api_enums::RetryAction>,
/// 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.
#[schema(value_type = Option<Object>, example = r#"{ "udf1": "some-value", "udf2": "some-value" }"#)]
pub metadata: Option<pii::SecretSerdeValue>,
/// additional data related to some connectors
/// Some connectors like Apple pay, Airwallex and Noon might require some additional information, find specific details in the child attributes below.
pub connector_metadata: Option<ConnectorMetadata>,
/// additional data that might be required by hyperswitch
/// Additional data that might be required by hyperswitch based on the requested features by the merchants.
#[remove_in(PaymentsUpdateRequest, PaymentsCreateRequest, PaymentsConfirmRequest)]
pub feature_metadata: Option<FeatureMetadata>,
/// Whether to get the payment link (if applicable)
#[schema(default = false, example = true)]
pub payment_link: Option<bool>,
/// custom payment link config for the particular payment
#[schema(value_type = Option<PaymentCreatePaymentLinkConfig>)]
pub payment_link_config: Option<PaymentCreatePaymentLinkConfig>,
@ -473,7 +474,6 @@ pub struct PaymentsRequest {
#[remove_in(PaymentsUpdateRequest, PaymentsConfirmRequest)]
pub profile_id: Option<String>,
/// surcharge_details for this payment
#[remove_in(PaymentsConfirmRequest)]
#[schema(value_type = Option<RequestSurchargeDetails>)]
pub surcharge_details: Option<RequestSurchargeDetails>,
@ -490,7 +490,7 @@ pub struct PaymentsRequest {
#[schema(example = 900)]
pub session_expiry: Option<u32>,
/// additional data related to some frm connectors
/// 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>,
@ -505,6 +505,7 @@ pub struct PaymentsRequest {
pub charges: Option<PaymentChargeRequest>,
}
/// Fee information to be charged on the payment being collected
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct PaymentChargeRequest {
@ -530,6 +531,8 @@ impl PaymentsRequest {
.map(|amount| MinorUnit::from(amount) + surcharge_amount)
}
}
/// details of surcharge applied on this payment, if applicable
#[derive(
Default, Debug, Clone, serde::Serialize, serde::Deserialize, Copy, ToSchema, PartialEq,
)]
@ -905,6 +908,7 @@ impl Default for MandateType {
}
}
/// We will be Passing this "CustomerAcceptance" object during Payments-Confirm. The customer_acceptance sub object is usually passed by the SDK or client
#[derive(Default, Eq, PartialEq, Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct CustomerAcceptance {
@ -1462,6 +1466,7 @@ mod payment_method_data_serde {
}
}
/// The payment method information provided for making a payment
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema, Eq, PartialEq)]
pub struct PaymentMethodDataRequest {
#[serde(flatten)]
@ -3037,7 +3042,7 @@ pub struct PaymentsCaptureRequest {
/// Concatenated with the statement descriptor suffix thats set on the account to form the complete statement descriptor.
pub statement_descriptor_prefix: Option<String>,
/// Merchant connector details used to make payments.
#[schema(value_type = Option<MerchantConnectorDetailsWrap>)]
#[schema(value_type = Option<MerchantConnectorDetailsWrap>, deprecated)]
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
}
@ -3290,7 +3295,18 @@ pub struct ReceiverDetails {
amount_remaining: Option<i64>,
}
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
#[derive(
Setter,
Clone,
Default,
Debug,
PartialEq,
serde::Serialize,
ToSchema,
router_derive::PolymorphicSchema,
)]
#[generate_schemas(PaymentsCreateResponseOpenApi)]
pub struct PaymentsResponse {
/// Unique identifier for the payment. This ensures idempotency for multiple payments
/// that have been done by a single merchant.
@ -3306,7 +3322,6 @@ pub struct PaymentsResponse {
#[schema(max_length = 255, example = "merchant_1668273825")]
pub merchant_id: Option<String>,
/// The status of the current payment that was made
#[schema(value_type = IntentStatus, example = "failed", default = "requires_confirmation")]
pub status: api_enums::IntentStatus,
@ -3323,7 +3338,7 @@ pub struct PaymentsResponse {
#[schema(value_type = i64, minimum = 100, example = 6540)]
pub amount_capturable: Option<MinorUnit>,
/// The amount which is already captured from the payment
/// The amount which is already captured from the payment, this helps in the cases where merchants can't capture all capturable amount at once.
#[schema(value_type = i64, example = 6540)]
pub amount_received: Option<MinorUnit>,
@ -3355,14 +3370,13 @@ pub struct PaymentsResponse {
)]
pub customer_id: Option<id_type::CustomerId>,
/// Details of customer attached to this payment
pub customer: Option<CustomerDetailsResponse>,
/// A description of the payment
#[schema(example = "It's my first payment request")]
pub description: Option<String>,
/// List of refund that happened on this intent
/// List of refunds that happened on this intent, as same payment intent can have multiple refund requests depending on the nature of order
#[schema(value_type = Option<Vec<RefundResponse>>)]
pub refunds: Option<Vec<refunds::RefundResponse>>,
@ -3380,7 +3394,7 @@ pub struct PaymentsResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub captures: Option<Vec<CaptureResponse>>,
/// A unique identifier to link the payment to a mandate, can be use instead of payment_method_data
/// A unique identifier to link the payment to a mandate, can be used instead of payment_method_data, in case of setting up recurring payments
#[schema(max_length = 255, example = "mandate_iwer89rnjef349dni3")]
pub mandate_id: Option<String>,
@ -3454,7 +3468,7 @@ pub struct PaymentsResponse {
#[schema(example = "https://hyperswitch.io")]
pub return_url: Option<String>,
/// The transaction authentication can be set to undergo payer authentication. By default, the authentication will be marked as NO_THREE_DS
/// The transaction authentication can be set to undergo payer authentication. By default, the authentication will be marked as NO_THREE_DS, as the 3DS method helps with more robust payer authentication
#[schema(value_type = Option<AuthenticationType>, example = "no_three_ds", default = "three_ds")]
pub authentication_type: Option<api_enums::AuthenticationType>,
@ -3481,16 +3495,18 @@ pub struct PaymentsResponse {
pub error_message: Option<String>,
/// error code unified across the connectors is received here if there was an error while calling connector
#[remove_in(PaymentsCreateResponseOpenApi)]
pub unified_code: Option<String>,
/// error message unified across the connectors is received here if there was an error while calling connector
#[remove_in(PaymentsCreateResponseOpenApi)]
pub unified_message: Option<String>,
/// Payment Experience for the current payment
#[schema(value_type = Option<PaymentExperience>, example = "redirect_to_url")]
pub payment_experience: Option<api_enums::PaymentExperience>,
/// Payment Method Type
/// Can be used to specify the Payment Method Type
#[schema(value_type = Option<PaymentMethodType>, example = "gpay")]
pub payment_method_type: Option<api_enums::PaymentMethodType>,
@ -3537,10 +3553,11 @@ pub struct PaymentsResponse {
#[schema(value_type = Option<FeatureMetadata>)]
pub feature_metadata: Option<serde_json::Value>, // This is Value because it is fetched from DB and before putting in DB the type is validated
/// reference to the payment at connector side
/// reference(Identifier) to the payment at connector side
#[schema(value_type = Option<String>, example = "993672945374576J")]
pub reference_id: Option<String>,
/// Details for Payment link
pub payment_link: Option<PaymentLinkResponse>,
/// The business profile that is associated with this payment
pub profile_id: Option<String>,
@ -3557,7 +3574,7 @@ pub struct PaymentsResponse {
/// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
pub merchant_connector_id: Option<String>,
/// If true incremental authorization can be performed on this payment
/// If true, incremental authorization can be performed on this payment, in case the funds authorized initially fall short.
pub incremental_authorization_allowed: Option<bool>,
/// Total number of authorizations happened in an incremental_authorization payment
@ -3572,19 +3589,20 @@ pub struct PaymentsResponse {
/// Flag indicating if external 3ds authentication is made or not
pub external_3ds_authentication_attempted: Option<bool>,
/// Date Time expiry of the payment
/// Date Time for expiry of the payment
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub expires_on: Option<PrimitiveDateTime>,
/// Payment Fingerprint
/// Payment Fingerprint, to identify a particular card.
/// It is a 20 character long alphanumeric code.
pub fingerprint: Option<String>,
#[schema(value_type = Option<BrowserInformation>)]
/// The browser information used for this payment
pub browser_info: Option<serde_json::Value>,
/// Payment Method Id
/// Identifier for Payment Method
pub payment_method_id: Option<String>,
/// Payment Method Status
@ -3604,6 +3622,7 @@ pub struct PaymentsResponse {
pub frm_metadata: Option<pii::SecretSerdeValue>,
}
/// Fee information to be charged on the payment being collected
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct PaymentChargeResponse {
/// Identifier for charge created for the payment
@ -3621,6 +3640,7 @@ pub struct PaymentChargeResponse {
pub transfer_account_id: String,
}
/// Details of external authentication
#[derive(Setter, Clone, Default, Debug, PartialEq, serde::Serialize, ToSchema)]
pub struct ExternalAuthenticationDetailsResponse {
/// Authentication Type - Challenge / Frictionless
@ -4227,6 +4247,7 @@ pub struct ApplepaySessionRequest {
pub initiative_context: String,
}
/// additional data related to some connectors
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct ConnectorMetadata {
pub apple_pay: Option<ApplepayConnectorMetadataRequest>,
@ -4633,7 +4654,7 @@ pub struct PaymentsCancelRequest {
/// The reason for the payment cancel
pub cancellation_reason: Option<String>,
/// Merchant connector details used to make payments.
#[schema(value_type = Option<MerchantConnectorDetailsWrap>)]
#[schema(value_type = Option<MerchantConnectorDetailsWrap>, deprecated)]
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
}
@ -4665,6 +4686,7 @@ pub struct PaymentsExternalAuthenticationRequest {
pub threeds_method_comp_ind: ThreeDsCompletionIndicator,
}
/// Indicates if 3DS method data was successfully completed or not
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentsManualUpdateRequest {
/// The identifier for the payment
@ -4697,6 +4719,7 @@ pub enum ThreeDsCompletionIndicator {
NotAvailable,
}
/// Device Channel indicating whether request is coming from App or Browser
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema, Eq, PartialEq)]
pub enum DeviceChannel {
#[serde(rename = "APP")]
@ -4705,6 +4728,7 @@ pub enum DeviceChannel {
Browser,
}
/// SDK Information if request is from SDK
#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct SdkInformation {
/// Unique ID created on installations of the 3DS Requestor App on a Consumer Device
@ -4723,7 +4747,7 @@ pub struct SdkInformation {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentsExternalAuthenticationResponse {
/// Indicates the trans status
/// Indicates the transaction status
#[serde(rename = "trans_status")]
#[schema(value_type = TransactionStatus)]
pub transaction_status: common_enums::TransactionStatus,
@ -4731,13 +4755,13 @@ pub struct PaymentsExternalAuthenticationResponse {
pub acs_url: Option<String>,
/// Challenge request which should be sent to acs_url
pub challenge_request: Option<String>,
/// Unique identifier assigned by the EMVCo
/// Unique identifier assigned by the EMVCo(Europay, Mastercard and Visa)
pub acs_reference_number: Option<String>,
/// Unique identifier assigned by the ACS to identify a single transaction
pub acs_trans_id: Option<String>,
/// Unique identifier assigned by the 3DS Server to identify a single transaction
pub three_dsserver_trans_id: Option<String>,
/// Contains the JWS object created by the ACS for the ARes message
/// Contains the JWS object created by the ACS for the ARes(Authentication Response) message
pub acs_signed_content: Option<String>,
/// Three DS Requestor URL
pub three_ds_requestor_url: String,
@ -4768,6 +4792,7 @@ pub struct PaymentsStartRequest {
pub attempt_id: String,
}
/// additional data that might be required by hyperswitch
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct FeatureMetadata {
/// Redirection response coming in request as metadata field only for redirection scenarios
@ -4959,6 +4984,7 @@ mod tests {
#[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)]
pub struct RetrievePaymentLinkRequest {
/// It's a token used for client side verification.
pub client_secret: Option<String>,
}
@ -4970,16 +4996,24 @@ pub struct PaymentLinkResponse {
#[derive(Clone, Debug, serde::Serialize, ToSchema)]
pub struct RetrievePaymentLinkResponse {
/// Identifier for Payment Link
pub payment_link_id: String,
/// Identifier for Merchant
pub merchant_id: String,
/// Payment Link
pub link_to_pay: String,
/// The payment amount. Amount for the payment in the lowest denomination of the currency
#[schema(value_type = i64, example = 6540)]
pub amount: MinorUnit,
/// Date and time of Payment Link creation
#[serde(with = "common_utils::custom_serde::iso8601")]
pub created_at: PrimitiveDateTime,
/// Date and time of Expiration for Payment Link
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub expiry: Option<PrimitiveDateTime>,
/// Description for Payment Link
pub description: Option<String>,
/// Status Of the Payment Link
pub status: PaymentLinkStatus,
#[schema(value_type = Option<Currency>)]
pub currency: Option<api_enums::Currency>,
@ -5090,6 +5124,7 @@ pub struct PaymentLinkListResponse {
pub data: Vec<PaymentLinkResponse>,
}
/// custom payment link config for the particular payment
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
pub struct PaymentCreatePaymentLinkConfig {
#[serde(flatten)]
@ -5111,6 +5146,7 @@ pub struct OrderDetailsWithStringAmount {
pub product_img_link: Option<String>,
}
/// Status Of the Payment Link
#[derive(PartialEq, Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum PaymentLinkStatus {