# Sale (CCAUTHCAP)

Authorize and capture funds in a single request.

Source: https://developer.inoviopay.com/api/sale.html  
Markdown: https://developer.inoviopay.com/api/sale.md

The Authorization and Capture request will authorize and request capture of the funds in a single request to the Payment Service.

See [Authorize](https://developer.inoviopay.com/api/authorize.md#authorize) for the full parameter table; the fields required for `CCAUTHCAP` are identical to those required for `CCAUTHORIZE`.

**POST** `https://api.inoviopay.com/payment/pmt_service.cfm`

### Request Parameters

| Parameter | Description |
|---|---|
| `REQUEST_ACTION` (required) | Must be set to `CCAUTHCAP`. |
| `XTL_ORDER_ID` (optional) | Merchant's Order ID to associate with the transaction. |

### Handling the Response

Monitor these key fields to verify the sale was successfully authorized and captured. If a membership was created during this transaction, you will also receive the new membership ID.

| Field Name | Description |
|---|---|
| `TRANS_STATUS_NAME` | Check this to ensure the transaction was `APPROVED`. |
| `TRANS_VALUE_SETTLED` | The final amount that has been captured and settled. |
| `TRANS_ID / PO_ID` | Unique identifiers for the transaction and the overarching order. |
| `PROC_AUTH_RESPONSE` | The authorization code generated by the processor. |
| `MBSHP_ID_x` | If the sale triggered a membership creation, the newly generated Membership ID will be returned here. |
| `TRANS_NTOKEN_USED` | Indicates if a Network Token (1) or raw PAN (0) was used for the transaction. |

**cURL**

```bash
curl -X POST "https://api.inoviopay.com/payment/pmt_service.cfm" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "request_action=CCAUTHCAP&req_username=api_user&req_password=P%40ssw0rd%21&site_id=12345&request_api_version=4.14&request_response_format=JSON&pmt_numb=4111111111111111&pmt_expiry=122026&pmt_key=123&request_currency=USD&li_value_1=49.99&xtl_order_id=INV-999"
```

**PHP**

```php
use Inovio\Gateway\{Credentials, InovioClient};
use Inovio\Gateway\Model\{LineItem, Money, PaymentMethods};
use Inovio\Gateway\Request\TransactionRequest;

$client = new InovioClient(new Credentials('api_user', 'P@ssw0rd!', '12345'), 'SANDBOX');

$req = (new TransactionRequest(
    PaymentMethods::card('4111111111111111', '122026', '123'),
    [new LineItem('SKU-992', 1, Money::of('49.99', 'USD'))]
))->withIdempotency('INV-999');   // retry-safe by default

$sale = $client->sale($req);

switch ($sale->status) {
    case 'APPROVED':
        echo 'fulfil order ', $sale->orderRef?->poId(), "\n";
        break;
    case 'DECLINED':
        echo 'declined: ', $sale->outcome->service->code, "\n";
        break;
    case 'PENDING':
        echo 'pending: ', $sale->nextAction->kind ?? '?', "\n";
        break;
}
```

**Node**

```ts
import { InovioClient, Money, PaymentMethods } from '@inovio/gateway-sdk';

const client = new InovioClient(
  { reqUsername: 'api_user', reqPassword: 'P@ssw0rd!', siteId: '12345' },
  { environment: 'SANDBOX' }
);

const sale = await client.sale({
  paymentMethod: PaymentMethods.card('4111111111111111', '122026', '123'),
  lineItems: [{ productId: 'SKU-992', count: 1, value: Money.of('49.99', 'USD') }],
  idempotency: { xtlOrderId: 'INV-999' },   // retry-safe by default
});

switch (sale.status) {
  case 'APPROVED':
    console.log('fulfil order', sale.orderRef?.poId);
    break;
  case 'DECLINED':
    console.log('declined:', sale.outcome.service.code);
    break;
  case 'PENDING':
    console.log('pending:', sale.nextAction?.kind);
    break;
}
```

**Python**

```python
from inovio_gateway import Credentials, InovioClient, Money, PaymentMethods, TransactionStatus
from inovio_gateway.model import Idempotency, LineItem
from inovio_gateway.request import TransactionRequest

client = InovioClient(Credentials("api_user", "P@ssw0rd!", "12345"), environment="SANDBOX")

req = TransactionRequest(
    payment_method=PaymentMethods.card("4111111111111111", "122026", "123"),
    line_items=[LineItem("SKU-992", 1, Money.of("49.99", "USD"))],
    idempotency=Idempotency(xtl_order_id="INV-999"),   # retry-safe by default
)

sale = client.sale(req)

if sale.status is TransactionStatus.APPROVED:
    print("fulfil order", sale.order_ref.po_id if sale.order_ref else "-")
elif sale.status is TransactionStatus.DECLINED:
    print("declined:", sale.outcome.service.code)
elif sale.status is TransactionStatus.PENDING:
    print("pending:", sale.next_action.kind if sale.next_action else "?")
```

**Java**

```java
TransactionRequest req = new TransactionRequest(
    PaymentMethods.card("4111111111111111", "122026", "123"),
    new LineItem("SKU-992", 1, Money.of("49.99", "USD")))
    .idempotency("INV-999");   // retry-safe by default

TransactionResult sale = client.sale(req);

switch (sale.status()) {
    case APPROVED:
        System.out.println("fulfil order " + sale.orderRef().poId());
        break;
    case DECLINED:
        System.out.println("declined: " + sale.outcome().service().code());
        break;
    case PENDING:
        System.out.println("pending: " + sale.nextAction().kind());
        break;
    default:
        break;
}
```

**Response**

```json
{
  "REQUEST_ACTION": "CCAUTHCAP",
  "REQ_ID": "68192033",
  "TRANS_STATUS_NAME": "APPROVED",
  "TRANS_VALUE": 49.99,
  "CURR_CODE_ALPHA": "USD",
  "TRANS_VALUE_SETTLED": 49.99,
  "CURR_CODE_ALPHA_SETTLED": "USD",
  "TRANS_EXCH_RATE": "",
  "TRANS_ID": 8839201112,
  "CUST_ID": 9928102,
  "XTL_CUST_ID": "cUsT992xP",
  "PO_ID": 77281920,
  "XTL_ORDER_ID": "INV-999",
  "BATCH_ID": 882910,
  "PROC_NAME": "Inovio Primary",
  "MERCH_ACCT_ID": 110203,
  "CARD_BRAND_NAME": "Mastercard",
  "CARD_TYPE": "MASTERCARD BLACK CARD",
  "CARD_CLASS": "Consumer Credit",
  "CARD_PREPAID": 0,
  "CARD_BANK": "CREDOMATIC INTERNATIONAL",
  "CARD_COUNTRY": "CRI",
  "CARD_DETAIL": "Credit",
  "CARD_BALANCE": "",
  "PMT_L4": "3535",
  "PMT_ID": 8829102,
  "PMT_ID_XTL": "",
  "PMT_AAU_UPDATE_DT": "",
  "PMT_AAU_UPDATE_DESC": "",
  "PROC_UDF01": "",
  "ANI_RESP_DECISION": "",
  "PROC_UDF02": "",
  "PROC_AUTH_RESPONSE": "AUTH99",
  "PROC_RETRIEVAL_NUM": "1029384A-B8C7-D6E5-F4G3-H2I1J0K9L8M7",
  "PROC_REFERENCE_NUM": "REF10293847",
  "PROC_REDIRECT_URL": "",
  "AVS_RESPONSE": "M",
  "CVV_RESPONSE": "M",
  "CARD_BRAND_TRANSID": "",
  "REQUEST_API_VERSION": "4.14",
  "P3DS_VENDOR": "",
  "P3DS_RESPONSE": "",
  "PO_LI_ID_1": "8829103",
  "PO_LI_COUNT_1": 1,
  "PO_LI_AMOUNT_1": "49.99",
  "PO_LI_PROD_ID_1": "SKU-992",
  "MBSHP_ID_1": "88291",
  "TRANS_NTOKEN_USED": 1
}
```
