Class: LitleOnline::LitleAUBatch
- Inherits:
-
Object
- Object
- LitleOnline::LitleAUBatch
- Includes:
- XML::Mapping
- Defined in:
- lib/LitleBatchRequest.rb
Overview
IF YOU ARE A MERCHANT, DON’T LOOK HERE. IT’S SCARY!
Instance Method Summary collapse
- #account_update(options) ⇒ Object
- #close_batch(txn_location = @txn_file) ⇒ Object
- #create_new_batch(path) ⇒ Object
- #get_batch_name ⇒ Object
- #get_counts_and_amounts ⇒ Object
-
#initialize ⇒ LitleAUBatch
constructor
A new instance of LitleAUBatch.
- #open_existing_batch(pathToBatchFile) ⇒ Object
Constructor Details
#initialize ⇒ LitleAUBatch
Returns a new instance of LitleAUBatch.
424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/LitleBatchRequest.rb', line 424 def initialize #load configuration data @config_hash = Configuration.new.config @txn_counts = { :id=>nil, :merchantId=>nil, :numAccountUpdates=>0, :total=>0 } @litle_txn = LitleTransaction.new @path_to_batch = nil @txn_file = nil @MAX_TXNS_IN_BATCH = 100000 end |
Instance Method Details
#account_update(options) ⇒ Object
509 510 511 512 513 514 |
# File 'lib/LitleBatchRequest.rb', line 509 def account_update() transaction = @litle_txn.account_update() @txn_counts[:numAccountUpdates] += 1 add_txn_to_batch(transaction, :authorization, ) end |
#close_batch(txn_location = @txn_file) ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/LitleBatchRequest.rb', line 494 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 File.foreach(txn_location) do |li| fo.puts li end fo.puts('</batchRequest>') end File.delete(txn_location) end |
#create_new_batch(path) ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/LitleBatchRequest.rb', line 439 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 |
#get_batch_name ⇒ Object
519 520 521 |
# File 'lib/LitleBatchRequest.rb', line 519 def get_batch_name return @path_to_batch end |
#get_counts_and_amounts ⇒ Object
516 517 518 |
# File 'lib/LitleBatchRequest.rb', line 516 def get_counts_and_amounts return @txn_counts end |
#open_existing_batch(pathToBatchFile) ⇒ Object
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/LitleBatchRequest.rb', line 472 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) } if(temp_counts.keys.size > 4) then raise RuntimeException, "Tried to open an AU batch with a non-AU batch file" end @txn_counts[:id] = temp_counts[:id] @txn_counts[:merchantId] = temp_counts[:merchantId] @txn_counts[:numAccountUpdates] = temp_counts[:numAccountUpdates] @txn_counts[:total] = temp_counts[:total] end |