Class: LitleOnline::LitleBatchRequest
- Inherits:
-
Object
- Object
- LitleOnline::LitleBatchRequest
- Includes:
- XML::Mapping
- Defined in:
- lib/LitleBatchRequest.rb
Instance Method Summary collapse
- #account_update(options) ⇒ Object
- #activate(options) ⇒ Object
- #au_batch? ⇒ Boolean
- #auth_reversal(options) ⇒ Object
- #authorization(options) ⇒ Object
- #balance_inquiry(options) ⇒ Object
- #cancel_subscription(options) ⇒ Object
- #capture(options) ⇒ Object
- #capture_given_auth(options) ⇒ Object
- #close_batch(txn_location = @txn_file) ⇒ Object
- #create_new_batch(path) ⇒ Object
- #create_plan(options) ⇒ Object
- #credit(options) ⇒ Object
- #deactivate(options) ⇒ Object
- #echeck_credit(options) ⇒ Object
- #echeck_redeposit(options) ⇒ Object
- #echeck_sale(options) ⇒ Object
- #echeck_verification(options) ⇒ Object
- #force_capture(options) ⇒ Object
- #get_au_batch ⇒ Object
- #get_batch_name ⇒ Object
- #get_counts_and_amounts ⇒ Object
- #has_transactions? ⇒ Boolean
-
#initialize ⇒ LitleBatchRequest
constructor
A new instance of LitleBatchRequest.
- #load_request(options) ⇒ Object
- #open_existing_batch(pathToBatchFile) ⇒ Object
- #register_token_request(options) ⇒ Object
- #sale(options) ⇒ Object
- #unload_request(options) ⇒ Object
- #update_card_validation_num_on_token(options) ⇒ Object
- #update_plan(options) ⇒ Object
- #update_subscription(options) ⇒ Object
Constructor Details
#initialize ⇒ LitleBatchRequest
Returns a new instance of LitleBatchRequest.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/LitleBatchRequest.rb', line 36 def initialize #load configuration data @config_hash = Configuration.new.config @txn_counts = { :id=>nil, :merchantId=>nil, :auth=>{ :numAuths=>0, :authAmount=>0 }, :sale=>{ :numSales=>0, :saleAmount=>0 }, :credit=>{ :numCredits=>0, :creditAmount=>0 }, :numTokenRegistrations=>0, :captureGivenAuth=>{ :numCaptureGivenAuths=>0, :captureGivenAuthAmount=>0 }, :forceCapture=>{ :numForceCaptures=>0, :forceCaptureAmount=>0 }, :authReversal=>{ :numAuthReversals=>0, :authReversalAmount=>0 }, :capture=>{ :numCaptures=>0, :captureAmount=>0 }, :echeckVerification=>{ :numEcheckVerification=>0, :echeckVerificationAmount=>0 }, :echeckCredit=>{ :numEcheckCredit=>0, :echeckCreditAmount=>0 }, :numEcheckRedeposit=>0, :echeckSale=>{ :numEcheckSales=>0, :echeckSalesAmount=>0 }, :numUpdateCardValidationNumOnTokens=>0, :numAccountUpdates=>0, :total=>0, :numCancelSubscriptions=>0, :numUpdateSubscriptions=>0, :numCreatePlans=>0, :numUpdatePlans=>0, :activate=>{:numActivates=>0, :activateAmount=>0}, :numDeactivates=>0, :load=>{:numLoads=>0, :loadAmount=>0}, :unload=>{:numUnloads=>0, :unloadAmount=>0}, :numBalanceInquirys=>0, :merchantSdk=>nil } @litle_txn = LitleTransaction.new @path_to_batch = nil @txn_file = nil @MAX_TXNS_IN_BATCH = 100000 @au_batch = nil end |
Instance Method Details
#account_update(options) ⇒ Object
324 325 326 327 328 329 330 331 |
# File 'lib/LitleBatchRequest.rb', line 324 def account_update() if(@au_batch == nil) then @au_batch = LitleAUBatch.new @au_batch.create_new_batch(File.dirname(@path_to_batch)) end @au_batch.account_update() end |
#activate(options) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/LitleBatchRequest.rb', line 221 def activate() transaction = @litle_txn.activate() @txn_counts[:numActivates] += 1 add_txn_to_batch(transaction, :activate, ) end |
#au_batch? ⇒ Boolean
136 137 138 |
# File 'lib/LitleBatchRequest.rb', line 136 def au_batch? !@au_batch.nil? end |
#auth_reversal(options) ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/LitleBatchRequest.rb', line 185 def auth_reversal() transaction = @litle_txn.auth_reversal() @txn_counts[:authReversal][:numAuthReversals] += 1 @txn_counts[:authReversal][:authReversalAmount] += ['amount'].to_i add_txn_to_batch(transaction, :authReversal, ) end |
#authorization(options) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/LitleBatchRequest.rb', line 161 def () transaction = @litle_txn.() @txn_counts[:auth][:numAuths] += 1 @txn_counts[:auth][:authAmount] += ['amount'].to_i add_txn_to_batch(transaction, :authorization, ) end |
#balance_inquiry(options) ⇒ Object
249 250 251 252 253 254 |
# File 'lib/LitleBatchRequest.rb', line 249 def balance_inquiry() transaction = @litle_txn.balance_inquiry() @txn_counts[:numBalanceInquirys] += 1 add_txn_to_batch(transaction, :balanceInquirys, ) end |
#cancel_subscription(options) ⇒ Object
193 194 195 196 197 198 |
# File 'lib/LitleBatchRequest.rb', line 193 def cancel_subscription() transaction = @litle_txn.cancel_subscription() @txn_counts[:numCancelSubscriptions] += 1 add_txn_to_batch(transaction, :cancelSubscription, ) end |
#capture(options) ⇒ Object
277 278 279 280 281 282 283 |
# File 'lib/LitleBatchRequest.rb', line 277 def capture() transaction = @litle_txn.capture() @txn_counts[:capture][:numCaptures] += 1 @txn_counts[:capture][:captureAmount] += ['amount'].to_i add_txn_to_batch(transaction, :capture, ) end |
#capture_given_auth(options) ⇒ Object
285 286 287 288 289 290 291 |
# File 'lib/LitleBatchRequest.rb', line 285 def capture_given_auth() transaction = @litle_txn.capture_given_auth() @txn_counts[:captureGivenAuth][:numCaptureGivenAuths] += 1 @txn_counts[:captureGivenAuth][:captureGivenAuthAmount] += ['amount'].to_i add_txn_to_batch(transaction, :captureGivenAuth, ) end |
#close_batch(txn_location = @txn_file) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/LitleBatchRequest.rb', line 140 def close_batch(txn_location = @txn_file) header = build_batch_header(@txn_counts) File.rename(@path_to_batch, @path_to_batch + '.closed-' + @txn_counts[:total].to_s) @path_to_batch = @path_to_batch + '.closed-' + @txn_counts[:total].to_s File.open(@path_to_batch, 'w') do |fo| # fo.puts header put_header = !au_batch? || has_transactions? fo.puts header if put_header File.foreach(txn_location) do |li| fo.puts li end # fo.puts('</batchRequest>') fo.puts('</batchRequest>') if put_header end File.delete(txn_location) if(@au_batch != nil) then @au_batch.close_batch end end |
#create_new_batch(path) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/LitleBatchRequest.rb', line 75 def create_new_batch(path) ts = Time::now.to_i.to_s begin ts += Time::now.nsec.to_s rescue NoMethodError # ruby 1.8.7 fix ts += Time::now.usec.to_s end if(File.file?(path)) then raise ArgumentError, "Entered a file not a path." end if(path[-1,1] != '/' && path[-1,1] != '\\') then path = path + File::SEPARATOR end if(!File.directory?(path)) then Dir.mkdir(path) end @path_to_batch = path + 'batch_' + ts @txn_file = @path_to_batch + '_txns' if(File.file?(@path_to_batch)) then create_new_batch(path) return end File.open(@path_to_batch, 'a+') do |file| file.write("") end File.open(@txn_file, 'a+') do |file| file.write("") end end |
#create_plan(options) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/LitleBatchRequest.rb', line 207 def create_plan() transaction = @litle_txn.create_plan() @txn_counts[:numCreatePlans] += 1 add_txn_to_batch(transaction, :createPlan, ) end |
#credit(options) ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/LitleBatchRequest.rb', line 177 def credit() transaction = @litle_txn.credit() @txn_counts[:credit][:numCredits] += 1 @txn_counts[:credit][:creditAmount] += ['amount'].to_i add_txn_to_batch(transaction, :credit, ) end |
#deactivate(options) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/LitleBatchRequest.rb', line 228 def deactivate() transaction = @litle_txn.deactivate() @txn_counts[:numDeactivates] += 1 add_txn_to_batch(transaction, :deactivate, ) end |
#echeck_credit(options) ⇒ Object
301 302 303 304 305 306 307 |
# File 'lib/LitleBatchRequest.rb', line 301 def echeck_credit() transaction = @litle_txn.echeck_credit() @txn_counts[:echeckCredit][:numEcheckCredit] += 1 @txn_counts[:echeckCredit][:echeckCreditAmount] += ['amount'].to_i add_txn_to_batch(transaction, :echeckCredit, ) end |
#echeck_redeposit(options) ⇒ Object
309 310 311 312 313 314 |
# File 'lib/LitleBatchRequest.rb', line 309 def echeck_redeposit() transaction = @litle_txn.echeck_redeposit() @txn_counts[:numEcheckRedeposit] += 1 add_txn_to_batch(transaction, :echeckRedeposit, ) end |
#echeck_sale(options) ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/LitleBatchRequest.rb', line 316 def echeck_sale() transaction = @litle_txn.echeck_sale() @txn_counts[:echeckSale][:numEcheckSales] += 1 @txn_counts[:echeckSale][:echeckSalesAmount] += ['amount'].to_i add_txn_to_batch(transaction, :echeckSale, ) end |
#echeck_verification(options) ⇒ Object
293 294 295 296 297 298 299 |
# File 'lib/LitleBatchRequest.rb', line 293 def echeck_verification() transaction = @litle_txn.echeck_verification() @txn_counts[:echeckVerification][:numEcheckVerification] += 1 @txn_counts[:echeckVerification][:echeckVerificationAmount] += ['amount'].to_i add_txn_to_batch(transaction, :echeckVerification, ) end |
#force_capture(options) ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/LitleBatchRequest.rb', line 269 def force_capture() transaction = @litle_txn.force_capture() @txn_counts[:forceCapture][:numForceCaptures] += 1 @txn_counts[:forceCapture][:forceCaptureAmount] += ['amount'].to_i add_txn_to_batch(transaction, :forceCapture, ) end |
#get_au_batch ⇒ Object
339 340 341 |
# File 'lib/LitleBatchRequest.rb', line 339 def get_au_batch return @au_batch end |
#get_batch_name ⇒ Object
336 337 338 |
# File 'lib/LitleBatchRequest.rb', line 336 def get_batch_name return @path_to_batch end |
#get_counts_and_amounts ⇒ Object
333 334 335 |
# File 'lib/LitleBatchRequest.rb', line 333 def get_counts_and_amounts return @txn_counts end |
#has_transactions? ⇒ Boolean
107 108 109 |
# File 'lib/LitleBatchRequest.rb', line 107 def has_transactions? !@txn_counts[:total].eql?(0) end |
#load_request(options) ⇒ Object
235 236 237 238 239 240 |
# File 'lib/LitleBatchRequest.rb', line 235 def load_request() transaction = @litle_txn.load_request() @txn_counts[:numLoads] += 1 add_txn_to_batch(transaction, :load, ) end |
#open_existing_batch(pathToBatchFile) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/LitleBatchRequest.rb', line 111 def open_existing_batch(pathToBatchFile) if(!File.file?(pathToBatchFile)) then raise ArgumentError, "No batch file exists at the passed location!" end if((pathToBatchFile =~ /batch_\d+.closed-\d+\z/) != nil) then raise ArgumentError, "The passed batch file is closed!" end @txn_file = pathToBatchFile + '_txns' @path_to_batch = pathToBatchFile temp_counts = File.open(@path_to_batch, "rb") { |f| Marshal.load(f) } # woops, they opened an AU batch if(temp_counts[:numAccountUpdates] != 0) then au_batch = LitleAUBatch.new au_batch.open_existing_batch(pathToBatchFile) initialize() create_new_batch(File.dirname(pathToBatchFile)) @au_batch = au_batch elsif @txn_counts = temp_counts end end |
#register_token_request(options) ⇒ Object
255 256 257 258 259 260 |
# File 'lib/LitleBatchRequest.rb', line 255 def register_token_request() transaction = @litle_txn.register_token_request() @txn_counts[:numTokenRegistrations] += 1 add_txn_to_batch(transaction, :numTokenRegistrations, ) end |
#sale(options) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/LitleBatchRequest.rb', line 169 def sale() transaction = @litle_txn.sale() @txn_counts[:sale][:numSales] += 1 @txn_counts[:sale][:saleAmount] += ['amount'].to_i add_txn_to_batch(transaction, :sale, ) end |
#unload_request(options) ⇒ Object
242 243 244 245 246 247 |
# File 'lib/LitleBatchRequest.rb', line 242 def unload_request() transaction = @litle_txn.unload_request() @txn_counts[:numunLoads] += 1 add_txn_to_batch(transaction, :unload, ) end |
#update_card_validation_num_on_token(options) ⇒ Object
262 263 264 265 266 267 |
# File 'lib/LitleBatchRequest.rb', line 262 def update_card_validation_num_on_token() transaction = @litle_txn.update_card_validation_num_on_token() @txn_counts[:numUpdateCardValidationNumOnTokens] += 1 add_txn_to_batch(transaction, :numUpdateCardValidationNumOnTokens, ) end |
#update_plan(options) ⇒ Object
214 215 216 217 218 219 |
# File 'lib/LitleBatchRequest.rb', line 214 def update_plan() transaction = @litle_txn.update_plan() @txn_counts[:numUpdatePlans] += 1 add_txn_to_batch(transaction, :updatePlan, ) end |
#update_subscription(options) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/LitleBatchRequest.rb', line 200 def update_subscription() transaction = @litle_txn.update_subscription() @txn_counts[:numUpdateSubscriptions] += 1 add_txn_to_batch(transaction, :updateSubscription, ) end |