fastbill-automatic 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/Gemfile +8 -0
- data/LICENSE +23 -0
- data/README.md +203 -0
- data/Rakefile +8 -0
- data/doc/API-Doku_FBA_V1-8.pdf +0 -0
- data/fastbill-automatic.gemspec +20 -0
- data/lib/data/fastbill.crt +17 -0
- data/lib/fastbill-automatic/article.rb +14 -0
- data/lib/fastbill-automatic/base.rb +35 -0
- data/lib/fastbill-automatic/coupon.rb +12 -0
- data/lib/fastbill-automatic/customer.rb +16 -0
- data/lib/fastbill-automatic/invoice.rb +25 -0
- data/lib/fastbill-automatic/item.rb +10 -0
- data/lib/fastbill-automatic/request/base.rb +36 -0
- data/lib/fastbill-automatic/request/connection.rb +37 -0
- data/lib/fastbill-automatic/request/info.rb +32 -0
- data/lib/fastbill-automatic/request/validator.rb +33 -0
- data/lib/fastbill-automatic/services/cancel.rb +22 -0
- data/lib/fastbill-automatic/services/changearticle.rb +19 -0
- data/lib/fastbill-automatic/services/complete.rb +22 -0
- data/lib/fastbill-automatic/services/create.rb +19 -0
- data/lib/fastbill-automatic/services/delete.rb +22 -0
- data/lib/fastbill-automatic/services/delete_item.rb +21 -0
- data/lib/fastbill-automatic/services/get.rb +28 -0
- data/lib/fastbill-automatic/services/sendbyemail.rb +19 -0
- data/lib/fastbill-automatic/services/sendbypost.rb +22 -0
- data/lib/fastbill-automatic/services/setaddon.rb +19 -0
- data/lib/fastbill-automatic/services/setpaid.rb +19 -0
- data/lib/fastbill-automatic/services/setusagedata.rb +21 -0
- data/lib/fastbill-automatic/services/sign.rb +22 -0
- data/lib/fastbill-automatic/services/update.rb +28 -0
- data/lib/fastbill-automatic/subscription.rb +16 -0
- data/lib/fastbill-automatic/template.rb +12 -0
- data/lib/fastbill-automatic/usage_data.rb +171 -0
- data/lib/fastbill-automatic/version.rb +5 -0
- data/lib/fastbill-automatic.rb +93 -0
- data/spec/fastbill-automatic/base_spec.rb +35 -0
- data/spec/fastbill-automatic/customer_spec.rb +100 -0
- data/spec/fastbill-automatic/subscription_spec.rb +61 -0
- data/spec/fastbill-automatic/usage_data_spec.rb +340 -0
- data/spec/fastbill-automatic_spec.rb +37 -0
- data/spec/spec_helper.rb +10 -0
- metadata +116 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module DeleteItem
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def delete(id)
|
8
|
+
attributes = {}
|
9
|
+
attributes[:invoice_item_id] = id
|
10
|
+
response = Fastbill::Automatic.request("item.delete", attributes)
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(base)
|
16
|
+
base.extend(ClassMethods)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Get
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def get(options = {})
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.get", options)
|
9
|
+
results_from(response)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def results_from(response)
|
14
|
+
results = []
|
15
|
+
response["RESPONSE"]["#{self.name.split("::").last.upcase}S"].each do |obj|
|
16
|
+
results << self.new(obj)
|
17
|
+
end
|
18
|
+
results
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(base)
|
23
|
+
base.extend(ClassMethods)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Sendbyemail
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def sendbyemail(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.sendbyemail", attributes)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Sendbypost
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def sendbypost(id)
|
8
|
+
id_attribute = "#{self.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes = {}
|
10
|
+
attributes[id_attribute] = id
|
11
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.sendbypost", attributes)
|
12
|
+
self.new(response["RESPONSE"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Setaddon
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def setaddon(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.setaddon", attributes)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Setpaid
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def setpaid(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.setpaid", attributes)
|
9
|
+
self.new(response["RESPONSE"])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Setusagedata
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def setusagedata(attributes)
|
8
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.setusagedata", attributes)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Sign
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def sign(id)
|
8
|
+
id_attribute = "#{self.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes = {}
|
10
|
+
attributes[id_attribute] = id
|
11
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.sign", attributes)
|
12
|
+
self.new(response["data"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
module Services
|
4
|
+
module Update
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def update_attributes(id, attributes)
|
8
|
+
id_attribute = "#{self.class.name.split("::").last.downcase}_id".to_sym
|
9
|
+
attributes[id_attribute] = id
|
10
|
+
response = Fastbill::Automatic.request("#{self.name.split("::").last.downcase}.update", attributes)
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.included(base)
|
16
|
+
base.extend(ClassMethods)
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_attributes(attributes)
|
20
|
+
id_attribute = "#{self.class.name.split("::").last.downcase}_id".to_sym
|
21
|
+
attributes[id_attribute] = self.send(id_attribute)
|
22
|
+
response = Fastbill::Automatic.request("#{self.class.name.split("::").last.downcase}.update", attributes)
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class Subscription < Base
|
4
|
+
include Fastbill::Automatic::Services::Update
|
5
|
+
include Fastbill::Automatic::Services::Changearticle
|
6
|
+
include Fastbill::Automatic::Services::Setaddon
|
7
|
+
include Fastbill::Automatic::Services::Setusagedata
|
8
|
+
include Fastbill::Automatic::Services::Cancel
|
9
|
+
|
10
|
+
attr_accessor :subscription_id, :customer_id, :subscription_ext_uid, :article_number, :customer_id,
|
11
|
+
:coupon, :title, :unit_price, :currency_code, :next_event, :quantity, :description,
|
12
|
+
:usage_date, :article_code, :start_date, :last_event, :cancellation_date, :status,
|
13
|
+
:expiration_date, :created, :addons
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module Fastbill
|
2
|
+
module Automatic
|
3
|
+
class UsageData < Base
|
4
|
+
|
5
|
+
ATTRIBUTES = [
|
6
|
+
:subscription_id,
|
7
|
+
:customer_id,
|
8
|
+
:article_number,
|
9
|
+
:unit_price,
|
10
|
+
:description,
|
11
|
+
:currency_code,
|
12
|
+
:status,
|
13
|
+
:usage_date,
|
14
|
+
:created,
|
15
|
+
:quantity,
|
16
|
+
:usagedata_id
|
17
|
+
]
|
18
|
+
|
19
|
+
attr_accessor *ATTRIBUTES
|
20
|
+
|
21
|
+
def attributes
|
22
|
+
Hash[*ATTRIBUTES.map{|a| [a, instance_variable_get("@#{a}")]}.flatten]
|
23
|
+
end
|
24
|
+
|
25
|
+
def unit_price
|
26
|
+
@unit_price.to_f
|
27
|
+
end
|
28
|
+
|
29
|
+
def usage_date
|
30
|
+
Time.parse(@usage_date)
|
31
|
+
end
|
32
|
+
|
33
|
+
def created
|
34
|
+
Time.parse(@created)
|
35
|
+
end
|
36
|
+
|
37
|
+
def quantity
|
38
|
+
@quantity.to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
def currency_code
|
42
|
+
if @currency_code.is_a?(Array)
|
43
|
+
@currency_code.join('')
|
44
|
+
else
|
45
|
+
@currency_code.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create
|
50
|
+
save
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete
|
55
|
+
UsageData.deleteusagedata(delete_params)
|
56
|
+
end
|
57
|
+
|
58
|
+
def update_attributes(attributes)
|
59
|
+
initialize(UsageData.prepare_attributes(attributes.merge(attributes)))
|
60
|
+
save
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def save
|
65
|
+
UsageData.deleteusagedata(delete_params) if persisted?
|
66
|
+
UsageData.setusagedata(set_params)
|
67
|
+
|
68
|
+
if remote_attributes = UsageData.get_remote_attributes(get_params)
|
69
|
+
initialize(remote_attributes)
|
70
|
+
true
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.get_remote_attributes(get_params)
|
78
|
+
response = UsageData.getusagedata(get_params)
|
79
|
+
binding.pry
|
80
|
+
item_attributes = response['RESPONSE']['ITEMS'].last
|
81
|
+
item_attributes
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def self.find_by_usage_date(subscription_id, time)
|
86
|
+
time = time.strftime("%Y-%m-%d %H:%M:%S")
|
87
|
+
result = getusagedata(subscription_id: subscription_id, start: time, end: time)
|
88
|
+
|
89
|
+
result_items = result['RESPONSE']['ITEMS']
|
90
|
+
last_item_attributes = result_items ? result_items.last : nil
|
91
|
+
|
92
|
+
if last_item_attributes
|
93
|
+
|
94
|
+
if last_item_attributes['CURRENCY_CODE'] == []
|
95
|
+
last_item_attributes['CURRENCY_CODE'] = ''
|
96
|
+
end
|
97
|
+
|
98
|
+
init_attributes = Hash[*last_item_attributes.map{|k,v| [k.downcase.to_sym, v]}.flatten]
|
99
|
+
|
100
|
+
self.new(init_attributes)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def ==(other)
|
106
|
+
other.attributes == self.attributes
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def persisted?
|
112
|
+
if usagedata_id
|
113
|
+
true
|
114
|
+
else
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_params
|
120
|
+
all_attributes = attributes
|
121
|
+
all_attributes.delete(:usagedata_id)
|
122
|
+
all_attributes
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_params
|
126
|
+
{
|
127
|
+
subscription_id: self.subscription_id,
|
128
|
+
start: @usage_date,
|
129
|
+
end: @usage_date
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def delete_params
|
134
|
+
{
|
135
|
+
usagedata_id: @usagedata_id
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
class << self
|
140
|
+
|
141
|
+
def prepare_attributes(attributes)
|
142
|
+
Hash[*attributes.map{|k,v| [k.downcase.to_sym, v.to_s]}.flatten]
|
143
|
+
end
|
144
|
+
|
145
|
+
def setusagedata(set_params)
|
146
|
+
response = Fastbill::Automatic.request("subscription.setusagedata", set_params)
|
147
|
+
end
|
148
|
+
|
149
|
+
def getusagedata(get_params)
|
150
|
+
response = Fastbill::Automatic.request("subscription.getusagedata", get_params)
|
151
|
+
end
|
152
|
+
|
153
|
+
def deleteusagedata(delete_params)
|
154
|
+
response = Fastbill::Automatic.request("subscription.deleteusagedata", delete_params)
|
155
|
+
end
|
156
|
+
|
157
|
+
def where(get_params)
|
158
|
+
response = UsageData.getusagedata(get_params)
|
159
|
+
result = []
|
160
|
+
items = response['RESPONSE']['ITEMS']||[]
|
161
|
+
items.each do|item|
|
162
|
+
result << UsageData.new(prepare_attributes(item))
|
163
|
+
end
|
164
|
+
result
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "json"
|
4
|
+
require "fastbill-automatic/version"
|
5
|
+
|
6
|
+
module Fastbill
|
7
|
+
module Automatic
|
8
|
+
API_BASE = "automatic.fastbill.com"
|
9
|
+
API_VERSION = "1.0"
|
10
|
+
ROOT_PATH = File.dirname(__FILE__)
|
11
|
+
|
12
|
+
@@api_key = nil
|
13
|
+
@@email = nil
|
14
|
+
@@request_method = :https
|
15
|
+
|
16
|
+
autoload :Base, "fastbill-automatic/base"
|
17
|
+
autoload :Customer, "fastbill-automatic/customer"
|
18
|
+
autoload :Invoice, "fastbill-automatic/invoice"
|
19
|
+
autoload :Item, "fastbill-automatic/item"
|
20
|
+
autoload :Subscription, "fastbill-automatic/subscription"
|
21
|
+
autoload :Template, "fastbill-automatic/template"
|
22
|
+
autoload :Article, "fastbill-automatic/article"
|
23
|
+
autoload :Coupon, "fastbill-automatic/coupon"
|
24
|
+
autoload :UsageData, "fastbill-automatic/usage_data"
|
25
|
+
|
26
|
+
module Services
|
27
|
+
autoload :Get, "fastbill-automatic/services/get"
|
28
|
+
autoload :Create, "fastbill-automatic/services/create"
|
29
|
+
autoload :Update, "fastbill-automatic/services/update"
|
30
|
+
autoload :Delete, "fastbill-automatic/services/delete"
|
31
|
+
autoload :DeleteItem, "fastbill-automatic/services/delete_item"
|
32
|
+
autoload :Cancel, "fastbill-automatic/services/cancel"
|
33
|
+
autoload :Changearticle, "fastbill-automatic/services/changearticle"
|
34
|
+
autoload :Complete, "fastbill-automatic/services/complete"
|
35
|
+
autoload :Sign, "fastbill-automatic/services/sign"
|
36
|
+
autoload :Sendbyemail, "fastbill-automatic/services/sendbyemail"
|
37
|
+
autoload :Sendbypost, "fastbill-automatic/services/sendbypost"
|
38
|
+
autoload :Setaddon, "fastbill-automatic/services/setaddon"
|
39
|
+
autoload :Setpaid, "fastbill-automatic/services/setpaid"
|
40
|
+
autoload :Setusagedata, "fastbill-automatic/services/setusagedata"
|
41
|
+
end
|
42
|
+
|
43
|
+
module Request
|
44
|
+
autoload :Base, "fastbill-automatic/request/base"
|
45
|
+
autoload :Connection, "fastbill-automatic/request/connection"
|
46
|
+
autoload :Info, "fastbill-automatic/request/info"
|
47
|
+
autoload :Validator, "fastbill-automatic/request/validator"
|
48
|
+
end
|
49
|
+
|
50
|
+
class FastbillError < StandardError; end
|
51
|
+
class AuthenticationError < FastbillError; end
|
52
|
+
class APIError < FastbillError; end
|
53
|
+
class NonSupportedRequestMethod < FastbillError; end
|
54
|
+
|
55
|
+
|
56
|
+
def self.request_method
|
57
|
+
@@request_method
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.request_method=(method)
|
61
|
+
if [:https, :test].include? method
|
62
|
+
@@request_method = method
|
63
|
+
else
|
64
|
+
raise NonSupportedRequestMethod
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.api_key
|
69
|
+
@@api_key
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.api_key=(api_key)
|
73
|
+
@@api_key = api_key
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.email
|
77
|
+
@@email
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.email=(email)
|
81
|
+
@@email = email
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.request(service, data)
|
85
|
+
info = Request::Info.new(service, data)
|
86
|
+
if request_method == :https
|
87
|
+
Request::Base.new(info).perform
|
88
|
+
else
|
89
|
+
Fastbill::Automatic::Base.request_infos << info
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include Fastbill::Automatic
|
4
|
+
|
5
|
+
describe Fastbill::Automatic do
|
6
|
+
|
7
|
+
|
8
|
+
context "delivery method is :test" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
Fastbill::Automatic.request_method = :test
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Fastbill::Automatic.request_method = :https
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must not perform the actual request" do
|
19
|
+
Request::Base.any_instance.should_not_receive(:perform) do
|
20
|
+
Fastbill::Automatic.request('subscription.usage', {})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "must store the request" do
|
25
|
+
Fastbill::Automatic.request('service.request', {number: 'one'})
|
26
|
+
Fastbill::Automatic.request('service.request', {number: 'two'})
|
27
|
+
Fastbill::Automatic::Base.request_infos.should eq [
|
28
|
+
Request::Info.new('service.request', number: 'one'),
|
29
|
+
Request::Info.new('service.request', number: 'two')
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Fastbill::Automatic::Customer do
|
4
|
+
|
5
|
+
let(:valid_attributes) do
|
6
|
+
{ customer_number: "5", country_code: "de", customer_ext_uid: "123456", days_for_payment: "14", payment_type: "1", show_payment_notice: "1",
|
7
|
+
customer_type: "consumer", organization: "Server Hosting GmbH", salutation: "mr", first_name: "Klaus", account_receivable: "123456",
|
8
|
+
last_name: "Testname", address: "Test Street 12", address_2: "Test Street 12", zipcode: "26123", city: "Oldenburg", phone: "049 123 456 789",
|
9
|
+
phone_2: "049 123 456 789", fax: "049 123 456 987", mobile: "049 123 456 987", email: "support@fastbill.com", paymill_token: "123456", comment: "some comment",
|
10
|
+
newsletter_optin: "1", language_code: "de", changedata_url: "https://automatic.fastbill.com/accountdata/123456/123456", currency_code: "EUR", vat_id: "123456",
|
11
|
+
position: "test position", bank_name: "Test name", bank_code: "123456", bank_account_number: "123456", bank_account_owner: "Some Name",
|
12
|
+
dashboard_url: "https://automatic.fastbill.com/dashboard/123456/123456", hash: "fcbab5d76170d15e86f97f644385d5e3"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
let (:customer) do
|
17
|
+
Fastbill::Automatic::Customer.new(valid_attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
it "initializes all attributes correctly" do
|
22
|
+
customer.customer_number.should eql("5")
|
23
|
+
customer.customer_ext_uid.should eql("123456")
|
24
|
+
customer.days_for_payment.should eql("14")
|
25
|
+
customer.payment_type.should eql("1")
|
26
|
+
customer.show_payment_notice.should eql("1")
|
27
|
+
customer.customer_type.should eql("consumer")
|
28
|
+
customer.organization.should eql("Server Hosting GmbH")
|
29
|
+
customer.salutation.should eql("mr")
|
30
|
+
customer.first_name.should eql("Klaus")
|
31
|
+
customer.last_name.should eql("Testname")
|
32
|
+
customer.address.should eql("Test Street 12")
|
33
|
+
customer.address_2.should eql("Test Street 12")
|
34
|
+
customer.zipcode.should eql("26123")
|
35
|
+
customer.city.should eql("Oldenburg")
|
36
|
+
customer.phone.should eql("049 123 456 789")
|
37
|
+
customer.phone_2.should eql("049 123 456 789")
|
38
|
+
customer.fax.should eql("049 123 456 987")
|
39
|
+
customer.mobile.should eql("049 123 456 987")
|
40
|
+
customer.email.should eql("support@fastbill.com")
|
41
|
+
customer.paymill_token.should eql("123456")
|
42
|
+
customer.comment.should eql("some comment")
|
43
|
+
customer.newsletter_optin.should eql("1")
|
44
|
+
customer.language_code.should eql("de")
|
45
|
+
customer.country_code.should eql("de")
|
46
|
+
customer.changedata_url.should eql("https://automatic.fastbill.com/accountdata/123456/123456")
|
47
|
+
customer.dashboard_url.should eql("https://automatic.fastbill.com/dashboard/123456/123456")
|
48
|
+
customer.position.should eql("test position")
|
49
|
+
customer.account_receivable.should eql("123456")
|
50
|
+
customer.vat_id.should eql("123456")
|
51
|
+
customer.currency_code.should eql("EUR")
|
52
|
+
customer.bank_name.should eql("Test name")
|
53
|
+
customer.bank_code.should eql("123456")
|
54
|
+
customer.bank_account_number.should eql("123456")
|
55
|
+
customer.bank_account_owner.should eql("Some Name")
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not overwrite the hash method' do
|
59
|
+
customer.hash.class.should eql Fixnum
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe ".attributes" do
|
65
|
+
it "makes all attributes accessible by hash" do
|
66
|
+
customer.attributes.should eql(valid_attributes)
|
67
|
+
customer.attributes[:hash].should eql("fcbab5d76170d15e86f97f644385d5e3")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe ".get" do
|
72
|
+
it "gets a specific customer" do
|
73
|
+
Fastbill::Automatic.should_receive(:request).with("customer.get", {customer_id: "123456"}).and_return("RESPONSE" => { "CUSTOMERS" => {}})
|
74
|
+
Fastbill::Automatic::Customer.get(customer_id: "123456")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".delete" do
|
79
|
+
it "deletes a customer" do
|
80
|
+
Fastbill::Automatic.should_receive(:request).with("customer.delete", {customer_id: "123456"}).and_return("RESPONSE" => { "STATUS" => "success"})
|
81
|
+
Fastbill::Automatic::Customer.delete("123456")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ".create" do
|
86
|
+
it "creates a customer" do
|
87
|
+
Fastbill::Automatic.should_receive(:request).with("customer.create", valid_attributes).and_return("RESPONSE" => { "STATUS" => "success", "CUSTOMER_ID" => "123456"})
|
88
|
+
Fastbill::Automatic::Customer.create(valid_attributes)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#update_attributes" do
|
93
|
+
it "update customer" do
|
94
|
+
tmp_customer = Fastbill::Automatic::Customer.new(customer_id: "123456")
|
95
|
+
Fastbill::Automatic.should_receive(:request).with("customer.update", {:email => "some_name@exmaple.com", customer_id: "123456"}).and_return("RESPONSE" => { "STATUS" => "success"})
|
96
|
+
|
97
|
+
tmp_customer.update_attributes({:email => "some_name@exmaple.com"})
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|