klarna-xmlrpc 0.2.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +13 -0
- data/Gemfile +14 -0
- data/Guardfile +16 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +139 -0
- data/Rakefile +22 -0
- data/TODO +30 -0
- data/examples/Gemfile +8 -0
- data/examples/config/initializer.rb +15 -0
- data/examples/console.rb +71 -0
- data/examples/public/images/klarna.png +0 -0
- data/examples/public/images/ruby.png +0 -0
- data/examples/views/_address.haml +22 -0
- data/examples/views/_articles.haml +21 -0
- data/examples/views/checkout_page_example.haml +2 -0
- data/examples/views/essential/add_transaction/_form.haml +32 -0
- data/examples/views/essential/add_transaction/result.haml +7 -0
- data/examples/views/essential/calculate_monthly_cost/_form.haml +16 -0
- data/examples/views/essential/calculate_monthly_cost/result.haml +7 -0
- data/examples/views/essential/get_addresses/_form.haml +9 -0
- data/examples/views/essential/get_addresses/result.haml +8 -0
- data/examples/views/index.haml +296 -0
- data/examples/views/layout.haml +48 -0
- data/examples/views/payment_terms_example.haml +102 -0
- data/examples/views/product_page_example.haml +2 -0
- data/examples/views/reservation/activate_reservation/_form.haml +54 -0
- data/examples/views/reservation/activate_reservation/result.haml +7 -0
- data/examples/views/reservation/cancel_reservation/_form.haml +8 -0
- data/examples/views/reservation/cancel_reservation/result.haml +7 -0
- data/examples/views/reservation/change_reservation/_form.haml +10 -0
- data/examples/views/reservation/change_reservation/result.haml +7 -0
- data/examples/views/reservation/reserve_amount/_form.haml +58 -0
- data/examples/views/reservation/reserve_amount/result.haml +7 -0
- data/examples/views/reservation/reserve_ocr_numbers/_form.haml +8 -0
- data/examples/views/reservation/reserve_ocr_numbers/result.haml +7 -0
- data/examples/views/reservation/split_reservation/_form.haml +14 -0
- data/examples/views/reservation/split_reservation/result.haml +7 -0
- data/examples/views/special/get_pclasses/_form.haml +8 -0
- data/examples/views/special/get_pclasses/result.haml +7 -0
- data/examples/views/special/invoice_address/_form.haml +8 -0
- data/examples/views/special/invoice_address/result.haml +7 -0
- data/examples/views/special/invoice_amount/_form.haml +8 -0
- data/examples/views/special/invoice_amount/result.haml +7 -0
- data/examples/views/special/is_invoice_paid/_form.haml +8 -0
- data/examples/views/special/is_invoice_paid/result.haml +7 -0
- data/examples/views/special/update_charge_amount/_form.haml +15 -0
- data/examples/views/special/update_charge_amount/result.haml +7 -0
- data/examples/views/special/update_goods_quantity/_form.haml +17 -0
- data/examples/views/special/update_goods_quantity/result.haml +7 -0
- data/examples/views/special/update_order_number/_form.haml +10 -0
- data/examples/views/special/update_order_number/result.haml +7 -0
- data/examples/views/useful/activate_invoice/_form.haml +9 -0
- data/examples/views/useful/activate_invoice/result.haml +7 -0
- data/examples/views/useful/credit_invoice/_form.haml +11 -0
- data/examples/views/useful/credit_invoice/result.haml +7 -0
- data/examples/views/useful/delete_invoice/_form.haml +9 -0
- data/examples/views/useful/delete_invoice/result.haml +7 -0
- data/examples/views/useful/email_invoice/_form.haml +9 -0
- data/examples/views/useful/email_invoice/result.haml +7 -0
- data/examples/views/useful/has_account/_form.haml +9 -0
- data/examples/views/useful/has_account/result.haml +7 -0
- data/examples/views/useful/return_amount/_form.haml +15 -0
- data/examples/views/useful/return_amount/result.haml +7 -0
- data/examples/views/useful/send_invoice/_form.haml +9 -0
- data/examples/views/useful/send_invoice/result.haml +7 -0
- data/examples/web.rb +349 -0
- data/klarna.gemspec +34 -0
- data/lib/klarna.rb +171 -0
- data/lib/klarna/api.rb +187 -0
- data/lib/klarna/api/client.rb +126 -0
- data/lib/klarna/api/constants.rb +647 -0
- data/lib/klarna/api/errors.rb +154 -0
- data/lib/klarna/api/methods.rb +16 -0
- data/lib/klarna/api/methods/cost_calculations.rb +134 -0
- data/lib/klarna/api/methods/invoicing.rb +304 -0
- data/lib/klarna/api/methods/reservation.rb +188 -0
- data/lib/klarna/api/methods/standard.rb +126 -0
- data/lib/klarna/version.rb +5 -0
- data/test/fixtures/api/companies.yml +97 -0
- data/test/fixtures/api/pclasses.yml +37 -0
- data/test/fixtures/api/persons.yml +144 -0
- data/test/fixtures/api/stores.yml +6 -0
- data/test/fixtures/klarna.yml +10 -0
- data/test/klarna/api/client_test.rb +288 -0
- data/test/klarna/api/errors_test.rb +34 -0
- data/test/klarna/api/methods/cost_calculations_test.rb +78 -0
- data/test/klarna/api/methods/invoicing_test.rb +409 -0
- data/test/klarna/api/methods/reservation_test.rb +66 -0
- data/test/klarna/api/methods/standard_test.rb +244 -0
- data/test/klarna/api_test.rb +184 -0
- data/test/klarna_test.rb +204 -0
- data/test/support/assertions_helper.rb +40 -0
- data/test/test_helper.rb +55 -0
- metadata +335 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
describe Klarna::API::Methods::Reservation do
|
5
|
+
|
6
|
+
# TODO: Mock responses using VCR.
|
7
|
+
|
8
|
+
before do
|
9
|
+
valid_credentials!
|
10
|
+
@client = Klarna::API::Client.new
|
11
|
+
|
12
|
+
@protocol_version = ::Klarna::API::PROTOCOL_VERSION.to_s
|
13
|
+
@user_agent = ::XMLRPC::Client::USER_AGENT.to_s
|
14
|
+
|
15
|
+
expose_protected_methods_in @client.class
|
16
|
+
end
|
17
|
+
|
18
|
+
# Spec: http://integration.klarna.com/en/api/advanced-integration/functions/reserveamount
|
19
|
+
describe '#reserve_amount' do
|
20
|
+
it 'should be defined' do
|
21
|
+
assert_respond_to @client, :reserve_amount
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Spec: http://integration.klarna.com/en/api/advanced-integration/functions/activatereservation
|
26
|
+
describe '#activate_reservation' do
|
27
|
+
it 'should be defined' do
|
28
|
+
assert_respond_to @client, :activate_reservation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Spec: http://integration.klarna.com/en/api/advanced-integration/functions/cancelreservation
|
33
|
+
describe '#cancel_reservation' do
|
34
|
+
it 'should be defined' do
|
35
|
+
assert_respond_to @client, :cancel_reservation
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#split_reservation' do
|
40
|
+
it 'should be defined' do
|
41
|
+
assert_respond_to @client, :split_reservation
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Spec: http://integration.klarna.com/en/api/advanced-integration/functions/changereservation
|
46
|
+
describe '#change_reservation' do
|
47
|
+
it 'should be defined' do
|
48
|
+
assert_respond_to @client, :change_reservation
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Spec: http://integration.klarna.com/en/api/advanced-integration/functions/reserveocrnums
|
53
|
+
describe '#reserve_ocr_numbers' do
|
54
|
+
it 'should be defined' do
|
55
|
+
assert_respond_to @client, :reserve_ocr_numbers
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# http://integration.klarna.com/en/api/advanced-integration/functions/mkaddress
|
60
|
+
describe '#make_reservation_address' do
|
61
|
+
it 'should be defined' do
|
62
|
+
assert_respond_to @client, :make_reservation_address
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
describe Klarna::API::Methods::Standard do
|
5
|
+
|
6
|
+
# TODO: Mock responses using VCR.
|
7
|
+
|
8
|
+
before do
|
9
|
+
valid_credentials!
|
10
|
+
@klarna = Klarna::API::Client.new
|
11
|
+
@klarna.client_ip = '127.0.0.1'
|
12
|
+
|
13
|
+
@protocol_version = ::Klarna::API::PROTOCOL_VERSION.to_s
|
14
|
+
@user_agent = ::XMLRPC::Client::USER_AGENT.to_s
|
15
|
+
|
16
|
+
@pno_format_sweden = ::Klarna::API::COUNTRIES[:SE]
|
17
|
+
@country_sweden = ::Klarna::API::COUNTRIES[:SE]
|
18
|
+
|
19
|
+
expose_protected_methods_in @klarna.class
|
20
|
+
end
|
21
|
+
|
22
|
+
# Spec:
|
23
|
+
# http://integration.klarna.com/en/api/standard-integration/functions/getaddresses
|
24
|
+
describe '#get_addresses' do
|
25
|
+
it 'should be defined' do
|
26
|
+
assert_respond_to @klarna, :get_addresses
|
27
|
+
end
|
28
|
+
|
29
|
+
# it 'should require: pno, country'
|
30
|
+
|
31
|
+
it 'should handle pno-format as integer (pno-format ID)' do
|
32
|
+
assert @klarna.get_addresses("4304158399", 2) # a.k.a. ::Klarna::API::PNO_FORMATS[:SE]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should handle pno-format as integer (pno-format ID)' do
|
36
|
+
assert @klarna.get_addresses("4304158399", :SE)
|
37
|
+
end
|
38
|
+
|
39
|
+
# it 'should pre-validate the specified pno, and raise validation error if it s invalid without any service call'
|
40
|
+
|
41
|
+
describe "SE" do
|
42
|
+
it 'should return address for a valid pno' do
|
43
|
+
result = @klarna.get_addresses("4304158399", :SE)
|
44
|
+
assert_equal [@protocol_version, @user_agent, "4304158399", @klarna.store_id, @klarna.digest("4304158399"), 2, 5, '127.0.0.1'], @klarna.last_request_params
|
45
|
+
assert_equal [["Karl", "Lidin", "Junibacksg 42", "23634", "Hollviken", 209]], result
|
46
|
+
|
47
|
+
result = @klarna.get_addresses("5311096845", :SE)
|
48
|
+
assert_equal [@protocol_version, @user_agent, "5311096845", @klarna.store_id, @klarna.digest("5311096845"), 2, 5, '127.0.0.1'], @klarna.last_request_params
|
49
|
+
assert_equal [["Maud", "Johansson", "Köpmansg 7", "12149", "Johanneshov", 209]], result
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should ignore format symbols in pno' do
|
53
|
+
result = @klarna.get_addresses("430415-8399", :SE)
|
54
|
+
assert_equal [@protocol_version, @user_agent, "4304158399", @klarna.store_id, @klarna.digest("4304158399"), 2, 5, '127.0.0.1'], @klarna.last_request_params
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#get_address' do
|
60
|
+
it 'should be defined' do
|
61
|
+
assert_respond_to @klarna, :get_address
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should only return first returned address for a valid SSN' do
|
65
|
+
result = @klarna.get_address("4304158399", :SE)
|
66
|
+
assert_equal ["Karl", "Lidin", "Junibacksg 42", "23634", "Hollviken", 209], result
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Spec:
|
71
|
+
# http://integration.klarna.com/en/api/standard-integration/functions/mkaddr
|
72
|
+
describe '#make_address' do
|
73
|
+
it 'should be defined' do
|
74
|
+
assert_respond_to @klarna, :make_address
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "SE" do
|
78
|
+
it 'should generate an valid address array' do
|
79
|
+
assert_equal ({
|
80
|
+
'careof' => "c/o Lidin",
|
81
|
+
'street' => "Junibackg. 42",
|
82
|
+
'postno' => "23634",
|
83
|
+
'city' => "Hollviken",
|
84
|
+
'country' => 209,
|
85
|
+
'telno' => "0765260000",
|
86
|
+
'cellno' => "0765260000",
|
87
|
+
'email' => "karl.lidin@klarna.com"
|
88
|
+
}),
|
89
|
+
@klarna.make_address("c/o Lidin", "Junibackg. 42", "23634", "Hollviken", :SE, "076 526 00 00", "076 526 00 00", "karl.lidin@klarna.com")
|
90
|
+
end
|
91
|
+
|
92
|
+
# TODO
|
93
|
+
describe 'argument constraints: raise argument error if not true (no API-call)' do
|
94
|
+
describe 'care_of' do
|
95
|
+
# it 'should be a string or nil'
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'street' do
|
99
|
+
# it 'should be a string'
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'postal code' do
|
103
|
+
# it 'should be a string/integer'
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'city' do
|
107
|
+
# it 'should be a string'
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'country' do
|
111
|
+
# it 'should be a string/symbol/integer (-> valid Klarna country ID)'
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'phone' do
|
115
|
+
# it 'should be a string/integer'
|
116
|
+
|
117
|
+
# it 'should ignore whitespace'
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'cell_phone' do
|
121
|
+
# it 'should be a string/integer'
|
122
|
+
|
123
|
+
# it 'should ignore whitespace'
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'email' do
|
127
|
+
# it 'should be a valid email (string)'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Spec:
|
134
|
+
# http://integration.klarna.com/en/api/standard-integration/functions/mkgoodsflags
|
135
|
+
describe '#make_goods' do
|
136
|
+
it 'should be defined' do
|
137
|
+
assert_respond_to @klarna, :make_goods
|
138
|
+
end
|
139
|
+
|
140
|
+
# it 'should require: quantity, artno vs title, price, vat'
|
141
|
+
|
142
|
+
# it 'should pre-validate the specified address values, and raise validation error if it s invalid without any service call'
|
143
|
+
|
144
|
+
describe 'argument constraints: raise argument error if not true (no API-call)' do
|
145
|
+
describe 'quantity' do
|
146
|
+
# it 'should be a integer/string'
|
147
|
+
|
148
|
+
# it 'should be >= 1'
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'artno' do
|
152
|
+
# it 'should be a integer/string if no title is specified'
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'title' do
|
156
|
+
# it 'should be a integer/string if no artno is specified'
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'price' do
|
160
|
+
# it 'should be a integer/string/decimal if no artno is specified'
|
161
|
+
|
162
|
+
# it 'should convert to cents if decimal (assumption)'
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'vat' do
|
166
|
+
# it 'should be a integer/string/decimal if no artno is specified'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should generate an valid address structure: quantity, artno, title, price, vat' do
|
171
|
+
assert_equal ({
|
172
|
+
'goods' => {
|
173
|
+
'artno' => "ABC123",
|
174
|
+
'title' => "T-shirt",
|
175
|
+
'price' => 2500,
|
176
|
+
'vat' => 25.00,
|
177
|
+
'discount' => 0.00,
|
178
|
+
'flags' => 0
|
179
|
+
},
|
180
|
+
'qty' => 5
|
181
|
+
}),
|
182
|
+
@klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should generate an valid address structure: quantity, artno, title, price, vat, discount' do
|
186
|
+
assert_equal ({
|
187
|
+
'goods' => {
|
188
|
+
'artno' => "ABC123",
|
189
|
+
'title' => "T-shirt",
|
190
|
+
'price' => 2500,
|
191
|
+
'vat' => 25.00,
|
192
|
+
'discount' => 10.00,
|
193
|
+
'flags' => 0
|
194
|
+
},
|
195
|
+
'qty' => 5
|
196
|
+
}),
|
197
|
+
@klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 10)
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should generate an valid address structure: quantity, artno, title, price, vat, discount, flags' do
|
201
|
+
assert_equal ({
|
202
|
+
'goods' => {
|
203
|
+
'artno' => "ABC123",
|
204
|
+
'title' => "T-shirt",
|
205
|
+
'price' => 2500,
|
206
|
+
'vat' => 25.00,
|
207
|
+
'discount' => 10.00,
|
208
|
+
'flags' => 32
|
209
|
+
},
|
210
|
+
'qty' => 5
|
211
|
+
}),
|
212
|
+
@klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 10, ::Klarna::API::GOODS[:INC_VAT])
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should be possible to set flags via options' do
|
216
|
+
assert_equal ({
|
217
|
+
'goods' => {
|
218
|
+
'artno' => "ABC123",
|
219
|
+
'title' => "T-shirt",
|
220
|
+
'price' => 2500,
|
221
|
+
'vat' => 25.00,
|
222
|
+
'discount' => 0.00,
|
223
|
+
'flags' => 48
|
224
|
+
},
|
225
|
+
'qty' => 5
|
226
|
+
}),
|
227
|
+
@klarna.make_goods(5, "ABC123", "T-shirt", 25.00 * 100, 25, 0, :inc_vat => true, :is_handling => true)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Spec:
|
232
|
+
# http://integration.klarna.com/en/api/advanced-integration/functions/hasaccount
|
233
|
+
describe '#has_account?' do
|
234
|
+
it 'should be defined' do
|
235
|
+
assert_respond_to @klarna, :has_account?
|
236
|
+
end
|
237
|
+
|
238
|
+
# FIXME: Throws error "Unknown call (-99)". :S
|
239
|
+
it 'should be true' # do
|
240
|
+
# assert_equal true, @klarna.has_account?("4304158399", :SE)
|
241
|
+
# end
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'iconv'
|
4
|
+
|
5
|
+
describe ::Klarna::API do
|
6
|
+
|
7
|
+
before do
|
8
|
+
::Klarna.setup do |c|
|
9
|
+
c.store_id = VALID_STORE_ID
|
10
|
+
c.store_secret = VALID_STORE_SECRET
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Helpers" do
|
15
|
+
|
16
|
+
describe '.client' do
|
17
|
+
it 'should be defined' do
|
18
|
+
assert_respond_to ::Klarna::API, :client
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should create a new ::Klarna RPC-API client with default settings' do
|
22
|
+
client = ::Klarna::API.client
|
23
|
+
assert_instance_of ::Klarna::API::Client, client
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should reuse existing ::Klarna RPC-API client instance if exists' do
|
27
|
+
assert_equal ::Klarna::API.client, ::Klarna::API.client
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should be possible to force-re-initialize the client even though it is already initialized' do
|
31
|
+
client_1 = ::Klarna::API.client(true)
|
32
|
+
client_2 = ::Klarna::API.client(true)
|
33
|
+
refute_equal client_1, client_2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.validated_kind' do
|
38
|
+
it 'should be defined' do
|
39
|
+
assert_respond_to ::Klarna::API, :validated_kind
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should only allow kinds: :country, :currency, :language, :pno_format, :address_format' do
|
43
|
+
assert_equal :COUNTRIES, ::Klarna::API.validated_kind(:country)
|
44
|
+
assert_equal :COUNTRIES, ::Klarna::API.validated_kind('country')
|
45
|
+
|
46
|
+
assert_equal :CURRENCIES, ::Klarna::API.validated_kind(:currency)
|
47
|
+
assert_equal :CURRENCIES, ::Klarna::API.validated_kind('currency')
|
48
|
+
|
49
|
+
assert_equal :LANGUAGES, ::Klarna::API.validated_kind(:language)
|
50
|
+
assert_equal :LANGUAGES, ::Klarna::API.validated_kind('language')
|
51
|
+
|
52
|
+
assert_equal :PNO_FORMATS, ::Klarna::API.validated_kind(:pno_format)
|
53
|
+
assert_equal :PNO_FORMATS, ::Klarna::API.validated_kind('pno_format')
|
54
|
+
|
55
|
+
assert_equal :ADDRESS_FORMATS, ::Klarna::API.validated_kind(:address_format)
|
56
|
+
assert_equal :ADDRESS_FORMATS, ::Klarna::API.validated_kind('address_format')
|
57
|
+
|
58
|
+
assert_raises ::Klarna::API::KlarnaArgumentError do
|
59
|
+
::Klarna::API.validated_kind(:hello)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '.key_for' do
|
65
|
+
it 'should be defined' do
|
66
|
+
assert_respond_to ::Klarna::API, :key_for
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return valid format KEY for a specified kind-key' do
|
70
|
+
assert_equal :SE, ::Klarna::API.key_for(:pno_format, 'SE')
|
71
|
+
assert_equal :SE, ::Klarna::API.key_for(:pno_format, :SE)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return valid format KEY for a specified kind-value' do
|
75
|
+
assert_equal :SE, ::Klarna::API.key_for(:pno_format, '2')
|
76
|
+
assert_equal :SE, ::Klarna::API.key_for(:pno_format, 2)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '.id_for' do
|
81
|
+
it 'should be defined' do
|
82
|
+
assert_respond_to ::Klarna::API, :id_for
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should return valid format ID for a specified kind-key' do
|
86
|
+
assert_equal 2, ::Klarna::API.id_for(:pno_format, 'SE')
|
87
|
+
assert_equal 2, ::Klarna::API.id_for(:pno_format, :SE)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should return valid format ID for a specified kind-value' do
|
91
|
+
assert_equal 2, ::Klarna::API.id_for(:pno_format, '2')
|
92
|
+
assert_equal 2, ::Klarna::API.id_for(:pno_format, 2)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '.validate_arg' do
|
97
|
+
it 'should be defined' do
|
98
|
+
assert_respond_to ::Klarna::API, :validate_arg
|
99
|
+
end
|
100
|
+
|
101
|
+
# TODO: Add missing specs.
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.parse_flags' do
|
105
|
+
it 'should be defined' do
|
106
|
+
assert_respond_to ::Klarna::API, :parse_flags
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should calculate value for one flag properly' do
|
110
|
+
assert_equal 0, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => false)
|
111
|
+
assert_equal 8, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => true)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should calculate value for multiple flags properly using hash (bitwise OR - a.k.a sum)' do
|
115
|
+
# Maybe overkill, but here we go... ;)
|
116
|
+
|
117
|
+
# Uppercase
|
118
|
+
assert_equal 0, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => false, :IS_HANDLING => false, :INC_VAT => false)
|
119
|
+
assert_equal 8, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => true, :IS_HANDLING => false, :INC_VAT => false)
|
120
|
+
assert_equal 16, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => false, :IS_HANDLING => true, :INC_VAT => false)
|
121
|
+
assert_equal 32, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => false, :IS_HANDLING => false, :INC_VAT => true)
|
122
|
+
assert_equal 24, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => true, :IS_HANDLING => true, :INC_VAT => false)
|
123
|
+
assert_equal 48, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => false, :IS_HANDLING => true, :INC_VAT => true)
|
124
|
+
assert_equal 56, ::Klarna::API.parse_flags(:GOODS, :IS_SHIPMENT => true, :IS_HANDLING => true, :INC_VAT => true)
|
125
|
+
|
126
|
+
# Lowercase (for readability)
|
127
|
+
assert_equal 0, ::Klarna::API.parse_flags(:goods, :is_shipment => false, :is_handling => false, :inc_vat => false)
|
128
|
+
assert_equal 8, ::Klarna::API.parse_flags(:goods, :is_shipment => true, :is_handling => false, :inc_vat => false)
|
129
|
+
assert_equal 16, ::Klarna::API.parse_flags(:goods, :is_shipment => false, :is_handling => true, :inc_vat => false)
|
130
|
+
assert_equal 32, ::Klarna::API.parse_flags(:goods, :is_shipment => false, :is_handling => false, :inc_vat => true)
|
131
|
+
assert_equal 24, ::Klarna::API.parse_flags(:goods, :is_shipment => true, :is_handling => true, :inc_vat => false)
|
132
|
+
assert_equal 48, ::Klarna::API.parse_flags(:goods, :is_shipment => false, :is_handling => true, :inc_vat => true)
|
133
|
+
assert_equal 56, ::Klarna::API.parse_flags(:goods, :is_shipment => true, :is_handling => true, :inc_vat => true)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '.digest' do
|
138
|
+
it 'should be defined' do
|
139
|
+
assert_respond_to ::Klarna::API, :digest
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should calculate a valid digest secret for single value' do
|
143
|
+
assert_equal "RvaNtGgJzI4FLDLz7dH4PIwWl3vYwR6qpx/whgCf7qkxj4+0prU0zXOAw9Jc\nSQw+iMqzgAMyjq79azKmp40uWg==", ::Klarna::API.digest("secret 123")
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should calculate a valid digest secret for an array of values' do
|
147
|
+
assert_equal ::Klarna::API.digest("secret 1:secret 2:secret 3"), ::Klarna::API.digest("secret 1", "secret 2", "secret 3")
|
148
|
+
assert_equal "yKMen8LPEev5yLYUTjFvJdWY/t2tTx3JsK2s1nIgwu3wFfrdu6Kzce1VcGfo\nC/6OXQtR6nGVntYhEP7KUmtADw==", ::Klarna::API.digest("secret 1", "secret 2", "secret 3")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '.encode' do
|
153
|
+
it 'should be defined' do
|
154
|
+
assert_respond_to ::Klarna::API, :encode
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should encode a specified string from "UTF-8" to "ISO-8859-1" properly' do
|
158
|
+
if RUBY_VERSION > '1.9'
|
159
|
+
assert_equal 'ISO-8859-1', ::Klarna::API.encode("ÅÄÖ".force_encoding('UTF-8')).encoding.name
|
160
|
+
else
|
161
|
+
::Iconv rescue require 'iconv'
|
162
|
+
assert_equal 1, ::Klarna::API.encode("Ö").length # if it is UTF-8 String#length returns 2 bytes in Ruby < 1.9
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '.decode' do
|
168
|
+
it 'should be defined' do
|
169
|
+
assert_respond_to ::Klarna::API, :decode
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should encode a specified string from "ISO-8859-1" to "UTF-8" properly' do
|
173
|
+
if RUBY_VERSION > '1.9'
|
174
|
+
assert_equal 'UTF-8', ::Klarna::API.decode("ÅÄÖ".force_encoding('ISO-8859-1')).encoding.name
|
175
|
+
else
|
176
|
+
::Iconv rescue require 'iconv'
|
177
|
+
assert_equal 2, ::Klarna::API.decode("Ö").length # if it is UTF-8 String#length returns 2 bytes in Ruby < 1.9
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|