trustcommerce 0.5.0 → 0.5.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.
- data/README +0 -1
- data/lib/trustcommerce.rb +21 -2
- data/lib/version.rb +1 -1
- data/test/trustcommerce_test.rb +7 -2
- metadata +2 -2
data/README
CHANGED
data/lib/trustcommerce.rb
CHANGED
@@ -155,6 +155,25 @@ class TrustCommerce
|
|
155
155
|
|
156
156
|
end
|
157
157
|
|
158
|
+
class Result < Hash
|
159
|
+
|
160
|
+
def initialize(constructor = {})
|
161
|
+
if constructor.is_a?(Hash)
|
162
|
+
super()
|
163
|
+
update(constructor)
|
164
|
+
else
|
165
|
+
super(constructor)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
%w(approved accepted declined baddata error).each do |status|
|
170
|
+
define_method("#{status}?") do
|
171
|
+
self[:status] == status
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
158
177
|
# It is highly recommended to download and install the
|
159
178
|
# [TCLink ruby extension](http://www.trustcommerce.com/tclink.php).
|
160
179
|
# This extension provides failover capability and enhanced security features.
|
@@ -184,13 +203,13 @@ class TrustCommerce
|
|
184
203
|
options.update(:demo => 'y') if ENV['RAILS_ENV'] != 'production'
|
185
204
|
parameters = stringify_hash(options)
|
186
205
|
if tclink? # use TCLink extension if installed
|
187
|
-
return symbolize_hash(TCLink.send(parameters))
|
206
|
+
return Result.new(symbolize_hash(TCLink.send(parameters)))
|
188
207
|
else # TCLink library not installed - use https post
|
189
208
|
parameters[:password] = self.vault_password.to_s
|
190
209
|
response = send_https_request(API_SETTINGS[:trans_path], parameters)
|
191
210
|
|
192
211
|
# parse response
|
193
|
-
results =
|
212
|
+
results = Result.new
|
194
213
|
response.body.split("\n").each do |line|
|
195
214
|
k, v = line.split('=')
|
196
215
|
results[k.to_sym] = v
|
data/lib/version.rb
CHANGED
data/test/trustcommerce_test.rb
CHANGED
@@ -40,10 +40,11 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
40
40
|
:cycle => '1m',
|
41
41
|
:demo => 'y'
|
42
42
|
)
|
43
|
-
assert_equal
|
43
|
+
assert_equal TrustCommerce::Result, response.class
|
44
44
|
assert_not_nil response[:billingid]
|
45
45
|
assert response.keys.include?(:transid)
|
46
46
|
assert_equal 'approved', response[:status]
|
47
|
+
assert response.approved?
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -59,6 +60,7 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
59
60
|
:avs => 'y'
|
60
61
|
)
|
61
62
|
assert_equal 'accepted', response[:status]
|
63
|
+
assert response.accepted?
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -70,6 +72,7 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
70
72
|
)
|
71
73
|
assert response.keys.include?(:transid)
|
72
74
|
assert_equal 'accepted', response[:status]
|
75
|
+
assert response.accepted?
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
@@ -85,6 +88,7 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
85
88
|
)
|
86
89
|
assert charge_response.keys.include?(:transid)
|
87
90
|
assert_equal 'approved', charge_response[:status]
|
91
|
+
assert charge_response.approved?
|
88
92
|
|
89
93
|
# credit
|
90
94
|
credit_response = TrustCommerce::Subscription.credit(
|
@@ -94,6 +98,7 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
94
98
|
)
|
95
99
|
assert credit_response.keys.include?(:transid)
|
96
100
|
assert_equal 'accepted', credit_response[:status]
|
101
|
+
assert credit_response.accepted?
|
97
102
|
end
|
98
103
|
end
|
99
104
|
|
@@ -143,7 +148,7 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
|
|
143
148
|
def test_symbolize_hash
|
144
149
|
assert_equal ({ :a => '1', :b => '2' }), TrustCommerce.symbolize_hash('a' => '1', 'b' => '2')
|
145
150
|
assert_equal ({ :a => '1', :b => '2' }), TrustCommerce.symbolize_hash(:a => 1, 'b' => 2)
|
146
|
-
assert_equal
|
151
|
+
assert_equal 1, TrustCommerce.symbolize_hash(:a => 1, 'a' => 2).size
|
147
152
|
end
|
148
153
|
|
149
154
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: trustcommerce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.5.1
|
7
|
+
date: 2007-04-27 00:00:00 -07:00
|
8
8
|
summary: TrustCommerce Subscription Library
|
9
9
|
require_paths:
|
10
10
|
- lib
|