Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. =begin
  2. Copyright (c) 2011 Litle & Co.
  3.  
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12.  
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. OTHER DEALINGS IN THE SOFTWARE.
  24. =end
  25.  
  26. #Sample Batch Driver
  27. require 'lib/LitleOnline'
  28.  
  29. saleHash = {
  30. 'reportGroup'=>'Planets',
  31. 'id' => '006',
  32. 'orderId'=>'12344',
  33. 'amount'=>'6000',
  34. 'orderSource'=>'ecommerce',
  35. 'card'=>{
  36. 'type'=>'VI',
  37. 'number' =>'4100000000000001',
  38. 'expDate' =>'1210'
  39. }}
  40.  
  41. updateCardHash = {
  42. 'merchantId' => '101',
  43. 'version'=>'8.8',
  44. 'reportGroup'=>'Planets',
  45. 'id'=>'12345',
  46. 'customerId'=>'0987',
  47. 'orderId'=>'12344',
  48. 'litleToken'=>'1233456789103801',
  49. 'cardValidationNum'=>'123'
  50. }
  51.  
  52. accountUpdateHash = {
  53. 'reportGroup'=>'Planets',
  54. 'id'=>'12345',
  55. 'customerId'=>'0987',
  56. 'orderId'=>'1234',
  57. 'card'=>{
  58. 'type'=>'VI',
  59. 'number' =>'4100000000000001',
  60. 'expDate' =>'1210'
  61. }}
  62.  
  63. path = Dir.pwd
  64.  
  65. request = LitleOnline::LitleRequest.new({'sessionId'=>'8675309'})
  66.  
  67. request.create_new_litle_request(path)
  68. puts "Created new LitleRequest at location: " + path
  69. start = Time::now
  70. #create five batches, each with 10 sales
  71. 5.times{
  72. batch = LitleOnline::LitleBatchRequest.new
  73. batch.create_new_batch(path)
  74.  
  75. #add the same sale ten times
  76. 10.times{
  77. batch.sale(saleHash)
  78. }
  79.  
  80. #close the batch, indicating we plan to add no more transactions
  81. batch.close_batch()
  82. #add the batch to the LitleRequest
  83. request.commit_batch(batch)
  84. }
  85.  
  86. # puts "Finished adding batches to LitleRequest at " + request.get_path_to_batches
  87. #finish the Litle Request, indicating we plan to add no more batches
  88. request.finish_request
  89. puts "Generated final XML markup of the LitleRequest"
  90.  
  91. #send the batch files at the given directory over sFTP
  92. request.send_to_litle
  93. puts "Dropped off the XML of the LitleRequest over FTP"
  94. #grab the expected number of responses from the sFTP server and save them to the given path
  95. request.get_responses_from_server()
  96. puts "Received the LitleRequest responses from the server"
  97. #process the responses from the server with a listener which applies the given block
  98. start = Time::now
  99. request.process_responses({:transaction_listener => LitleOnline::DefaultLitleListener.new do |transaction|
  100. type = transaction["type"]
  101. #if we're dealing with a saleResponse (check the Litle XML Reference Guide!)
  102. if(type == "saleResponse") then
  103. #grab an attribute of the parent of the response
  104. puts "Report Group: " + transaction["reportGroup"]
  105.  
  106. #grab some child elements of the transaction
  107. puts "Litle Txn Id: " + transaction["litleTxnId"]
  108. puts "Order Id: " + transaction["orderId"]
  109. puts "Response: " + transaction["response"]
  110.  
  111. #grab a child element of a child element of the transation
  112. puts "AVS Result: " + transaction["fraudResult"]["avsResult"]
  113. puts "Token Response Message: " + transaction["tokenResponse"]["tokenMessage"]
  114. end
  115. end})
  116. stop = Time::now
  117. puts "Total time: " + (stop - start).to_s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement