klarna 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +9 -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 +175 -0
  70. data/lib/klarna/api.rb +170 -0
  71. data/lib/klarna/api/client.rb +128 -0
  72. data/lib/klarna/api/constants.rb +638 -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 +149 -0
  78. data/lib/klarna/api/methods/standard.rb +123 -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 +272 -0
  86. data/test/klarna/api/errors_test.rb +46 -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 +137 -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 +312 -0
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require 'active_support/test_case'
3
+
4
+ module Klarna
5
+ module AssertionsHelper
6
+ def assert_not(assertion)
7
+ assert !assertion
8
+ end
9
+
10
+ def assert_blank(assertion)
11
+ assert assertion.blank?
12
+ end
13
+
14
+ def assert_not_blank(assertion)
15
+ assert !assertion.blank?
16
+ end
17
+ alias :assert_present :assert_not_blank
18
+
19
+ # Execute the block setting the given values and restoring old values after
20
+ # the block is executed.
21
+ def swap(object, new_values)
22
+ old_values = {}
23
+ new_values.each do |key, value|
24
+ old_values[key] = object.send key
25
+ object.send :"#{key}=", value
26
+ end
27
+ yield
28
+ ensure
29
+ old_values.each do |key, value|
30
+ object.send :"#{key}=", value
31
+ end
32
+ end
33
+
34
+ def expose_protected_methods_in(*args)
35
+ args.each do |klass|
36
+ klass.send(:public, *[klass.protected_instance_methods, klass.private_instance_methods].flatten)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ require 'mocha' # REVIEW: Had to place this before MiniTest - if placed after ~100 failing specs. :S
5
+ require 'minitest/unit'
6
+ require 'minitest/spec'
7
+ require 'minitest/pride'
8
+ require 'minitest/autorun'
9
+
10
+ require 'klarna'
11
+
12
+ Dir[File.join(File.dirname(__FILE__), *%w[support ** *.rb]).to_s].each { |f| require f }
13
+
14
+ MiniTest::Unit::TestCase.class_eval do
15
+ include Klarna::AssertionsHelper
16
+ end
17
+
18
+ # For now Travis CI don't support multiple ENV-variables per testrun, so need this.
19
+ KLARNA_ESTORE_ID, KLARNA_ESTORE_SECRET = ENV['KLARNA_ESTORE'].to_s.split(',')
20
+
21
+ VALID_STORE_ID = ENV['KLARNA_ESTORE_ID'].presence || KLARNA_ESTORE_ID
22
+ VALID_STORE_SECRET = ENV['KLARNA_ESTORE_SECRET'].presence || KLARNA_ESTORE_SECRET
23
+ VALID_COUNTRY = :SE
24
+
25
+ Klarna.store_config_file = File.join(File.dirname(__FILE__), 'fixtures', 'klarna.yml')
26
+
27
+ FIXTURES_FILES = {
28
+ :persons => File.join(File.dirname(__FILE__), 'fixtures', 'api', 'persons.yml'),
29
+ :companies => File.join(File.dirname(__FILE__), 'fixtures', 'api', 'companies.yml'),
30
+ :stores => File.join(File.dirname(__FILE__), 'fixtures', 'api', 'stores.yml')
31
+ }
32
+
33
+ @@fixtures = {}
34
+ FIXTURES_FILES.each do |fixture_key, fixture_file_path|
35
+ @@fixtures[fixture_key] = File.open(fixture_file_path) { |file| YAML.load(file).with_indifferent_access }
36
+ end
37
+ @@fixtures = @@fixtures.with_indifferent_access
38
+
39
+ def fixture(model)
40
+ @@fixtures[model]
41
+ end
42
+
43
+ def valid_credentials!
44
+ Klarna.setup do |c|
45
+ c.store_id = VALID_STORE_ID.to_i
46
+ c.store_secret = VALID_STORE_SECRET
47
+ c.country = VALID_COUNTRY
48
+ c.mode = ENV['KLARNA_MODE'].presence || :test
49
+ c.http_logging = (ENV['KLARNA_DEBUG'].to_s =~ /(true|1)/) || false
50
+ end
51
+ end
52
+
53
+ def digest(*args)
54
+ Klarna::API::Client.digest(*args)
55
+ end
metadata ADDED
@@ -0,0 +1,312 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: klarna
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.3
6
+ platform: ruby
7
+ authors:
8
+ - Jonas Grimfelt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-16 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activesupport
18
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ requirement: *id001
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ requirement: *id002
36
+ prerelease: false
37
+ type: :runtime
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirement: *id003
47
+ prerelease: false
48
+ type: :development
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ version_requirements: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ requirement: *id004
58
+ prerelease: false
59
+ type: :development
60
+ - !ruby/object:Gem::Dependency
61
+ name: rdoc
62
+ version_requirements: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ requirement: *id005
69
+ prerelease: false
70
+ type: :development
71
+ - !ruby/object:Gem::Dependency
72
+ name: minitest
73
+ version_requirements: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ requirement: *id006
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ name: mocha
84
+ version_requirements: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ requirement: *id007
91
+ prerelease: false
92
+ type: :development
93
+ - !ruby/object:Gem::Dependency
94
+ name: guard
95
+ version_requirements: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ requirement: *id008
102
+ prerelease: false
103
+ type: :development
104
+ - !ruby/object:Gem::Dependency
105
+ name: guard-bundler
106
+ version_requirements: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ requirement: *id009
113
+ prerelease: false
114
+ type: :development
115
+ - !ruby/object:Gem::Dependency
116
+ name: guard-minitest
117
+ version_requirements: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ requirement: *id010
124
+ prerelease: false
125
+ type: :development
126
+ - !ruby/object:Gem::Dependency
127
+ name: sinatra
128
+ version_requirements: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ requirement: *id011
135
+ prerelease: false
136
+ type: :development
137
+ - !ruby/object:Gem::Dependency
138
+ name: sinatra-mapping
139
+ version_requirements: &id012 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ requirement: *id012
146
+ prerelease: false
147
+ type: :development
148
+ - !ruby/object:Gem::Dependency
149
+ name: haml
150
+ version_requirements: &id013 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: "0"
156
+ requirement: *id013
157
+ prerelease: false
158
+ type: :development
159
+ description: A Ruby wrapper for Klarna/Kreditor XML-RPC API.
160
+ email:
161
+ - jonas@merchii.com
162
+ executables: []
163
+
164
+ extensions: []
165
+
166
+ extra_rdoc_files: []
167
+
168
+ files:
169
+ - .gitignore
170
+ - .travis.yml
171
+ - Gemfile
172
+ - Guardfile
173
+ - MIT-LICENSE
174
+ - README.textile
175
+ - Rakefile
176
+ - TODO
177
+ - examples/Gemfile
178
+ - examples/config/initializer.rb
179
+ - examples/console.rb
180
+ - examples/public/images/klarna.png
181
+ - examples/public/images/ruby.png
182
+ - examples/views/_address.haml
183
+ - examples/views/_articles.haml
184
+ - examples/views/checkout_page_example.haml
185
+ - examples/views/essential/add_transaction/_form.haml
186
+ - examples/views/essential/add_transaction/result.haml
187
+ - examples/views/essential/calculate_monthly_cost/_form.haml
188
+ - examples/views/essential/calculate_monthly_cost/result.haml
189
+ - examples/views/essential/get_addresses/_form.haml
190
+ - examples/views/essential/get_addresses/result.haml
191
+ - examples/views/index.haml
192
+ - examples/views/layout.haml
193
+ - examples/views/payment_terms_example.haml
194
+ - examples/views/product_page_example.haml
195
+ - examples/views/reservation/activate_reservation/_form.haml
196
+ - examples/views/reservation/activate_reservation/result.haml
197
+ - examples/views/reservation/cancel_reservation/_form.haml
198
+ - examples/views/reservation/cancel_reservation/result.haml
199
+ - examples/views/reservation/change_reservation/_form.haml
200
+ - examples/views/reservation/change_reservation/result.haml
201
+ - examples/views/reservation/reserve_amount/_form.haml
202
+ - examples/views/reservation/reserve_amount/result.haml
203
+ - examples/views/reservation/reserve_ocr_numbers/_form.haml
204
+ - examples/views/reservation/reserve_ocr_numbers/result.haml
205
+ - examples/views/reservation/split_reservation/_form.haml
206
+ - examples/views/reservation/split_reservation/result.haml
207
+ - examples/views/special/get_pclasses/_form.haml
208
+ - examples/views/special/get_pclasses/result.haml
209
+ - examples/views/special/invoice_address/_form.haml
210
+ - examples/views/special/invoice_address/result.haml
211
+ - examples/views/special/invoice_amount/_form.haml
212
+ - examples/views/special/invoice_amount/result.haml
213
+ - examples/views/special/is_invoice_paid/_form.haml
214
+ - examples/views/special/is_invoice_paid/result.haml
215
+ - examples/views/special/update_charge_amount/_form.haml
216
+ - examples/views/special/update_charge_amount/result.haml
217
+ - examples/views/special/update_goods_quantity/_form.haml
218
+ - examples/views/special/update_goods_quantity/result.haml
219
+ - examples/views/special/update_order_number/_form.haml
220
+ - examples/views/special/update_order_number/result.haml
221
+ - examples/views/useful/activate_invoice/_form.haml
222
+ - examples/views/useful/activate_invoice/result.haml
223
+ - examples/views/useful/credit_invoice/_form.haml
224
+ - examples/views/useful/credit_invoice/result.haml
225
+ - examples/views/useful/delete_invoice/_form.haml
226
+ - examples/views/useful/delete_invoice/result.haml
227
+ - examples/views/useful/email_invoice/_form.haml
228
+ - examples/views/useful/email_invoice/result.haml
229
+ - examples/views/useful/has_account/_form.haml
230
+ - examples/views/useful/has_account/result.haml
231
+ - examples/views/useful/return_amount/_form.haml
232
+ - examples/views/useful/return_amount/result.haml
233
+ - examples/views/useful/send_invoice/_form.haml
234
+ - examples/views/useful/send_invoice/result.haml
235
+ - examples/web.rb
236
+ - klarna.gemspec
237
+ - lib/klarna.rb
238
+ - lib/klarna/api.rb
239
+ - lib/klarna/api/client.rb
240
+ - lib/klarna/api/constants.rb
241
+ - lib/klarna/api/errors.rb
242
+ - lib/klarna/api/methods.rb
243
+ - lib/klarna/api/methods/cost_calculations.rb
244
+ - lib/klarna/api/methods/invoicing.rb
245
+ - lib/klarna/api/methods/reservation.rb
246
+ - lib/klarna/api/methods/standard.rb
247
+ - lib/klarna/version.rb
248
+ - test/fixtures/api/companies.yml
249
+ - test/fixtures/api/pclasses.yml
250
+ - test/fixtures/api/persons.yml
251
+ - test/fixtures/api/stores.yml
252
+ - test/fixtures/klarna.yml
253
+ - test/klarna/api/client_test.rb
254
+ - test/klarna/api/errors_test.rb
255
+ - test/klarna/api/methods/cost_calculations_test.rb
256
+ - test/klarna/api/methods/invoicing_test.rb
257
+ - test/klarna/api/methods/reservation_test.rb
258
+ - test/klarna/api/methods/standard_test.rb
259
+ - test/klarna/api_test.rb
260
+ - test/klarna_test.rb
261
+ - test/support/assertions_helper.rb
262
+ - test/test_helper.rb
263
+ has_rdoc: true
264
+ homepage: http://github.com/merchii/klarna
265
+ licenses: []
266
+
267
+ post_install_message:
268
+ rdoc_options: []
269
+
270
+ require_paths:
271
+ - lib
272
+ required_ruby_version: !ruby/object:Gem::Requirement
273
+ none: false
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ hash: 2
278
+ segments:
279
+ - 0
280
+ version: "0"
281
+ required_rubygems_version: !ruby/object:Gem::Requirement
282
+ none: false
283
+ requirements:
284
+ - - ">="
285
+ - !ruby/object:Gem::Version
286
+ hash: 2
287
+ segments:
288
+ - 0
289
+ version: "0"
290
+ requirements: []
291
+
292
+ rubyforge_project:
293
+ rubygems_version: 1.5.1
294
+ signing_key:
295
+ specification_version: 3
296
+ summary: A Ruby wrapper for Klarna/Kreditor XML-RPC API.
297
+ test_files:
298
+ - test/fixtures/api/companies.yml
299
+ - test/fixtures/api/pclasses.yml
300
+ - test/fixtures/api/persons.yml
301
+ - test/fixtures/api/stores.yml
302
+ - test/fixtures/klarna.yml
303
+ - test/klarna/api/client_test.rb
304
+ - test/klarna/api/errors_test.rb
305
+ - test/klarna/api/methods/cost_calculations_test.rb
306
+ - test/klarna/api/methods/invoicing_test.rb
307
+ - test/klarna/api/methods/reservation_test.rb
308
+ - test/klarna/api/methods/standard_test.rb
309
+ - test/klarna/api_test.rb
310
+ - test/klarna_test.rb
311
+ - test/support/assertions_helper.rb
312
+ - test/test_helper.rb