Deprecated
This component is deprecated. See below for guidance about what to use instead.
Transactions API: Cookbook

Itemize Transactions

Note

Transactions API is deprecated. The API functionality is split into the new Payments API and a more robust Orders API. For more information, Payments and Refunds Overview and Orders: What it Does .

Orders API
Transactions API

You can itemize your transactions by linking them to existing order objects which capture itemized details. Linking orders and transaction enables Square Dashboard reporting on purchase items, taxes, and discounts. If the Order object references catalog items and the catalog items have inventory tracking enabled, you can track product inventory through the Square Dashboard.

Before you start Permalink Get a link to this section

  • You will need an access token. If you are using OAuth, you will need the PAYMENTS_WRITE permission.

  • You will need a valid Location ID.

  • You need to have created an Order object using the Orders API. See Build with Orders for help creating your first Orders object.

  • You need to know how to create a Charge request object. See Build with Transactions for help creating your first Charge request.

Step 1: Reference the order ID in your transaction request Permalink Get a link to this section

To link an order to your transaction, you need to set the order ID field in your Charge request to a valid order ID.

Important

The value of amount_money in the Charge request object and the value of total_money in the linked Order object must match or the Charge endpoint will decline the transaction and return an error.


//Make sure you have your order ID and location ID
$orderId = "{ORDER_ID}";

//Make your Charge request object
$chargeRequest = new \SquareConnect\Model\ChargeRequest();

// Link an order ID
$chargeRequest->setOrderId($orderId);

// Build the rest of the Charge request
// ..

Step 2: Complete the transaction Permalink Get a link to this section

Call the Charge endpoint normally.


$locationId = "LOCATION_ID";

try {

  $apiResponse = $transactionsApi->charge($locationId, $chargeRequest);

  // For now, just print the result to the screen
  echo "<pre>" . print_r($apiResponse, true) . "</pre>";

} catch (\SquareConnect\ApiException $e) {
  echo "<hr>" .
       "The SquareConnect\Api\TransactionsApi object threw an exception.<br>" .
       "API call: <code>TransactionsApi->charge</code>" .
       "<pre>" . var_dump($e) . "</pre>";
  throw $e;
}