vindicia 0.2.2 → 0.2.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 (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/vindicia.rb +13 -4
  3. data/spec/vindicia_spec.rb +48 -0
  4. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.4
data/lib/vindicia.rb CHANGED
@@ -2,9 +2,6 @@ require 'savon'
2
2
  require 'savon_patches'
3
3
 
4
4
  Savon.configure do |config|
5
- config.log = false # disable logging
6
- #config.log_level = :info # changing the log level
7
- #config.logger = Rails.logger # using the Rails logger
8
5
  config.soap_version = 1
9
6
  end
10
7
 
@@ -90,6 +87,7 @@ module Vindicia
90
87
  when /ArrayOf/
91
88
  return [] if value.nil?
92
89
  if value.kind_of? Hash
90
+ return [] if value[:array_type] =~ /\[0\]$/
93
91
  if value[name.to_sym]
94
92
  return coerce(name, type, [value[name.to_sym]].flatten)
95
93
  else
@@ -106,6 +104,12 @@ module Vindicia
106
104
  else
107
105
  value
108
106
  end
107
+ when "xsd:string"
108
+ if value == {:type=>"xsd:string", :xmlns=>""}
109
+ nil
110
+ else
111
+ value
112
+ end
109
113
  when "xsd:int"
110
114
  value.to_i
111
115
  else
@@ -290,6 +294,11 @@ module Vindicia
290
294
  end
291
295
  end
292
296
 
297
+ def [](attr)
298
+ key = camelcase(attr.to_s)
299
+ Vindicia.coerce(key, attributes[key], instance_variable_get("@#{underscore(attr)}"))
300
+ end
301
+
293
302
  def build(xml, tag)
294
303
  xml.tag!(tag, {"xsi:type" => "vin:#{classname}"}) do |xml|
295
304
  attributes.each do |name, type|
@@ -353,7 +362,7 @@ module Vindicia
353
362
  key = camelcase(attr.to_s)
354
363
 
355
364
  if attributes[key]
356
- Vindicia.coerce(key, attributes[key], instance_variable_get("@#{attr}"))
365
+ self[key]
357
366
  else
358
367
  super
359
368
  end
@@ -1,6 +1,12 @@
1
1
  require 'vindicia'
2
2
  require 'authenticate'
3
3
 
4
+ Savon.configure do |config|
5
+ config.log = false # disable logging
6
+ #config.log_level = :info # changing the log level
7
+ #config.logger = Rails.logger # using the Rails logger
8
+ end
9
+
4
10
  describe Vindicia::Account do
5
11
  it 'should return a singleton soap wrapper' do
6
12
  a = Vindicia::Account
@@ -85,6 +91,14 @@ describe Vindicia::SoapObject do
85
91
  product.default_billing_plan.should be_kind_of(Vindicia::BillingPlan)
86
92
  end
87
93
 
94
+ it 'should allow hash access' do
95
+ product = Vindicia::Product.new(
96
+ :default_billing_plan => {:status => "Active"}
97
+ )
98
+ product['defaultBillingPlan'].should_not be_nil
99
+ product['defaultBillingPlan'].should == product.default_billing_plan
100
+ end
101
+
88
102
  it 'should deserialze arrays' do
89
103
  plan = Vindicia::BillingPlan.new(
90
104
  :periods => [{
@@ -130,6 +144,13 @@ describe Vindicia::SoapObject do
130
144
  plan.periods.size.should == 1
131
145
  plan.periods.first.should be_kind_of(Vindicia::BillingPlanPeriod)
132
146
  end
147
+
148
+ it 'should deserialize empty arrays from soap' do
149
+ ret, transactions = Vindicia::Transaction.fetchDeltaSince(Date.new(2011,2,1), Date.new(2011,2,2), 500, 10, nil)
150
+
151
+ ret.should be_kind_of(Vindicia::Return)
152
+ transactions.should == []
153
+ end
133
154
  end
134
155
 
135
156
  describe Vindicia::Product do
@@ -175,6 +196,10 @@ describe Vindicia do
175
196
  @account.paymentMethods.first.class.should == Vindicia::PaymentMethod
176
197
  end
177
198
 
199
+ it 'should map nil objects to nil' do
200
+ @account.preferred_language.should be_nil
201
+ end
202
+
178
203
  it 'should map associated arrays to a Vindicia:: class' do
179
204
  transaction = Vindicia::Transaction.auth({
180
205
  :account => @account.ref,
@@ -221,6 +246,23 @@ describe Vindicia do
221
246
  }, 100, false)
222
247
  transaction.request_status.code.should == 200
223
248
  end
249
+
250
+ it 'should auth a purchase with payment method ID' do
251
+ payment_id = @account.paymentMethods.first.merchant_payment_method_id
252
+ transaction = Vindicia::Transaction.auth({
253
+ :account => @account.ref,
254
+ :merchantTransactionId => "Purchase.id (#{Time.now.to_i})",
255
+ :sourcePaymentMethod => {:merchant_payment_method_id => payment_id},
256
+ :amount => 49.00,
257
+ :transactionItems => [{:sku => 'sku', :name => 'Established Men Subscription', :price => 49.00, :quantity => 1}]
258
+ #:divisionNumber xsd:string
259
+ #:userAgent xsd:string
260
+ #:sourceMacAddress xsd:string
261
+ #:sourceIp xsd:string
262
+ #:billingStatementIdentifier xsd:string
263
+ }, 100, false)
264
+ transaction.request_status.code.should == 200
265
+ end
224
266
  end
225
267
 
226
268
  describe '#capture' do
@@ -235,6 +277,12 @@ describe Vindicia do
235
277
  }, 100, false)
236
278
  end
237
279
 
280
+ it 'should look up authorization' do
281
+ @transaction['merchantTransactionId'].should =~ /^Purchase.id /
282
+ @transaction.merchantTransactionId.should =~ /^Purchase.id /
283
+ @transaction.merchant_transaction_id.should =~ /^Purchase.id /
284
+ end
285
+
238
286
  it 'should capture an authorized purchase' do
239
287
  ret, success, fail, results = Vindicia::Transaction.capture([@transaction.ref])
240
288
  success.should == 1
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vindicia
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jamie Macey
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 -05:00
18
+ date: 2011-02-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency