Permalink
Browse files

Add support for order payment

  • Loading branch information...
1 parent df9bea3 commit 274f5bf65b7af58d25a7d94f5deb567de3c4aa1f @patchfx committed Nov 12, 2011
Showing with 29 additions and 0 deletions.
  1. +1 −0 lib/fastspring-saasy.rb
  2. +8 −0 lib/fastspring-saasy/order.rb
  3. +14 −0 lib/fastspring-saasy/payment.rb
  4. +6 −0 spec/order_spec.rb
@@ -6,5 +6,6 @@
require_relative 'fastspring-saasy/customer'
require_relative 'fastspring-saasy/order'
require_relative 'fastspring-saasy/item'
+require_relative 'fastspring-saasy/payment'
require_relative 'fastspring-saasy/address'
require_relative 'fastspring-saasy/error'
@@ -15,6 +15,14 @@ def items
@items ||= [Item.new(parsed_response['orderItems']['orderItem'])]
end
+ def payments
+ @payments ||= [Payment.new(parsed_response['payments']['payment'])]
+ end
+
+ def payment
+ payments[0]
+ end
+
# Return the order reference
def reference
value_for('reference')
@@ -0,0 +1,14 @@
+module FastSpring
+ class Payment
+ attr_reader :status, :status_changed, :method_type, :declined_reason,
+ :currency, :total
+
+ def initialize(details)
+ @status = details.fetch('status')
+ @status_changed = Date.parse(details.fetch('statusChanged'))
+ @declined_reason = details.fetch('declinedReason')
+ @currency = details.fetch('currency')
+ @total = details.fetch('total').to_f
+ end
+ end
+end
View
@@ -27,13 +27,15 @@
let(:customer) { mock(:customer) }
let(:address) { mock(:address) }
let(:item) { mock(:item) }
+ let(:payment) { mock(:payment) }
before do
stub_request(:get, "https://admin:test@api.fastspring.com/company/acme/order/test_ref").
to_return(stub_http_response_with('basic_order.xml'))
FastSpring::Customer.stub(:new => customer)
FastSpring::Address.stub(:new => address)
FastSpring::Item.stub(:new => item)
+ FastSpring::Payment.stub(:new => payment)
end
it 'returns the status' do
@@ -94,6 +96,10 @@
end
end
+ it 'has a payment' do
+ subject.payment.should == payment
+ end
+
end
end

0 comments on commit 274f5bf

Please sign in to comment.