Docs/API/Batch

Batch

Upload a CSV of transactions and let the gateway process them asynchronously. Download the results when the batch completes.

The batch endpoints let you upload a CSV file of transactions, check on processing status, and download a results CSV once the batch completes. Typical uses are nightly billing runs, migrating historical data, and any bulk charge that does not warrant individual API calls.

Request format

The uploaded file must meet these rules:

  • The first row is a header with the field names below. Columns can be in any order, and only some are required.
  • Each value is wrapped in double quotes. Values themselves must not contain quotes.
  • Fields are separated by commas.
  • Each row ends with a newline (\n).
"transaction_type","amount","cc_number","cc_expiration"
"sale","100","4111111111111111","12/25"

A sample CSV is available at batch_example.csv.

Building the CSV in a spreadsheet

When creating the file in Excel or Numbers you do not need to type the double quotes yourself — the export will add them. You may, however, need to force numeric cells to text format so that leading zeros and long card numbers survive the export. Save the file as CSV.

Valid fields

FieldRequiredDescription
transaction_typerequiredOne of sale, authorize, credit.
cc_numberrequired for cardCard number, digits only.
cc_expirationrequired for cardExpiration date, MM/YY.
cc_cvcoptionalCVC — required only if your account enforces it.
ach_account_numberrequired for ACHBank account number.
ach_routing_numberrequired for ACHBank routing number.
ach_account_typerequired for ACHchecking or savings.
ach_sec_coderequired for ACHSEC code: WEB, CCD, or PPD.
customer_idrequired if vaultedCustomer vault ID to charge.
payment_method_typeoptionalcard or ach, when pairing with payment_method_id.
payment_method_idoptionalThe specific vault payment method to charge.
amountrequiredAmount in cents. $1.00 is 100.
base_amountoptionalAlternative to amount. The gateway adds surcharge and tax to this value before processing.
surchargeoptionalSurcharge amount in cents — included in amount.
shipping_amountoptionalShipping amount, included in amount.
tax_amountoptionalTax amount, included in amount.
discount_amountoptionalDiscount amount, included in amount.
surcharge_exemptoptionaltrue or false. Exempt this row from any configured surcharge.
order_idoptionalUp to 17 alphanumeric characters.
descriptionoptionalUp to 100 alphanumeric characters.
po_numberoptionalUp to 17 alphanumeric characters.
tax_exemptoptionaltrue or false. Default false.
email_addressoptionalTagged onto the transaction. No email is sent automatically.
email_receiptoptionaltrue or false — sends a receipt if true.
processor_idoptionalOverride your default processor for this row.
billing_*optionalBilling address fields: first_name, last_name, company, address_line_1, address_line_2, city, state, postal_code, country, phone, fax, email.
shipping_*optionalShipping address fields — same shape as billing.

Response format

The downloaded results file is also CSV, with one row per input transaction. Columns include the basics (id, amount, status), the billing/shipping that was sent in, and processor-side details like response_code, processor_response_code, processor_response_text, auth_code, avs_response_code, and cvv_response_code.

Endpoints

Upload a file

POST /api/filebatch
curl -v \
  -H "Authorization: YOUR_API_KEY" \
  -F "file=@<FILENAME>" \
  "https://sandbox.fluidpay.com/api/filebatch"

Response:

{
  "status": "success",
  "msg": "success",
  "data": {
    "id": "bj1o70m9ku6fr2s21fig",
    "file_name": "testfile.csv",
    "status": "pending",
    "num_lines": 1,
    "created_at": "2019-04-26T22:17:38.078185288Z",
    "updated_at": "2019-04-26T22:17:38.078185288Z"
  }
}

JavaScript example:

function uploadFile() {
  const headers = new Headers();
  headers.append("Authorization", apiKey);

  const formData = new FormData();
  formData.append("file", "testBatch.csv");

  fetch("https://sandbox.fluidpay.com/api/filebatch", {
    method: "POST",
    headers,
    body: formData,
    redirect: "follow"
  })
    .then(r => r.json())
    .then(result => {
      if (result.status === "success") {
        const batchId = result.data.id;
        // ...
      }
    })
    .catch(err => console.log("error", err));
}

Check batch status

GET /api/filebatch/{batch_id}
curl -v \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  "https://sandbox.fluidpay.com/api/filebatch/<batch_id>"
{
  "id": "bj1o70m9ku6fr2s21fig",
  "user_id": "bj1o70m9ku6fr2s21fig",
  "file_name": "testfile.csv",
  "status": "pending",
  "num_lines": 1,
  "processed_lines": 1,
  "created_at": "2019-04-26T22:17:38.078185288Z",
  "updated_at": "2019-04-26T22:17:38.078185288Z"
}

status is one of unknown, pending, queued, processing, failed, completed.

Download the results

GET /api/filebatch/{batch_id}/download
10-day retention

Only batches with status completed can be downloaded, and results expire after ten days.

curl -v \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  "https://sandbox.fluidpay.com/api/filebatch/<batch_id>/download"

On success, the response streams the results CSV. On failure you'll get a JSON error:

{
  "status": "failed",
  "msg": "batch is not in completed status",
  "data": null
}