Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created January 11, 2014 11:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AeroNotix/17904c5daef83d1cbe05 to your computer and use it in GitHub Desktop.
(ns payments.reporting
(:require [payments.mode :use [mode]])
(:import [java.util Date])
(:import [net.authorize Environment])
(:import [net.authorize Merchant])
(:import [net.authorize.data.xml.reporting ReportingDetails])
(:import [net.authorize.reporting TransactionType]))
(defn- message-to-map [message]
{:code (.getCode message)
:result-code (.getResultCode message)
:text (.getText message)})
(defprotocol Reporter
(transaction [this txntype from to & rest])
(settled-batch-list [this batchid from to])
(reporting-transaction [this transactionid]))
(defrecord ReportingClient [merchant]
Reporter
(transaction [this txntype from to
& {:keys [batchid transactionid]}]
(let [merchant (.merchant this)
transaction (.createReportingTransaction merchant txntype)
reporting-details (ReportingDetails/createReportingDetails)]
(doto reporting-details
(.setBatchFirstSettlementDate from)
(.setBatchLastSettlementDate to)
(.setBatchIncludeStatistics true))
(when batchid
(.setBatchId reporting-details batchid))
(when transactionid
(.setTransactionId reporting-details transactionid))
(.setReportingDetails transaction reporting-details)
(let [result (.postTransaction merchant transaction)
messages (.getMessages result)
batchdetails (.. result
(getReportingDetails)
(getBatchDetailsList))]
(doseq [message messages]
(prn (message-to-map message)))
(doseq [batchdetail batchdetails]
(prn batchdetail)))))
(settled-batch-list [this batchid from to]
(.transaction this TransactionType/GET_SETTLED_BATCH_LIST
from to :batchid batchid))
(reporting-transaction [this transactionid]
(.transaction this TransactionType/GET_TRANSACTION_DETAILS
transactionid)))
(defn create-client [loginid txnid]
(let [merchant (Merchant/createMerchant mode loginid txnid)]
(ReportingClient. merchant)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment