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.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +13 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +16 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.textile +139 -0
  7. data/Rakefile +22 -0
  8. data/TODO +30 -0
  9. data/examples/Gemfile +8 -0
  10. data/examples/config/initializer.rb +15 -0
  11. data/examples/console.rb +71 -0
  12. data/examples/public/images/klarna.png +0 -0
  13. data/examples/public/images/ruby.png +0 -0
  14. data/examples/views/_address.haml +22 -0
  15. data/examples/views/_articles.haml +21 -0
  16. data/examples/views/checkout_page_example.haml +2 -0
  17. data/examples/views/essential/add_transaction/_form.haml +32 -0
  18. data/examples/views/essential/add_transaction/result.haml +7 -0
  19. data/examples/views/essential/calculate_monthly_cost/_form.haml +16 -0
  20. data/examples/views/essential/calculate_monthly_cost/result.haml +7 -0
  21. data/examples/views/essential/get_addresses/_form.haml +9 -0
  22. data/examples/views/essential/get_addresses/result.haml +8 -0
  23. data/examples/views/index.haml +296 -0
  24. data/examples/views/layout.haml +48 -0
  25. data/examples/views/payment_terms_example.haml +102 -0
  26. data/examples/views/product_page_example.haml +2 -0
  27. data/examples/views/reservation/activate_reservation/_form.haml +54 -0
  28. data/examples/views/reservation/activate_reservation/result.haml +7 -0
  29. data/examples/views/reservation/cancel_reservation/_form.haml +8 -0
  30. data/examples/views/reservation/cancel_reservation/result.haml +7 -0
  31. data/examples/views/reservation/change_reservation/_form.haml +10 -0
  32. data/examples/views/reservation/change_reservation/result.haml +7 -0
  33. data/examples/views/reservation/reserve_amount/_form.haml +58 -0
  34. data/examples/views/reservation/reserve_amount/result.haml +7 -0
  35. data/examples/views/reservation/reserve_ocr_numbers/_form.haml +8 -0
  36. data/examples/views/reservation/reserve_ocr_numbers/result.haml +7 -0
  37. data/examples/views/reservation/split_reservation/_form.haml +14 -0
  38. data/examples/views/reservation/split_reservation/result.haml +7 -0
  39. data/examples/views/special/get_pclasses/_form.haml +8 -0
  40. data/examples/views/special/get_pclasses/result.haml +7 -0
  41. data/examples/views/special/invoice_address/_form.haml +8 -0
  42. data/examples/views/special/invoice_address/result.haml +7 -0
  43. data/examples/views/special/invoice_amount/_form.haml +8 -0
  44. data/examples/views/special/invoice_amount/result.haml +7 -0
  45. data/examples/views/special/is_invoice_paid/_form.haml +8 -0
  46. data/examples/views/special/is_invoice_paid/result.haml +7 -0
  47. data/examples/views/special/update_charge_amount/_form.haml +15 -0
  48. data/examples/views/special/update_charge_amount/result.haml +7 -0
  49. data/examples/views/special/update_goods_quantity/_form.haml +17 -0
  50. data/examples/views/special/update_goods_quantity/result.haml +7 -0
  51. data/examples/views/special/update_order_number/_form.haml +10 -0
  52. data/examples/views/special/update_order_number/result.haml +7 -0
  53. data/examples/views/useful/activate_invoice/_form.haml +9 -0
  54. data/examples/views/useful/activate_invoice/result.haml +7 -0
  55. data/examples/views/useful/credit_invoice/_form.haml +11 -0
  56. data/examples/views/useful/credit_invoice/result.haml +7 -0
  57. data/examples/views/useful/delete_invoice/_form.haml +9 -0
  58. data/examples/views/useful/delete_invoice/result.haml +7 -0
  59. data/examples/views/useful/email_invoice/_form.haml +9 -0
  60. data/examples/views/useful/email_invoice/result.haml +7 -0
  61. data/examples/views/useful/has_account/_form.haml +9 -0
  62. data/examples/views/useful/has_account/result.haml +7 -0
  63. data/examples/views/useful/return_amount/_form.haml +15 -0
  64. data/examples/views/useful/return_amount/result.haml +7 -0
  65. data/examples/views/useful/send_invoice/_form.haml +9 -0
  66. data/examples/views/useful/send_invoice/result.haml +7 -0
  67. data/examples/web.rb +349 -0
  68. data/klarna.gemspec +34 -0
  69. data/lib/klarna.rb +171 -0
  70. data/lib/klarna/api.rb +187 -0
  71. data/lib/klarna/api/client.rb +126 -0
  72. data/lib/klarna/api/constants.rb +647 -0
  73. data/lib/klarna/api/errors.rb +154 -0
  74. data/lib/klarna/api/methods.rb +16 -0
  75. data/lib/klarna/api/methods/cost_calculations.rb +134 -0
  76. data/lib/klarna/api/methods/invoicing.rb +304 -0
  77. data/lib/klarna/api/methods/reservation.rb +188 -0
  78. data/lib/klarna/api/methods/standard.rb +126 -0
  79. data/lib/klarna/version.rb +5 -0
  80. data/test/fixtures/api/companies.yml +97 -0
  81. data/test/fixtures/api/pclasses.yml +37 -0
  82. data/test/fixtures/api/persons.yml +144 -0
  83. data/test/fixtures/api/stores.yml +6 -0
  84. data/test/fixtures/klarna.yml +10 -0
  85. data/test/klarna/api/client_test.rb +288 -0
  86. data/test/klarna/api/errors_test.rb +34 -0
  87. data/test/klarna/api/methods/cost_calculations_test.rb +78 -0
  88. data/test/klarna/api/methods/invoicing_test.rb +409 -0
  89. data/test/klarna/api/methods/reservation_test.rb +66 -0
  90. data/test/klarna/api/methods/standard_test.rb +244 -0
  91. data/test/klarna/api_test.rb +184 -0
  92. data/test/klarna_test.rb +204 -0
  93. data/test/support/assertions_helper.rb +40 -0
  94. data/test/test_helper.rb +55 -0
  95. metadata +335 -0
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna::API::Errors do
5
+
6
+ describe Klarna::API::Errors::KlarnaStandardError do
7
+ it 'should be defined' do
8
+ assert defined?(::Klarna::API::Errors::KlarnaStandardError)
9
+ end
10
+ end
11
+
12
+ describe Klarna::API::Errors::KlarnaCredentialsError do
13
+ it 'should be defined' do
14
+ assert defined?(::Klarna::API::Errors::KlarnaCredentialsError)
15
+ end
16
+ end
17
+
18
+ describe Klarna::API::Errors::KlarnaServiceError do
19
+ it 'should be defined' do
20
+ assert defined?(::Klarna::API::Errors::KlarnaServiceError)
21
+ end
22
+ end
23
+
24
+ describe ".error_message" do
25
+ it "should return correct error key from a ID" do
26
+ assert_equal :no_such_subscription, ::Klarna::API::Errors.error_message(7101)
27
+ end
28
+
29
+ it "should return correct error key from a key" do
30
+ assert_equal :no_such_subscription, ::Klarna::API::Errors.error_message(:no_such_subscription)
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna::API::Methods::CostCalculations 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/monthly-cost-functions/functions/fetchpclasses
19
+ describe '#fetch_pclasses' do
20
+ it 'should be defined' do
21
+ assert_respond_to @client, :fetch_pclasses
22
+ end
23
+ end
24
+
25
+ # Spec: http://integration.klarna.com/en/api/monthly-cost-functions/functions/calcmonthlycost
26
+ describe '#calculate_monthly_cost' do
27
+ it 'should be defined' do
28
+ assert_respond_to @client, :calculate_monthly_cost
29
+ end
30
+ end
31
+
32
+ describe '#periodic_cost' do
33
+ it 'should be defined' do
34
+ assert_respond_to @client, :periodic_cost
35
+ end
36
+ end
37
+
38
+ describe '#monthly_cost' do
39
+ it 'should be defined' do
40
+ assert_respond_to @client, :monthly_cost
41
+ end
42
+ end
43
+
44
+ describe 'protected/private methods' do
45
+
46
+ describe '#calculate_interest_cost' do
47
+ it 'should be defined' do
48
+ assert_respond_to @client, :calculate_interest_cost
49
+ end
50
+ end
51
+
52
+ describe '#calculate_monthly_payment' do
53
+ it 'should be defined' do
54
+ assert_respond_to @client, :calculate_monthly_payment
55
+ end
56
+ end
57
+
58
+ describe '#calculate_daily_rate' do
59
+ it 'should be defined' do
60
+ assert_respond_to @client, :calculate_daily_rate
61
+ end
62
+ end
63
+
64
+ describe '#get_denominator' do
65
+ it 'should be defined' do
66
+ assert_respond_to @client, :get_denominator
67
+ end
68
+ end
69
+
70
+ describe '#round_up' do
71
+ it 'should be defined' do
72
+ assert_respond_to @client, :round_up
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,409 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ describe Klarna::API::Methods::Invoicing do
5
+
6
+ # TODO: Mock responses using VCR.
7
+
8
+ INVALID_ORDER_NO = '12312312312312312'
9
+
10
+ before do
11
+ valid_credentials!
12
+ @klarna = Klarna::API::Client.new
13
+ @klarna.client_ip = '85.230.98.196'
14
+
15
+ @protocol_version = ::Klarna::API::PROTOCOL_VERSION.to_s
16
+ @user_agent = ::XMLRPC::Client::USER_AGENT.to_s
17
+
18
+ expose_protected_methods_in @klarna.class
19
+
20
+ @order_items = []
21
+ @order_items << @klarna.make_goods(1, 'ABC1', "T-shirt 1", 1.00 * 100, 25, 0, :INC_VAT => true)
22
+ @order_items << @klarna.make_goods(3, 'ABC2', "T-shirt 2", 7.00 * 100, 25, 0, :INC_VAT => true)
23
+ @order_items << @klarna.make_goods(7, 'ABC3', "T-shirt 3", 17.00 * 100, 25, 0, :INC_VAT => true)
24
+ @order_items_total = (1 * (1.00 * 100) + 3 * (7.00 * 100) + 7 * (17.00 * 100)).to_i
25
+
26
+ @address_SE = @klarna.make_address("c/o Lidin", "Junibackg. 42", "23634", "Höllviken", :SE, "076 526 00 00", "076 526 00 00", "karl.lidin@klarna.com")
27
+
28
+ @valid_invoice_args_SE =
29
+ ['USER-4304158399', 'ORDER-1', @order_items, 0, 0, :NORMAL, '4304158399', 'Karl', 'Lidin', @address_SE, '85.230.98.196', :SEK, :SE, :SV, :SE, nil, nil, nil, nil, nil, nil, nil, 2]
30
+ end
31
+
32
+ # Spec: http://integration.klarna.com/en/api/standard-integration/functions/addtransaction
33
+ describe '#add_invoice' do
34
+ it 'should be defined' do
35
+ assert_respond_to @klarna, :add_transaction
36
+ end
37
+
38
+ describe "SE" do
39
+ it 'should create order successfully with valid arguments' do
40
+ invoice_no = @klarna.add_transaction(
41
+ 'USER-4304158399', 'ORDER-1', @order_items, 0, 0, ::Klarna::API::SHIPMENT_TYPES[:NORMAL], '4304158399', 'Karl', 'Lidin', @address_SE, '85.230.98.196', ::Klarna::API::CURRENCIES[:SEK], ::Klarna::API::COUNTRIES[:SE], ::Klarna::API::LANGUAGES[:SV], ::Klarna::API::PNO_FORMATS[:SE])
42
+
43
+ assert_match /^\d+$/, invoice_no
44
+ end
45
+
46
+ it 'should accept shortcut arguments for: shipment_type, currency, country, language, pno_encoding' do
47
+ invoice_no = @klarna.add_invoice(
48
+ 'USER-4304158399', 'ORDER-1', @order_items, 0, 0, :NORMAL, '4304158399', 'Karl', 'Lidin', @address_SE, '85.230.98.196', :SEK, :SE, :SV, :SE)
49
+
50
+ assert_match /^\d+$/, invoice_no
51
+ end
52
+ end
53
+ end
54
+
55
+ # NOTE: active_invoice don't seem to work with the Klarna 2.0 backend currently, raises "invoice_in_test_mode" (which it didn't before).
56
+
57
+ # Spec:
58
+ # http://integration.klarna.com/en/api/standard-integration/functions/activateinvoice
59
+ # http://integration.klarna.com/en/api/standard-integration/functions/activatepart (combined)
60
+ describe '#activate_invoice' do
61
+ it 'should be defined' do
62
+ assert_respond_to @klarna, :activate_invoice
63
+ end
64
+
65
+ describe 'full' do
66
+ it 'should raise error for when trying to activate an non-existing invoice' do
67
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
68
+ @klarna.activate_invoice(INVALID_ORDER_NO)
69
+ end
70
+ end
71
+
72
+ it 'should successfully activate an existing invoice' # do
73
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
74
+ #
75
+ # assert_equal "#{@klarna.endpoint_uri}/temp/#{invoice_no}.pdf", @klarna.activate_invoice(invoice_no)
76
+ # end
77
+ end
78
+
79
+ describe 'partial' do
80
+ it 'should raise error for when trying to activate an non-existing invoice' do
81
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
82
+ activate_articles = [@order_items.first]
83
+ @klarna.activate_invoice(INVALID_ORDER_NO, activate_articles)
84
+ end
85
+ end
86
+
87
+ # FAILS: Klarna API 2.0 don't support this for test-accounts. :(
88
+ it 'should successfully activate an existing partial invoice' # do
89
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
90
+ # activate_articles = [@order_items.first]
91
+ #
92
+ # assert_equal "#{@klarna.endpoint_uri}/temp/#{invoice_no}.pdf", @klarna.activate_invoice(invoice_no, activate_articles)
93
+ # end
94
+ end
95
+ end
96
+
97
+ # Spec:
98
+ # http://integration.klarna.com/en/api/standard-integration/functions/deleteinvoice
99
+ describe '#delete_invoice' do
100
+ it 'should be defined' do
101
+ assert_respond_to @klarna, :delete_invoice
102
+ end
103
+
104
+ it 'should raise error when trying to delete an non-existing invoice' do
105
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
106
+ @klarna.delete_invoice(INVALID_ORDER_NO)
107
+ end
108
+ end
109
+
110
+ it 'should successfully delete an existing invoice' do
111
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
112
+
113
+ assert_equal 'ok', @klarna.delete_invoice(invoice_no)
114
+ end
115
+ end
116
+
117
+ # Spec:
118
+ # http://integration.klarna.com/en/api/invoice-handling-functions/functions/returnamount
119
+ describe '#return_amount' do
120
+ it 'should be defined' do
121
+ assert_respond_to @klarna, :return_amount
122
+ end
123
+
124
+ it 'should raise error for non-existing invoice' do
125
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
126
+ amount = 100
127
+ vat = 25
128
+ @klarna.return_amount(INVALID_ORDER_NO, amount, vat)
129
+ end
130
+ end
131
+
132
+ it 'should raise error for existing but un-activated invoice' do
133
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
134
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
135
+ amount = 100
136
+ vat = 25
137
+
138
+ assert_equal invoice_no, @klarna.return_amount(invoice_no, amount, vat)
139
+ end
140
+ end
141
+
142
+ # FAILS: Klarna API 2.0 don't support this for test-accounts. :(
143
+ it 'should successfully return amount for an activated invoice' # do
144
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
145
+ # amount = 100
146
+ # vat = 25
147
+ #
148
+ # assert_equal invoice_no, @klarna.credit_invoice(invoice_no, credit_no)
149
+ # end
150
+ end
151
+
152
+ # Spec:
153
+ # http://integration.klarna.com/en/api/invoice-handling-functions/functions/returnamount
154
+ describe '#credit_invoice' do
155
+ it 'should be defined' do
156
+ assert_respond_to @klarna, :credit_invoice
157
+ end
158
+
159
+ describe 'full' do
160
+ it 'should raise error for non-existing invoice' do
161
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
162
+ credit_no = ''
163
+ @klarna.credit_invoice(INVALID_ORDER_NO, credit_no)
164
+ end
165
+ end
166
+
167
+ it 'should raise error for existing but un-activated invoice' do
168
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
169
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
170
+ credit_no = ''
171
+ @klarna.credit_invoice(invoice_no, credit_no)
172
+ end
173
+ end
174
+
175
+ # FAILS: Klarna API 2.0 don't support this for test-accounts. :(
176
+ it 'should successfully credit an activated invoice' # do
177
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
178
+ # invoice_url = @klarna.activate_invoice(invoice_no)
179
+ # credit_no = ''
180
+ #
181
+ # assert_equal invoice_no, @klarna.credit_invoice(invoice_no, credit_no)
182
+ # end
183
+ end
184
+
185
+ describe 'partial' do
186
+ it 'should raise error for existing but un-activated invoice' do
187
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
188
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
189
+ refund_articles = [@order_items.first]
190
+ credit_no = ''
191
+ @klarna.credit_invoice(invoice_no, credit_no, refund_articles)
192
+ end
193
+ end
194
+
195
+ it 'should successfully credit an activated invoice' # do
196
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
197
+ # invoice_url = @klarna.activate_invoice(invoice_no)
198
+ # refund_articles = [@order_items.first]
199
+ # credit_no = ''
200
+ #
201
+ # assert_equal invoice_no, @klarna.credit_invoice(invoice_no, credit_no, refund_articles)
202
+ # end
203
+ end
204
+ end
205
+
206
+ # Spec:
207
+ # http://integration.klarna.com/en/api/invoice-handling-functions/functions/emailinvoice
208
+ describe '#email_invoice' do
209
+ it 'should be defined' do
210
+ assert_respond_to @klarna, :email_invoice
211
+ end
212
+
213
+ it 'should raise error for e-mail request of an existing but un-activated invoice' do
214
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
215
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
216
+ @klarna.email_invoice(invoice_no)
217
+ end
218
+ end
219
+
220
+ # FAILS: Klarna API 2.0 don't support this for test-accounts. :(
221
+ it 'should successfully accept email request of an activated invoice' # do
222
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
223
+ # invoice_url = @klarna.activate_invoice(invoice_no)
224
+ #
225
+ # assert_equal invoice_no, @klarna.email_invoice(invoice_no)
226
+ # end
227
+ end
228
+
229
+ # Spec:
230
+ # http://integration.klarna.com/en/api/invoice-handling-functions/functions/sendinvoice
231
+ describe '#send_invoice' do
232
+ it 'should be defined' do
233
+ assert_respond_to @klarna, :send_invoice
234
+ end
235
+
236
+ it 'should raise error for snail-mail request of an existing but un-activated invoice' do
237
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
238
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
239
+ @klarna.send_invoice(invoice_no)
240
+ end
241
+ end
242
+
243
+ # FAILS: Klarna API 2.0 don't support this for test-accounts. :(
244
+ it 'should successfully accept snail-mail request of an activated invoice' # do
245
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
246
+ # invoice_url = @klarna.activate_invoice(invoice_no)
247
+ #
248
+ # assert_equal invoice_no, @klarna.send_invoice(invoice_no)
249
+ # end
250
+ end
251
+
252
+ # Spec:
253
+ # http://integration.klarna.com/en/api/invoice-handling-functions/functions/mkartno
254
+ describe '#make_article' do
255
+ it 'should be defined' do
256
+ assert_respond_to @klarna, :make_article
257
+ end
258
+
259
+ it 'should generate valid article structure' do
260
+ assert_equal [5, '12345'], @klarna.make_article(5, 12345)
261
+ assert_equal [5, '12345'], @klarna.make_article(5, '12345')
262
+ end
263
+ end
264
+
265
+ # Spec:
266
+ # http://integration.klarna.com/en/api/other-functions/functions/updategoodsqty
267
+ describe '#update_goods_quantity' do
268
+ it 'should be defined' do
269
+ assert_respond_to @klarna, :update_goods_quantity
270
+ end
271
+
272
+ it 'should raise error for an non-existing invoice' do
273
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
274
+ @klarna.update_goods_quantity(INVALID_ORDER_NO, 'ABC1', 10)
275
+ end
276
+ end
277
+
278
+ it 'should raise error for an non-existing article-no for an existing invoice' do
279
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
280
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
281
+
282
+ @klarna.update_goods_quantity(invoice_no, 'XXX', 10)
283
+ end
284
+ end
285
+
286
+ it 'should successfully update goods quantity for an existing invoice and valid article-no' do
287
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
288
+
289
+ assert_equal invoice_no, @klarna.update_goods_quantity(invoice_no, 'ABC1', 10)
290
+ end
291
+ end
292
+
293
+ # Spec:
294
+ # http://integration.klarna.com/en/api/other-functions/functions/updatechargeamount
295
+ describe '#update_charge_amount' do
296
+ it 'should be defined' do
297
+ assert_respond_to @klarna, :update_charge_amount
298
+ end
299
+
300
+ it 'should raise error for an non-existing invoice' do
301
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
302
+ @klarna.update_charge_amount(INVALID_ORDER_NO, 1, 10.00 * 100)
303
+ end
304
+ end
305
+
306
+ it 'should successfully update shipment fee for an existing invoice'
307
+
308
+ it 'should successfully update handling fee for an existing invoice'
309
+ end
310
+
311
+ # Spec: http://integration.klarna.com/en/api/other-functions/functions/updateorderno
312
+ describe '#update_order_no' do
313
+ it 'should be defined' do
314
+ assert_respond_to @klarna, :update_order_no
315
+ end
316
+
317
+ it 'should raise error for an non-existing invoice' do
318
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
319
+ @klarna.update_order_no(INVALID_ORDER_NO, '123')
320
+ end
321
+ end
322
+
323
+ # FIXME: Throws "invno"-error - don't know why. :S
324
+ it 'should successfully update order-no for an existing invoice' # do
325
+ # invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
326
+ # new_invoice_no = (invoice_no.to_i + 1).to_s
327
+
328
+ # assert_equal new_invoice_no, @klarna.update_order_no(invoice_no, new_invoice_no)
329
+ # end
330
+ end
331
+
332
+ # Spec:
333
+ # http://integration.klarna.com/en/api/other-functions/functions/invoiceaddress
334
+ describe '#invoice_address' do
335
+ it 'should be defined' do
336
+ assert_respond_to @klarna, :invoice_address
337
+ end
338
+
339
+ it 'should raise error for an non-existing invoice' do
340
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
341
+ @klarna.invoice_address(INVALID_ORDER_NO)
342
+ end
343
+ end
344
+
345
+ it 'should successfully return the address for an existing invoice' do
346
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
347
+
348
+ assert_equal ["Karl", "Lidin", "Junibacksg 42", "23634", "Hollviken", 'SE'], @klarna.invoice_address(invoice_no)
349
+ end
350
+ end
351
+
352
+ # Spec:
353
+ # http://integration.klarna.com/en/api/other-functions/functions/invoiceamount
354
+ # http://integration.klarna.com/en/api/other-functions/functions/invoicepartamount (combined)
355
+ describe '#invoice_amount' do
356
+ it 'should be defined' do
357
+ assert_respond_to @klarna, :invoice_amount
358
+ end
359
+
360
+ describe 'full' do
361
+ it 'should raise error for an non-existing invoice' do
362
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
363
+ @klarna.invoice_amount(INVALID_ORDER_NO)
364
+ end
365
+ end
366
+
367
+ it 'should successfully return the invoice amount for an existing invoice' do
368
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
369
+
370
+ assert_equal @order_items_total, @klarna.invoice_amount(invoice_no)
371
+ end
372
+ end
373
+
374
+ describe 'partial' do
375
+ it 'should raise error for an non-existing invoice' do
376
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
377
+ articles = [@order_items.last]
378
+ @klarna.invoice_amount(INVALID_ORDER_NO, articles)
379
+ end
380
+ end
381
+
382
+ it 'should successfully return the invoice amount for an existing invoice' do
383
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
384
+ articles = [@order_items.last]
385
+
386
+ assert_equal 7*(17.00 * 100), @klarna.invoice_amount(invoice_no, articles)
387
+ end
388
+ end
389
+ end
390
+
391
+ describe '#invoice_paid?' do
392
+ it 'should be defined' do
393
+ assert_respond_to @klarna, :invoice_paid?
394
+ end
395
+
396
+ it 'should raise error for an non-existing invoice' do
397
+ assert_raises ::Klarna::API::Errors::KlarnaServiceError do
398
+ @klarna.invoice_paid?(INVALID_ORDER_NO)
399
+ end
400
+ end
401
+
402
+ it 'should be unpaid for an existing but un-activated invoice' do
403
+ invoice_no = @klarna.add_invoice(*@valid_invoice_args_SE)
404
+
405
+ assert_equal false, @klarna.invoice_paid?(invoice_no)
406
+ end
407
+ end
408
+
409
+ end