Class: LitleOnline::LitleBatchRequest

Inherits:
Object
  • Object
show all
Includes:
XML::Mapping
Defined in:
lib/LitleBatchRequest.rb

Instance Method Summary collapse

Constructor Details

#initializeLitleBatchRequest

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 (options)
   
  if(@au_batch == nil) then
    @au_batch = LitleAUBatch.new
    @au_batch.create_new_batch(File.dirname(@path_to_batch))
  end 
  @au_batch.(options)
end

#activate(options) ⇒ Object



221
222
223
224
225
226
# File 'lib/LitleBatchRequest.rb', line 221

def activate(options)
  transaction = @litle_txn.activate(options)  
  @txn_counts[:numActivates] += 1
  
  add_txn_to_batch(transaction, :activate, options)
end

#au_batch?Boolean

Returns:

  • (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(options)
  transaction = @litle_txn.auth_reversal(options)
  @txn_counts[:authReversal][:numAuthReversals] += 1     
  @txn_counts[:authReversal][:authReversalAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :authReversal, options)
end

#authorization(options) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/LitleBatchRequest.rb', line 161

def authorization(options)
  transaction = @litle_txn.authorization(options)
  @txn_counts[:auth][:numAuths] += 1
  @txn_counts[:auth][:authAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :authorization, options)
end

#balance_inquiry(options) ⇒ Object



249
250
251
252
253
254
# File 'lib/LitleBatchRequest.rb', line 249

def balance_inquiry(options)
  transaction = @litle_txn.balance_inquiry(options)  
  @txn_counts[:numBalanceInquirys] += 1
  
  add_txn_to_batch(transaction, :balanceInquirys, options)
end

#cancel_subscription(options) ⇒ Object



193
194
195
196
197
198
# File 'lib/LitleBatchRequest.rb', line 193

def cancel_subscription(options)
  transaction = @litle_txn.cancel_subscription(options)
  @txn_counts[:numCancelSubscriptions] += 1
  
  add_txn_to_batch(transaction, :cancelSubscription, options)
end

#capture(options) ⇒ Object



277
278
279
280
281
282
283
# File 'lib/LitleBatchRequest.rb', line 277

def capture(options)
  transaction = @litle_txn.capture(options)
  @txn_counts[:capture][:numCaptures] += 1
  @txn_counts[:capture][:captureAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :capture, options)
end

#capture_given_auth(options) ⇒ Object



285
286
287
288
289
290
291
# File 'lib/LitleBatchRequest.rb', line 285

def capture_given_auth(options)
  transaction = @litle_txn.capture_given_auth(options)
  @txn_counts[:captureGivenAuth][:numCaptureGivenAuths] += 1
  @txn_counts[:captureGivenAuth][:captureGivenAuthAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :captureGivenAuth, options)
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(options)
  transaction = @litle_txn.create_plan(options)  
  @txn_counts[:numCreatePlans] += 1
  
  add_txn_to_batch(transaction, :createPlan, options)
end

#credit(options) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/LitleBatchRequest.rb', line 177

def credit(options)
  transaction = @litle_txn.credit(options)
  @txn_counts[:credit][:numCredits] += 1
  @txn_counts[:credit][:creditAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :credit, options)
end

#deactivate(options) ⇒ Object



228
229
230
231
232
233
# File 'lib/LitleBatchRequest.rb', line 228

def deactivate(options)
  transaction = @litle_txn.deactivate(options)  
  @txn_counts[:numDeactivates] += 1
  
  add_txn_to_batch(transaction, :deactivate, options)
end

#echeck_credit(options) ⇒ Object



301
302
303
304
305
306
307
# File 'lib/LitleBatchRequest.rb', line 301

def echeck_credit(options)
  transaction = @litle_txn.echeck_credit(options)
  @txn_counts[:echeckCredit][:numEcheckCredit] += 1
  @txn_counts[:echeckCredit][:echeckCreditAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :echeckCredit, options)
end

#echeck_redeposit(options) ⇒ Object



309
310
311
312
313
314
# File 'lib/LitleBatchRequest.rb', line 309

def echeck_redeposit(options)
  transaction = @litle_txn.echeck_redeposit(options)
  @txn_counts[:numEcheckRedeposit] += 1
  
  add_txn_to_batch(transaction, :echeckRedeposit, options)
end

#echeck_sale(options) ⇒ Object



316
317
318
319
320
321
322
# File 'lib/LitleBatchRequest.rb', line 316

def echeck_sale(options)
  transaction = @litle_txn.echeck_sale(options)
  @txn_counts[:echeckSale][:numEcheckSales] += 1
  @txn_counts[:echeckSale][:echeckSalesAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :echeckSale, options)
end

#echeck_verification(options) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/LitleBatchRequest.rb', line 293

def echeck_verification(options)
  transaction = @litle_txn.echeck_verification(options)
  @txn_counts[:echeckVerification][:numEcheckVerification] += 1
  @txn_counts[:echeckVerification][:echeckVerificationAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :echeckVerification, options)
end

#force_capture(options) ⇒ Object



269
270
271
272
273
274
275
# File 'lib/LitleBatchRequest.rb', line 269

def force_capture(options)
  transaction = @litle_txn.force_capture(options)
  @txn_counts[:forceCapture][:numForceCaptures] += 1
  @txn_counts[:forceCapture][:forceCaptureAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :forceCapture, options)
end

#get_au_batchObject



339
340
341
# File 'lib/LitleBatchRequest.rb', line 339

def get_au_batch
  return @au_batch
end

#get_batch_nameObject



336
337
338
# File 'lib/LitleBatchRequest.rb', line 336

def get_batch_name
  return @path_to_batch
end

#get_counts_and_amountsObject



333
334
335
# File 'lib/LitleBatchRequest.rb', line 333

def get_counts_and_amounts
  return @txn_counts
end

#has_transactions?Boolean

Returns:

  • (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(options)
  transaction = @litle_txn.load_request(options)  
  @txn_counts[:numLoads] += 1
  
  add_txn_to_batch(transaction, :load, options)
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(options)
  transaction = @litle_txn.register_token_request(options)
  @txn_counts[:numTokenRegistrations] += 1
  
  add_txn_to_batch(transaction, :numTokenRegistrations, options)
end

#sale(options) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/LitleBatchRequest.rb', line 169

def sale(options)
  transaction = @litle_txn.sale(options)
  @txn_counts[:sale][:numSales] += 1
  @txn_counts[:sale][:saleAmount] += options['amount'].to_i
  
  add_txn_to_batch(transaction, :sale, options)
end

#unload_request(options) ⇒ Object



242
243
244
245
246
247
# File 'lib/LitleBatchRequest.rb', line 242

def unload_request(options)
  transaction = @litle_txn.unload_request(options)  
  @txn_counts[:numunLoads] += 1
  
  add_txn_to_batch(transaction, :unload, options)
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(options)
  transaction = @litle_txn.update_card_validation_num_on_token(options)
  @txn_counts[:numUpdateCardValidationNumOnTokens] += 1
  
  add_txn_to_batch(transaction, :numUpdateCardValidationNumOnTokens, options)
end

#update_plan(options) ⇒ Object



214
215
216
217
218
219
# File 'lib/LitleBatchRequest.rb', line 214

def update_plan(options)
  transaction = @litle_txn.update_plan(options)  
  @txn_counts[:numUpdatePlans] += 1
  
  add_txn_to_batch(transaction, :updatePlan, options)
end

#update_subscription(options) ⇒ Object



200
201
202
203
204
205
# File 'lib/LitleBatchRequest.rb', line 200

def update_subscription(options)
  transaction = @litle_txn.update_subscription(options)
  @txn_counts[:numUpdateSubscriptions] += 1
  
  add_txn_to_batch(transaction, :updateSubscription, options)
end