> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Transaction.cancel

The `cancel` method cancels a batch of previously authorized (but not yet captured) one-time `Transaction` objects, so that Subscribe does not attempt to capture them with your payment processor. See the [Transaction.auth](Transaction_auth#) and [Transaction.capture](Transaction_capture#) methods for details.

For certain payment processors, who charge a fee if you do not capture an authorized transaction, Subscribe also reverses the authorization. For other processors, Subscribe simply deletes its internal to-be-captured flag so that the `Transaction` is no longer scheduled for capture. To determine whether Subscribe performs authorization reversal with your payment processor as a part of this call, contact your Vindicia Client Services representative.

For the `Transaction` objects for which this call is successful, Subscribe changes their status to `Cancelled`. For those transactions whose authorization Subscribe was able to reverse with the payment processors concerned, the status `Void` is displayed on the Subscribe Portal. However, if you fetch those transactions with a `fetch` call, the status in the corresponding `Transaction` objects is `Cancelled`.

**Note:** You may only cancel `Transactions` that have not yet been captured. You may refund captured transactions but not cancel them. For details on refunds, see the `Refund` object.

## Input

*srd*: sparse response description, a SOAP string (which must be a JSON object), in which you specify the elements you want returned.This parameter enables the calling system to constrain a `method` call to return only components you specify. This gives you greater control over returned content, and improves response time within the Vindicia platform by reducing the processing needed for the call.

Some fields are required, either practically or in the WSDL, and will be returned regardless of the *srd*. A null *srd* returns the complete response.

*transactions*: an array of `Transaction` objects to cancel.

## Output

*return*: an object of type `Return` that indicates the success or failure of the call.

*qtySuccess*: the number of successful cancellations.

*qtyFail*: the number of failed cancellations.

*results*: an array of `CancelResult` objects that contain information on the success or failure of the call on each transaction.

The following table lists and describes the data members for the `CancelResult` object.

| Data Members | Data Type | Description |
| - | - | - |
| `merchantTransactionId` | `string` | Your unique identifier for the `Transaction` object you asked to cancel. |
| `returnCode` | `integer` | The reason for the success or failure: - `200: cancel() succeeded.` - `402: The Transaction object has expired and cannot be cancelled.` - `404: cancel() cannot load the Transaction object, likely because the VID or your transaction ID (merchantTransactionId) is invalid.` - `405: You did not specify an authorized transaction.` |

## Returns

In addition to those listed in [The Return Object](The_Return_Object#), this call returns:

| Return Code | Return String |
| - | - |
| `400` | One of the following: - `Must specify transaction.` - `Unable to save transactions:` *error-description*. |
| **Note:** A return code of `200` does not mean that all input transactions have been successfully cancelled. Be sure to examine the output parameters, such as *qtySuccess*, *qtyFail*, and *results*, to check which transactions were successfully cancelled and which failed to cancel. | |

## Example

```

// create an empty transaction object to the make the SOAP calls
// against
$soap_tx = new Transaction();
 
$tx1 = new Transaction();
$tx2 = new Transaction();
 
// ids of previously authorized transactions
$merchantTxnId1 = '9876-5432';
$merchantTxnId2 = '9876-5437';
 
$tx1->setMerchantTransactionId($merchantTxnId1);
$tx2->setMerchantTransactionId($merchantTxnId2);
 
$txnArray = array($tx1, $tx2);
 
$response = $soap_tx->cancel($txnArray);
 
if($response['returnCode']==200) {
   $cancelResults = $response['results'];
   foreach ($cancelResults as $cancelResult) {
      if ($cancelResult->returnCode == 200) {
      print ("Transaction with id " . 
         $cancelResult->merchantTransactionId .
         " was successfully cancelled");
      }
   }
}
```

**Parent topic:**[Transaction Methods](../topics/Transaction_Methods)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.