# Transactions

Records that increment or decrement inventory based on customer interactions with a store

## Getting all Transactions

 - [GET /transactions](https://developer.yellowdogsoftware.com/rest/fetch/api/transactions/get-transactions.md): This endpoint allows for pulling of raw transaction information that is stored in the Yellow 
Dog Database. As this data is considered to be raw and not processed there is not a way to
determine directly with certainty what items or recipes had inventory adjustments from this 
endpoint. Due to the various Point of Sale integrations that may be connected with the 
database instance, there is not a guarentee that all transactions will match using the 
criteria represented in the POST /transactions Endpoint documentation.

## Creates or Updates Transactions

 - [POST /transactions](https://developer.yellowdogsoftware.com/rest/fetch/api/transactions/post-transactions.md): ##### Matching and Processing


 The transactionNumber field uniquely identifies a transaction. 

This POST endpoint will record a new transaction if the __transactionNumber__ does not
yet exist. If it does exist, it will overwrite the transaction previously submitted with
this value. Both cases assume that the request is not blocked by a closeout date.

Note that since this endpoint uses POST, not PATCH, a request that refers to an existing
__transactionNumber__ will rewrite the entire transaction and any unspecified
fields will be set to empty.




 Use thirdPartyId & thirdPartyLineId to associate lines within a transaction. 

When inserting a new record, it is highly recommended that you specify __thirdPartyId__
and __thirdPartyLineId__ values to help you update transactions, when necessary, and
to assist in troubleshooting. It is considered a best practice to use a __thirdPartyId__
that corresponds to the ID your system uses to uniquely identify the transaction.
If not provided, the API will insert default values in these
fields for you. The system uses the __thirdPartyId__ to mantain an internal
association between a set of lines and the transaction that contains them.

When specifying a preexisting __transactionNumber__ to update a previously submitted
transaction, the endpoint will first remove any existing transaction line records that
match the specified __thirdPartyId__. It will then record the lines provided in 
the current payload as the only lines associated with this transaction.




 Match transaction lines to Yellow Dog Items via id,
sku, or itemNumber. 

This endpoint matches transaction lines to Yellow Dog Items by either the __id__,
__sku__, or __itemNumber__ field.

- line[].item.id
  - This will match a transaction line immediately to the Yellow Dog Item with the same id.
  - This is the preferred method for matching Transaction Lines to the appropriate Yellow Dog Item.
- line[].sku
  - This will match a transaction line to the Yellow Dog Item with the same SKU.
- line[].itemNumber
  - This will match a transaction line to the Yellow Dog Item using a Third Party ItemNumber.
  - This can be performed by using the POS Item Map feature in Yellow Dog.

Only one of the three fields are required to have a non-null or non-whitespace value.




 Processing depends on checkClosed and closeout dates. 

Only transactions with a __checkClosed__ date later than the current closeout date will
be processed. This setting can be found in the Stores Tab of YDInv.




 Hourly processing matches lines to items. 

Transactions will be processed on an hourly basis.
Each transaction line will be matched to the appropriate Yellow Dog item when
processing occurs.
For assistance on this matter, please contact your Implementation Guide.






##### Examples

For the examples that follow, select the corresponding sample payload from the pull-down
menu in the request pane.



 Example A: Sending a transaction with multiple lines 

In ___Example A___, there was a sale of a Burger and a bottle of water.
The expected total for the transaction with all the lines will have a retail of $17.00.




 Example B: A transaction with item modifier lines 

In ___Example B___, there was a sale of a Burger with the additional modifiers for adding
cheese and bacon.
As part of the inventory processing the use of the modifiers will allow for the
processing of the transactions to deduct the 2 cheese and 2 bacon appropriately.
In this example the expected total for the transaction with all the lines will have
a retail of $23.00.




 Example C: A transaction with a Check-Wide Discount 

In ___Example C___, there was a sale of a Burger with the additional modifiers for adding
cheese and bacon.
There was also a discount set for 20% off the entire check.
Notice how the itemDiscount is set for each line of the transaction.
This allows for proper setting of the item price.
In this example the expected total for the transaction with all the lines will have a
retail of $18.40.




 Examples D&E: Handling of Refunded Return 

In this example, there was a sale of a Tee Shirt that was then returned with refund
the following day.
To properly handle the deduction and then increment of inventory for the two actions,
there should be two separate transactions sent to the api.
Here, ___Example D___ shows the initial sale and ___Example E___ shows the return.
Ideally, the transactions should be marked for the appropriate times that they
happened at.
Notice that in this example the __thirdPartyId__ and __thirdPartyLineId__ are different values
between the sale and the refund.




 Examples F&G: Handling of a Void or a Cancellation 

In this example, there was a sale of a Tee Shirt that was canceled or voided without a
decrement of inventory.
This could have been an accidential addition of an item for the transaction.
Here, ___Example F___ shows the initial sale and ___Example G___ shows the cancellation.
Since this this event is not supposed to impact the inventory onhand, it is
appropriate to set the quantity of the existing line to 0 as an update to the original
transaction.
Notice that in this example the __thirdPartyId__ and __thirdPartyLineId__ are the same values
between the sale and the voided line.

## Gets Transactions by Store

 - [GET /transactions/store/{storeId}](https://developer.yellowdogsoftware.com/rest/fetch/api/transactions/get-transactions-store.md)

## Gets Transaction by ThirdPartyId

 - [GET /transactions/{thirdPartyId}](https://developer.yellowdogsoftware.com/rest/fetch/api/transactions/get-transactions-byid.md): This endpoint is intended to be used for looking up a specific Transaction record.

