# Charge credit card at checkout (API example)

Source: https://developer.avalara.com/hospitality-integration-guide/ofi9277717903198/

# Charge credit card at checkout (API example)

Learn how to process credit card transactions for reservations, including authorization, tax verification, and final charge at checkout.

In this scenario, a guest is making a reservation well in advance. In this case, we’ll authorize the transaction at the time of booking, and then charge the guest's credit card at checkout.

In this example, a guest is booking a two-week stay a year in advance. In this case, we’ll create 3 transactions. Transaction 1 will be a sales order to authorize the credit card. Transaction 2 will rerun Transaction 1 at the time of checkout to verify whether the amount of tax has changed. And finally, Transaction 3 will be a sales invoice that charges the customer's credit card at checkout.

## Transaction 1

-   This example uses `alocationCode` of `SEATAC1` for the address rather than a physical address.

-   This example also includes `areportingLocationCode`. Including `alocationCode` and `areportingLocationCode` ensures that AvaTax pulls in the attributes/parameters that were configured when the location was set up.

-   The document date is September 25, 2020.

-   The document type `isSalesOrder`.

-   `TheNumberOfNights` is the only [parameter](https://developer.avalara.com/api-reference/avatax/rest/v2/models/TransactionLineParameterModel/) specified on this transaction. AvaTax will pull in additional parameters that were specified when the `SEATAC1` location was configured.

**View example**:

```
curl
    -X POST
    -H 'Accept: application/json'
    -H 'Authorization: Basic ${btoa(`:`)}'
    -H 'Content-Type: application/json'
    --data '{
      "lines": [
{
  "number": "1",
  "quantity": 1,
  "amount": 100,
  "taxCode": "SL090200",
  "description": "Lodging",
  "addresses": {
    "singleLocation": {
      "locationCode": "SEATAC1"
    }
  },
  "parameters":[
    {
      "name":"NumberOfNights",
      "value":"14",
      "unit": "Count"
    }
  ]
}
      ],
      "type": "SalesOrder",
      "date": "2020-09-25",
      "code": "2020-09-25-GUEST",
      "companyCode": "ROSEBUDMOTELS",
      "customerCode": "GUEST",
      "reportingLocationCode": "SEATAC1",
      "commit": false,
      "currencyCode": "USD",
      "description": "Lodging"
    }'
    'https://sandbox-rest.avatax.com/api/v2/transactions/create'
```

## Transaction 2

-   Rerun Transaction 1, but change the date to the current date.

-   Verify whether the tax amount has changed. Follow your own guidelines for what to do if the tax amount between Transactions 1 and 2 is different.

**View example**:

```
curl
    -X POST
    -H 'Accept: application/json'
    -H 'Authorization: Basic ${btoa(`:`)}'
    -H 'Content-Type: application/json'
    --data '{
      "lines": [
{
  "number": "1",
  "quantity": 1,
  "amount": 100,
  "taxCode": "SL090200",
  "description": "Lodging",
  "addresses": {
    "singleLocation": {
      "locationCode": "SEATAC1"
    }
  },
  "parameters":[
    {
      "name":"NumberOfNights",
      "value":"14",
      "unit": "Count"
    }
  ]
}
      ],
      "type": "SalesOrder",
      "date": "2021-05-25",
      "code": "2020-09-25-GUEST",
      "companyCode": "ROSEBUDMOTELS",
      "customerCode": "GUEST",
      "reportingLocationCode": "SEATAC1",
      "commit": false,
      "currencyCode": "USD",
      "description": "Lodging"
    }'
    'https://sandbox-rest.avatax.com/api/v2/transactions/create'
```

## Transaction 3

Rerun Transaction 2, but change the document type to `SalesInvoice` and set the `commit` flag to `true`.

**View example**:

```
curl
    -X POST
    -H 'Accept: application/json'
    -H 'Authorization: Basic ${btoa(`:`)}'
    -H 'Content-Type: application/json'
    --data '{
      "lines": [
{
  "number": "1",
  "quantity": 1,
  "amount": 100,
  "taxCode": "SL090200",
  "description": "Lodging",
  "addresses": {
    "singleLocation": {
      "locationCode": "SEATAC1"
    }
  },
  "parameters":[
    {
      "name":"NumberOfNights",
      "value":"14",
      "unit": "Count"
    }
  ]
}
      ],
      "type": "SalesInvoice",
      "date": "2021-05-25",
      "code": "2020-09-25-GUEST",
      "companyCode": "ROSEBUDMOTELS",
      "customerCode": "GUEST",
      "reportingLocationCode": "SEATAC1",
      "commit": true,
      "currencyCode": "USD",
      "description": "Lodging"
    }'
    'https://sandbox-rest.avatax.com/api/v2/transactions/create'
```