diff --git a/fern/apis/signalwire-rest/openapi.yaml b/fern/apis/signalwire-rest/openapi.yaml index ac060b0db6..1b2d3cf13c 100644 --- a/fern/apis/signalwire-rest/openapi.yaml +++ b/fern/apis/signalwire-rest/openapi.yaml @@ -43579,7 +43579,7 @@ components: The URL to make POST requests with all the gathered payment details. This URL is used to process the final payment transaction and return the results through the response. - Visit [pay documentation](/docs/swml/reference/pay#payment_connector_url) for more important information. + Visit [pay documentation](/docs/swml/reference/calling/pay#payment_connector_url) for more important information. examples: - https://example.com/payment-connector charge_amount: @@ -43661,7 +43661,7 @@ components: description: |- The URL to send requests for each status change during the payment process. - Visit [pay documentation](/docs/swml/reference/pay#status_url-request-body) for more important information. + Visit [pay documentation](/docs/swml/reference/calling/pay#status_url-request-body) for more important information. examples: - https://example.com/payment-status timeout: diff --git a/fern/products/compatibility-api/pages/cxml/voice/pay/index.mdx b/fern/products/compatibility-api/pages/cxml/voice/pay/index.mdx index bd7219f711..41f84a3f4d 100644 --- a/fern/products/compatibility-api/pages/cxml/voice/pay/index.mdx +++ b/fern/products/compatibility-api/pages/cxml/voice/pay/index.mdx @@ -50,30 +50,20 @@ To tokenize payment information: ``` -You can also omit the `chargeAmount` attribute entirely: +You can also omit the `chargeAmount` attribute entirely. - -to re-enter their payment details. This may differ depending on the payment processor you are using. - +Your payment connector creates the token with your payment processor and returns it as `token_id`. SignalWire passes it to your `action` URL as `PaymentToken`, and you can use it for future transactions without asking the customer to re-enter their payment details. See the [tokenization example](#tokenize-a-card-end-to-end) for the full flow. --- ## Attributes - - Minimum required length for postal code input. Used for input validation. - - - The URL to which to POST the encrypted payment data. - - - - Controls whether CVV/security code collection is required. When `false`, skips security code collection. + The HTTPS URL of your payment connector. SignalWire sends it a `POST` request with the collected payment details. See [`paymentConnectorUrl` request parameters](#paymentconnectorurl-request-parameters) and [securing your payment connector](#securing-your-payment-connector). - HTTPS endpoint that receives POST requests after payment completion. Must be HTTPS. Response determines next cXML instructions. For tokenization, receives `PaymentToken` and `ProfileId`. For charges, receives `PaymentConfirmationCode`. Defaults to the current cXML document URL. + HTTPS endpoint that receives POST requests after payment completion. Must be HTTPS. Response determines next cXML instructions. For tokenization, receives the token as `PaymentToken`. For charges, receives `PaymentConfirmationCode`. Defaults to the current cXML document URL. @@ -100,6 +90,10 @@ to re-enter their payment details. This may differ depending on the payment proc Maximum number of retry attempts when timeout occurs or invalid data is received. Allowed values are `1`, `2`, or `3`. Payment flow terminates after `maxAttempts` is reached. + + Minimum required length for postal code input. Used for input validation. + + Determines payment collection flow. Credit card flow captures card number, expiration, security code, and postal code. ACH flow captures routing and account numbers. @@ -108,6 +102,10 @@ to re-enter their payment details. This may differ depending on the payment proc Controls postal code collection. When `false`, skips collection for postal code. When `true`, prompts the user for collection. When a String value, uses provided value without needing to collect the postal code from the user. + + Controls whether CVV/security code collection is required. When `false`, skips security code collection. + + HTTPS endpoint that receives real-time payment status updates via POST requests. Includes details about current payment stage, errors, and attempt counts. See [Status Callback Parameters](#statuscallback-request-parameters) for more details. @@ -129,102 +127,44 @@ to re-enter their payment details. This may differ depending on the payment proc ### `paymentConnectorUrl` request parameters -When a transaction is completed, SignalWire will `POST` to your `paymentConnectorUrl` URL. Based on the [transaction type](#transaction-types), -the body of the request will contain the below parameters: +When all payment details have been collected from the caller, SignalWire sends a `POST` request with a JSON body to your `paymentConnectorUrl`. +Charges and [tokenization](#tokenization) send the same fields. SignalWire signs the request, so see [securing your payment connector](#securing-your-payment-connector) to verify it. A valid response from your `paymentConnectorUrl` must be provided to indicate the success or failure of the transaction. More information can be found in the [Webhook Response](#paymentconnectorurl-response) section. - - - - - Customer's credit card number. + + Unique identifier for the transaction. - - Amount to charge. + + Payment method (`credit-card`). - - Three-letter currency code. + + Customer's full credit card number. Card security code. - - Transaction description. - - - - Card expiration month (2 digits). - - - - Card expiration year (2 digits). - - - - Payment method (`credit-card`). - - - - Custom key-value parameters. - - Billing postal code. - - Unique identifier for the transaction. - - -#### Example - -```json -{ - "transaction_id":"id", - "method":"credit-card", - "cardnumber":"1234123412341234", - "cvv":"123", - "postal_code":"12345", - "description":"renew plan", - "chargeAmount":123.45, - "expiry_month":"01", - "expiry_year":"38", - "currency_code":"USD", - "parameters":{ - "custom1":"value1" - } -} -``` - - - - - - Set to 0 for tokenization. - - - - Customer's credit card number. - - - - Three-letter currency code. + + Transaction description. - - Card security code. + + Amount to charge, from the `chargeAmount` attribute. `0` for tokenization, or `0.00` when the attribute is omitted. - - Transaction description. + + Token persistence (`reusable` or `one-time`), from the `tokenType` attribute. @@ -235,45 +175,35 @@ More information can be found in the [Webhook Response](#paymentconnectorurl-res Card expiration year (2 digits). - - Custom key-value parameters. - - - - Billing postal code. - - - - Token persistence (`reusable` or `one-time`). + + Three-letter currency code, from the `currency` attribute. - - Unique identifier for the transaction. + + Custom parameters from the [``](/docs/compatibility-api/cxml/reference/voice/pay/parameter) nouns, as an array with one single-key object per parameter. Omitted when `` has no ``. #### Example ```json { - "transaction_id":"id", - "cardnumber":"1234123412341234", - "cvv":"123", - "postal_code":"12345", - "description":"save card", - "amount":0, - "token_type":"reusable", - "expiry_month":"01", - "expiry_year":"38", - "currency_code":"USD", - "parameters":{ - "custom1":"value1" - } + "transaction_id": "8c9d14d5-52ae-4e2e-b880-a14e6e1cda7d", + "method": "credit-card", + "cardnumber": "4242424242424242", + "cvv": "123", + "postal_code": "12345", + "description": "renew plan", + "chargeAmount": "123.45", + "token_type": "reusable", + "expiry_month": "01", + "expiry_year": "38", + "currency_code": "usd", + "parameters": [ + { "custom1": "value1" } + ] } ``` - - - --- @@ -288,25 +218,21 @@ A valid cXML response must be provided if the `action` URL is provided. More inf - Masked bank account number. + Masked bank account number. ACH payments only. - - Bank routing number. + + Bank account type. ACH payments only. - - Raw processor error details. + + Bank routing number. ACH payments only. - + Card expiration in MMYY format. - - Numeric error reference. - - Masked card number (last 4 digits visible). @@ -315,38 +241,46 @@ A valid cXML response must be provided if the `action` URL is provided. More inf Postal code provided. + + Masked security code. + + Card brand (visa, mastercard, etc.). - Transaction confirmation code. + The `charge_id` your payment connector returned for a successful charge. + + + + The `error_message` your payment connector returned. + + + + The `error_code` your payment connector returned. Detailed error information. + + Numeric error reference. + + Type of payment method used. - Tokenized payment method reference. + The `token_id` your payment connector returned for a successful tokenization. Otherwise, the token type (`reusable` or `one-time`) from the `tokenType` attribute. - - Customer profile identifier from payment processor. - - - + Final outcome of the payment attempt. The possible values can be seen in the [Result Values](#result-values) table. - - Masked security code. - - #### Result values | Value | Description | @@ -401,19 +335,6 @@ When a status change occurs, the following parameters are sent to your statusCal Masked security code. -#### Status callback events - -| Event | Description | -|-------|-------------| -| `payment-card-number` | Collecting card number | -| `expiration-date` | Collecting expiration date | -| `security-code` | Collecting CVV/security code | -| `postal-code` | Collecting postal code | -| `bank-routing-number` | Collecting routing number | -| `bank-account-number` | Collecting account number | -| `payment-processing` | Processing transaction | - - #### For values | Value | Description | @@ -422,7 +343,14 @@ When a status change occurs, the following parameters are sent to your statusCal | `expiration-date` | Requesting the expiration date of the customer's payment card | | `security-code` | Requesting the security code (CVV) of the customer's payment card | | `postal-code` | Requesting the postal code linked to the customer's payment card | -| `payment-processing` | Executing the payment transaction | +| `bank-routing-number` | Requesting the customer's bank routing number | +| `bank-account-number` | Requesting the customer's bank account number | +| `payment-processing` | Sending the payment details to your payment connector | +| `payment-completed` | Your payment connector returned HTTP `200`. This doesn't mean the payment succeeded: a decline returned with HTTP `200` also sends `payment-completed` | +| `payment-failed` | Payment details couldn't be collected, or your payment connector didn't return HTTP `200` | +| `payment-canceled` | The caller pressed `*` to cancel | + +To find out whether the payment succeeded, check `PayResult` on the [`action` request](#action-request-parameters). #### Error types @@ -469,6 +397,8 @@ When a transaction is successful, the webhook should respond with one of the fol ``` +SignalWire passes `charge_id` to your `action` URL as `PaymentConfirmationCode`. When `chargeAmount` is zero or omitted, it passes `token_id` as `PaymentToken`. + #### Unsuccessful transaction When a transaction is unsuccessful (declined by the payment processor), the webhook should respond with the following format: @@ -590,6 +520,36 @@ All credit card payments support the following languages: ``` +### Tokenize a card end to end + +This `` saves a card without charging it: + +```xml + + + Please enter your card information to save for future use + + +``` + +SignalWire collects the card details and sends them to your payment connector with `"chargeAmount": "0"` and `"token_type": "reusable"`. +Your connector saves the card with your payment processor and replies with the processor's token: + +```json +{ + "token_id": "pm_1234567890", + "error_code": null, + "error_message": null +} +``` + +SignalWire then sends your `action` URL `PayResult=success` and `PaymentToken=pm_1234567890`. +Store the token to charge the card later through your payment processor. ### Custom retry logic: ```xml @@ -608,7 +568,7 @@ All credit card payments support the following languages: ```xml - Por favor, ingrese su información de pago + Por favor, ingrese su información de pago - Let's collect your payment information. Please enter your credit card number - Please enter your credit card number - Please enter your credit card’s security code. It's the 4 digits located on the front of your card. - + Let's collect your payment information. Please enter your credit card number + Please enter your credit card number + Please enter your credit card's security code. It's the 4 digits located on the front of your card. ``` -## Security best practices - -1. Always use HTTPS for callback URLs -2. Implement webhook validation -3. Monitor payment status callbacks -4. Handle errors gracefully -5. Store tokens securely -6. Use appropriate timeout values -7. Implement proper error handling -8. Validate all inputs -9. Monitor transaction patterns -10. Keep payment connector configurations secure +## Securing your payment connector + +Requests to your `paymentConnectorUrl` carry the `X-SignalWire-Signature` and `X-SignalWire-SHA256-Signature` headers, keyed with your project's [Signing Key](/docs/platform/webhooks#verify-webhook-signature). They don't come from a published IP range, so verify the signature and reject any request that doesn't match. +The connector request is signed like a JSON webhook, not like your `action` and `statusCallback` requests: `X-SignalWire-Signature` is the lowercase hex HMAC-SHA1 of the connector URL, with any credentials removed, followed by the raw JSON body. The form-parameter validation you use for other cXML webhooks won't match it. +SignalWire normalizes the URL before signing it: the scheme is lowercased, `.` and `..` path segments are resolved, and a URL without a path gets `/`, so `https://example.com` is signed as `https://example.com/`. + +For a second layer, put credentials in the connector URL. +Credentials such as `https://payuser:@pay.example.com/connector` are sent as a standard Basic `Authorization` header and aren't part of the signed URL, so your connector can check both. +A long random token in the URL path works too, and it is part of the signed URL. + + +The full `paymentConnectorUrl`, including any credentials or token in it, is visible in your call logs in the Dashboard. +Use a secret that protects only this endpoint, and rotate it periodically. + diff --git a/fern/products/swml/pages/reference/methods/calling/pay/index.mdx b/fern/products/swml/pages/reference/methods/calling/pay/index.mdx index 3307315c7b..65526cf7fb 100644 --- a/fern/products/swml/pages/reference/methods/calling/pay/index.mdx +++ b/fern/products/swml/pages/reference/methods/calling/pay/index.mdx @@ -152,11 +152,11 @@ sections: - The identifier for your custom parameter. This will be the key in the `parameters` object. + The identifier for your custom parameter. In the [`payment_connector_url` request](#request-body), each parameter becomes a single-key object with this name as its key. - The value associated with the parameter. This will be the value in the `parameters` object. + The value associated with the parameter. In the [`payment_connector_url` request](#request-body), this is the value of the parameter's single-key object. @@ -315,7 +315,13 @@ The `status_url` parameter is used to send requests for each status change durin - The status of the payment process. + The stage of the payment process. Possible values: + + - `payment-card-number`, `expiration-date`, `security-code`, `postal-code`, `bank-routing-number`, `bank-account-number` - Requesting that value from the caller. + - `payment-processing` - Sending the payment details to your payment connector. + - `payment-completed` - Your payment connector returned HTTP `200`. A decline returned with HTTP `200` also sends `payment-completed`, so check [`pay_result`](#variables) for the outcome. + - `payment-failed` - Payment details couldn't be collected, or your payment connector didn't return HTTP `200`. + - `payment-canceled` - The caller pressed `*` to cancel. @@ -404,6 +410,17 @@ Below is an example of the request body that will be sent to the `status_url`. SignalWire sends a `POST` request to the `payment_connector_url` once all required payment information has been collected from the caller. Your endpoint processes the payment and returns the result. +SignalWire signs this request with your project's [Signing Key](/docs/platform/webhooks#verify-webhook-signature). The `X-SignalWire-Signature` header holds the lowercase hex HMAC-SHA1 of the connector URL, with any credentials removed, followed by the raw request body, and `X-SignalWire-SHA256-Signature` holds the same value computed with HMAC-SHA256. +SignalWire normalizes the URL before signing it: the scheme is lowercased, `.` and `..` path segments are resolved, and a URL without a path gets `/`, so `https://example.com` is signed as `https://example.com/`. +The request doesn't come from a published IP range, so verify the signature and reject any request that doesn't match. +For a second layer, put credentials in the URL, such as `https://payuser:@pay.example.com/connector`. They are sent as a standard Basic `Authorization` header and aren't part of the signed URL. +A long random token in the URL path works too, and it is part of the signed URL. + + +The full `payment_connector_url`, including any credentials or token in it, is visible in your call logs in the Dashboard. +Use a secret that protects only this endpoint, and rotate it periodically. + + ### Request body @@ -435,7 +452,7 @@ Your endpoint processes the payment and returns the result. - The amount to charge. + The amount to charge, from `charge_amount`. `0` for tokenization. This is the only camelCase field in the request body. @@ -450,21 +467,28 @@ Your endpoint processes the payment and returns the result. The payment description provided in the `pay` method. + + Your custom [`parameters`](#properties), as an array with one single-key object per parameter, such as `[{ "custom1": "value1" }]`. Omitted when `pay` has no `parameters`. + + #### Request example ```json { "transaction_id": "8c9d14d5-52ae-4e2e-b880-a14e6e1cda7d", "method": "credit-card", - "cardnumber": "************1234", - "cvv": "***", + "cardnumber": "4242424242424242", + "cvv": "123", "postal_code": "123456", "description": "Payment description", "chargeAmount": "10.55", "token_type": "reusable", "expiry_month": "12", "expiry_year": "99", - "currency_code": "usd" + "currency_code": "usd", + "parameters": [ + { "custom1": "value1" } + ] } ``` @@ -579,6 +603,8 @@ Return a non-`200` HTTP status code with: Error responses will trigger the `payment-failed` prompt in your SWML application. +SignalWire sets `charge_id` as [`pay_payment_results.payment_confirmation_code`](#variables). When `charge_amount` is zero or omitted, it sets `token_id` as [`pay_payment_results.payment_token`](#variables). + ## **Variables** When the payment process completes, the following [variables](/docs/swml/reference/variables) are set in the `vars` scope. @@ -605,11 +631,11 @@ Access them in subsequent SWML instructions using the `${variable}` syntax (e.g. - Token generated by the payment processor. Use this for future transactions when using tokenization (`charge_amount: 0`). + The `token_id` your payment connector returned for a successful tokenization (`charge_amount: 0`). Use it for future transactions through your payment processor. Otherwise, the token type (`reusable` or `one-time`) from `token_type`. - Confirmation code returned by the payment processor for a successful charge. + The `charge_id` your payment connector returned for a successful charge. diff --git a/specs/swml/calling/Methods/pay/main.tsp b/specs/swml/calling/Methods/pay/main.tsp index 95bd6d2eaa..ccf7176e32 100644 --- a/specs/swml/calling/Methods/pay/main.tsp +++ b/specs/swml/calling/Methods/pay/main.tsp @@ -18,7 +18,7 @@ model Pay { The URL to make POST requests with all the gathered payment details. This URL is used to process the final payment transaction and return the results through the response. - Visit [pay documentation](/docs/swml/reference/pay#payment_connector_url) for more important information. + Visit [pay documentation](/docs/swml/reference/calling/pay#payment_connector_url) for more important information. """) @example("https://example.com/payment-connector") payment_connector_url: url; @@ -72,7 +72,7 @@ model Pay { @doc(""" The URL to send requests for each status change during the payment process. - Visit [pay documentation](/docs/swml/reference/pay#status_url-request-body) for more important information. + Visit [pay documentation](/docs/swml/reference/calling/pay#status_url-request-body) for more important information. """) @example("https://example.com/payment-status") status_url?: url; diff --git a/specs/swml/calling/tsp-output/@typespec/json-schema/SWMLObject.json b/specs/swml/calling/tsp-output/@typespec/json-schema/SWMLObject.json index da9b34ecc3..f498ef568f 100644 --- a/specs/swml/calling/tsp-output/@typespec/json-schema/SWMLObject.json +++ b/specs/swml/calling/tsp-output/@typespec/json-schema/SWMLObject.json @@ -2199,7 +2199,7 @@ "examples": [ "https://example.com/payment-connector" ], - "description": "The URL to make POST requests with all the gathered payment details.\nThis URL is used to process the final payment transaction and return the results through the response.\n\nVisit [pay documentation](/docs/swml/reference/pay#payment_connector_url) for more important information." + "description": "The URL to make POST requests with all the gathered payment details.\nThis URL is used to process the final payment transaction and return the results through the response.\n\nVisit [pay documentation](/docs/swml/reference/calling/pay#payment_connector_url) for more important information." }, "charge_amount": { "type": "string", @@ -2328,7 +2328,7 @@ "examples": [ "https://example.com/payment-status" ], - "description": "The URL to send requests for each status change during the payment process.\n\nVisit [pay documentation](/docs/swml/reference/pay#status_url-request-body) for more important information." + "description": "The URL to send requests for each status change during the payment process.\n\nVisit [pay documentation](/docs/swml/reference/calling/pay#status_url-request-body) for more important information." }, "timeout": { "anyOf": [