bluepay 1.0.1

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 (5) hide show
  1. data/README +28 -0
  2. data/Rakefile +89 -0
  3. data/lib/Bluepay.rb +206 -0
  4. data/test/bp20post_test.rb +12 -0
  5. metadata +49 -0
data/README ADDED
@@ -0,0 +1,28 @@
1
+ == Welcome to Bluepay
2
+
3
+ Bluepay is used to process credit cards and ach transactions using the BluePay 2.0 Gateway.
4
+
5
+ BluePay, Inc. is a merchant account provider and payment gateway. The BluePay 2.0 Gateway processes credit card and
6
+ ACH transactions through a virtual terminal and various API/SDK/Payment Interfaces.
7
+
8
+ To apply for a BluePay merchant account and payment gateway, visit http://www.bluepay.com.
9
+
10
+ == Example
11
+
12
+ require "Bluepay"
13
+
14
+ tob = Bluepay.new("123123123123", "ABCDabcdABCDabcdABCDabcdABCDabcd")
15
+ tob.easy_sale("1.00")
16
+ tob.use_card("4111111111111111", "1109", "123")
17
+ tob.process()
18
+ puts "Status: " + tob.get_status()
19
+ puts "Message: " + tob.get_message()
20
+ puts "Transaction ID: " + tob.get_trans_id()
21
+
22
+ == About
23
+
24
+ Author:: Chris Jansen
25
+ ReadmeDoc:: Christopher Kois
26
+ Copyright:: Copyright (c) 2008 BluePay, Inc.
27
+ License:: GPL - GNU General Public License - http://www.gnu.org/licenses/gpl.html
28
+
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/contrib/rubyforgepublisher'
7
+
8
+ PKG_VERSION = "1.0.1"
9
+
10
+ PKG_FILES = FileList[
11
+ "lib/**/*", "bin/*", "test/**/*", "[A-Z]*", "Rakefile", "doc/**/*"
12
+ ]
13
+
14
+ desc "Default Task"
15
+ task :default => [ :test ]
16
+
17
+ # Run the unit tests
18
+ desc "Run all unit tests"
19
+ Rake::TestTask.new("test") { |t|
20
+ t.libs << "lib"
21
+ t.pattern = 'test/*/*_test.rb'
22
+ t.verbose = true
23
+ }
24
+
25
+ # Make a console, useful when working on tests
26
+ desc "Generate a test console"
27
+ task :console do
28
+ verbose( false ) { sh "irb -I lib/ -r 'bluepay'" }
29
+ end
30
+
31
+ # Genereate the RDoc documentation
32
+ desc "Create documentation"
33
+ Rake::RDocTask.new("doc") { |rdoc|
34
+ rdoc.title = "Ruby Merchant Bluepay"
35
+ rdoc.rdoc_dir = 'doc'
36
+ rdoc.rdoc_files.include('README')
37
+ rdoc.rdoc_files.include('lib/*.rb')
38
+ }
39
+
40
+ # Genereate the package
41
+ spec = Gem::Specification.new do |s|
42
+
43
+ #### Basic information.
44
+
45
+ s.name = 'bluepay'
46
+ s.version = PKG_VERSION
47
+ s.summary = <<-EOF
48
+ Bluepay is used to process credit card and ach transactions through the BluePay 2.0 Gateway.
49
+ EOF
50
+ s.description = <<-EOF
51
+ This package allows a user to run credit card and ach transactions through the BluePay 2.0
52
+ Gateway. BluePay is a merchant account provider and payment gateway. BluePay, Inc. is a
53
+ one-stop shop merchant services provider. For more information, visit: http://www.bluepay.com
54
+ EOF
55
+
56
+ #### Which files are to be included in this gem? Everything! (Except SVN directories.)
57
+
58
+ s.files = PKG_FILES
59
+
60
+ #### Load-time details: library and application (you will need one or both).
61
+
62
+ s.require_path = 'lib'
63
+ s.autorequire = 'bluepay'
64
+
65
+ #### Documentation and testing.
66
+
67
+ s.has_rdoc = true
68
+
69
+ #### Author and project details.
70
+
71
+ s.author = "Chris Jansen"
72
+ s.email = "cjansen@bluepay.com"
73
+ s.homepage = "http://www.bluepay.com/"
74
+ end
75
+
76
+ Rake::GemPackageTask.new(spec) do |pkg|
77
+ pkg.need_zip = true
78
+ pkg.need_tar = true
79
+ end
80
+
81
+ desc "Report code statistics (KLOCs, etc) from the application"
82
+ task :stats do
83
+ require 'code_statistics'
84
+ CodeStatistics.new(
85
+ ["Library", "lib"],
86
+ ["Units", "test"]
87
+ ).to_s
88
+ end
89
+
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/ruby
2
+ #--
3
+ # Copyright (c) 2008 BluePay, Inc.
4
+ # Author: Chris Jansen
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #++
25
+ #
26
+ # See Bluepay documentation.
27
+
28
+ require "net/http"
29
+ require "net/https"
30
+ require "uri"
31
+ require "md5"
32
+
33
+
34
+
35
+ class Bluepay
36
+
37
+ @@SERVER = "secure.bluepay.com"
38
+ @@PATH = "/interfaces/bp20post"
39
+
40
+ def initialize(account,key,mode='TEST')
41
+ @ACCOUNT_ID = account
42
+ @SECRET_KEY = key
43
+ @PARAM_HASH = { 'MODE' => mode }
44
+ @RETURN_HASH = Hash.new()
45
+ end
46
+
47
+ # used to set all other parameters... there's a lot of them.
48
+ # See Bluepay20post.txt
49
+ def set_param(key, val)
50
+ @PARAM_HASH[key] = val
51
+ end
52
+
53
+ # Set up an ACH transaction. Expects:
54
+ # acc_type: C for Checking, S for Savings
55
+ # routing: Bank routing number
56
+ # account: Customer's checking or savings account number
57
+ # doc_type: WEB, TEL, ARC, etc -- see docs. Optional.
58
+ # REMEMBER: Ach requires some other fields,
59
+ # such as address and phone
60
+ def use_check(acc_type, routing, account, doc_type)
61
+ @PARAM_HASH['PAYMENT_ACCOUNT'] = "#{acc_type}:#{routing}:#{account}"
62
+ @PARAM_HASH['DOC_TYPE'] = doc_type
63
+ @PARAM_HASH['PAYMENT_TYPE'] = "ACH"
64
+ end
65
+
66
+ # Set up a credit card payment.
67
+ def use_card(account, expire, cvv)
68
+ @PARAM_HASH['PAYMENT_ACCOUNT'] = account
69
+ @PARAM_HASH['CARD_EXPIRE'] = expire
70
+ @PARAM_HASH['CARD_CVV2'] = cvv
71
+ end
72
+
73
+ # Set up a sale
74
+ def easy_sale(amount)
75
+ @PARAM_HASH['TRANS_TYPE'] = 'SALE'
76
+ @PARAM_HASH['AMOUNT'] = amount
77
+ end
78
+
79
+ # Set up an Auth-only
80
+ def easy_auth(amount)
81
+ @PARAM_HASH['TRANS_TYPE'] = 'AUTH'
82
+ @PARAM_HASH['AMOUNT'] = amount
83
+ end
84
+
85
+ # Capture an auth
86
+ def easy_capture(trans_id)
87
+ @PARAM_HASH['TRANS_TYPE'] = 'CAPTURE'
88
+ @PARAM_HASH['MASTER_ID'] = trans_id
89
+ end
90
+
91
+ # Refund
92
+ def easy_refund(trans_id)
93
+ @PARAM_HASH['TRANS_TYPE'] = 'REFUND'
94
+ @PARAM_HASH['MASTER_ID'] = trans_id
95
+ end
96
+
97
+ # This is the important stuff to get
98
+ # the best rates on CC transactions.
99
+ def customer_data(name1, name2, addr1, city, state, zip)
100
+ @PARAM_HASH['NAME1'] = name1
101
+ @PARAM_HASH['NAME2'] = name2
102
+ @PARAM_HASH['ADDR1'] = addr1
103
+ @PARAM_HASH['CITY'] = city
104
+ @PARAM_HASH['STATE'] = state
105
+ @PARAM_HASH['ZIP'] = zip
106
+ end
107
+
108
+ # Turns a hash into a foo=bar&baz=bat style string
109
+ def uri_query(h)
110
+ a = Array.new()
111
+ h.each_pair {|key, val| a.push(URI.escape(key) + "=" + URI.escape(val)) }
112
+ return a.join("&")
113
+ end
114
+
115
+ # Sets TAMPER_PROOF_SEAL in @PARAM_HASH
116
+ def calc_tps()
117
+ # Take the cheap way out. I wrote bp20post and I hereby publically
118
+ # state the TPS in bp20post is stupid.
119
+ @PARAM_HASH["TPS_DEF"] = "HELLO_MOTHER"
120
+ @PARAM_HASH["TAMPER_PROOF_SEAL"] = MD5.new(@SECRET_KEY).hexdigest
121
+ end
122
+
123
+ # Run a transaction - you must have called appropriate functions
124
+ # to set the transaction type, etc before calling this.
125
+ def process()
126
+ ua = Net::HTTP.new(@@SERVER, 443)
127
+ ua.use_ssl = true
128
+
129
+ # Generate the query string and headers
130
+ calc_tps()
131
+ query = "ACCOUNT_ID=#{@ACCOUNT_ID}&"
132
+ query += uri_query(@PARAM_HASH)
133
+
134
+ queryheaders = {
135
+ 'User-Agent' => 'Bluepay Ruby Client',
136
+ 'Content-Type' => 'application/x-www-form-urlencoded'
137
+ }
138
+
139
+ # Make Bluepay do Super CreditCard Magic
140
+ headers, body = ua.post(@@PATH, query, queryheaders)
141
+
142
+ # Split the response into the response hash.
143
+ # Also, we stuff in RESPONSE_CODE expected to be 200 or 400...
144
+ @RESPONSE_HASH = { "RESPONSE_CODE" => headers.code }
145
+ body.split("&").each { |pair|
146
+ (key, val) = pair.split("=")
147
+ val = "" if(val == nil)
148
+ @RESPONSE_HASH[URI.unescape(key)] = URI.unescape(val)
149
+ }
150
+ end
151
+
152
+ # Returns ! on WTF, E for Error, 1 for Approved, 0 for Decline
153
+ def get_status()
154
+ return 'E' if(@RESPONSE_HASH['RESPONSE_CODE'] == 400)
155
+ return '1' if(@RESPONSE_HASH['STATUS'] == '1');
156
+ return '0' if(@RESPONSE_HASH['STATUS'] == '0');
157
+ return 'E' if(@RESPONSE_HASH['STATUS'] == 'E');
158
+ return '!'
159
+ end
160
+
161
+ # Returns the human-readable response from Bluepay.
162
+ # Or a nasty error.
163
+ def get_message()
164
+ m = @RESPONSE_HASH['MESSAGE']
165
+ if (m == nil or m == "")
166
+ return "ERROR - NO MESSAGE FROM BLUEPAY"
167
+ end
168
+ return m
169
+ end
170
+
171
+ # Returns the single-character AVS response from the
172
+ # Card Issuing Bank
173
+ def get_avs_code()
174
+ return @RESPONSE_HASH['AVS']
175
+ end
176
+
177
+ # Same as avs_code, but for CVV2
178
+ def get_cvv2_code()
179
+ return @RESPONSE_HASH['CVV2']
180
+ end
181
+
182
+ # In the case of an approved transaction, contains the
183
+ # 6-character authorization code from the processing network.
184
+ # In the case of a decline or error, the contents may be junk.
185
+ def get_auth_code()
186
+ return @RESPONSE_HASH['AUTH_CODE']
187
+ end
188
+
189
+ # The all-important transaction ID.
190
+ def get_trans_id()
191
+ return @RESPONSE_HASH['TRANS_ID']
192
+ end
193
+
194
+ # If you set up a rebilling, this'll get it's ID.
195
+ def get_rebill_id()
196
+ return @RESPONSE_HASH['REBID']
197
+ end
198
+
199
+ end
200
+
201
+
202
+
203
+
204
+
205
+
206
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "Bluepay"
4
+
5
+ tob = Bluepay.new("123123123123", "ABCDabcdABCDabcdABCDabcdABCDabcd")
6
+ tob.easy_sale("1.00")
7
+ tob.use_card("4111111111111111", "1109", "123")
8
+ tob.process()
9
+ puts "Status: " + tob.get_status()
10
+ puts "Message: " + tob.get_message()
11
+ puts "Transaction ID: " + tob.get_trans_id()
12
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: bluepay
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.1
7
+ date: 2008-05-23 00:00:00 -05:00
8
+ summary: Bluepay is used to process credit card and ach transactions through the BluePay 2.0 Gateway.
9
+ require_paths:
10
+ - lib
11
+ email: cjansen@bluepay.com
12
+ homepage: http://www.bluepay.com/
13
+ rubyforge_project:
14
+ description: "This package allows a user to run credit card and ach transactions through the BluePay 2.0 Gateway. BluePay is a merchant account provider and payment gateway. BluePay, Inc. is a one-stop shop merchant services provider. For more information, visit: http://www.bluepay.com"
15
+ autorequire: bluepay
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Chris Jansen
31
+ files:
32
+ - lib/Bluepay.rb
33
+ - test/bp20post_test.rb
34
+ - README
35
+ - Rakefile
36
+ test_files: []
37
+
38
+ rdoc_options: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ requirements: []
47
+
48
+ dependencies: []
49
+