bluepay 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -7
  2. data/Rakefile +1 -1
  3. data/bluepay.gemspec +3 -3
  4. data/lib/api_request.rb +125 -0
  5. data/lib/api_response.rb +150 -0
  6. data/lib/bluepay.rb +94 -332
  7. data/lib/cacert.pem +3860 -0
  8. data/test/Get_Data/Retrieve_Settlement_Data.rb +34 -0
  9. data/test/Get_Data/Retrieve_Transaction_Data.rb +33 -0
  10. data/test/Get_Data/Single_Transaction_Query.rb +42 -0
  11. data/test/Get_Data/Transaction_Notification.rb +61 -0
  12. data/test/Rebill/Cancel_Recurring_Payment.rb +82 -0
  13. data/test/Rebill/Create_Recurring_Payment_ACH.rb +60 -0
  14. data/test/Rebill/Create_Recurring_Payment_CC.rb +62 -0
  15. data/test/Rebill/Get_Recurring_Payment_Status.rb +82 -0
  16. data/test/Rebill/Update_Recurring_Payment.rb +111 -0
  17. data/test/Transactions/Cancel_Transaction.rb +74 -0
  18. data/test/Transactions/Charge_Customer_ACH.rb +54 -0
  19. data/test/Transactions/Charge_Customer_CC.rb +60 -0
  20. data/test/Transactions/Check_Customer_Credit.rb +58 -0
  21. data/test/Transactions/Customer_Defined_Data.rb +71 -0
  22. data/test/Transactions/How_To_Use_Token.rb +42 -0
  23. data/test/Transactions/Return_Funds.rb +77 -0
  24. data/test/Transactions/Store_Payment_Information.rb +58 -0
  25. metadata +42 -93
  26. data/doc/BluePay.html +0 -2699
  27. data/doc/README.html +0 -174
  28. data/doc/created.rid +0 -3
  29. data/doc/fonts.css +0 -167
  30. data/doc/fonts/Lato-Light.ttf +0 -0
  31. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  32. data/doc/fonts/Lato-Regular.ttf +0 -0
  33. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  34. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  35. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  36. data/doc/images/add.png +0 -0
  37. data/doc/images/arrow_up.png +0 -0
  38. data/doc/images/brick.png +0 -0
  39. data/doc/images/brick_link.png +0 -0
  40. data/doc/images/bug.png +0 -0
  41. data/doc/images/bullet_black.png +0 -0
  42. data/doc/images/bullet_toggle_minus.png +0 -0
  43. data/doc/images/bullet_toggle_plus.png +0 -0
  44. data/doc/images/date.png +0 -0
  45. data/doc/images/delete.png +0 -0
  46. data/doc/images/find.png +0 -0
  47. data/doc/images/loadingAnimation.gif +0 -0
  48. data/doc/images/macFFBgHack.png +0 -0
  49. data/doc/images/package.png +0 -0
  50. data/doc/images/page_green.png +0 -0
  51. data/doc/images/page_white_text.png +0 -0
  52. data/doc/images/page_white_width.png +0 -0
  53. data/doc/images/plugin.png +0 -0
  54. data/doc/images/ruby.png +0 -0
  55. data/doc/images/tag_blue.png +0 -0
  56. data/doc/images/tag_green.png +0 -0
  57. data/doc/images/transparent.png +0 -0
  58. data/doc/images/wrench.png +0 -0
  59. data/doc/images/wrench_orange.png +0 -0
  60. data/doc/images/zoom.png +0 -0
  61. data/doc/index.html +0 -92
  62. data/doc/js/darkfish.js +0 -140
  63. data/doc/js/jquery.js +0 -18
  64. data/doc/js/navigation.js +0 -142
  65. data/doc/js/search.js +0 -109
  66. data/doc/js/search_index.js +0 -1
  67. data/doc/js/searcher.js +0 -228
  68. data/doc/rdoc.css +0 -580
  69. data/doc/table_of_contents.html +0 -405
  70. data/test/get_data/retrieve_settlement_data.rb +0 -39
  71. data/test/get_data/retrieve_transaction_data.rb +0 -37
  72. data/test/get_data/transaction_query.rb +0 -48
  73. data/test/getting_stuff_done/get_transaction_data.rb +0 -37
  74. data/test/getting_stuff_done/run_ach_payment.rb +0 -75
  75. data/test/getting_stuff_done/run_cc_payment.rb +0 -73
  76. data/test/getting_stuff_done/set_up_rebill_ach.rb +0 -85
  77. data/test/getting_stuff_done/set_up_rebill_cc.rb +0 -84
  78. data/test/rebills/cancel_rebill.rb +0 -96
  79. data/test/rebills/create_rebill.rb +0 -84
  80. data/test/rebills/get_rebill.rb +0 -97
  81. data/test/rebills/update_rebill.rb +0 -128
  82. data/test/transactions/cancel_transaction.rb +0 -85
  83. data/test/transactions/charge_customer.rb +0 -74
  84. data/test/transactions/check_customer_credit.rb +0 -74
  85. data/test/transactions/credit_customer.rb +0 -75
  86. data/test/transactions/customer_defined_data.rb +0 -99
  87. data/test/transactions/return_funds.rb +0 -86
  88. data/test/transactions/store_payment_information.rb +0 -74
  89. data/test/transactions/use_token.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- metadata.gz: 16fe99ad7bb131897c195bd4be3a6bd9098e605c49b0bcaae46a965ce9e6cbe357968888a81bb94ab1c8c2308dbbc3c5e6f1fe00149b48e2661652d08820affc
4
- data.tar.gz: 8c31b1b5bb101da007ad018d7d0a00815ea44e0f4b9527781b26fe3a68c87046616944fd7eb5c51d3c919713cf3afb2afc7593767c7eb0eb2f0eb9497803ddf4
5
- SHA1:
6
- metadata.gz: 59d38c075ef13dfdfabcc957f5dcee2358abf43c
7
- data.tar.gz: 67d0f249d522f2edebe463bcd6db16330978b76c
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7535b98d5bd56bece87ec37a62ec281374bbd032
4
+ data.tar.gz: 4b461cf8c17e9bc247183298da6021f3e031e69e
5
+ SHA512:
6
+ metadata.gz: 18cb2fff25162948c844faafa6d43e6c7a862e6985c2e43ad1501d3b16b8426701b6a563a61cbbfce6120dfba8370008e1c3d34c1d6b62addc05024c291aa5b7
7
+ data.tar.gz: 5471afaf85203866ba10bad7c8ba69afdccf57543bbfbf9da00618d9d1472aa0f644c201eb0c4e253073a037e154b8843b4b9a5c29b85c1556c43b4f4257dbdf
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ end
15
15
  Rake::TestTask.new do |t|
16
16
  t.libs << 'test'
17
17
  t.test_files = FileList['test/*/*.rb']
18
- t.verbose = true
18
+ t.verbose = false
19
19
  end
20
20
 
21
21
  # Genereate the RDoc documentation
data/bluepay.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bluepay'
3
- s.version = '1.0.3'
4
- s.date = '2014-06-17'
5
- s.summary = "BluePay gateway rubygem."
3
+ s.version = '1.0.4'
4
+ s.date = '2015-11-30'
5
+ s.summary = "BluePay gateway rubygem"
6
6
  s.description = "This gem is intended to be used along with a BluePay gateway account to process credit card and ACH transactions"
7
7
  s.authors = ["Justin Slingerland"]
8
8
  s.email = 'jslingerland@bluepay.com'
@@ -0,0 +1,125 @@
1
+ class BluePay
2
+
3
+ # Turns a hash into a nvp style string
4
+ def uri_query(param_hash)
5
+ array = []
6
+ param_hash.each_pair {|key, val| array << (URI.escape(key) + "=" + URI.escape(val))}
7
+ array.join("&")
8
+ end
9
+
10
+ # Sets TAMPER_PROOF_SEAL in @PARAM_HASH
11
+ def calc_tps
12
+ @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(
13
+ @SECRET_KEY +
14
+ @ACCOUNT_ID +
15
+ (@PARAM_HASH["TRANSACTION_TYPE"] || '') +
16
+ @PARAM_HASH["AMOUNT"] +
17
+ (@PARAM_HASH["REBILLING"] || '') +
18
+ (@PARAM_HASH["REB_FIRST_DATE"] || '') +
19
+ (@PARAM_HASH["REB_EXPR"] || '') +
20
+ (@PARAM_HASH["REB_CYCLES"] || '') +
21
+ (@PARAM_HASH["REB_AMOUNT"] || '') +
22
+ (@PARAM_HASH["RRNO"] || '') +
23
+ @PARAM_HASH["MODE"]
24
+ )
25
+ end
26
+
27
+ # Sets TAMPER_PROOF_SEAL in @PARAM_HASH for rebadmin API
28
+ def calc_rebill_tps
29
+ @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(
30
+ @SECRET_KEY +
31
+ @ACCOUNT_ID +
32
+ @PARAM_HASH["TRANS_TYPE"] +
33
+ @PARAM_HASH["REBILL_ID"]
34
+ )
35
+ end
36
+
37
+ # Sets TAMPER_PROOF_SEAL in @PARAM_HASH for bpdailyreport2 API
38
+ def calc_report_tps
39
+ @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(
40
+ @SECRET_KEY +
41
+ @ACCOUNT_ID +
42
+ @PARAM_HASH["REPORT_START_DATE"] +
43
+ @PARAM_HASH["REPORT_END_DATE"]
44
+ )
45
+ end
46
+
47
+ # Calculates TAMPER_PROOF_SEAL to be used with Trans Notify API
48
+ def self.calc_trans_notify_tps(secret_key, trans_id, trans_status, trans_type, amount, batch_id, batch_status, total_count, total_amount, batch_upload_id, rebill_id, rebill_amount, rebill_status)
49
+ Digest::MD5.hexdigest(
50
+ secret_key +
51
+ trans_id +
52
+ trans_status +
53
+ trans_type +
54
+ amount +
55
+ batch_id +
56
+ batch_status +
57
+ total_count +
58
+ total_amount +
59
+ batch_upload_id +
60
+ rebill_id +
61
+ rebill_amount +
62
+ rebill_status
63
+ )
64
+ end
65
+
66
+ # sends HTTPS POST to BluePay gateway for processing
67
+ def process
68
+ ua = Net::HTTP.new(SERVER, 443)
69
+ ua.use_ssl = true
70
+ if File.directory?(RootCA)
71
+ ua.ca_path = RootCA
72
+ ua.verify_mode = OpenSSL::SSL::VERIFY_PEER
73
+ ua.verify_depth = 3
74
+ else
75
+ puts "Invalid CA certificates directory. Exiting..."
76
+ exit
77
+ end
78
+ begin
79
+ @PARAM_HASH["REMOTE_IP"] = request.env['REMOTE_ADDR']
80
+ rescue Exception
81
+ end
82
+ # Generate the query string and headers
83
+
84
+ # Chooses which API to make request to
85
+ case @api
86
+ when "bpdailyreport2"
87
+ calc_report_tps
88
+ path = "/interfaces/bpdailyreport2"
89
+ query = "ACCOUNT_ID=#{@ACCOUNT_ID}&" + uri_query(@PARAM_HASH)
90
+ when "stq"
91
+ calc_report_tps
92
+ path = "/interfaces/stq"
93
+ query = "ACCOUNT_ID=#{@ACCOUNT_ID}&" + uri_query(@PARAM_HASH)
94
+ when "bp10emu"
95
+ calc_tps
96
+ path = "/interfaces/bp10emu"
97
+ query = "MERCHANT=#{@ACCOUNT_ID}&" + uri_query(@PARAM_HASH)
98
+ # puts "****"; puts uri_query(@PARAM_HASH).inspect
99
+ when "bp20rebadmin"
100
+ calc_rebill_tps
101
+ path = "/interfaces/bp20rebadmin"
102
+ query = "ACCOUNT_ID=#{@ACCOUNT_ID}&" + uri_query(@PARAM_HASH)
103
+ end
104
+ queryheaders = {
105
+ 'User-Agent' => 'BluePay Ruby Library/1.0.4',
106
+ 'Content-Type' => 'application/x-www-form-urlencoded'
107
+ }
108
+ # Response version to be returned
109
+ @PARAM_HASH["VERSION"] = '3'
110
+ # Post parameters to BluePay gateway
111
+ headers, body = ua.post(path, query, queryheaders)
112
+ # Split the response into the response hash.
113
+ @RESPONSE_HASH = {}
114
+ if path == "/interfaces/bp10emu"
115
+ response = headers["Location"].split("?")[1]
116
+ else
117
+ response = headers.body
118
+ end
119
+ response.split("&").each do |pair|
120
+ (key, val) = pair.split("=")
121
+ val = "" if val == nil
122
+ @RESPONSE_HASH[URI.unescape(key)] = URI.unescape(val)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,150 @@
1
+ class BluePay
2
+ def get_response
3
+ @RESPONSE_HASH
4
+ end
5
+
6
+ # Returns true if response status is approved and not a duplicate, else returns false
7
+ def successful_response?
8
+ self.get_status == "APPROVED" && self.get_message != "DUPLICATE"
9
+ end
10
+
11
+ # Returns E for Error, 1 for Approved, 0 for Decline
12
+ def get_status
13
+ @RESPONSE_HASH['Result']
14
+ end
15
+
16
+ # Returns the human-readable response from Bluepay.
17
+ # Or a nasty error.
18
+ def get_message
19
+ m = @RESPONSE_HASH['MESSAGE']
20
+ if m == nil or m == ""
21
+ "ERROR - NO MESSAGE FROM BLUEPAY"
22
+ else
23
+ m
24
+ end
25
+ end
26
+
27
+ # Returns the single-character AVS response from the
28
+ # Card Issuing Bank
29
+ def get_avs_code
30
+ @RESPONSE_HASH['AVS']
31
+ end
32
+
33
+ # Same as avs_code, but for CVV2
34
+ def get_cvv2_code
35
+ @RESPONSE_HASH['CVV2']
36
+ end
37
+
38
+ # In the case of an approved transaction, contains the
39
+ # 6-character authorization code from the processing network.
40
+ # In the case of a decline or error, the contents may be junk.
41
+ def get_auth_code
42
+ @RESPONSE_HASH['AUTH_CODE']
43
+ end
44
+
45
+ # The all-important transaction ID.
46
+ def get_trans_id
47
+ @RESPONSE_HASH['RRNO']
48
+ end
49
+
50
+ # If you set up a rebilling, this'll get its ID.
51
+ def get_rebill_id
52
+ @RESPONSE_HASH['REBID']
53
+ end
54
+
55
+ # Masked credit card or ACH account
56
+ def get_masked_account
57
+ @RESPONSE_HASH['PAYMENT_ACCOUNT']
58
+ end
59
+
60
+ # Card type used in transaction
61
+ def get_card_type
62
+ @RESPONSE_HASH['CARD_TYPE']
63
+ end
64
+
65
+ # Bank account used in transaction
66
+ def get_bank_name
67
+ @RESPONSE_HASH['BANK_NAME']
68
+ end
69
+
70
+ # Rebill ID from bprebadmin API
71
+ def get_reb_id
72
+ @RESPONSE_HASH['rebill_id']
73
+ end
74
+
75
+ # Template ID of rebilling
76
+ def get_template_id
77
+ @RESPONSE_HASH['template_id']
78
+ end
79
+
80
+ # Status of rebilling
81
+ def get_rebill_status
82
+ @RESPONSE_HASH['status']
83
+ end
84
+
85
+ # Creation date of rebilling
86
+ def get_creation_date
87
+ @RESPONSE_HASH['creation_date']
88
+ end
89
+
90
+ # Next date that the rebilling is set to fire off on
91
+ def get_next_date
92
+ @RESPONSE_HASH['next_date']
93
+ end
94
+
95
+ # Last date that the rebilling fired off on
96
+ def get_last_date
97
+ @RESPONSE_HASH['last_date']
98
+ end
99
+
100
+ # Rebilling expression
101
+ def get_sched_expression
102
+ @RESPONSE_HASH['sched_expr']
103
+ end
104
+
105
+ # Number of cycles remaining on rebilling
106
+ def get_cycles_remaining
107
+ @RESPONSE_HASH['cycles_remain']
108
+ end
109
+
110
+ # Amount to charge when rebilling fires off
111
+ def get_rebill_amount
112
+ @RESPONSE_HASH['reb_amount']
113
+ end
114
+
115
+ # Next amount to charge when rebilling fires off
116
+ def get_next_amount
117
+ @RESPONSE_HASH['next_amount']
118
+ end
119
+
120
+ # Transaction ID used with stq API
121
+ def get_id
122
+ @RESPONSE_HASH['id']
123
+ end
124
+
125
+ # First name associated with the transaction
126
+ def get_name1
127
+ @RESPONSE_HASH['name1']
128
+ end
129
+
130
+ # Last name associated with the transaction
131
+ def get_name2
132
+ @RESPONSE_HASH['name2']
133
+ end
134
+
135
+ # Payment type associated with the transaction
136
+ def get_payment_type
137
+ @RESPONSE_HASH['payment_type']
138
+ end
139
+
140
+ # Transaction type associated with the transaction
141
+ def get_trans_type
142
+ @RESPONSE_HASH['trans_type']
143
+ end
144
+
145
+ # Amount associated with the transaction
146
+ def get_amount
147
+ @RESPONSE_HASH['amount']
148
+ end
149
+
150
+ end
data/lib/bluepay.rb CHANGED
@@ -1,31 +1,30 @@
1
- #!/usr/bin/ruby
2
1
  require "net/http"
3
2
  require "net/https"
4
3
  require "uri"
5
4
  require "digest/md5"
6
5
 
6
+ # Files
7
+ require_relative "api_request"
8
+ require_relative "api_response"
9
+
7
10
  class BluePay
8
11
  SERVER = "secure.bluepay.com"
9
12
  # Make sure this is the correct path to your CA certificates directory
10
- RootCA = "/etc/ssl/certs"
11
-
12
- def initialize(account,key,mode='TEST')
13
- @ACCOUNT_ID = account
14
- @SECRET_KEY = key
15
- @PARAM_HASH = { 'MODE' => mode }
16
- @RETURN_HASH = Hash.new()
17
- end
13
+ # For testing purposes, this gem comes with a CA bundle.
14
+ RootCA = "."
18
15
 
19
- def set_param(key, val)
20
- @PARAM_HASH[key] = val
16
+ def initialize(params = {})
17
+ @ACCOUNT_ID = params[:account_id]
18
+ @SECRET_KEY = params[:secret_key]
19
+ @PARAM_HASH = {'MODE' => params[:mode]}
21
20
  end
22
21
 
23
22
  # Set up a credit card payment.
24
- def set_cc_information(account, expire, cvv='')
23
+ def set_cc_information(params={})
25
24
  @PARAM_HASH['PAYMENT_TYPE'] = 'CREDIT'
26
- @PARAM_HASH['CC_NUM'] = account
27
- @PARAM_HASH['CC_EXPIRES'] = expire
28
- @PARAM_HASH['CVCVV2'] = cvv
25
+ @PARAM_HASH['CC_NUM'] = params[:cc_number] || ''
26
+ @PARAM_HASH['CC_EXPIRES'] = params[:cc_expiration] || ''
27
+ @PARAM_HASH['CVCVV2'] = params[:cvv2] || ''
29
28
  end
30
29
 
31
30
  # Set up an ACH transaction. Expects:
@@ -33,49 +32,44 @@ class BluePay
33
32
  # routing: Bank routing number
34
33
  # account: Customer's checking or savings account number
35
34
  # doc_type: WEB, TEL, ARC, etc -- see docs. Optional.
36
- # REMEMBER: Ach requires some other fields,
37
- # such as address and phone
38
- def set_ach_information(routing, account, acc_type, doc_type='')
35
+ def set_ach_information(params = {})
39
36
  @PARAM_HASH['PAYMENT_TYPE'] = 'ACH'
40
- @PARAM_HASH['ACH_ROUTING'] = routing
41
- @PARAM_HASH['ACH_ACCOUNT'] = account
42
- @PARAM_HASH['ACH_ACCOUNT_TYPE'] = acc_type
43
- @PARAM_HASH['DOC_TYPE'] = doc_type
37
+ @PARAM_HASH['ACH_ROUTING'] = params[:ach_routing]
38
+ @PARAM_HASH['ACH_ACCOUNT'] = params[:ach_account]
39
+ @PARAM_HASH['ACH_ACCOUNT_TYPE'] = params[:ach_account_type]
40
+ @PARAM_HASH['DOC_TYPE'] = params[:doc_type] || ''
44
41
  end
45
42
 
46
43
  # Set up a sale
47
- def sale(amount, trans_id='')
44
+ def sale(params = {})
48
45
  @PARAM_HASH['TRANSACTION_TYPE'] = 'SALE'
49
- @PARAM_HASH['AMOUNT'] = amount
50
- @PARAM_HASH['RRNO'] = trans_id
46
+ @PARAM_HASH['AMOUNT'] = params[:amount]
47
+ @PARAM_HASH['RRNO'] = params[:trans_id] || ''
48
+ @api = "bp10emu"
51
49
  end
52
50
 
53
51
  # Set up an Auth
54
- def auth(amount, trans_id='')
52
+ def auth(params ={})
55
53
  @PARAM_HASH['TRANSACTION_TYPE'] = 'AUTH'
56
- @PARAM_HASH['AMOUNT'] = amount
57
- @PARAM_HASH['RRNO'] = trans_id
54
+ @PARAM_HASH['AMOUNT'] = params[:amount]
55
+ @PARAM_HASH['RRNO'] = params[:trans_id] || ''
56
+ @api = "bp10emu"
58
57
  end
59
58
 
60
- # Credit
61
- def credit(amount, trans_id='')
62
- @PARAM_HASH['TRANSACTION_TYPE'] = 'CREDIT'
63
- @PARAM_HASH['AMOUNT'] = amount
64
- @PARAM_HASH['RRNO'] = trans_id
65
- end
66
-
67
59
  # Capture an Auth
68
60
  def capture(trans_id, amount='')
69
61
  @PARAM_HASH['TRANSACTION_TYPE'] = 'CAPTURE'
70
62
  @PARAM_HASH['AMOUNT'] = amount
71
63
  @PARAM_HASH['RRNO'] = trans_id
64
+ @api = "bp10emu"
72
65
  end
73
66
 
74
67
  # Refund
75
- def refund(trans_id, amount='')
68
+ def refund(params = {})
76
69
  @PARAM_HASH['TRANSACTION_TYPE'] = 'REFUND'
77
- @PARAM_HASH['RRNO'] = trans_id
78
- @PARAM_HASH['AMOUNT'] = amount
70
+ @PARAM_HASH['RRNO'] = params[:trans_id]
71
+ @PARAM_HASH['AMOUNT'] = params[:amount] || ''
72
+ @api = "bp10emu"
79
73
  end
80
74
 
81
75
  # Void
@@ -83,94 +77,99 @@ class BluePay
83
77
  @PARAM_HASH['TRANSACTION_TYPE'] = 'VOID'
84
78
  @PARAM_HASH['AMOUNT'] = ''
85
79
  @PARAM_HASH['RRNO'] = trans_id
80
+ @api = "bp10emu"
86
81
  end
87
82
 
88
83
  # Sets customer information for the transaction
89
- def set_customer_information(name1, name2, addr1, city, state, zip, addr2='', country='')
90
- @PARAM_HASH['NAME1'] = name1
91
- @PARAM_HASH['NAME2'] = name2
92
- @PARAM_HASH['ADDR1'] = addr1
93
- @PARAM_HASH['CITY'] = city
94
- @PARAM_HASH['STATE'] = state
95
- @PARAM_HASH['ZIPCODE'] = zip
96
- @PARAM_HASH['ADDR2'] = addr2
97
- @PARAM_HASH['COUNTRY'] = country
84
+ def set_customer_information(params={})
85
+ @PARAM_HASH['NAME1'] = params[:first_name]
86
+ @PARAM_HASH['NAME2'] = params[:last_name]
87
+ @PARAM_HASH['ADDR1'] = params[:address1]
88
+ @PARAM_HASH['ADDR2'] = params[:address2]
89
+ @PARAM_HASH['CITY'] = params[:city]
90
+ @PARAM_HASH['STATE'] = params[:state]
91
+ @PARAM_HASH['ZIPCODE'] = params[:zip_code]
92
+ @PARAM_HASH['COUNTRY'] = params[:country]
93
+ @PARAM_HASH['PHONE'] = params[:phone]
94
+ @PARAM_HASH['EMAIL'] = params[:email]
98
95
  end
99
96
 
100
- # Set customer phone #
101
- def set_phone(phone)
102
- @PARAM_HASH['PHONE'] = phone
97
+ # Set customer Phone
98
+ def phone=(number)
99
+ @PARAM_HASH['PHONE'] = number
103
100
  end
104
101
 
105
102
  # Set customer E-mail address
106
- def set_email(email)
103
+ def email=(email)
107
104
  @PARAM_HASH['EMAIL'] = email
108
105
  end
109
106
 
110
107
  # Set MEMO field
111
- def set_memo(memo)
108
+ def memo=(memo)
112
109
  @PARAM_HASH['COMMENT'] = memo
113
110
  end
114
111
 
115
112
  # Set CUSTOM_ID field
116
- def set_custom_id1(custom_id1)
113
+ def custom_id1=(custom_id1)
117
114
  @PARAM_HASH['CUSTOM_ID'] = custom_id1
118
115
  end
119
116
 
120
117
  # Set CUSTOM_ID2 field
121
- def set_custom_id2(custom_id2)
118
+ def custom_id2=(custom_id2)
122
119
  @PARAM_HASH['CUSTOM_ID2'] = custom_id2
123
120
  end
124
121
 
125
122
  # Set INVOICE_ID field
126
- def set_invoice_id(invoice_id)
123
+ def invoice_id=(invoice_id)
127
124
  @PARAM_HASH['INVOICE_ID'] = invoice_id
128
125
  end
129
126
 
130
127
  # Set ORDER_ID field
131
- def set_order_id(order_id)
128
+ def order_id=(order_id)
132
129
  @PARAM_HASH['ORDER_ID'] = order_id
133
130
  end
134
131
 
135
132
  # Set AMOUNT_TIP field
136
- def set_amount_tip(amount_tip)
133
+ def amount_tip=(amount_tip)
137
134
  @PARAM_HASH['AMOUNT_TIP'] = amount_tip
138
135
  end
139
136
 
140
137
  # Set AMOUNT_TAX field
141
- def set_amount_tax(amount_tax)
138
+ def amount_tax=(amount_tax)
142
139
  @PARAM_HASH['AMOUNT_TAX'] = amount_tax
143
140
  end
144
141
 
145
142
  # Set AMOUNT_FOOD field
146
- def set_amount_food(amount_food)
143
+ def amount_food=(amount_food)
147
144
  @PARAM_HASH['AMOUNT_FOOD'] = amount_food
148
145
  end
149
146
 
150
147
  # Set AMOUNT_MISC field
151
- def set_amount_misc(amount_misc)
148
+ def amount_misc=(amount_misc)
152
149
  @PARAM_HASH['AMOUNT_MISC'] = amount_misc
153
150
  end
154
151
 
155
152
  # Set fields for a recurring payment
156
- def add_recurring_fields(rebill_first_date, rebill_expr, reb_cycles, reb_amount)
153
+ def set_recurring_payment(params = {})
157
154
  @PARAM_HASH['REBILLING'] = '1'
158
- @PARAM_HASH['REB_FIRST_DATE'] = rebill_first_date
159
- @PARAM_HASH['REB_EXPR'] = rebill_expr
160
- @PARAM_HASH['REB_CYCLES'] = reb_cycles
161
- @PARAM_HASH['REB_AMOUNT'] = reb_amount
155
+ @PARAM_HASH['REB_FIRST_DATE'] = params[:reb_first_date]
156
+ @PARAM_HASH['REB_EXPR'] = params[:reb_expr]
157
+ @PARAM_HASH['REB_CYCLES'] = params[:reb_cycles]
158
+ @PARAM_HASH['REB_AMOUNT'] = params[:reb_amount]
159
+ # @api = "bp10emu"
162
160
  end
163
161
 
164
162
  # Set fields to do an update on an existing rebilling cycle
165
- def update_rebilling_cycle(rebill_id, rebill_next_date, rebill_expr, rebill_cycles, rebill_amount,
166
- rebill_next_amount)
163
+ def update_rebill(params = {})
167
164
  @PARAM_HASH['TRANS_TYPE'] = "SET"
168
- @PARAM_HASH['REBILL_ID'] = rebill_id
169
- @PARAM_HASH['NEXT_DATE'] = rebill_next_date
170
- @PARAM_HASH['REB_EXPR'] = rebill_expr
171
- @PARAM_HASH['REB_CYCLES'] = rebill_cycles
172
- @PARAM_HASH['REB_AMOUNT'] = rebill_amount
173
- @PARAM_HASH['NEXT_AMOUNT'] = rebill_next_amount
165
+ @PARAM_HASH['REBILL_ID'] = params[:rebill_id]
166
+ @PARAM_HASH['NEXT_DATE'] = params[:next_date] || ''
167
+ @PARAM_HASH['REB_EXPR'] = params[:reb_expr] || ''
168
+ @PARAM_HASH['REB_CYCLES'] = params[:reb_cycles] || ''
169
+ @PARAM_HASH['REB_AMOUNT'] = params[:reb_amount] || ''
170
+ @PARAM_HASH['NEXT_AMOUNT'] = params[:next_amount] || ''
171
+ @PARAM_HASH["TEMPLATE_ID"] = params[:template_id] || ''
172
+ @api = "bp20rebadmin"
174
173
  end
175
174
 
176
175
  # Set fields to cancel an existing rebilling cycle
@@ -178,12 +177,14 @@ class BluePay
178
177
  @PARAM_HASH["TRANS_TYPE"] = "SET"
179
178
  @PARAM_HASH["STATUS"] = "stopped"
180
179
  @PARAM_HASH["REBILL_ID"] = rebill_id
180
+ @api = "bp20rebadmin"
181
181
  end
182
182
 
183
183
  # Set fields to get the status of an existing rebilling cycle
184
184
  def get_rebilling_cycle_status(rebill_id)
185
185
  @PARAM_HASH["TRANS_TYPE"] = "GET"
186
186
  @PARAM_HASH["REBILL_ID"] = rebill_id
187
+ @api = "bp20rebadmin"
187
188
  end
188
189
 
189
190
  # Updates an existing rebilling cycle's payment information.
@@ -192,35 +193,34 @@ class BluePay
192
193
  end
193
194
 
194
195
  # Gets a report on all transactions within a specified date range
195
- def get_transaction_report(report_start, report_end, subaccounts_searched, do_not_escape = '', errors = '')
196
+ def get_transaction_report(params = {})
196
197
  @PARAM_HASH["QUERY_BY_SETTLEMENT"] = '0'
197
- @PARAM_HASH["REPORT_START_DATE"] = report_start
198
- @PARAM_HASH["REPORT_END_DATE"] = report_end
199
- @PARAM_HASH["QUERY_BY_HIERARCHY"] = subaccounts_searched
200
- @PARAM_HASH["DO_NOT_ESCAPE"] = do_not_escape
201
- @PARAM_HASH["EXCLUDE_ERRORS"] = errors
198
+ @PARAM_HASH["REPORT_START_DATE"] = params[:report_start_date]
199
+ @PARAM_HASH["REPORT_END_DATE"] = params[:report_end_date]
200
+ @PARAM_HASH["QUERY_BY_HIERARCHY"] = params[:query_by_hierarchy]
201
+ @PARAM_HASH["DO_NOT_ESCAPE"] = params[:do_not_escape] || ''
202
+ @PARAM_HASH["EXCLUDE_ERRORS"] = params[:exclude_errors] || ''
203
+ @api = "bpdailyreport2"
202
204
  end
203
205
 
204
206
  # Gets a report on all settled transactions within a specified date range
205
- def get_settled_transaction_report(report_start, report_end, subaccounts_searched, do_not_escape = '', errors = '')
207
+ def get_settled_transaction_report(params = {})
206
208
  @PARAM_HASH["QUERY_BY_SETTLEMENT"] = '1'
207
- @PARAM_HASH["REPORT_START_DATE"] = report_start
208
- @PARAM_HASH["REPORT_END_DATE"] = report_end
209
- @PARAM_HASH["QUERY_BY_HIERARCHY"] = subaccounts_searched
210
- @PARAM_HASH["DO_NOT_ESCAPE"] = do_not_escape
211
- @PARAM_HASH["EXCLUDE_ERRORS"] = errors
209
+ @PARAM_HASH["REPORT_START_DATE"] = params[:report_start_date]
210
+ @PARAM_HASH["REPORT_END_DATE"] = params[:report_end_date]
211
+ @PARAM_HASH["QUERY_BY_HIERARCHY"] = params[:query_by_hierarchy]
212
+ @PARAM_HASH["DO_NOT_ESCAPE"] = params[:do_not_escape] || ''
213
+ @PARAM_HASH["EXCLUDE_ERRORS"] = params[:exclude_errors] || ''
214
+ @api = "bpdailyreport2"
212
215
  end
213
216
 
214
217
  # Gets data on a specific transaction
215
- def get_single_trans_query(report_start, report_end, errors = "")
216
- @PARAM_HASH["REPORT_START_DATE"] = report_start
217
- @PARAM_HASH["REPORT_END_DATE"] = report_end
218
- @PARAM_HASH["EXCLUDE_ERRORS"] = errors
219
- end
220
-
221
- # Queries by a specific Transaction ID. To be used with get_single_trans_query
222
- def query_by_transaction_id(trans_id)
223
- @PARAM_HASH["id"] = trans_id;
218
+ def get_single_transaction_query(params = {})
219
+ @PARAM_HASH["REPORT_START_DATE"] = params[:report_start_date]
220
+ @PARAM_HASH["REPORT_END_DATE"] = params[:report_end_date]
221
+ @PARAM_HASH["id"] = params[:transaction_id]
222
+ @PARAM_HASH["EXCLUDE_ERRORS"] = params[:exclude_errors] || ''
223
+ @api = "stq"
224
224
  end
225
225
 
226
226
  # Queries by a specific Payment Type. To be used with get_single_trans_query
@@ -247,242 +247,4 @@ class BluePay
247
247
  def query_by_name2(name2)
248
248
  @PARAM_HASH["name2"] = name2
249
249
  end
250
-
251
- # Turns a hash into a nvp style string
252
- def uri_query(h)
253
- a = Array.new()
254
- h.each_pair {|key, val| a.push(URI.escape(key) + "=" + URI.escape(val)) }
255
- return a.join("&")
256
- end
257
-
258
- # Sets TAMPER_PROOF_SEAL in @PARAM_HASH
259
- def calc_tps()
260
- @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(@SECRET_KEY + @ACCOUNT_ID +
261
- (@PARAM_HASH["TRANSACTION_TYPE"] || '') + @PARAM_HASH["AMOUNT"] + (@PARAM_HASH["REBILLING"] || '') +
262
- (@PARAM_HASH["REB_FIRST_DATE"] || '') + (@PARAM_HASH["REB_EXPR"] || '') + (@PARAM_HASH["REB_CYCLES"] || '') +
263
- (@PARAM_HASH["REB_AMOUNT"] || '') + (@PARAM_HASH["RRNO"] || '') + @PARAM_HASH["MODE"])
264
- end
265
-
266
- # Sets TAMPER_PROOF_SEAL in @PARAM_HASH for rebadmin API
267
- def calc_rebill_tps()
268
- @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(@SECRET_KEY + @ACCOUNT_ID +
269
- @PARAM_HASH["TRANS_TYPE"] + @PARAM_HASH["REBILL_ID"])
270
- end
271
-
272
- # Sets TAMPER_PROOF_SEAL in @PARAM_HASH for bpdailyreport2 API
273
- def calc_report_tps()
274
- @PARAM_HASH["TAMPER_PROOF_SEAL"] = Digest::MD5.hexdigest(@SECRET_KEY + @ACCOUNT_ID +
275
- @PARAM_HASH["REPORT_START_DATE"] + @PARAM_HASH["REPORT_END_DATE"])
276
- end
277
-
278
- # Calculates TAMPER_PROOF_SEAL to be used with Trans Notify API
279
- def self.calc_trans_notify_tps(secret_key, trans_id, trans_status, trans_type, amount, batch_id, batch_status,
280
- total_count, total_amount, batch_upload_id, rebill_id, rebill_amount, rebill_status)
281
- return Digest::MD5.hexdigest(@SECRET_KEY + trans_id + trans_status + transtype +
282
- amount + batch_id + batch_status + total_count + total_amount + batch_upload_id + rebill_id + rebill_amount + rebill_status)
283
- end
284
-
285
- # sends HTTPS POST to BluePay gateway for processing
286
- def process()
287
- ua = Net::HTTP.new(SERVER, 443)
288
- ua.use_ssl = true
289
- if File.directory? RootCA
290
- ua.ca_path = RootCA
291
- ua.verify_mode = OpenSSL::SSL::VERIFY_PEER
292
- ua.verify_depth = 3
293
- else
294
- puts "Invalid CA certificates directory. Exiting..."
295
- exit
296
- end
297
- begin
298
- @PARAM_HASH["REMOTE_IP"] = request.env['REMOTE_ADDR']
299
- rescue Exception
300
- end
301
- # Generate the query string and headers
302
- if (@PARAM_HASH.has_key?("QUERY_BY_HIERARCHY"))
303
- calc_report_tps()
304
- path = "/interfaces/bpdailyreport2"
305
- query = "ACCOUNT_ID=#{@ACCOUNT_ID}&"
306
- query += uri_query(@PARAM_HASH)
307
- elsif (@PARAM_HASH.has_key?("REPORT_START_DATE"))
308
- calc_report_tps()
309
- path = "/interfaces/stq"
310
- query = "ACCOUNT_ID=#{@ACCOUNT_ID}&"
311
- query += uri_query(@PARAM_HASH)
312
- elsif (@PARAM_HASH["TRANS_TYPE"] != "SET" and @PARAM_HASH["TRANS_TYPE"] != "GET")
313
- calc_tps()
314
- path = "/interfaces/bp10emu"
315
- query = "MERCHANT=#{@ACCOUNT_ID}&"
316
- query += uri_query(@PARAM_HASH)
317
- else
318
- calc_rebill_tps()
319
- path = "/interfaces/bp20rebadmin"
320
- query = "ACCOUNT_ID=#{@ACCOUNT_ID}&"
321
- query += uri_query(@PARAM_HASH)
322
- end
323
-
324
- queryheaders = {
325
- 'User-Agent' => 'Bluepay Ruby Client',
326
- 'Content-Type' => 'application/x-www-form-urlencoded'
327
- }
328
- @PARAM_HASH["VERSION"] = '3'
329
- # Post parameters to BluePay gateway
330
- headers, body = ua.post(path, query, queryheaders)
331
- # Split the response into the response hash.
332
- @RESPONSE_HASH = {}
333
- if path == "/interfaces/bp10emu"
334
- response = headers["Location"].split("?")[1]
335
- else
336
- response = headers.body
337
- end
338
- response.split("&").each { |pair|
339
- (key, val) = pair.split("=")
340
- val = "" if(val == nil)
341
- @RESPONSE_HASH[URI.unescape(key)] = URI.unescape(val)
342
- }
343
- end
344
-
345
- def get_response()
346
- return @RESPONSE_HASH
347
- end
348
-
349
- # Returns E for Error, 1 for Approved, 0 for Decline
350
- def get_status()
351
- return @RESPONSE_HASH['Result']
352
- end
353
-
354
- # Returns the human-readable response from Bluepay.
355
- # Or a nasty error.
356
- def get_message()
357
- m = @RESPONSE_HASH['MESSAGE']
358
- if (m == nil or m == "")
359
- return "ERROR - NO MESSAGE FROM BLUEPAY"
360
- end
361
- return m
362
- end
363
-
364
- # Returns the single-character AVS response from the
365
- # Card Issuing Bank
366
- def get_avs_code()
367
- return @RESPONSE_HASH['AVS']
368
- end
369
-
370
- # Same as avs_code, but for CVV2
371
-
372
- def get_cvv2_code()
373
- return @RESPONSE_HASH['CVV2']
374
- end
375
-
376
- # In the case of an approved transaction, contains the
377
- # 6-character authorization code from the processing network.
378
- # In the case of a decline or error, the contents may be junk.
379
- def get_auth_code()
380
- return @RESPONSE_HASH['AUTH_CODE']
381
- end
382
-
383
- # The all-important transaction ID.
384
- def get_trans_id()
385
- return @RESPONSE_HASH['RRNO']
386
- end
387
-
388
- # If you set up a rebilling, this'll get its ID.
389
- def get_rebill_id()
390
- return @RESPONSE_HASH['REBID']
391
- end
392
-
393
- # Masked credit card or ACH account
394
- def get_masked_account()
395
- return @RESPONSE_HASH['PAYMENT_ACCOUNT']
396
- end
397
-
398
- # Card type used in transaction
399
- def get_card_type()
400
- return @RESPONSE_HASH['CARD_TYPE']
401
- end
402
-
403
- # Bank account used in transaction
404
- def get_bank_name()
405
- return @RESPONSE_HASH['BANK_NAME']
406
- end
407
-
408
- # Rebill ID from bprebadmin API
409
- def get_reb_id()
410
- return @RESPONSE_HASH['rebill_id']
411
- end
412
-
413
- # Template ID of rebilling
414
- def get_template_id()
415
- return @RESPONSE_HASH['template_id']
416
- end
417
-
418
- # Status of rebilling
419
- def get_rebill_status()
420
- return @RESPONSE_HASH['status']
421
- end
422
-
423
- # Creation date of rebilling
424
- def get_creation_date()
425
- return @RESPONSE_HASH['creation_date']
426
- end
427
-
428
- # Next date that the rebilling is set to fire off on
429
- def get_next_date()
430
- return @RESPONSE_HASH['next_date']
431
- end
432
-
433
- # Last date that the rebilling fired off on
434
- def get_last_date()
435
- return @RESPONSE_HASH['last_date']
436
- end
437
-
438
- # Rebilling expression
439
- def get_sched_expression()
440
- return @RESPONSE_HASH['sched_expr']
441
- end
442
-
443
- # Number of cycles remaining on rebilling
444
- def get_cycles_remaining()
445
- return @RESPONSE_HASH['cycles_remain']
446
- end
447
-
448
- # Amount to charge when rebilling fires off
449
- def get_rebill_amount()
450
- return @RESPONSE_HASH['reb_amount']
451
- end
452
-
453
- # Next amount to charge when rebilling fires off
454
- def get_next_amount()
455
- return @RESPONSE_HASH['next_amount']
456
- end
457
-
458
- # Transaction ID used with stq API
459
- def get_id()
460
- return @RESPONSE_HASH['id']
461
- end
462
-
463
- # First name associated with the transaction
464
- def get_name1()
465
- return @RESPONSE_HASH['name1']
466
- end
467
-
468
- # Last name associated with the transaction
469
- def get_name2()
470
- return @RESPONSE_HASH['name2']
471
- end
472
-
473
- # Payment type associated with the transaction
474
- def get_payment_type()
475
- return @RESPONSE_HASH['payment_type']
476
- end
477
-
478
- # Transaction type associated with the transaction
479
- def get_trans_type()
480
- return @RESPONSE_HASH['trans_type']
481
- end
482
-
483
- # Amount associated with the transaction
484
- def get_amount()
485
- return @RESPONSE_HASH['amount']
486
- end
487
-
488
250
  end