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 CHANGED
@@ -1,4 +1,3 @@
1
- = TrustCommerce Subscription Library
2
1
 
3
2
  [TrustCommerce](http://www.trustcommerce.com) is a payment gateway providing credit card
4
3
  processing and recurring / subscription billing services.
@@ -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
@@ -2,7 +2,7 @@ class TrustCommerce
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = '0'
4
4
  MINOR = '5'
5
- TINY = '0'
5
+ TINY = '1'
6
6
  end
7
7
 
8
8
  Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY].compact * '.'
@@ -40,10 +40,11 @@ class TrustCommerceSubscriptionTest < Test::Unit::TestCase
40
40
  :cycle => '1m',
41
41
  :demo => 'y'
42
42
  )
43
- assert_equal Hash, response.class
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 ({ :a => '1' }), TrustCommerce.symbolize_hash(:a => 1, 'a' => 2)
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.0
7
- date: 2007-02-28 00:00:00 -08:00
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