Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
docs(openapi): add telephone order charge endpoint to API reference (#14987)
Ankit Kumar Gupta218f5640eff9
diff --git a/api-reference/docs.json b/api-reference/docs.jsonindex 4e3a4c4465..3c81467e29 100644--- a/api-reference/docs.json+++ b/api-reference/docs.json@@ -88,6 +88,12 @@"v2/proxy/proxy-v1"]},+ {+ "group": "Telephone Order",+ "pages": [+ "v1/telephone-order/telephone-order--charge"+ ]+ },{"group": "Payment Method Session","pages": [diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 7f84660c51..d5de8f75b9 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -10680,6 +10680,146 @@}]}+ },+ "/telephone_order/{merchant_id}/{provider}": {+ "post": {+ "tags": [+ "Telephone Order"+ ],+ "summary": "Telephone Order - Charge",+ "description": "Charges a card that an IVR provider collected over the phone. Only `twilio` is supported as `{provider}`.",+ "operationId": "Charge a telephone order",+ "parameters": [+ {+ "name": "merchant_id",+ "in": "path",+ "description": "The unique identifier for the merchant account the card is charged under",+ "required": true,+ "schema": {+ "type": "string"+ },+ "example": "merchant_1791294465"+ },+ {+ "name": "provider",+ "in": "path",+ "description": "The telephone order provider posting the request. Currently only `twilio`.",+ "required": true,+ "schema": {+ "type": "string"+ },+ "example": "twilio"+ }+ ],+ "requestBody": {+ "description": "The provider's charge request. Shown here in Twilio's Generic Pay Connector shape.",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/TwilioGenericPayRequest"+ },+ "examples": {+ "Charge a card collected over the phone": {+ "value": {+ "amount": "1.00",+ "cardnumber": "4242424242424242",+ "currency_code": "USD",+ "cvv": "123",+ "description": "Order placed over the phone",+ "expiry_month": "12",+ "expiry_year": "28",+ "method": "charge",+ "parameters": {+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "profile_id": "pro_GUMsmmzTU7oadT00pJeo"+ },+ "postal_code": "94122",+ "transaction_id": "IPe16430-39ba-4820-bedc-7aad0762a487"+ }+ }+ }+ }+ },+ "required": true+ },+ "responses": {+ "200": {+ "description": "The outcome of the charge, in the provider's response shape.",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/TwilioGenericPayResponse"+ },+ "examples": {+ "01. The card was charged": {+ "value": {+ "charge_id": "pay_8320b449b06630271e378214dab80ce5",+ "error_code": null,+ "error_message": null,+ "parameters": {+ "amount_capturable": "0",+ "amount_received": "100",+ "connector": "stripe",+ "connector_transaction_id": "pi_3URyI8D5R7gDAGff17RhZpfW",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487",+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "succeeded"+ }+ }+ },+ "02. The card was declined": {+ "value": {+ "charge_id": null,+ "error_code": "card_declined",+ "error_message": "Your card was declined.",+ "parameters": {+ "connector": "stripe",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487",+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "failed",+ "unified_code": "UE_9000"+ }+ }+ },+ "03. The charge has no final outcome": {+ "value": {+ "charge_id": null,+ "error_code": "PAYMENT_PENDING",+ "error_message": "Payment is not yet complete",+ "parameters": {+ "connector": "stripe",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487",+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "processing"+ }+ }+ }+ }+ }+ }+ },+ "400": {+ "description": "The request was rejected before a charge was attempted: the API key is missing or does not belong to this merchant, the provider in the path is unknown, or the body is not a valid charge request for that provider.",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/GenericErrorResponseOpenApi"+ },+ "example": {+ "code": "IR_04",+ "message": "Missing required param: transaction_id",+ "type": "invalid_request"+ }+ }+ }+ }+ },+ "security": [+ {+ "basic_api_key": []+ }+ ]+ }}},"components": {@@ -49869,6 +50009,127 @@}}},+ "TwilioGenericPayRequest": {+ "type": "object",+ "required": [+ "method",+ "transaction_id"+ ],+ "properties": {+ "method": {+ "$ref": "#/components/schemas/TwilioPayMethod"+ },+ "transaction_id": {+ "type": "string",+ "description": "Twilio's id for this attempt. Stable across its retries, and used to derive the `payment_id` so a retry replays the original charge.",+ "example": "IPe16430-39ba-4820-bedc-7aad0762a487"+ },+ "cardnumber": {+ "type": "string",+ "description": "Card number collected over DTMF. Required for a charge.",+ "example": "4242424242424242",+ "nullable": true+ },+ "cvv": {+ "type": "string",+ "description": "Card security code collected over DTMF. Required for a charge.",+ "example": "123",+ "nullable": true+ },+ "expiry_month": {+ "type": "string",+ "description": "Two digit card expiry month. Required for a charge.",+ "example": "12",+ "nullable": true+ },+ "expiry_year": {+ "type": "string",+ "description": "Two or four digit card expiry year. Required for a charge.",+ "example": "28",+ "nullable": true+ },+ "postal_code": {+ "type": "string",+ "description": "Billing postal code, collected for AVS.",+ "example": "94122",+ "nullable": true+ },+ "bankaccountnumber": {+ "type": "string",+ "description": "Bank account number for ACH debits. Not supported.",+ "nullable": true+ },+ "routingnumber": {+ "type": "string",+ "description": "Bank routing number for ACH debits. Not supported.",+ "nullable": true+ },+ "amount": {+ "type": "string",+ "description": "Amount in major units, as a decimal string. Absent for `tokenize`.",+ "example": "1.00",+ "nullable": true+ },+ "currency_code": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Currency"+ }+ ],+ "nullable": true+ },+ "description": {+ "type": "string",+ "description": "Free-form description configured on the `<Pay>` verb.",+ "example": "Order placed over the phone",+ "nullable": true+ },+ "parameters": {+ "type": "object",+ "description": "Values from the IVR's `<Parameter>` tags, stored unmasked in the payment's `metadata`. `profile_id`, `payment_id` and `customer_id` are also read.",+ "nullable": true+ }+ }+ },+ "TwilioGenericPayResponse": {+ "type": "object",+ "description": "Body Twilio expects back. It reads `error_code` to decide the outcome, so a decline is a `200` with that set.",+ "required": [+ "parameters"+ ],+ "properties": {+ "charge_id": {+ "type": "string",+ "description": "The Hyperswitch `payment_id`, on a successful charge.",+ "example": "pay_8320b449b06630271e378214dab80ce5",+ "nullable": true+ },+ "error_code": {+ "type": "string",+ "description": "Set when the payment did not succeed: the connector's decline code, or one of `INVALID_REQUEST`, `PROFILE_NOT_FOUND`, `PAYMENT_NOT_COMPLETED`, `PAYMENT_PENDING`, `DUPLICATE_TRANSACTION`, `PROCESSING_ERROR`, `TOKENIZE_UNSUPPORTED`, `BANK_ACCOUNT_UNSUPPORTED`. On `PAYMENT_PENDING` the funds may be held, so do not re-prompt for a card.",+ "example": "PAYMENT_NOT_COMPLETED",+ "nullable": true+ },+ "error_message": {+ "type": "string",+ "description": "Human readable counterpart to `error_code`.",+ "example": "Your card was declined.",+ "nullable": true+ },+ "parameters": {+ "type": "object",+ "description": "Returned either way, and the only channel carrying a `payment_id` when `charge_id` is `null`. Flat and all-string; the request's own `parameters` are never echoed back."+ }+ }+ },+ "TwilioPayMethod": {+ "type": "string",+ "description": "The operation Twilio is asking us to perform.",+ "enum": [+ "charge",+ "tokenize"+ ]+ },"TxnStatus": {"type": "string","enum": [@@ -52321,6 +52582,11 @@"name": "api-key","description": "Use the API key created under your merchant account from the HyperSwitch dashboard. API key is used to authenticate API requests from your merchant server only. Don't expose this key on a website or embed it in a mobile application."},+ "basic_api_key": {+ "type": "http",+ "scheme": "basic",+ "description": "HTTP Basic authentication with a merchant API key as the password. The username is ignored. Used by endpoints that a third party posts to, such as telephone order providers."+ },"ephemeral_key": {"type": "apiKey","in": "header",@@ -52408,6 +52674,10 @@{"name": "Card Issuer","description": "Create and manage card issuers"+ },+ {+ "name": "Telephone Order",+ "description": "Charge cards collected over the phone by an IVR provider"}]}\ No newline at end of filediff --git a/api-reference/v1/telephone-order/telephone-order--charge.mdx b/api-reference/v1/telephone-order/telephone-order--charge.mdxnew file mode 100644index 0000000000..9b732b04aa--- /dev/null+++ b/api-reference/v1/telephone-order/telephone-order--charge.mdx@@ -0,0 +1,3 @@+---+openapi: post /telephone_order/{merchant_id}/{provider}+---diff --git a/crates/api_models/src/telephone_order/twilio.rs b/crates/api_models/src/telephone_order/twilio.rsindex b611d6469a..084f687919 100644--- a/crates/api_models/src/telephone_order/twilio.rs+++ b/crates/api_models/src/telephone_order/twilio.rs@@ -1,9 +1,10 @@use std::collections::HashMap;use hyperswitch_masking::Secret;+use utoipa::ToSchema;/// The operation Twilio is asking us to perform.-#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]#[serde(rename_all = "snake_case")]pub enum TwilioPayMethod {/// Move money for the collected payment method.@@ -12,64 +13,86 @@ pub enum TwilioPayMethod {Tokenize,}-#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]pub struct TwilioGenericPayRequest {- /// Whether Twilio wants a charge or a tokenization.+ /// The operation requested. Only `charge` is supported; `tokenize` is rejected.+ #[schema(value_type = TwilioPayMethod, example = "charge")]pub method: TwilioPayMethod,- /// Twilio's identifier for this payment attempt. Stable across Twilio's retries.+ /// Twilio's id for this attempt. Stable across its retries, and used to derive the `payment_id` so a retry replays the original charge.+ #[schema(example = "IPe16430-39ba-4820-bedc-7aad0762a487")]pub transaction_id: String,- /// Card number collected over DTMF.+ /// Card number collected over DTMF. Required for a charge.+ #[schema(value_type = Option<String>, example = "4242424242424242")]pub cardnumber: Option<cards::CardNumber>,- /// Card security code collected over DTMF.+ /// Card security code collected over DTMF. Required for a charge.+ #[schema(value_type = Option<String>, example = "123")]pub cvv: Option<Secret<String>>,- /// Two digit card expiry month.+ /// Two digit card expiry month. Required for a charge.+ #[schema(value_type = Option<String>, example = "12")]pub expiry_month: Option<Secret<String>>,- /// Two or four digit card expiry year.+ /// Two or four digit card expiry year. Required for a charge.+ #[schema(value_type = Option<String>, example = "28")]pub expiry_year: Option<Secret<String>>,/// Billing postal code, collected for AVS.+ #[schema(value_type = Option<String>, example = "94122")]pub postal_code: Option<Secret<String>>,- /// Bank account number, sent for ACH debits. Not supported.+ /// Bank account number for ACH debits. Not supported.+ #[schema(value_type = Option<String>)]pub bankaccountnumber: Option<Secret<String>>,- /// Bank routing number, sent for ACH debits. Not supported.+ /// Bank routing number for ACH debits. Not supported.+ #[schema(value_type = Option<String>)]pub routingnumber: Option<Secret<String>>,/// Amount in major units, as a decimal string. Absent for `tokenize`.+ #[schema(value_type = Option<String>, example = "1.00")]pub amount: Option<common_utils::types::StringMajorUnit>,/// Currency of `amount`. Absent for `tokenize`.+ #[schema(value_type = Option<Currency>, example = "USD")]pub currency_code: Option<common_enums::Currency>,/// Free-form description configured on the `<Pay>` verb.+ #[schema(example = "Order placed over the phone")]pub description: Option<String>,- /// Values supplied by the IVR through `<Parameter>` tags on the `<Pay>` verb. Not a `Secret`:- /// the core persists these unmasked in the payment's `metadata`, so keep nothing sensitive here.+ /// Values from the IVR's `<Parameter>` tags, stored unmasked in the payment's `metadata`. `profile_id`, `payment_id` and `customer_id` are also read.+ #[schema(value_type = Option<Object>, example = json!({"payment_id": "pay_8320b449b06630271e378214dab80ce5", "profile_id": "pro_GUMsmmzTU7oadT00pJeo"}))]pub parameters: Option<HashMap<String, String>>,}-/// Body Twilio expects back. It reads `error_code` to decide whether the payment succeeded, so a-/// decline is a `200` with that set; every field is serialized even when `None`.-#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+/// Body Twilio expects back. It reads `error_code` to decide the outcome, so a decline is a `200` with that set.+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]pub struct TwilioGenericPayResponse {- /// Reference for a successful charge. This is the Hyperswitch `payment_id`.+ /// The Hyperswitch `payment_id`, on a successful charge.+ #[schema(value_type = Option<String>, example = "pay_8320b449b06630271e378214dab80ce5")]pub charge_id: Option<common_utils::id_type::PaymentId>,- /// Set when the payment did not succeed. `null` on success.+ /// Set when the payment did not succeed: the connector's decline code, or one of `INVALID_REQUEST`, `PROFILE_NOT_FOUND`, `PAYMENT_NOT_COMPLETED`, `PAYMENT_PENDING`, `DUPLICATE_TRANSACTION`, `PROCESSING_ERROR`, `TOKENIZE_UNSUPPORTED`, `BANK_ACCOUNT_UNSUPPORTED`. On `PAYMENT_PENDING` the funds may be held, so do not re-prompt for a card.+ #[schema(example = "PAYMENT_NOT_COMPLETED")]pub error_code: Option<String>,- /// Human readable counterpart to `error_code`. `null` on success.+ /// Human readable counterpart to `error_code`.+ #[schema(example = "Your card was declined.")]pub error_message: Option<String>,- /// Handed back either way — the only channel carrying a `payment_id` when `charge_id` is- /// `null`. Flat and all-string: Twilio raises a JSON mapping exception on anything else.+ /// Returned either way, and the only channel carrying a `payment_id` when `charge_id` is `null`. Flat and all-string; the request's own `parameters` are never echoed back.+ #[schema(value_type = Object, example = json!({+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "succeeded",+ "amount_capturable": "0",+ "amount_received": "100",+ "connector": "stripe",+ "connector_transaction_id": "pi_3URyI8D5R7gDAGff17RhZpfW",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487"+ }))]pub parameters: HashMap<String, String>,}diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex d4fe876030..69a5e35f47 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -68,7 +68,8 @@ Never share your secret api keys. Keep them guarded and secure.(name = "Event", description = "Manage events"),(name = "Authentication", description = "Create and manage authentication"),(name = "Subscriptions", description = "Subscription management and billing endpoints"),- (name = "Card Issuer", description = "Create and manage card issuers")+ (name = "Card Issuer", description = "Create and manage card issuers"),+ (name = "Telephone Order", description = "Charge cards collected over the phone by an IVR provider")),// The paths will be displayed in the same order as they are registered herepaths(@@ -277,6 +278,9 @@ Never share your secret api keys. Keep them guarded and secure.routes::card_issuer::update_card_issuer,routes::card_issuer::delete_card_issuer,routes::card_issuer::list_card_issuers,++ // Routes for telephone orders+ routes::telephone_order::telephone_order_charge,),components(schemas(common_utils::types::MinorUnit,@@ -901,6 +905,9 @@ Never share your secret api keys. Keep them guarded and secure.api_models::unreferenced_refund::RecipientCardData,api_models::enums::RelayStatus,api_models::relay::RelayError,+ api_models::telephone_order::twilio::TwilioGenericPayRequest,+ api_models::telephone_order::twilio::TwilioGenericPayResponse,+ api_models::telephone_order::twilio::TwilioPayMethod,api_models::payments::AmountFilter,api_models::mandates::MandateRevokedResponse,api_models::mandates::MandateResponse,@@ -1321,6 +1328,19 @@ impl utoipa::Modify for SecurityAddon {to a single customer object for a short period of time."))),),+ (+ "basic_api_key",+ SecurityScheme::Http(+ HttpBuilder::new()+ .scheme(HttpAuthScheme::Basic)+ .description(Some(+ "HTTP Basic authentication with a merchant API key as the \+ password. The username is ignored. Used by endpoints that a \+ third party posts to, such as telephone order providers."+ ))+ .build()+ )+ ),("jwt_key",SecurityScheme::Http(HttpBuilder::new().scheme(HttpAuthScheme::Bearer).bearer_format("JWT").build())diff --git a/crates/openapi/src/routes.rs b/crates/openapi/src/routes.rsindex 3bb18dc5c9..430f148d88 100644--- a/crates/openapi/src/routes.rs+++ b/crates/openapi/src/routes.rs@@ -26,6 +26,7 @@ pub mod relay;pub mod revenue_recovery;pub mod routing;pub mod subscriptions;+pub mod telephone_order;pub mod three_ds_decision_rule;pub mod tokenization;pub mod webhook_events;diff --git a/crates/openapi/src/routes/telephone_order.rs b/crates/openapi/src/routes/telephone_order.rsnew file mode 100644index 0000000000..8f05355e09--- /dev/null+++ b/crates/openapi/src/routes/telephone_order.rs@@ -0,0 +1,96 @@+#[cfg(feature = "v1")]+/// Telephone Order - Charge+///+/// Charges a card that an IVR provider collected over the phone. Only `twilio` is supported as `{provider}`.+#[utoipa::path(+ post,+ path = "/telephone_order/{merchant_id}/{provider}",+ params(+ ("merchant_id" = String, Path, description = "The unique identifier for the merchant account the card is charged under", example = "merchant_1791294465"),+ ("provider" = String, Path, description = "The telephone order provider posting the request. Currently only `twilio`.", example = "twilio"),+ ),+ request_body(+ content = TwilioGenericPayRequest,+ description = "The provider's charge request. Shown here in Twilio's Generic Pay Connector shape.",+ examples((+ "Charge a card collected over the phone" = (+ value = json!({+ "method": "charge",+ "transaction_id": "IPe16430-39ba-4820-bedc-7aad0762a487",+ "cardnumber": "4242424242424242",+ "cvv": "123",+ "expiry_month": "12",+ "expiry_year": "28",+ "amount": "1.00",+ "currency_code": "USD",+ "postal_code": "94122",+ "description": "Order placed over the phone",+ "parameters": {+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "profile_id": "pro_GUMsmmzTU7oadT00pJeo"+ }+ })+ )+ ))+ ),+ responses(+ (status = 200, description = "The outcome of the charge, in the provider's response shape.", body = TwilioGenericPayResponse,+ examples(+ ("01. The card was charged" = (+ value = json!({+ "charge_id": "pay_8320b449b06630271e378214dab80ce5",+ "error_code": null,+ "error_message": null,+ "parameters": {+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "succeeded",+ "amount_capturable": "0",+ "amount_received": "100",+ "connector": "stripe",+ "connector_transaction_id": "pi_3URyI8D5R7gDAGff17RhZpfW",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487"+ }+ })+ )),+ ("02. The card was declined" = (+ value = json!({+ "charge_id": null,+ "error_code": "card_declined",+ "error_message": "Your card was declined.",+ "parameters": {+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "failed",+ "connector": "stripe",+ "unified_code": "UE_9000",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487"+ }+ })+ )),+ ("03. The charge has no final outcome" = (+ value = json!({+ "charge_id": null,+ "error_code": "PAYMENT_PENDING",+ "error_message": "Payment is not yet complete",+ "parameters": {+ "payment_id": "pay_8320b449b06630271e378214dab80ce5",+ "status": "processing",+ "connector": "stripe",+ "merchant_order_reference_id": "IPe16430-39ba-4820-bedc-7aad0762a487"+ }+ })+ ))+ )+ ),+ (status = 400, description = "The request was rejected before a charge was attempted: the API key is missing or does not belong to this merchant, the provider in the path is unknown, or the body is not a valid charge request for that provider.", body = GenericErrorResponseOpenApi,+ example = json!({+ "type": "invalid_request",+ "message": "Missing required param: transaction_id",+ "code": "IR_04"+ })+ ),+ ),+ tag = "Telephone Order",+ operation_id = "Charge a telephone order",+ security(("basic_api_key" = []))+)]+pub async fn telephone_order_charge() {}