netsuite 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,7 @@ require 'netsuite/namespaces/list_acct'
12
12
  require 'netsuite/namespaces/list_rel'
13
13
  require 'netsuite/namespaces/tran_sales'
14
14
  require 'netsuite/namespaces/setup_custom'
15
+ require 'netsuite/namespaces/tran_cust'
15
16
 
16
17
  # SUPPORT
17
18
  require 'netsuite/support/attributes'
@@ -47,6 +48,8 @@ require 'netsuite/records/classification'
47
48
  require 'netsuite/records/custom_record'
48
49
  require 'netsuite/records/custom_record_type'
49
50
  require 'netsuite/records/job'
51
+ require 'netsuite/records/customer_payment'
52
+ require 'netsuite/records/payment_method'
50
53
 
51
54
  module NetSuite
52
55
 
@@ -17,6 +17,7 @@ module NetSuite
17
17
  soap.namespaces['xmlns:tranSales'] = 'urn:sales_2011_2.transactions.webservices.netsuite.com'
18
18
  soap.namespaces['xmlns:platformCommon'] = 'urn:common_2011_2.platform.webservices.netsuite.com'
19
19
  soap.namespaces['xmlns:listAcct'] = 'urn:accounting_2011_2.lists.webservices.netsuite.com'
20
+ soap.namespaces['xmlns:tranCust'] = 'urn:customers_2011_2.transactions.webservices.netsuite.com'
20
21
  soap.header = auth_header
21
22
  soap.body = request_body
22
23
  end
@@ -3,8 +3,9 @@ module NetSuite
3
3
  class Initialize
4
4
  include Support::Requests
5
5
 
6
- def initialize(obj)
7
- @obj = obj
6
+ def initialize(klass, object)
7
+ @klass = klass
8
+ @object = object
8
9
  end
9
10
 
10
11
  def request
@@ -26,12 +27,12 @@ module NetSuite
26
27
  def request_body
27
28
  {
28
29
  'platformMsgs:initializeRecord' => {
29
- 'platformCore:type' => 'invoice',
30
+ 'platformCore:type' => @klass.to_s.split('::').last.lower_camelcase,
30
31
  'platformCore:reference' => {},
31
32
  :attributes! => {
32
33
  'platformCore:reference' => {
33
- 'internalId' => @obj.internal_id,
34
- :type => @obj.class.to_s.split('::').last.lower_camelcase
34
+ 'internalId' => @object.internal_id,
35
+ :type => @object.class.to_s.split('::').last.lower_camelcase
35
36
  }
36
37
  }
37
38
  }
@@ -0,0 +1,11 @@
1
+ module NetSuite
2
+ module Namespaces
3
+ module TranCust
4
+
5
+ def record_namespace
6
+ 'tranCust'
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ module NetSuite
2
+ module Records
3
+ class CustomerPayment
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+ include Support::Records
7
+ include Namespaces::TranCust
8
+
9
+ fields :auth_code, :auto_apply, :balance, :cc_approved, :cc_avs_street_match, :cc_avs_zip_match,
10
+ :cc_expire_date, :cc_name, :cc_number, :cc_security_code, :cc_security_code_match, :cc_street, :cc_zip_code,
11
+ :charge_it, :check_num, :created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :ignore_avs,
12
+ :last_modified_date, :memo, :payment, :pending, :pn_ref_num, :status, :three_d_status_code, :tran_date,
13
+ :undep_funds, :valid_from
14
+
15
+ field :custom_field_list, CustomFieldList
16
+
17
+ read_only_fields :applied, :total, :unapplied
18
+
19
+ record_refs :account, :ar_acct, :credit_card, :credit_card_processor, :custom_form, :customer, :department, :klass,
20
+ :location, :payment_method, :posting_period, :subsidiary
21
+
22
+ def initialize(attributes = {})
23
+ initialize_from_attributes_hash(attributes)
24
+ end
25
+
26
+ def self.get(options = {})
27
+ response = Actions::Get.call(self, options)
28
+ if response.success?
29
+ new(response.body)
30
+ else
31
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
32
+ end
33
+ end
34
+
35
+ def self.initialize(object)
36
+ response = Actions::Initialize.call(self, object)
37
+ if response.success?
38
+ new(response.body)
39
+ else
40
+ raise InitializationError, "#{self}.initialize with #{object} failed."
41
+ end
42
+ end
43
+
44
+ def add
45
+ response = Actions::Add.call(self)
46
+ response.success?
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -54,12 +54,12 @@ module NetSuite
54
54
  end
55
55
  end
56
56
 
57
- def self.initialize(customer)
58
- response = Actions::Initialize.call(customer)
57
+ def self.initialize(object)
58
+ response = Actions::Initialize.call(self, object)
59
59
  if response.success?
60
60
  new(response.body)
61
61
  else
62
- raise InitializationError, "#{self}.initialize with #{customer} failed."
62
+ raise InitializationError, "#{self}.initialize with #{object} failed."
63
63
  end
64
64
  end
65
65
 
@@ -23,7 +23,12 @@ module NetSuite
23
23
  record_refs :billing_schedule, :category, :currency, :custom_form, :entity_status, :estimate_rev_rec_template, :job_item,
24
24
  :job_type, :language, :parent, :subsidiary, :workplace
25
25
 
26
+ attr_reader :internal_id
27
+ attr_accessor :external_id
28
+
26
29
  def initialize(attributes = {})
30
+ @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
31
+ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id)
27
32
  initialize_from_attributes_hash(attributes)
28
33
  end
29
34
 
@@ -0,0 +1,32 @@
1
+ module NetSuite
2
+ module Records
3
+ class PaymentMethod
4
+ include Support::Fields
5
+ include Support::RecordRefs
6
+
7
+ fields :credit_card, :express_checkout_arrangement, :is_debit_card, :is_inactive, :is_online, :name,
8
+ :pay_pal_email_address, :undep_funds, :use_express_checkout
9
+
10
+ record_ref :account
11
+
12
+ attr_reader :internal_id
13
+ attr_accessor :external_id
14
+
15
+ def initialize(attributes = {})
16
+ @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
17
+ @external_id = attributes.delete(:external_id) || attributes.delete(:@external_id)
18
+ initialize_from_attributes_hash(attributes)
19
+ end
20
+
21
+ def self.get(options = {})
22
+ response = Actions::Get.call(self, options)
23
+ if response.success?
24
+ new(response.body)
25
+ else
26
+ raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.19'
2
+ VERSION = '0.0.20'
3
3
  end
@@ -21,11 +21,11 @@ describe NetSuite::Actions::Initialize do
21
21
  end
22
22
 
23
23
  it 'makes a valid request to the NetSuite API' do
24
- NetSuite::Actions::Initialize.call(customer)
24
+ NetSuite::Actions::Initialize.call(NetSuite::Records::Customer, customer)
25
25
  end
26
26
 
27
27
  it 'returns a valid Response object' do
28
- response = NetSuite::Actions::Initialize.call(customer)
28
+ response = NetSuite::Actions::Initialize.call(NetSuite::Records::Customer, customer)
29
29
  response.should be_kind_of(NetSuite::Response)
30
30
  response.should be_success
31
31
  end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::CustomerPayment do
4
+ let(:payment) { NetSuite::Records::CustomerPayment.new }
5
+ let(:invoice) { NetSuite::Records::Invoice.new }
6
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
7
+
8
+ # <element name="applyList" type="tranCust:CustomerPaymentApplyList" minOccurs="0"/>
9
+ # <element name="creditList" type="tranCust:CustomerPaymentCreditList" minOccurs="0"/>
10
+ # <element name="depositList" type="tranCust:CustomerPaymentDepositList" minOccurs="0"/>
11
+ it 'has all the right fields' do
12
+ [
13
+ :applied, :auth_code, :auto_apply, :balance, :cc_approved, :cc_avs_street_match, :cc_avs_zip_match, :cc_expire_date,
14
+ :cc_name, :cc_number, :cc_security_code, :cc_security_code_match, :cc_street, :cc_zip_code, :charge_it, :check_num,
15
+ :created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :ignore_avs, :last_modified_date, :memo, :payment,
16
+ :pending, :pn_ref_num, :status, :three_d_status_code, :total, :tran_date, :unapplied, :undep_funds, :valid_from
17
+ ].each do |field|
18
+ payment.should have_field(field)
19
+ end
20
+ end
21
+
22
+ it 'has all the right record refs' do
23
+ [
24
+ :account, :ar_acct, :credit_card, :credit_card_processor, :custom_form, :customer, :department, :klass, :location, :payment_method, :posting_period, :subsidiary
25
+ ].each do |record_ref|
26
+ payment.should have_record_ref(record_ref)
27
+ end
28
+ end
29
+
30
+ describe '#custom_field_list' do
31
+ it 'can be set from attributes' do
32
+ attributes = {
33
+ :custom_field => {
34
+ :amount => 10
35
+ }
36
+ }
37
+ payment.custom_field_list = attributes
38
+ payment.custom_field_list.should be_kind_of(NetSuite::Records::CustomFieldList)
39
+ payment.custom_field_list.custom_fields.length.should eql(1)
40
+ end
41
+
42
+ it 'can be set from a CustomFieldList object' do
43
+ custom_field_list = NetSuite::Records::CustomFieldList.new
44
+ payment.custom_field_list = custom_field_list
45
+ payment.custom_field_list.should eql(custom_field_list)
46
+ end
47
+ end
48
+
49
+ describe '.get' do
50
+ context 'when the response is successful' do
51
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :memo => 'This is a memo' }) }
52
+
53
+ it 'returns an CustomerPayment instance populated with the data from the response object' do
54
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::CustomerPayment, :external_id => 7).and_return(response)
55
+ payment = NetSuite::Records::CustomerPayment.get(:external_id => 7)
56
+ payment.should be_kind_of(NetSuite::Records::CustomerPayment)
57
+ payment.memo.should eql('This is a memo')
58
+ end
59
+ end
60
+
61
+ context 'when the response is unsuccessful' do
62
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
63
+
64
+ it 'raises a RecordNotFound exception' do
65
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::CustomerPayment, :external_id => 8).and_return(response)
66
+ lambda {
67
+ NetSuite::Records::CustomerPayment.get(:external_id => 8)
68
+ }.should raise_error(NetSuite::RecordNotFound,
69
+ /NetSuite::Records::CustomerPayment with OPTIONS=(.*) could not be found/)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '.initialize' do
75
+ context 'when the request is successful' do
76
+ it 'returns an initialized invoice from the customer entity' do
77
+ NetSuite::Actions::Initialize.should_receive(:call).with(NetSuite::Records::CustomerPayment, invoice).and_return(response)
78
+ payment = NetSuite::Records::CustomerPayment.initialize(invoice)
79
+ payment.should be_kind_of(NetSuite::Records::CustomerPayment)
80
+ end
81
+ end
82
+
83
+ context 'when the response is unsuccessful' do
84
+ pending
85
+ end
86
+ end
87
+
88
+ describe '#add' do
89
+ let(:test_data) { { :cc_name => 'Ryan Moran', :cc_number => '1234567890123456' } }
90
+
91
+ context 'when the response is successful' do
92
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
93
+
94
+ it 'returns true' do
95
+ payment = NetSuite::Records::CustomerPayment.new(test_data)
96
+ NetSuite::Actions::Add.should_receive(:call).
97
+ with(payment).
98
+ and_return(response)
99
+ payment.add.should be_true
100
+ end
101
+ end
102
+
103
+ context 'when the response is unsuccessful' do
104
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
105
+
106
+ it 'returns false' do
107
+ pyament = NetSuite::Records::CustomerPayment.new(test_data)
108
+ NetSuite::Actions::Add.should_receive(:call).
109
+ with(payment).
110
+ and_return(response)
111
+ payment.add.should be_false
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '#to_record' do
117
+ before do
118
+ payment.cc_name = 'Ryan Moran'
119
+ payment.cc_number = '1234567890123456'
120
+ end
121
+ it 'can represent itself as a SOAP record' do
122
+ record = {
123
+ 'tranCust:ccName' => 'Ryan Moran',
124
+ 'tranCust:ccNumber' => '1234567890123456'
125
+ }
126
+ payment.to_record.should eql(record)
127
+ end
128
+ end
129
+
130
+ describe '#record_type' do
131
+ it 'returns a string representation of the SOAP type' do
132
+ payment.record_type.should eql('tranCust:CustomerPayment')
133
+ end
134
+ end
135
+
136
+ end
@@ -156,7 +156,7 @@ describe NetSuite::Records::Invoice do
156
156
  describe '.initialize' do
157
157
  context 'when the request is successful' do
158
158
  it 'returns an initialized invoice from the customer entity' do
159
- NetSuite::Actions::Initialize.should_receive(:call).with(customer).and_return(response)
159
+ NetSuite::Actions::Initialize.should_receive(:call).with(NetSuite::Records::Invoice, customer).and_return(response)
160
160
  invoice = NetSuite::Records::Invoice.initialize(customer)
161
161
  invoice.should be_kind_of(NetSuite::Records::Invoice)
162
162
  end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::PaymentMethod do
4
+ let(:payment_method) { NetSuite::Records::PaymentMethod.new }
5
+
6
+ # <element name="merchantAccountsList" type="platformCore:RecordRefList" minOccurs="0"/>
7
+
8
+ it 'has all the right fields' do
9
+ [
10
+ :credit_card, :express_checkout_arrangement, :is_debit_card, :is_inactive, :is_online, :name, :pay_pal_email_address,
11
+ :undep_funds, :use_express_checkout
12
+ ].each do |field|
13
+ payment_method.should have_field(field)
14
+ end
15
+ end
16
+
17
+ it 'has all thr right record refs' do
18
+ [
19
+ :account
20
+ ].each do |record_ref|
21
+ payment_method.should have_record_ref(record_ref)
22
+ end
23
+ end
24
+
25
+ describe '.get' do
26
+ context 'when the response is successful' do
27
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :is_debit_card => true }) }
28
+
29
+ it 'returns an PaymentMethod instance populated with the data from the response object' do
30
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::PaymentMethod, :external_id => 10).and_return(response)
31
+ payment_method = NetSuite::Records::PaymentMethod.get(:external_id => 10)
32
+ payment_method.should be_kind_of(NetSuite::Records::PaymentMethod)
33
+ payment_method.is_debit_card.should be_true
34
+ end
35
+ end
36
+
37
+ context 'when the response is unsuccessful' do
38
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
39
+
40
+ it 'raises a RecordNotFound exception' do
41
+ NetSuite::Actions::Get.should_receive(:call).with(NetSuite::Records::PaymentMethod, :external_id => 10).and_return(response)
42
+ lambda {
43
+ NetSuite::Records::PaymentMethod.get(:external_id => 10)
44
+ }.should raise_error(NetSuite::RecordNotFound,
45
+ /NetSuite::Records::PaymentMethod with OPTIONS=(.*) could not be found/)
46
+ end
47
+ end
48
+ end
49
+
50
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 19
10
- version: 0.0.19
9
+ - 20
10
+ version: 0.0.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran
@@ -111,6 +111,7 @@ files:
111
111
  - lib/netsuite/namespaces/platform_common.rb
112
112
  - lib/netsuite/namespaces/platform_core.rb
113
113
  - lib/netsuite/namespaces/setup_custom.rb
114
+ - lib/netsuite/namespaces/tran_cust.rb
114
115
  - lib/netsuite/namespaces/tran_sales.rb
115
116
  - lib/netsuite/records/bill_address.rb
116
117
  - lib/netsuite/records/classification.rb
@@ -122,12 +123,14 @@ files:
122
123
  - lib/netsuite/records/customer.rb
123
124
  - lib/netsuite/records/customer_addressbook.rb
124
125
  - lib/netsuite/records/customer_addressbook_list.rb
126
+ - lib/netsuite/records/customer_payment.rb
125
127
  - lib/netsuite/records/duration.rb
126
128
  - lib/netsuite/records/invoice.rb
127
129
  - lib/netsuite/records/invoice_item.rb
128
130
  - lib/netsuite/records/invoice_item_list.rb
129
131
  - lib/netsuite/records/job.rb
130
132
  - lib/netsuite/records/non_inventory_sale_item.rb
133
+ - lib/netsuite/records/payment_method.rb
131
134
  - lib/netsuite/records/record_ref.rb
132
135
  - lib/netsuite/records/ship_address.rb
133
136
  - lib/netsuite/response.rb
@@ -152,6 +155,7 @@ files:
152
155
  - spec/netsuite/records/custom_record_type_spec.rb
153
156
  - spec/netsuite/records/customer_addressbook_list_spec.rb
154
157
  - spec/netsuite/records/customer_addressbook_spec.rb
158
+ - spec/netsuite/records/customer_payment_spec.rb
155
159
  - spec/netsuite/records/customer_spec.rb
156
160
  - spec/netsuite/records/duration_spec.rb
157
161
  - spec/netsuite/records/invoice_item_list_spec.rb
@@ -159,6 +163,7 @@ files:
159
163
  - spec/netsuite/records/invoice_spec.rb
160
164
  - spec/netsuite/records/job_spec.rb
161
165
  - spec/netsuite/records/non_inventory_sale_item_spec.rb
166
+ - spec/netsuite/records/payment_method_spec.rb
162
167
  - spec/netsuite/records/record_ref_spec.rb
163
168
  - spec/netsuite/records/ship_address_spec.rb
164
169
  - spec/netsuite/response_spec.rb
@@ -230,6 +235,7 @@ test_files:
230
235
  - spec/netsuite/records/custom_record_type_spec.rb
231
236
  - spec/netsuite/records/customer_addressbook_list_spec.rb
232
237
  - spec/netsuite/records/customer_addressbook_spec.rb
238
+ - spec/netsuite/records/customer_payment_spec.rb
233
239
  - spec/netsuite/records/customer_spec.rb
234
240
  - spec/netsuite/records/duration_spec.rb
235
241
  - spec/netsuite/records/invoice_item_list_spec.rb
@@ -237,6 +243,7 @@ test_files:
237
243
  - spec/netsuite/records/invoice_spec.rb
238
244
  - spec/netsuite/records/job_spec.rb
239
245
  - spec/netsuite/records/non_inventory_sale_item_spec.rb
246
+ - spec/netsuite/records/payment_method_spec.rb
240
247
  - spec/netsuite/records/record_ref_spec.rb
241
248
  - spec/netsuite/records/ship_address_spec.rb
242
249
  - spec/netsuite/response_spec.rb