Skip to content

Commit

Permalink
feat(core): Add payments update-intent API for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuthaDev committed Nov 6, 2024
1 parent 62c4479 commit fdebe64
Show file tree
Hide file tree
Showing 20 changed files with 1,216 additions and 262 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /v2/payments/{id}/update-intent
---
1 change: 1 addition & 0 deletions api-reference-v2/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"pages": [
"api-reference/payments/payments--create-intent",
"api-reference/payments/payments--get-intent",
"api-reference/payments/payments--update-intent",
"api-reference/payments/payments--session-token",
"api-reference/payments/payments--confirm-intent"
]
Expand Down
233 changes: 233 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,67 @@
]
}
},
"/v2/payments/{id}/update-intent": {
"post": {
"tags": [
"Payments"
],
"summary": "Payments - Update Intent",
"description": "**Update a payment intent object**\n\nYou will require the 'API - Key' from the Hyperswitch dashboard to make the call.",
"operationId": "Update a Payment Intent",
"parameters": [
{
"name": "id",
"in": "path",
"description": "The unique identifier for the Payment Intent",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentsUpdateIntentRequest"
},
"examples": {
"Update a payment intent with minimal fields": {
"value": {
"amount_details": {
"currency": "USD",
"order_amount": 6540
}
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Payment Intent Updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PaymentsIntentResponse"
}
}
}
},
"404": {
"description": "Payment Intent Not Found"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/v2/payments/{id}/confirm-intent": {
"post": {
"tags": [
Expand Down Expand Up @@ -15081,6 +15142,178 @@
}
}
},
"PaymentsUpdateIntentRequest": {
"type": "object",
"required": [
"capture_method",
"authentication_type",
"customer_present",
"setup_future_usage",
"apply_mit_exemption",
"payment_link_enabled",
"request_incremental_authorization",
"request_external_three_ds_authentication"
],
"properties": {
"amount_details": {
"allOf": [
{
"$ref": "#/components/schemas/AmountDetails"
}
],
"nullable": true
},
"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.",
"example": "pay_mbabizu24mvu3mela5njyhpit4",
"nullable": true,
"maxLength": 30,
"minLength": 30
},
"routing_algorithm_id": {
"type": "string",
"description": "The routing algorithm id to be used for the payment",
"nullable": true
},
"capture_method": {
"$ref": "#/components/schemas/CaptureMethod"
},
"authentication_type": {
"allOf": [
{
"$ref": "#/components/schemas/AuthenticationType"
}
],
"default": "no_three_ds"
},
"billing": {
"allOf": [
{
"$ref": "#/components/schemas/Address"
}
],
"nullable": true
},
"shipping": {
"allOf": [
{
"$ref": "#/components/schemas/Address"
}
],
"nullable": true
},
"customer_id": {
"type": "string",
"description": "The identifier for the customer",
"example": "cus_y3oqhf46pyzuxjbcn2giaqnb44",
"nullable": true,
"maxLength": 64,
"minLength": 1
},
"customer_present": {
"$ref": "#/components/schemas/PresenceOfCustomerDuringPayment"
},
"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 which you want the user to be redirected after the completion of the payment operation",
"example": "https://hyperswitch.io",
"nullable": true
},
"setup_future_usage": {
"$ref": "#/components/schemas/FutureUsage"
},
"apply_mit_exemption": {
"$ref": "#/components/schemas/MitExemptionRequest"
},
"payment_method_token": {
"type": "string",
"nullable": true
},
"statement_descriptor": {
"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": 22
},
"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
},
"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
},
"metadata": {
"type": "object",
"description": "Metadata is useful for storing additional, unstructured 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_enabled": {
"$ref": "#/components/schemas/EnablePaymentLinkRequest"
},
"payment_link_config": {
"allOf": [
{
"$ref": "#/components/schemas/PaymentLinkConfigRequest"
}
],
"nullable": true
},
"request_incremental_authorization": {
"$ref": "#/components/schemas/RequestIncrementalAuthorization"
},
"session_expiry": {
"type": "integer",
"format": "int32",
"description": "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\n(900) for 15 mins",
"example": 900,
"nullable": true,
"minimum": 0
},
"frm_metadata": {
"type": "object",
"description": "Additional data related to some frm(Fraud Risk Management) connectors",
"nullable": true
},
"request_external_three_ds_authentication": {
"$ref": "#/components/schemas/External3dsAuthenticationRequest"
}
},
"additionalProperties": false
},
"PayoutActionRequest": {
"type": "object"
},
Expand Down
116 changes: 116 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,122 @@ 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<AmountDetails>,

/// Unique identifier for the payment. This ensures idempotency for multiple payments
/// that have been done by a single merchant.
#[schema(
value_type = Option<String>,
min_length = 30,
max_length = 30,
example = "pay_mbabizu24mvu3mela5njyhpit4"
)]
pub merchant_reference_id: Option<id_type::PaymentReferenceId>,

/// 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 = CaptureMethod, example = "automatic")]
pub capture_method: Option<api_enums::CaptureMethod>,

#[schema(value_type = 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.
#[schema(value_type = Option<Address>)]
pub billing: Option<Address>,

/// The shipping address for the payment
#[schema(value_type = Option<Address>)]
pub shipping: Option<Address>,

/// The identifier for the customer
#[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)]
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 = FutureUsage, example = "off_session")]
pub setup_future_usage: Option<api_enums::FutureUsage>,

/// Apply MIT exemption for a payment
#[schema(value_type = MitExemptionRequest)]
pub apply_mit_exemption: Option<common_enums::MitExemptionRequest>,

// TODO: Verify this is required
pub payment_method_token: Option<String>,

/// 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<pii::SecretSerdeValue>,

/// Metadata is useful for storing additional, unstructured information on an object.
#[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<pii::SecretSerdeValue>,

/// Whether to generate the payment link for this payment or not (if applicable)
#[schema(value_type = EnablePaymentLinkRequest)]
pub payment_link_enabled: Option<common_enums::EnablePaymentLinkRequest>,

/// 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 = 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(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 = External3dsAuthenticationRequest)]
pub request_external_three_ds_authentication:
Option<common_enums::External3dsAuthenticationRequest>,
}

#[derive(Debug, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
#[cfg(feature = "v2")]
Expand Down
Loading

0 comments on commit fdebe64

Please sign in to comment.