Transactions examples

The examples assume that an access_token has been obtained and the client is ready to call the Merchant API. See Authentication example for more information.

List Accounts

api_client.config(API_ROOT => { 'headers' => { 'Authorization' => "Bearer #{access_token}" }})

accounts = api_client.get.links['ch:accounts']

accounts.get.body
=>
{
  "count" => 3,
  "page" => 1,
  "per_page" => 20,
  "_links" => {
    "self" => {
      "href" => "https://merchant.test.clearhaus.com/accounts"
    },
    "curies" => [
      {
        "href" => "https://developer.clearhaus.com/rels/{rel}",
        "templated" => true,
        "name" => "ch"
      }
    ]
  },
  "_embedded" => {
    "ch:accounts" => [
      {
        "id" => "f72e20a6-31dc-4c24-9314-4bcc5b8820d4",
        "name" => "Clearhaus A/S",
        "country" => "DK",
        "currency" => "EUR",
        "mcc" => "5611",
        "merchant_id" => "2000001",
        "descriptor" => "clearhaus.com",
        "timezone" => "Europe/Copenhagen",
        "transaction_rules" => "reject credit",
        "metadata" => {
          "state" => "live"
        },
        "_links" => {
          "self" => {
            "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4"
          },
          "ch:transactions" => {
            "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4/transactions{?query,per_page}",
            "templated" => true
          }
        }
      },
      ...
    ]
  }
}

List transactions

After retrieving accounts, one can list and query the transactions for a given account:

root_links = api_client.get.links

# Get first item on _embedded ch:accounts
account = root_links['ch:accounts'].get.objects['ch:accounts'].first

# Get transactions scoped to the account
transactions = account.get.links['ch:transactions']

The same can be accomplished using Transaction Query Language:

transactions = api_client.get.links['ch:transactions'] \
  .where(query: 'is:capture date:this_year mid:2000001')
transactions.get.body
=>
{
  "per_page" => 20,
  "_links" => {
    "self" => {
      "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4/transactions"
    },
    "next" => {
      "href" => ...
    },
    "curies" => [
      {
        "href" => "https://developer.clearhaus.com/rels/{rel}",
        "templated" => true,
        "name" => "ch"
      }
    ]
  },
  "_embedded" => {
    "ch:transactions" => [
      {
        "id" => "a51a3abe-8eee-4a92-b941-e89f18c5bf66",
        "rrn" => "619811057524",
        "arn" => "76874308121337230471105",
        "type" => "capture",
        "status" => {
          "code" => 20000
        },
        "processed_at" => "2016-07-16T11:07:17+00:00",
        "currency" => "DKK",
        "amount" => 10050,
        "text_on_statement" => "site.com",
        "reference" => "abc123",
        "threed_secure" => "attempt",
        "recurring" => false,
        "region" => "intra",
        "payment_method" => "applepay",
        "card" => {
          "scheme" => "visa",
          "last4" => "1111",
          "bin" => "411111",
          "type" => "credit",
          "country" => "US",
          "expire_year" => "2022",
          "expire_month" => "06"
        },
        "_links" => {
          "self" => {
            "href" => "https://merchant.test.clearhaus.com/transactions/a51a3abe-8eee-4a92-b941-e89f18c5bf66"
          }
        },
        "_embedded" => {
          "ch:account" => {
            "name" => "Clearhaus A/S",
            "country" => "DK",
            "mcc" => "5611",
            "currency" => "EUR",
            "merchant_id" => "2000001",
            "descriptor" => "clearhaus.com",
            "_links" => {
              "self" => {
                "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4"
              }
            }
          }
        }
      },
      ...
    ]
  }
}

Query fraudulent transactions (TC40/SAFE)

Please see Transaction Query Language for more.

transactions = api_client.get.links['ch:transactions'] \
  .where(query: 'fraud.date:this_month')
transactions.get.body
=>
{
  "per_page" => 20,
  "_links" => {
    "self" => {
      "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4/transactions"
    },
    "next" => {
      "href" => ...
    },
    "curies" => [
      {
        "href" => "https://developer.clearhaus.com/rels/{rel}",
        "templated" => true,
        "name" => "ch"
      }
    ]
  },
  "_embedded" => {
    "ch:transactions" => [
      {
        "id" => "a51a3abe-8eee-4a92-b941-e89f18c5bf66",
        "rrn" => "619811057524",
        "arn" => "76874308121337230471105",
        "type" => "capture",
        "status" => {
          "code" => 20000
        },
        "processed_at" => "2016-07-16T11:07:17+00:00",
        "currency" => "DKK",
        "amount" => 10050,
        "text_on_statement" => "site.com",
        "reference" => "abc123",
        "threed_secure" => "attempt",
        "recurring" => false,
        "region" => "intra",
        "payment_method" => "applepay",
        "card" => {
          "scheme" => "visa",
          "last4" => "1111",
          "bin" => "411111",
          "type" => "credit",
          "country" => "US",
          "expire_year" => "2022",
          "expire_month" => "06"
        },
        "fraud" => {
          "date" => "2016-08-01",
          "type" => "fraudulent_usage"
        },
        "_links" => {
          "self" => {
            "href" => "https://merchant.test.clearhaus.com/transactions/a51a3abe-8eee-4a92-b941-e89f18c5bf66"
          }
        },
        "_embedded" => {
          "ch:account" => {
            "name" => "Clearhaus A/S",
            "country" => "DK",
            "mcc" => "5611",
            "currency" => "EUR",
            "merchant_id" => "2000001",
            "descriptor" => "clearhaus.com",
            "_links" => {
              "self" => {
                "href" => "https://merchant.test.clearhaus.com/accounts/f72e20a6-31dc-4c24-9314-4bcc5b8820d4"
              }
            }
          }
        }
      },
      ...
    ]
  }
}