Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #89 from theinventor/payment_methods
Browse files Browse the repository at this point in the history
implement list payment methods for online flavor
  • Loading branch information
ruckus committed Aug 22, 2013
2 parents 32fc074 + 1aaee6b commit e588b10
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ coverage
.DS_Store
Gemfile.lock
.rvmrc
*~
*~
.idea
2 changes: 2 additions & 0 deletions lib/quickeebooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def to_xml(params = {})
require 'quickeebooks/online/model/payment_header'
require 'quickeebooks/online/model/payment_line_item'
require 'quickeebooks/online/model/payment_detail'
require 'quickeebooks/online/model/payment_method'
require 'quickeebooks/online/model/credit_card'
require 'quickeebooks/online/model/credit_charge_info'
require 'quickeebooks/online/model/credit_charge_response'
Expand Down Expand Up @@ -135,6 +136,7 @@ def to_xml(params = {})
require 'quickeebooks/online/service/item'
require 'quickeebooks/online/service/entitlement'
require 'quickeebooks/online/service/payment'
require 'quickeebooks/online/service/payment_method'
require 'quickeebooks/online/service/access_token'
require 'quickeebooks/online/service/vendor'
require 'quickeebooks/online/service/sales_receipt'
Expand Down
27 changes: 27 additions & 0 deletions lib/quickeebooks/online/model/payment_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Quickeebooks
module Online
module Model
class PaymentMethod < Quickeebooks::Online::Model::IntuitType
include ActiveModel::Validations

XML_COLLECTION_NODE = 'PaymentMethods'
XML_NODE = 'PaymentMethod'

# https://qbo.sbfinance.intuit.com/resource/payment-methods/v2/<realmID>
REST_RESOURCE = "payment-method"

xml_name 'PaymentMethod'
xml_convention :camelcase
xml_accessor :id, :from => 'Id', :as => Quickeebooks::Online::Model::Id
xml_accessor :sync_token, :from => 'SyncToken', :as => Integer
xml_accessor :meta_data, :from => 'MetaData', :as => Quickeebooks::Online::Model::MetaData
xml_accessor :external_key, :from => 'ExternalKey'
xml_accessor :name, :from => 'Name'
xml_accessor :active, :from => 'Active'
xml_accessor :type, :from => 'Type'

validates_length_of :name, :minimum => 1
end
end
end
end
12 changes: 12 additions & 0 deletions lib/quickeebooks/online/service/payment_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'quickeebooks/online/model/payment_method'
require 'quickeebooks/online/service/service_base'

module Quickeebooks
module Online
module Service
class PaymentMethod < ServiceBase
include ServiceCRUD
end
end
end
end
15 changes: 15 additions & 0 deletions spec/quickeebooks/online/services/payment_method_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe "Quickeebooks::Windows::Service::PaymentMethod" do
before(:all) do
construct_oauth_service :payment_method
end

it "can fetch a list of journal entries" do
xml = onlineFixture("payment_methods.xml")
url = @service.url_for_resource(Quickeebooks::Online::Model::PaymentMethod.resource_for_collection)
FakeWeb.register_uri(:post, url, :status => ["200", "OK"], :body => xml)
payment_methods = @service.list
payment_methods.current_page.should == 1
payment_methods.entries.count.should == 6
end

end
66 changes: 66 additions & 0 deletions spec/xml/online/payment_methods.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<qbo:SearchResults xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<qbo:CdmCollections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PaymentMethods">
<PaymentMethod>
<Id idDomain="QBO">3</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>American Express</Name>
<Type>CREDIT_CARD</Type>
</PaymentMethod>
<PaymentMethod>
<Id idDomain="QBO">1</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>Cash</Name>
<Type>NON_CREDIT_CARD</Type>
</PaymentMethod>
<PaymentMethod>
<Id idDomain="QBO">2</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>Check</Name>
<Type>NON_CREDIT_CARD</Type>
</PaymentMethod>
<PaymentMethod>
<Id idDomain="QBO">4</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>Discover</Name>
<Type>CREDIT_CARD</Type>
</PaymentMethod>
<PaymentMethod>
<Id idDomain="QBO">5</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>MasterCard</Name>
<Type>CREDIT_CARD</Type>
</PaymentMethod>
<PaymentMethod>
<Id idDomain="QBO">6</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2009-06-19T14:04:29-07:00</CreateTime>
<LastUpdatedTime>2009-06-19T14:04:29-07:00</LastUpdatedTime>
</MetaData>
<Name>Visa</Name>
<Type>CREDIT_CARD</Type>
</PaymentMethod>
</qbo:CdmCollections>
<qbo:Count>6</qbo:Count>
<qbo:CurrentPage>1</qbo:CurrentPage>
</qbo:SearchResults>

0 comments on commit e588b10

Please sign in to comment.