# Payments subresource

Payments is a subresource of [Calls](/docs/voice/api/call-resource).

## Agent-assisted payments

Agent-assisted payments allow agents to collect customer payment information in a PCI-compliant manner on Twilio voice calls in the contact center. With agent-assisted payments, the agent stays on the phone and guides the customer through the payment flow, requesting the various required pieces of payment information one item at a time.

The agent can control the payment flow asking for payment information in the order they see best for the customer and even re-request information as needed. When the customer is entering their payment information, the agent will not be able to hear the DTMF (Dual-Tone Multi-Frequency) tones, ensuring PCI DSS (Payment Card Industry Data Security Standard) compliance of the payment information and the security of the customer payment information.

Once the agent has progressed through all the steps to gather the payment information from the customer, they complete the capture via Twilio. Twilio sends the payment information directly to the payment connector for processing, ensuring no card information is ever divulged to the agent.

> \[!NOTE]
>
> [\<Pay>](/docs/voice/twiml/pay) and the [Payment resource](/docs/voice/api/payment-resource) are now available in the Ireland (IE1) and Australia (AU1) Regions for the following Pay Connectors: Base Commerce, Braintree, CardConnect, Chase Paymentech, [Generic Pay Connector](/docs/voice/twiml/pay/generic-pay-connector), and Shuttle.
>
> * For outbound calls, [follow the guide for outbound calls in non-US Regions](/docs/global-infrastructure/create-an-outbound-call-via-rest-api-in-a-non-us-twilio-region).
> * For inbound calls, [follow the guide for inbound call processing in non-US Regions](/docs/global-infrastructure/inbound-call-processing).
> * For more info on Twilio Regions, [visit the Global Infrastructure docs](/docs/global-infrastructure).

### Workflow

* Agent requests some information, including payment method, from the customer and [begins a Payment session](#create-a-payment-session).
* Agent triggers [API calls](#update-a-payment-session) through their UI to collect specific pieces of payment information from the customer, e.g., credit card number, expiration date, or bank account number.
* The Caller enters the requested payment information using their phone keypad. Agents are not able to hear any DTMF tones.
* Once the customer is done, the agent sees the result of the customer's input, e.g., `xxxx xxxx xxxx 4242` or `invalid-card-number`.
* Agent requests the next piece of required payment information and continues to do so until all the information needed is entered.
  * The agent can re-request a piece of payment information as needed in any order and at any point during the flow.
  * The agent is also able to [cancel the payment](#code-update-a-payment-cancel) at any point during the flow.
* Once all the information is collected, the agent [completes the Payment session](#code-update-a-payment-complete) and receives the result of the payment.

### API design and workflow

With Agent assistance the key is to capture customer information while the Agent is on the call with the customer. This means the agent can interact with the customer guiding them through the experience of entering their card details. A typical agent flow is outlined below:

* The agent collects and enters information like payment method, charge amount or token type, and then [starts the Payment session](#create-a-payment-session).
* The agent then makes an [update request](#update-a-payment-session) (through their own UI) for each piece of payment information in succession.
* If customers make a mistake while entering information, the agent makes an [update request](#update-a-payment-session) again to re-capture that particular information.
* Once all the required payment information has been collected, the Agent [completes the Payment session](#code-update-a-payment-complete) by setting the status to `complete`, which then processes the payment and completes the transaction. The agent can also [cancel the Payment session](#code-update-a-payment-cancel), if required at this stage, by setting the status in the [update request](#update-a-payment-session) to `cancel`.
* Resulting information in each of the calls above will be delivered via [status callbacks](#statuscallback), which can be used to update the agent UI in near real-time.

## Payments properties

```json
{"type":"object","refName":"api.v2010.account.call.payments","modelName":"api_v2010_account_call_payments","properties":{"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Account](/docs/iam/api/account) that created the Payments resource."},"call_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CA[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Call](/docs/voice/api/call-resource) the Payments resource is associated with. This will refer to the call sid that is producing the payment card (credit/ACH) information thru DTMF."},"sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^PK[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the Payments resource."},"date_created":{"type":"string","format":"date-time-rfc-2822","nullable":true,"description":"The date and time in GMT that the resource was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format."},"date_updated":{"type":"string","format":"date-time-rfc-2822","nullable":true,"description":"The date and time in GMT that the resource was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format."},"uri":{"type":"string","nullable":true,"description":"The URI of the resource, relative to `https://api.twilio.com`."}}}
```

## Create a Payment session

`POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json`

### Path parameters

```json
[{"name":"AccountSid","in":"path","description":"The SID of the [Account](/docs/iam/api/account) that will create the resource.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$"},"required":true},{"name":"CallSid","in":"path","description":"The SID of the call that will create the resource. Call leg associated with this sid is expected to provide payment information thru DTMF.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CA[0-9a-fA-F]{32}$"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"CreatePaymentsRequest","required":["IdempotencyKey","StatusCallback"],"properties":{"IdempotencyKey":{"type":"string","description":"A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated."},"StatusCallback":{"type":"string","format":"uri","description":"Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the [expected StatusCallback values](/docs/voice/api/payment-resource#statuscallback)"},"BankAccountType":{"type":"string","enum":["consumer-checking","consumer-savings","commercial-checking"],"description":"Type of bank account if payment source is ACH. One of `consumer-checking`, `consumer-savings`, or `commercial-checking`. The default value is `consumer-checking`.","refName":"payments_enum_bank_account_type","modelName":"payments_enum_bank_account_type"},"ChargeAmount":{"type":"number","description":"A positive decimal value less than 1,000,000 to charge against the credit card or bank account. Default currency can be overwritten with `currency` field. Leave blank or set to 0 to tokenize."},"Currency":{"type":"string","description":"The currency of the `charge_amount`, formatted as [ISO 4127](http://www.iso.org/iso/home/standards/currency_codes.htm) format. The default value is `USD` and all values allowed from the Pay Connector are accepted."},"Description":{"type":"string","description":"The description can be used to provide more details regarding the transaction. This information is submitted along with the payment details to the Payment Connector which are then posted on the transactions."},"Input":{"type":"string","description":"A list of inputs that should be accepted. Currently only `dtmf` is supported. All digits captured during a pay session are redacted from the logs."},"MinPostalCodeLength":{"type":"integer","description":"A positive integer that is used to validate the length of the `PostalCode` inputted by the user. User must enter this many digits."},"Parameter":{"description":"A single-level JSON object used to pass custom parameters to payment processors. (Required for ACH payments). The information that has to be included here depends on the <Pay> Connector. [Read more](https://www.twilio.com/console/voice/pay-connectors)."},"PaymentConnector":{"type":"string","description":"This is the unique name corresponding to the Pay Connector installed in the Twilio Add-ons. Learn more about [<Pay> Connectors](https://www.twilio.com/console/voice/pay-connectors). The default value is `Default`."},"PaymentMethod":{"type":"string","enum":["credit-card","ach-debit"],"description":"Type of payment being captured. One of `credit-card` or `ach-debit`. The default value is `credit-card`.","refName":"payments_enum_payment_method","modelName":"payments_enum_payment_method"},"PostalCode":{"type":"boolean","description":"Indicates whether the credit card postal code (zip code) is a required piece of payment information that must be provided by the caller. The default is `true`."},"SecurityCode":{"type":"boolean","description":"Indicates whether the credit card security code is a required piece of payment information that must be provided by the caller. The default is `true`."},"Timeout":{"type":"integer","description":"The number of seconds that <Pay> should wait for the caller to press a digit between each subsequent digit, after the first one, before moving on to validate the digits captured. The default is `5`, maximum is `600`."},"TokenType":{"type":"string","enum":["one-time","reusable","payment-method"],"description":"Indicates whether the payment method should be tokenized as a `one-time`, `reusable`, or `payment-method` token. The default value is `reusable`. Do not enter a charge amount when tokenizing. If a charge amount is entered, the payment method will be charged and not tokenized.","refName":"payments_enum_token_type","modelName":"payments_enum_token_type"},"ValidCardTypes":{"type":"string","description":"Credit card types separated by space that Pay should accept. The default value is `visa mastercard amex`"},"RequireMatchingInputs":{"type":"string","description":"A comma-separated list of payment information fields that require the caller to enter the same value twice for confirmation. Supported values are `payment-card-number`, `expiration-date`, `security-code`, and `postal-code`."},"Confirmation":{"type":"string","description":"Whether to prompt the caller to confirm their payment information before submitting to the payment gateway. If `true`, the caller will hear the last 4 digits of their card or account number and must press 1 to confirm or 2 to cancel. Default is `false`.","enum":["true","false"]}}},"examples":{"startPaymentSessionSuccess":{"value":{"lang":"json","value":"{\n  \"ChargeAmount\": \"12.00\",\n  \"Currency\": \"USD\",\n  \"Description\": \"api testing\",\n  \"IdempotencyKey\": \"abcd\",\n  \"Input\": \"dtmf\",\n  \"Parameter\": \"{'name':'foobar'}\",\n  \"PaymentConnector\": \"stripe_connector\",\n  \"PaymentMethod\": \"credit-card\",\n  \"PostalCode\": true,\n  \"SecurityCode\": true,\n  \"StatusCallback\": \"https://myapp.com/payments\",\n  \"ValidCardTypes\": \"visa amex\"\n}","meta":"","code":"{\n  \"ChargeAmount\": \"12.00\",\n  \"Currency\": \"USD\",\n  \"Description\": \"api testing\",\n  \"IdempotencyKey\": \"abcd\",\n  \"Input\": \"dtmf\",\n  \"Parameter\": \"{'name':'foobar'}\",\n  \"PaymentConnector\": \"stripe_connector\",\n  \"PaymentMethod\": \"credit-card\",\n  \"PostalCode\": true,\n  \"SecurityCode\": true,\n  \"StatusCallback\": \"https://myapp.com/payments\",\n  \"ValidCardTypes\": \"visa amex\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"ChargeAmount\"","#7EE787"],[":","#C9D1D9"]," ",["\"12.00\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Currency\"","#7EE787"],[":","#C9D1D9"]," ",["\"USD\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Description\"","#7EE787"],[":","#C9D1D9"]," ",["\"api testing\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"IdempotencyKey\"","#7EE787"],[":","#C9D1D9"]," ",["\"abcd\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Input\"","#7EE787"],[":","#C9D1D9"]," ",["\"dtmf\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Parameter\"","#7EE787"],[":","#C9D1D9"]," ",["\"{'name':'foobar'}\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"PaymentConnector\"","#7EE787"],[":","#C9D1D9"]," ",["\"stripe_connector\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"PaymentMethod\"","#7EE787"],[":","#C9D1D9"]," ",["\"credit-card\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"PostalCode\"","#7EE787"],[":","#C9D1D9"]," ",["true","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"SecurityCode\"","#7EE787"],[":","#C9D1D9"]," ",["true","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"StatusCallback\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://myapp.com/payments\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"ValidCardTypes\"","#7EE787"],[":","#C9D1D9"]," ",["\"visa amex\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Create a Payment session

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function createPayments() {
  const payment = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments.create({
      idempotencyKey: "IdempotencyKey",
      statusCallback: "https://www.example.com",
    });

  console.log(payment.accountSid);
}

createPayments();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

payment = client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").payments.create(
    idempotency_key="IdempotencyKey", status_callback="https://www.example.com"
)

print(payment.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var payment = await PaymentResource.CreateAsync(
            idempotencyKey: "IdempotencyKey",
            statusCallback: new Uri("https://www.example.com"),
            pathCallSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(payment.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.call.Payment;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Payment payment =
            Payment
                .creator("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "IdempotencyKey", URI.create("https://www.example.com"))
                .create();

        System.out.println(payment.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	api "github.com/twilio/twilio-go/rest/api/v2010"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &api.CreatePaymentsParams{}
	params.SetIdempotencyKey("IdempotencyKey")
	params.SetStatusCallback("https://www.example.com")

	resp, err := client.Api.CreatePayments("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$payment = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->payments->create(
        "IdempotencyKey", // IdempotencyKey
        "https://www.example.com" // StatusCallback
    );

print $payment->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

payment = @client
          .api
          .v2010
          .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .payments
          .create(
            idempotency_key: 'IdempotencyKey',
            status_callback: 'https://www.example.com'
          )

puts payment.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:core:calls:payments:create \
   --call-sid CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --idempotency-key IdempotencyKey \
   --status-callback https://www.example.com
```

```bash
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json" \
--data-urlencode "IdempotencyKey=IdempotencyKey" \
--data-urlencode "StatusCallback=https://www.example.com" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "Wed, 18 Dec 2019 20:02:01 +0000",
  "date_updated": "Wed, 18 Dec 2019 20:02:01 +0000",
  "sid": "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
}
```

### StatusCallback

Provide an absolute or relative URL for this parameter. Twilio Pay will make a `POST` request to this URL whenever there is an update to the Parameter being captured. The `POST` request will have the following parameters:

| **Parameter**      | **Description**                                                                                                                                 |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `AccountSid`       | The unique identifier of the Account responsible for this Payment session                                                                       |
| `CallSid`          | The unique identifier for the call associated with the Payment sessions. `CallSid` will always refer to the parent leg of a two-leg call        |
| `Sid`              | The unique identifier of the current Payment session                                                                                            |
| `DateCreated`      | The date when the Payment session was started                                                                                                   |
| `BankAccountType`  | If the `ach-debit` PaymentMethod is used, the Bank Account Type provided by the caller and entered by the agent                                 |
| `ChargeAmount`     | If not tokenizing — i.e., the charge amount is specified and greater than zero — the amount to charge the payment method                        |
| `PaymentConnector` | The unique name of Payment Connector corresponding to the [Pay Connector](/docs/voice/twiml/pay/pay-connectors) installed in Twilio Marketplace |
| `PaymentMethod`    | `Ach-debit` or `credit-card`                                                                                                                    |
| `TokenType`        | One-time or reusable if charge amount not specified                                                                                             |

> \[!NOTE]
>
> All `StatusCallback` requests will contain these fields. Additional `StatusCallback` values can be found during the [`Update`](#statuscallback-update-payment-session) and [`Complete/Cancel`](#statuscallback-cancelcomplete-payment-session) APIs.

## Update a Payment session

`POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json`

### Path parameters

```json
[{"name":"AccountSid","in":"path","description":"The SID of the [Account](/docs/iam/api/account) that will update the resource.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$"},"required":true},{"name":"CallSid","in":"path","description":"The SID of the call that will update the resource. This should be the same call sid that was used to create payments resource.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CA[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"The SID of Payments session that needs to be updated.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^PK[0-9a-fA-F]{32}$"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"UpdatePaymentsRequest","required":["IdempotencyKey","StatusCallback"],"properties":{"IdempotencyKey":{"type":"string","description":"A unique token that will be used to ensure that multiple API calls with the same information do not result in multiple transactions. This should be a unique string value per API call and can be a randomly generated."},"StatusCallback":{"type":"string","format":"uri","description":"Provide an absolute or relative URL to receive status updates regarding your Pay session. Read more about the [Update](/docs/voice/api/payment-resource#statuscallback-update) and [Complete/Cancel](/docs/voice/api/payment-resource#statuscallback-cancelcomplete) POST requests."},"Capture":{"type":"string","enum":["payment-card-number","expiration-date","security-code","postal-code","bank-routing-number","bank-account-number","payment-card-number-matcher","expiration-date-matcher","security-code-matcher","postal-code-matcher"],"description":"The piece of payment information that you wish the caller to enter. Must be one of `payment-card-number`, `expiration-date`, `security-code`, `postal-code`, `bank-routing-number`, `bank-account-number`, or their `-matcher` variants for input confirmation when `RequireMatchingInputs` is enabled.","refName":"payments_enum_capture","modelName":"payments_enum_capture"},"Status":{"type":"string","enum":["complete","cancel"],"description":"Indicates whether the current payment session should be cancelled or completed. When `cancel` the payment session is cancelled. When `complete`, Twilio sends the payment information to the selected Pay Connector for processing.","refName":"payments_enum_status","modelName":"payments_enum_status"}}},"examples":{"collectCreditCardNumber":{"value":{"lang":"json","value":"{\n  \"Capture\": \"payment-card-number\",\n  \"IdempotencyKey\": \"abcd\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","meta":"","code":"{\n  \"Capture\": \"payment-card-number\",\n  \"IdempotencyKey\": \"abcd\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"Capture\"","#7EE787"],[":","#C9D1D9"]," ",["\"payment-card-number\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"IdempotencyKey\"","#7EE787"],[":","#C9D1D9"]," ",["\"abcd\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"StatusCallback\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://myapp.com/payments\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}},"collectCreditCardExpiryDate":{"value":{"lang":"json","value":"{\n  \"Capture\": \"expiration-date\",\n  \"IdempotencyKey\": \"abcd\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","meta":"","code":"{\n  \"Capture\": \"expiration-date\",\n  \"IdempotencyKey\": \"abcd\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"Capture\"","#7EE787"],[":","#C9D1D9"]," ",["\"expiration-date\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"IdempotencyKey\"","#7EE787"],[":","#C9D1D9"]," ",["\"abcd\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"StatusCallback\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://myapp.com/payments\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}},"completePayment":{"value":{"lang":"json","value":"{\n  \"IdempotencyKey\": \"abcd\",\n  \"Status\": \"complete\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","meta":"","code":"{\n  \"IdempotencyKey\": \"abcd\",\n  \"Status\": \"complete\",\n  \"StatusCallback\": \"https://myapp.com/payments\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"IdempotencyKey\"","#7EE787"],[":","#C9D1D9"]," ",["\"abcd\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Status\"","#7EE787"],[":","#C9D1D9"]," ",["\"complete\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"StatusCallback\"","#7EE787"],[":","#C9D1D9"]," ",["\"https://myapp.com/payments\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Update a Payment session

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updatePayments() {
  const payment = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({
      capture: "payment-card-number",
      idempotencyKey: "request-4",
      statusCallback: "https://www.example.com",
    });

  console.log(payment.accountSid);
}

updatePayments();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

payments = (
    client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update(
        capture="payment-card-number",
        idempotency_key="request-4",
        status_callback="https://www.example.com",
    )
)

print(payments.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var payment = await PaymentResource.UpdateAsync(
            capture: PaymentResource.CaptureEnum.PaymentCardNumber,
            idempotencyKey: "request-4",
            statusCallback: new Uri("https://www.example.com"),
            pathCallSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(payment.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.call.Payment;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Payment payment = Payment
                              .updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "request-4",
                                  URI.create("https://www.example.com"))
                              .setCapture(Payment.Capture.PAYMENT_CARD_NUMBER)
                              .update();

        System.out.println(payment.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	api "github.com/twilio/twilio-go/rest/api/v2010"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &api.UpdatePaymentsParams{}
	params.SetCapture("payment-card-number")
	params.SetIdempotencyKey("request-4")
	params.SetStatusCallback("https://www.example.com")

	resp, err := client.Api.UpdatePayments("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$payments = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(
        "request-4", // IdempotencyKey
        "https://www.example.com", // StatusCallback
        ["capture" => "payment-card-number"]
    );

print $payments->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

payment = @client
          .api
          .v2010
          .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .payments('PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .update(
            capture: 'payment-card-number',
            idempotency_key: 'request-4',
            status_callback: 'https://www.example.com'
          )

puts payment.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:core:calls:payments:update \
   --call-sid CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --capture payment-card-number \
   --idempotency-key request-4 \
   --status-callback https://www.example.com
```

```bash
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" \
--data-urlencode "Capture=payment-card-number" \
--data-urlencode "IdempotencyKey=request-4" \
--data-urlencode "StatusCallback=https://www.example.com" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "Wed, 18 Dec 2019 20:02:01 +0000",
  "date_updated": "Wed, 18 Dec 2019 20:02:01 +0000",
  "sid": "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
}
```

### StatusCallback (Update Payment Session)

Provide an absolute or relative URL for this parameter. Twilio Pay will make a `POST` request to this URL whenever the update request is made and whenever there is an update to the Parameter being captured. The `POST` request will contain all of [common StatusCallback parameters](#statuscallback) as well as these additional parameters:

| **Parameter**           | **Description**                                                                                                                                                                                                                                                            |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DateUpdated`           | The date when the Payment session was last updated                                                                                                                                                                                                                         |
| `BankAccountNumber`     | If the `PaymentMethod` is arch-debit the Bank Account Number entered by the caller. Twilio will only return the last two digits. For example, if the Bank Account Number is 508862392, then Pay will return `BankAccountNumber=*******92`                                  |
| `BankRoutingNumber`     | If the `PaymentMethod` is arch-debit the Bank Routing Number provided by the caller. Twilio will return the full routing number entered. For example, if caller enters 121181976 as their Bank Routing Number provided, then Pay will return `BankRoutingNumber=121181976` |
| `Capture`               | The piece of payment information that Pay was expecting                                                                                                                                                                                                                    |
| `ChargeAmount`          | If not tokenizing — i.e., the charge amount was specified and greater than zero — the amount to charge the payment method                                                                                                                                                  |
| `ErrorType`             | The full list of error types is visible [here](/docs/voice/twiml/pay/prompt#errortype)                                                                                                                                                                                     |
| `ExpirationDate`        | If the `PaymentMethod` is `credit-card`, the expiration date that is input by the caller. For example, `ExpirationDate=0522`. The expiration date is not PCI data, so it can be clearly visible                                                                            |
| `PartialResult`         | `true` if DTMF is still being captured and `false` once all the digits of the piece of payment information being captured have been entered                                                                                                                                |
| `PaymentCardNumber`     | If the `PaymentMethod` is `credit-card`, the card number input by the caller with only the last 4 digits visible. For example, `PaymentCardNumber=xxxx-xxxxxx-x4001`                                                                                                       |
| `PaymentCardPostalCode` | If the `PaymentMethod` is `credit-card`, the postal code input by the caller or by the agent. For example, `PaymentCardPostalCode=94109`. Postal Code is not PCI data, so it can be clearly visible.                                                                       |
| `PaymentCardType`       | If the `PaymentMethod` is `credit-card`, the type of card input by the caller. For example, `PaymentCardType=amex`. The value provided here will be one of the values provided with the `cardTypes` parameter in the Start API                                             |
| `Required`              | The pieces of payment information that remain to be collected. For example, if postal code and security code are false and credit card number has already been input, then `Required=ExpirationDate`                                                                       |
| `SecurityCode`          | If the `PaymentMethod` is `credit-card`, the security code input by the caller with all digits redacted, for example, `SecurityCode=xxx`                                                                                                                                   |

### Status

Indicate whether the current payment session should be cancelled or completed when this API request is made. When the status is `cancel`, the payment session will be cancelled. You will have to make a [`POST` request](#create-a-payment-session) to start a new payment session. When the status is `complete`, Twilio sends the payment information to the selected Pay connector for processing.

Update a Payment: complete

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updatePayments() {
  const payment = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({
      idempotencyKey: "IdempotencyKey",
      status: "complete",
      statusCallback: "https://www.example.com",
    });

  console.log(payment.accountSid);
}

updatePayments();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

payments = (
    client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update(
        status="complete",
        idempotency_key="IdempotencyKey",
        status_callback="https://www.example.com",
    )
)

print(payments.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var payment = await PaymentResource.UpdateAsync(
            status: PaymentResource.StatusEnum.Complete,
            idempotencyKey: "IdempotencyKey",
            statusCallback: new Uri("https://www.example.com"),
            pathCallSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(payment.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.call.Payment;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Payment payment = Payment
                              .updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "IdempotencyKey",
                                  URI.create("https://www.example.com"))
                              .setStatus(Payment.Status.COMPLETE)
                              .update();

        System.out.println(payment.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	api "github.com/twilio/twilio-go/rest/api/v2010"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &api.UpdatePaymentsParams{}
	params.SetStatus("complete")
	params.SetIdempotencyKey("IdempotencyKey")
	params.SetStatusCallback("https://www.example.com")

	resp, err := client.Api.UpdatePayments("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$payments = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(
        "IdempotencyKey", // IdempotencyKey
        "https://www.example.com", // StatusCallback
        ["status" => "complete"]
    );

print $payments->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

payment = @client
          .api
          .v2010
          .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .payments('PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .update(
            status: 'complete',
            idempotency_key: 'IdempotencyKey',
            status_callback: 'https://www.example.com'
          )

puts payment.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:core:calls:payments:update \
   --call-sid CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --status complete \
   --idempotency-key IdempotencyKey \
   --status-callback https://www.example.com
```

```bash
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" \
--data-urlencode "Status=complete" \
--data-urlencode "IdempotencyKey=IdempotencyKey" \
--data-urlencode "StatusCallback=https://www.example.com" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "Wed, 18 Dec 2019 20:02:01 +0000",
  "date_updated": "Wed, 18 Dec 2019 20:02:01 +0000",
  "sid": "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
}
```

Update a Payment: cancel

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updatePayments() {
  const payment = await client
    .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({
      idempotencyKey: "IdempotencyKey",
      status: "cancel",
      statusCallback: "https://www.example.com",
    });

  console.log(payment.accountSid);
}

updatePayments();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

payments = (
    client.calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update(
        status="cancel",
        idempotency_key="IdempotencyKey",
        status_callback="https://www.example.com",
    )
)

print(payments.account_sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account.Call;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var payment = await PaymentResource.UpdateAsync(
            status: PaymentResource.StatusEnum.Cancel,
            idempotencyKey: "IdempotencyKey",
            statusCallback: new Uri("https://www.example.com"),
            pathCallSid: "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(payment.AccountSid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.call.Payment;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Payment payment = Payment
                              .updater("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                  "IdempotencyKey",
                                  URI.create("https://www.example.com"))
                              .setStatus(Payment.Status.CANCEL)
                              .update();

        System.out.println(payment.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	api "github.com/twilio/twilio-go/rest/api/v2010"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &api.UpdatePaymentsParams{}
	params.SetStatus("cancel")
	params.SetIdempotencyKey("IdempotencyKey")
	params.SetStatusCallback("https://www.example.com")

	resp, err := client.Api.UpdatePayments("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$payments = $twilio
    ->calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->payments("PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(
        "IdempotencyKey", // IdempotencyKey
        "https://www.example.com", // StatusCallback
        ["status" => "cancel"]
    );

print $payments->accountSid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

payment = @client
          .api
          .v2010
          .calls('CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .payments('PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .update(
            status: 'cancel',
            idempotency_key: 'IdempotencyKey',
            status_callback: 'https://www.example.com'
          )

puts payment.account_sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:core:calls:payments:update \
   --call-sid CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --status cancel \
   --idempotency-key IdempotencyKey \
   --status-callback https://www.example.com
```

```bash
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" \
--data-urlencode "Status=cancel" \
--data-urlencode "IdempotencyKey=IdempotencyKey" \
--data-urlencode "StatusCallback=https://www.example.com" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "date_created": "Wed, 18 Dec 2019 20:02:01 +0000",
  "date_updated": "Wed, 18 Dec 2019 20:02:01 +0000",
  "sid": "PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments/PKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
}
```

### StatusCallback (Cancel/Complete Payment Session)

Provide an absolute or relative URL for this parameter. Twilio Pay will make a `POST` request to this URL whenever the Cancel/Complete API is called. The `POST` request will contain all of [common StatusCallback parameters](#statuscallback) as well as these additional parameters:

| **Parameter**             | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DateUpdated`             | The date when the Payment session was last updated                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `ConnectorError`          | This parameter contains the error code/message received from the underlying payment gateway                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `PayErrorCode`            | A numerical error code that gives more details about the error. To learn more about the error, please visit the [error page](/docs/api/errors) and search for the error code                                                                                                                                                                                                                                                                                                                                |
| `PaymentError`            | Payment error for failures. For example, `card is declined`                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `PaymentConfirmationCode` | If the payment method provided was charged and not tokenized, this is the confirmation code from the Payment Gateway                                                                                                                                                                                                                                                                                                                                                                                        |
| `PaymentToken`            | The tokenized value of the credit card or ACH payment data. Payment will not be tokenized if a charge amount is provided. Values will vary by connector:<br />   Base Commerce: `BankCard token`<br />   Braintree:`token`<br />   CardConnect: `token`<br />   Chase: `no value`<br />   Stripe: `one-time token`                                                                                                                                                                                          |
| `ProfileId`               | The identifier of the customer object to which the payment is associated. Can be used as a token depending on the Connector. Payment will not be tokenized if a charge amount is provided. Values will vary by connector:<br />   Base Commerce: `no value`<br />   Braintree:  `ID of the customer object (cannot be used as a token)`<br />   CardConnect: `profile`<br />   Chase: `customer reference number`<br />   Stripe: `ID of the customer resource`                                             |
| `Result`                  | The result of the transaction. <br />  `success`: Twilio successfully captured the payment data and either tokenized or processed the payment <br />  `payment-connector-error`: Twilio Pay experienced an error communicating with Payment Gateway <br />  `caller-interrupted-with-star`: Caller pressed the **\*** (star) key to interrupt the Payment session <br />  `caller-hung-up`: The caller hung up the call <br />  `validation-error`: An invalid parameter value, e.g., `chargeAmount="-0.5"` |
