prismpay 0.0.0

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.
@@ -0,0 +1,50 @@
1
+ require 'activemerchant'
2
+ require 'prismpay'
3
+
4
+ module ActiveMerchant
5
+ module Billing
6
+
7
+ class PrismPayAM < Gateway
8
+ # gateway setup
9
+ self.supported_countries = ['US']
10
+ self.default_currency = 'USD'
11
+ self.supported_cardtypes = [:visa, :master, :american_express,
12
+ :discover, :diners_club, :jcb]
13
+
14
+ # need to support test probably
15
+
16
+ # init
17
+ def initialize(options = { })
18
+ requires!(options, :login)
19
+ @options = options
20
+ @gateway = PrismPay.new(options)
21
+ super
22
+ end
23
+
24
+
25
+ # Transactions
26
+ def purchase(money, creditcard, options = { })
27
+ result = @gateway.cc_purchase(money, creditcard, options)
28
+ result.active_merchant_response
29
+ end
30
+
31
+ def authorize(money, creditcard, options ={ })
32
+ result = @gateway.cc_authorize(money, creditcard, options)
33
+ result.active_merchant_response
34
+ end
35
+
36
+ def capture(money, identification, options = {})
37
+ result = @gateway.cc_capture(money, identification, options)
38
+ end
39
+
40
+ def void(identification, options = {})
41
+ result = @gateway.cc_void(identification, options)
42
+ end
43
+
44
+ def refund(money,identification, options ={ })
45
+ result = @gateway.credit(money, identification, options)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ require "prismpay"
2
+
3
+ describe PrismCreditResponse, "" do
4
+ end
@@ -0,0 +1,4 @@
1
+ require "prismpay"
2
+
3
+ describe PrismPayResponse, "" do
4
+ end
@@ -0,0 +1,2 @@
1
+ require "prismpay"
2
+
@@ -0,0 +1,345 @@
1
+ require 'prismpay'
2
+ require 'builder'
3
+
4
+ ########################################
5
+ # Helper Functions
6
+ ########################################
7
+
8
+ def save_auth_trans(orderid, historyid, amount)
9
+ # mechanism for saving hist id for testing auth/capture
10
+ File.open("./data~", "at") {|f|
11
+ f.puts "#{orderid}:#{historyid}:#{amount}"
12
+ }
13
+ end
14
+
15
+ def save_void_trans(orderid, historyid, amount)
16
+ # mechanism for saving hist id for testing auth/capture
17
+ File.open("./void~", "at") {|f|
18
+ f.puts "#{orderid}:#{historyid}:#{amount}"
19
+ }
20
+ end
21
+
22
+ def save_refund_trans(orderid, historyid, amount)
23
+ # mechanism for saving hist id for testing auth/capture
24
+ File.open("./credit~", "at") {|f|
25
+ f.puts "#{orderid}:#{historyid}:#{amount}"
26
+ }
27
+ end
28
+
29
+ def get_last_trans(file)
30
+ # gets the values of the last auth transaction needed for void or refund
31
+ ret = {}
32
+ File.open(file, "rt"){|f|
33
+ str = f.gets
34
+ str.chomp!
35
+ ret[:order_id], ret[:historyid], ret[:amount] = str.split ":"
36
+ }
37
+ ret
38
+ end
39
+
40
+ def processed_trans(line, file)
41
+ # loads histid numbers of auth transactions into an array
42
+ # removes the captured transaction and then rewrites the file
43
+ arr = []
44
+ File.open(file, "rt") {|f|
45
+ arr = f.readlines
46
+ }
47
+ arr = arr - [line]
48
+ File.open(file, "wt") { |f|
49
+ f.puts(arr)
50
+ }
51
+ end
52
+
53
+ def builder_wrapper()
54
+ # this should wrap the proc object the same way the
55
+ # savon.request call would.
56
+ bld = Builder::XmlMarkup.new
57
+ yield (bld)
58
+ return bld.target!
59
+ end
60
+
61
+ ############################################################
62
+ # Start Tests
63
+ ############################################################
64
+
65
+ describe PrismPay, "#cc_purchase" do
66
+ it "returns successful sale for sane values" do
67
+ amount = "10.00"
68
+ cc = CreditCard.new({})
69
+ cc.number = 5454545454545454
70
+ cc.month = 7
71
+ cc.year = 14
72
+ cc.name = "JohnDoe Soap"
73
+ cc.verification_value = 123
74
+ cc.type = "Visa"
75
+
76
+ addr2 = {
77
+ :name => "Fathead Don",
78
+ :address1 => "1501 S Delany Ave",
79
+ :city => "Orlando",
80
+ :state => "FL",
81
+ :zip => "32806",
82
+ :country => "US"
83
+ }
84
+
85
+ options = {
86
+ :login => "TEST0",
87
+ :order_id => Time.now.strftime("%y%m%d%H%M%S"),
88
+ :address => addr2
89
+ }
90
+
91
+ gateway = PrismPay.new(options)
92
+
93
+ purchase_amount = "23.32"
94
+
95
+ response = gateway.cc_purchase(purchase_amount, cc, options)
96
+
97
+ save_void_trans(response.body[:multi_ref][:orderid],
98
+ response.body[:multi_ref][:historyid],
99
+ purchase_amount)
100
+
101
+ response.body[:multi_ref][:status].should =~ (/Approved/)
102
+ end
103
+ end
104
+
105
+ describe PrismPay, "#cc_authorize" do
106
+ it "returns successful auth for sane values and saves orderid" do
107
+ amount = "10.00"
108
+ cc = CreditCard.new({})
109
+ cc.number = 5454545454545454
110
+ cc.month = 7
111
+ cc.year = 14
112
+ cc.name = "JohnDoe Soap"
113
+ cc.verification_value = 123
114
+ cc.type = "Visa"
115
+
116
+ addr2 = {
117
+ :name => "Fathead Don",
118
+ :address1 => "1501 S Delany Ave",
119
+ :city => "Orlando",
120
+ :state => "FL",
121
+ :zip => "32806",
122
+ :country => "US"
123
+ }
124
+
125
+ options = {
126
+ :login => "TEST0",
127
+ :order_id => Time.now.strftime("%y%m%d%H%M%S"),
128
+ :address => addr2
129
+ }
130
+
131
+ gateway = PrismPay.new(options)
132
+
133
+ purchase_amount = "23.32"
134
+
135
+ response = gateway.cc_authorize(purchase_amount, cc, options)
136
+
137
+ save_auth_trans(response.body[:multi_ref][:orderid],
138
+ response.body[:multi_ref][:historyid],
139
+ purchase_amount)
140
+
141
+ response.body[:multi_ref][:status].should =~ (/Approved/)
142
+ end
143
+ end
144
+
145
+
146
+ describe PrismPay, "#build_address" do
147
+ addr1 = {
148
+ :name => "testee mcgee",
149
+ :company => "widgets R us",
150
+ :address1 => "1 s orange ave",
151
+ :address2 => "st: 406",
152
+ :city => "Orlando",
153
+ :state => "FL",
154
+ :zip => "32801",
155
+ :country => "US"
156
+ }
157
+
158
+ addr2 = {
159
+ :name => "Fathead Don",
160
+ :address1 => "1501 S Delany Ave",
161
+ :city => "Orlando",
162
+ :state => "FL",
163
+ :zip => "32806",
164
+ :country => "US"
165
+ }
166
+
167
+ gw = PrismPay.new(addr1)
168
+
169
+ it "should return string" do
170
+ gw.build_address(addr1).class.should eq(String)
171
+ end
172
+
173
+ it "should return bill block for bad type" do
174
+ gw.build_address(addr1).should =~ /billaddress/
175
+ gw.build_address(addr1, {}).should =~ /billaddress/
176
+ gw.build_address(addr1, "junk").should =~ /billaddress/
177
+ end
178
+
179
+ it "should return ship string for ship type" do
180
+ gw.build_address(addr1, "ship").should =~ /shipaddress/
181
+ end
182
+
183
+ end
184
+
185
+ describe PrismPay, "#build_cc_sale_auth" do
186
+ amount = "10.00"
187
+ cc = CreditCard.new({})
188
+ cc.number = 5454545454545454
189
+ cc.month = 7
190
+ cc.year = 14
191
+ cc.name = "JohnDoe Soap"
192
+ cc.verification_value = 123
193
+ cc.type = "Visa"
194
+
195
+ addr2 = {
196
+ :name => "Fathead Don",
197
+ :address1 => "1501 S Delany Ave",
198
+ :city => "Orlando",
199
+ :state => "FL",
200
+ :zip => "32806",
201
+ :country => "US"
202
+ }
203
+
204
+ options = {
205
+ :login => "TEST0",
206
+ :order_id => Time.now.strftime("%y%m%d%H%M%S"),
207
+ :address => addr2
208
+ }
209
+
210
+
211
+ it "should return xml builder block for sale/auth" do
212
+ gw = PrismPay.new(options)
213
+ gw.build_cc_sale_auth(amount, cc, options).class.should eq(Proc)
214
+ end
215
+
216
+ it "should take 1 arg" do
217
+ gw = PrismPay.new(options)
218
+ myproc = gw.build_cc_sale_auth(amount, cc, options)
219
+ myproc.arity.should > 0
220
+ end
221
+
222
+ it "should create xml object when passed to builder" do
223
+ gw = PrismPay.new(options)
224
+ myproc = gw.build_cc_sale_auth(amount, cc, options)
225
+ str = builder_wrapper(&myproc)
226
+ str.should =~ /^<ccinfo[^&]*<\/ccinfo>$/ #match the object
227
+ end
228
+
229
+ end
230
+
231
+ describe PrismPay, "build_cc_void" do
232
+ it "should return xml builder block for void" do
233
+ gw = PrismPay.new({})
234
+ gw.build_cc_void("", {}).class.should eq(Proc)
235
+ end
236
+
237
+ end
238
+
239
+ describe PrismPay, "build_cc_capture" do
240
+ it "should return xml builder block for capture" do
241
+ gw = PrismPay.new({})
242
+ gw.build_cc_capture("", "", {}).class.should eq(Proc)
243
+ end
244
+ end
245
+
246
+ describe PrismPay, "build_credit" do
247
+ it "should return xml builder block for refund" do
248
+ gw = PrismPay.new({})
249
+ gw.build_credit("", "", {}).class.should eq(Proc)
250
+ end
251
+ end
252
+
253
+ describe PrismPay, "cc_capture" do
254
+ it "should capture an auth successfully with sane values" do
255
+ options = { }
256
+ values = get_last_trans("./data~")
257
+ options[:login] = "TEST0"
258
+ options[:orderid] = values[:order_id]
259
+ authcode = values[:historyid]
260
+ amount = values[:amount]
261
+
262
+ gw = PrismPay.new(options)
263
+
264
+ response = gw.cc_capture(amount, authcode, options)
265
+
266
+ response.body[:multi_ref][:status].should =~ /Approved/
267
+
268
+ if response.body[:multi_ref][:status] =~ /Approved/
269
+ processed_trans "#{options[:orderid]}:#{authcode}:#{amount}\n", "./data~"
270
+ end
271
+ end
272
+ end
273
+
274
+ describe PrismPay, "cc_void" do
275
+ it "should void a sale" do
276
+ options = { }
277
+ values = get_last_trans("./void~")
278
+ options[:login] = "TEST0"
279
+ options[:orderid] = values[:order_id]
280
+ authcode = values[:historyid]
281
+ options[:amount] = values[:amount]
282
+ amount = options[:amount]
283
+
284
+ gw = PrismPay.new(options)
285
+
286
+ response = gw.cc_void(authcode, options)
287
+
288
+ response.body[:multi_ref][:status].should =~ /Approved/
289
+
290
+ if response.body[:multi_ref][:status] =~ /Approved/
291
+ processed_trans "#{options[:orderid]}:#{authcode}:#{amount}\n", "./void~"
292
+ end
293
+ end
294
+ end
295
+
296
+ describe PrismPay, "credit" do
297
+ it "should refund a sale" do
298
+
299
+ amount = "10.00"
300
+ cc = CreditCard.new({})
301
+ cc.number = 5454545454545454
302
+ cc.month = 7
303
+ cc.year = 14
304
+ cc.name = "JohnDoe Soap"
305
+ cc.verification_value = 123
306
+ cc.type = "Visa"
307
+
308
+ addr2 = {
309
+ :name => "Fathead Don",
310
+ :address1 => "1501 S Delany Ave",
311
+ :city => "Orlando",
312
+ :state => "FL",
313
+ :zip => "32806",
314
+ :country => "US"
315
+ }
316
+
317
+ options = {
318
+ :login => "TEST0",
319
+ :order_id => Time.now.strftime("%y%m%d%H%M%S"),
320
+ :address => addr2
321
+ }
322
+
323
+ gateway = PrismPay.new(options)
324
+
325
+ response = gateway.cc_purchase(amount, cc, options)
326
+
327
+ save_refund_trans(response.body[:multi_ref][:orderid],
328
+ response.body[:multi_ref][:historyid],
329
+ amount)
330
+
331
+
332
+ values = get_last_trans("./credit~")
333
+ authcode = values[:historyid]
334
+
335
+ options[:orderid] = oid = values[:order_id]
336
+ response = gateway.credit(values[:amount], authcode, options)
337
+
338
+ response.body[:multi_ref][:status].should =~ /Approved/
339
+
340
+ if response.body[:multi_ref][:status] =~ /Approved/
341
+ processed_trans "#{oid}:#{authcode}:#{amount}\n", "./credit~"
342
+ end
343
+ end
344
+ end
345
+
@@ -0,0 +1,2 @@
1
+ require 'prismpay'
2
+
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prismpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Nash
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemerchant
16
+ requirement: &76803120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.20.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *76803120
25
+ - !ruby/object:Gem::Dependency
26
+ name: savon
27
+ requirement: &76802830 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.9
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *76802830
36
+ description:
37
+ email: rnash@tnsolutions.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/prismpay.rb
43
+ - lib/prism_credit_response.rb
44
+ - lib/TransactionService.xml
45
+ - lib/prismpay_am.rb
46
+ - README.md
47
+ - spec/prismpay_spec.rb
48
+ - spec/prismpay_response_spec.rb~
49
+ - spec/prism_credit_response_spec.rb
50
+ - spec/prism_credit_response_spec.rb~
51
+ - spec/prismpay_spec.rb~
52
+ homepage:
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.17
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Provide an interface to the Prismpay Gateway
76
+ test_files:
77
+ - spec/prismpay_spec.rb
78
+ - spec/prismpay_response_spec.rb~
79
+ - spec/prism_credit_response_spec.rb
80
+ - spec/prism_credit_response_spec.rb~
81
+ - spec/prismpay_spec.rb~