/gist:17904c5daef83d1cbe05 Secret
Created
January 11, 2014 11:17
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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