killbill 1.0.15 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/Jarfile +4 -2
  2. data/VERSION +1 -1
  3. data/lib/killbill.rb +69 -13
  4. data/lib/killbill/creator.rb +16 -2
  5. data/lib/killbill/enum.rb +72 -0
  6. data/lib/killbill/gen/account.rb +43 -0
  7. data/lib/killbill/gen/account_data.rb +39 -0
  8. data/lib/killbill/gen/account_email.rb +25 -0
  9. data/lib/killbill/gen/audit_log.rb +28 -0
  10. data/lib/killbill/gen/blocking_state.rb +32 -0
  11. data/lib/killbill/gen/call_context.rb +29 -0
  12. data/lib/killbill/gen/call_origin.rb +34 -0
  13. data/lib/killbill/gen/currency.rb +34 -0
  14. data/lib/killbill/gen/custom_field.rb +27 -0
  15. data/lib/killbill/gen/date_time_zone.rb +35 -0
  16. data/lib/killbill/gen/ext_bus_event.rb +25 -0
  17. data/lib/killbill/gen/ext_bus_event_type.rb +34 -0
  18. data/lib/killbill/gen/invoice.rb +39 -0
  19. data/lib/killbill/gen/invoice_item.rb +37 -0
  20. data/lib/killbill/gen/invoice_payment.rb +31 -0
  21. data/lib/killbill/gen/invoice_payment_type.rb +34 -0
  22. data/lib/killbill/gen/object_type.rb +34 -0
  23. data/lib/killbill/gen/payment.rb +36 -0
  24. data/lib/killbill/gen/payment_attempt.rb +27 -0
  25. data/lib/killbill/gen/payment_info_plugin.rb +28 -0
  26. data/lib/killbill/gen/payment_method_info_plugin.rb +24 -0
  27. data/lib/killbill/gen/payment_method_kv_info.rb +21 -0
  28. data/lib/killbill/gen/payment_method_plugin.rb +36 -0
  29. data/lib/killbill/gen/payment_plugin_status.rb +34 -0
  30. data/lib/killbill/gen/refund.rb +29 -0
  31. data/lib/killbill/gen/refund_info_plugin.rb +27 -0
  32. data/lib/killbill/gen/refund_plugin_status.rb +34 -0
  33. data/lib/killbill/gen/require_gen.rb +38 -0
  34. data/lib/killbill/gen/subscription.rb +44 -0
  35. data/lib/killbill/gen/subscription_bundle.rb +27 -0
  36. data/lib/killbill/gen/subscription_source_type.rb +34 -0
  37. data/lib/killbill/gen/subscription_state.rb +34 -0
  38. data/lib/killbill/gen/tag.rb +26 -0
  39. data/lib/killbill/gen/tag_definition.rb +27 -0
  40. data/lib/killbill/gen/tenant_context.rb +21 -0
  41. data/lib/killbill/gen/user_type.rb +34 -0
  42. data/lib/killbill/gen/uuid.rb +22 -0
  43. data/lib/killbill/http_servlet.rb +10 -3
  44. data/lib/killbill/jconverter.rb +540 -0
  45. data/lib/killbill/jkillbill_api.rb +137 -0
  46. data/lib/killbill/jnotification.rb +0 -1
  47. data/lib/killbill/jpayment.rb +7 -19
  48. data/lib/killbill/jplugin.rb +27 -16
  49. data/lib/killbill/killbill_api.rb +28 -0
  50. data/lib/killbill/killbill_logger.rb +31 -8
  51. data/lib/killbill/notification.rb +0 -1
  52. data/lib/killbill/payment.rb +0 -5
  53. data/lib/killbill/plugin.rb +4 -46
  54. data/spec/killbill/base_plugin_spec.rb +2 -1
  55. data/spec/killbill/{jresponse/jconverter_spec.rb → jconverter_spec.rb} +46 -90
  56. data/spec/killbill/jnotification_spec.rb +2 -1
  57. data/spec/killbill/jpayment_spec.rb +17 -16
  58. data/spec/killbill/killbill_integration_spec.rb +1 -1
  59. data/spec/killbill/killbillapi_spec.rb +49 -0
  60. data/spec/killbill/payment_test.rb +5 -5
  61. data/spec/killbill/rack_handler_spec.rb +1 -2
  62. data/spec/spec_helper.rb +3 -0
  63. data/tools/java2ruby.rb +440 -0
  64. metadata +48 -26
  65. data/lib/killbill/jresponse/jconverter.rb +0 -126
  66. data/lib/killbill/jresponse/jevent.rb +0 -58
  67. data/lib/killbill/jresponse/jpayment_method_response.rb +0 -148
  68. data/lib/killbill/jresponse/jpayment_method_response_internal.rb +0 -54
  69. data/lib/killbill/jresponse/jpayment_response.rb +0 -74
  70. data/lib/killbill/jresponse/jrefund_response.rb +0 -68
  71. data/lib/killbill/response/event.rb +0 -18
  72. data/lib/killbill/response/payment_method_response.rb +0 -50
  73. data/lib/killbill/response/payment_method_response_internal.rb +0 -20
  74. data/lib/killbill/response/payment_response.rb +0 -26
  75. data/lib/killbill/response/payment_status.rb +0 -10
  76. data/lib/killbill/response/refund_response.rb +0 -25
  77. data/spec/killbill/jresponse/jevent_spec.rb +0 -18
  78. data/spec/killbill/jresponse/jpayment_method_response_internal_spec.rb +0 -34
  79. data/spec/killbill/jresponse/jpayment_method_response_spec.rb +0 -53
  80. data/spec/killbill/jresponse/jpayment_response_spec.rb +0 -41
  81. data/spec/killbill/jresponse/jrefund_response_spec.rb +0 -41
@@ -0,0 +1,34 @@
1
+
2
+ #
3
+ # Ruby classes automatically generated from java classes-- don't edit
4
+ #
5
+ module Killbill
6
+ module Plugin
7
+ module Model
8
+
9
+ class UserType
10
+
11
+ @@admissible_values = [:SYSTEM, :ADMIN, :CUSTOMER, :MIGRATION, :TEST]
12
+ attr_reader :enum
13
+
14
+ def initialize(value)
15
+ raise ArgumentError.new("Enum UserType does not have such value : #{value}") if ! UserType.is_admissible_value?(value)
16
+ @enum = value
17
+ end
18
+
19
+ def ==(other)
20
+ return false if other.nil?
21
+ self.enum == other.enum
22
+ end
23
+
24
+ def self.is_admissible_value?(value)
25
+ @@admissible_values.include?(value)
26
+ end
27
+
28
+ def self.admissible_values
29
+ @@admissible_values
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # TODO STEPH Should have been generated--- but not yet
3
+ #
4
+ module Killbill
5
+ module Plugin
6
+ module Model
7
+
8
+ class UUID
9
+
10
+ attr_reader :uuid
11
+
12
+ def initialize(uuid)
13
+ @uuid = uuid
14
+ end
15
+
16
+ def to_s
17
+ @uuid.to_s
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -15,6 +15,10 @@ module Killbill
15
15
  @app = Rack::Builder.parse_file(config_ru).first
16
16
  end
17
17
 
18
+ def unconfigure
19
+ @app = nil
20
+ end
21
+
18
22
  def configured?
19
23
  !@app.nil?
20
24
  end
@@ -62,14 +66,17 @@ module Killbill
62
66
  end
63
67
 
64
68
  def rack_service(request_uri = '/', method = 'GET', query_string = '', input = '', scheme = 'http', server_name = 'localhost', server_port = 4567, content_type = 'text/plain', content_length = 0, headers = {})
69
+ return 503, {}, [] if @app.nil?
70
+
65
71
  rack_env = {
66
72
  'rack.version' => Rack::VERSION,
67
73
  'rack.multithread' => true,
68
74
  'rack.multiprocess' => false,
69
75
  'rack.input' => input,
70
- # TODO
71
- 'rack.errors' => java::lang::System::err.to_io,
72
- 'rack.logger' => java::lang::System::out.to_io,
76
+ # Don't use java::lang::System::err.to_io here!
77
+ # JRuby ChannelStream's finalize() may close it
78
+ 'rack.errors' => @logger,
79
+ 'rack.logger' => @logger,
73
80
  'rack.url_scheme' => scheme,
74
81
  'REQUEST_METHOD' => method,
75
82
  'SCRIPT_NAME' => '',
@@ -0,0 +1,540 @@
1
+
2
+ require 'date'
3
+
4
+ module Killbill
5
+ module Plugin
6
+
7
+ class JConverter
8
+
9
+ class << self
10
+
11
+ #
12
+ # Convert from ruby -> java
13
+ #
14
+ def to_account(data)
15
+ Killbill::Plugin::Model::Account.new(to_uuid(data.id),
16
+ nil,
17
+ to_joda_date_time(data.created_date),
18
+ to_joda_date_time(data.updated_date),
19
+ to_string(data.external_key),
20
+ to_string(data.name),
21
+ data.first_name_length,
22
+ to_string(data.email),
23
+ data.bill_cycle_day_local,
24
+ to_currency(data.currency),
25
+ to_uuid(data.payment_method_id),
26
+ to_date_time_zone(data.time_zone),
27
+ to_string(data.locale),
28
+ to_string(data.address1),
29
+ to_string(data.address2),
30
+ to_string(data.company_name),
31
+ to_string(data.city),
32
+ to_string(data.state_or_province),
33
+ to_string(data.postal_code),
34
+ to_string(data.country),
35
+ to_string(data.phone),
36
+ to_boolean(data.is_migrated),
37
+ to_boolean(data.is_notified_for_invoices))
38
+ end
39
+
40
+
41
+ def to_account_data(data)
42
+ Killbill::Plugin::Model::AccountData.new(to_string(data.external_key),
43
+ to_string(data.name),
44
+ data.first_name_length,
45
+ to_string(data.email),
46
+ data.bill_cycle_day_local,
47
+ to_currency(data.currency),
48
+ to_uuid(data.payment_method_id),
49
+ to_date_time_zone(data.time_zone),
50
+ to_string(data.locale),
51
+ to_string(data.address1),
52
+ to_string(data.address2),
53
+ to_string(data.company_name),
54
+ to_string(data.city),
55
+ to_string(data.state_or_province),
56
+ to_string(data.postal_code),
57
+ to_string(data.country),
58
+ to_string(data.phone),
59
+ to_boolean(data.is_migrated),
60
+ to_boolean(data.is_notified_for_invoices))
61
+ end
62
+
63
+ def to_payment_info_plugin(payment_response)
64
+ Killbill::Plugin::Model::PaymentInfoPlugin.new(to_big_decimal_with_cents_conversion(payment_response.amount),
65
+ to_joda_date_time(payment_response.created_date),
66
+ to_joda_date_time(payment_response.effective_date),
67
+ to_payment_plugin_status(payment_response.status),
68
+ to_string(payment_response.gateway_error),
69
+ to_string(payment_response.gateway_error_code),
70
+ to_string(payment_response.first_payment_reference_id),
71
+ to_string(payment_response.second_payment_reference_id))
72
+ end
73
+
74
+ def to_refund_info_plugin(refund_response)
75
+ Killbill::Plugin::Model::RefundInfoPlugin.new(to_big_decimal_with_cents_conversion(refund_response.amount),
76
+ to_joda_date_time(refund_response.created_date),
77
+ to_joda_date_time(refund_response.effective_date),
78
+ to_refund_plugin_status(refund_response.status),
79
+ to_string(refund_response.gateway_error),
80
+ to_string(refund_response.gateway_error_code),
81
+ to_string(refund_response.reference_id))
82
+ end
83
+
84
+ def to_payment_method_response(pm)
85
+ props = java.util.ArrayList.new
86
+ pm.properties.each do |p|
87
+ jp = Killbill::Plugin::Model::PaymentMethodKVInfo.new(p.is_updatable, p.key, p.value)
88
+ @props.add(jp)
89
+ end
90
+ Killbill::Plugin::Model::PaymentMethodPlugin.new(to_string(pm.external_payment_method_id),
91
+ to_boolean(pm.is_default_payment_method),
92
+ props,
93
+ nil,
94
+ to_string(pm.type),
95
+ to_string(pm.cc_name),
96
+ to_string(pm.cc_type),
97
+ to_string(pm.cc_expiration_month),
98
+ to_string(pm.cc_expiration_year),
99
+ to_string(pm.cc_last4),
100
+ to_string(pm.address1),
101
+ to_string(pm.address2),
102
+ to_string(pm.city),
103
+ to_string(pm.state),
104
+ to_string(pm.zip),
105
+ to_string(pm.country))
106
+ end
107
+
108
+ def to_payment_method_info_plugin(pm)
109
+ Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(to_uuid(pm.account_id),
110
+ to_uuid(pm.payment_method_id),
111
+ to_boolean(pm.is_default),
112
+ to_string(pm.external_payment_method_id))
113
+ end
114
+
115
+
116
+ def to_uuid(uuid)
117
+ uuid.nil? ? nil : java.util.UUID.fromString(uuid.to_s)
118
+ end
119
+
120
+ def to_joda_date_time(time)
121
+ date_time = (time.kind_of? Time) ? DateTime.parse(time.to_s) : time
122
+ date_time.nil? ? nil : org.joda.time.DateTime.new(date_time.to_s, org.joda.time.DateTimeZone::UTC)
123
+ end
124
+
125
+ def to_string(str)
126
+ str.nil? ? nil : java.lang.String.new(str.to_s)
127
+ end
128
+
129
+
130
+ def to_currency(currency)
131
+ if currency.nil?
132
+ return nil
133
+ end
134
+ if currency.enum == :GBP
135
+ return Java::com.ning.billing.catalog.api.Currency::GBP
136
+ elsif currency.enum == :MXN
137
+ return Java::com.ning.billing.catalog.api.Currency::MXN
138
+ elsif currency.enum == :BRL
139
+ return Java::com.ning.billing.catalog.api.Currency::BRL
140
+ elsif currency.enum == :EUR
141
+ return Java::com.ning.billing.catalog.api.Currency::EUR
142
+ elsif currency.enum == :AUD
143
+ return Java::com.ning.billing.catalog.api.Currency::AUD
144
+ elsif currency.enum == :USD
145
+ return Java::com.ning.billing.catalog.api.Currency::USD
146
+ end
147
+ nil
148
+ end
149
+
150
+
151
+ def to_date_time_zone(date_time_zone)
152
+ if date_time_zone.nil?
153
+ return nil
154
+ end
155
+ if date_time_zone.enum == :UTC
156
+ return org.joda.time.DateTimeZone::UTC
157
+ end
158
+ nil
159
+ end
160
+
161
+
162
+ def to_payment_plugin_status(status)
163
+ if status.enum == :PROCESSED
164
+ Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::PROCESSED
165
+ elsif status.enum == :ERROR
166
+ Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::ERROR
167
+ else
168
+ Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::UNDEFINED
169
+ end
170
+ end
171
+
172
+ def to_refund_plugin_status(status)
173
+ if status.enum == :PROCESSED
174
+ Java::com.ning.billing.payment.plugin.api.RefundPluginStatus::PROCESSED
175
+ elsif status.enum == :ERROR
176
+ Java::com.ning.billing.payment.plugin.api.RefundPluginStatus::ERROR
177
+ else
178
+ Java::com.ning.billing.payment.plugin.api.RefundPluginStatus::UNDEFINED
179
+ end
180
+ end
181
+
182
+ def to_object_type(type)
183
+ if type.enum == :ACCOUNT
184
+ Java::com.ning.billing.ObjectType::ACCOUNT
185
+ elsif type.enum == :ACCOUNT_EMAIL
186
+ Java::com.ning.billing.ObjectType::ACCOUNT_EMAIL
187
+ elsif type.enum == :BLOCKING_STATES
188
+ Java::com.ning.billing.ObjectType::BLOCKING_STATES
189
+ elsif type.enum == :BUNDLE
190
+ Java::com.ning.billing.ObjectType::BUNDLE
191
+ elsif type.enum == :CUSTOM_FIELD
192
+ Java::com.ning.billing.ObjectType::CUSTOM_FIELD
193
+ elsif type.enum == :INVOICE
194
+ Java::com.ning.billing.ObjectType::INVOICE
195
+ elsif type.enum == :PAYMENT
196
+ Java::com.ning.billing.ObjectType::PAYMENT
197
+ elsif type.enum == :INVOICE_ITEM
198
+ Java::com.ning.billing.ObjectType::INVOICE_ITEM
199
+ elsif type.enum == :INVOICE_PAYMENT
200
+ Java::com.ning.billing.ObjectType::INVOICE_PAYMENT
201
+ elsif type.enum == :SUBSCRIPTION
202
+ Java::com.ning.billing.ObjectType::SUBSCRIPTION
203
+ elsif type.enum == :SUBSCRIPTION_EVENT
204
+ Java::com.ning.billing.ObjectType::SUBSCRIPTION_EVENT
205
+ elsif type.enum == :PAYMENT_ATTEMPT
206
+ Java::com.ning.billing.ObjectType::PAYMENT_ATTEMPT
207
+ elsif type.enum == :PAYMENT_METHOD
208
+ Java::com.ning.billing.ObjectType::PAYMENT_METHOD
209
+ elsif type.enum == :REFUND
210
+ Java::com.ning.billing.ObjectType::REFUND
211
+ elsif type.enum == :TAG
212
+ Java::com.ning.billing.ObjectType::TAG
213
+ elsif type.enum == :TAG_DEFINITION
214
+ Java::com.ning.billing.ObjectType::TAG_DEFINITION
215
+ elsif type.enum == :TENANT
216
+ Java::com.ning.billing.ObjectType::TENANT
217
+ else # type.enum == :TENANT_KVS
218
+ Java::com.ning.billing.ObjectType::TENANT_KVS
219
+ end
220
+ end
221
+
222
+ def to_big_decimal_with_cents_conversion(amount_in_cents)
223
+ amount_in_cents.nil? ? java.math.BigDecimal::ZERO : java.math.BigDecimal.new('%.2f' % (amount_in_cents.to_i/100.0))
224
+ end
225
+
226
+ def to_boolean(b)
227
+ b.nil? ? java.lang.Boolean.new(false) : java.lang.Boolean.new(b)
228
+ end
229
+
230
+
231
+ #
232
+ # Convert from java -> ruby
233
+ #
234
+
235
+
236
+ def from_account(data)
237
+ Killbill::Plugin::Model::Account.new(from_uuid(data.id),
238
+ nil,
239
+ #from_blocking_state(data.blocking_state),
240
+ from_joda_date_time(data.created_date),
241
+ from_joda_date_time(data.updated_date),
242
+ from_string(data.external_key),
243
+ from_string(data.name),
244
+ data.first_name_length,
245
+ from_string(data.email),
246
+ data.bill_cycle_day_local,
247
+ from_currency(data.currency),
248
+ from_uuid(data.payment_method_id),
249
+ from_date_time_zone(data.time_zone),
250
+ from_string(data.locale),
251
+ from_string(data.address1),
252
+ from_string(data.address2),
253
+ from_string(data.company_name),
254
+ from_string(data.city),
255
+ from_string(data.state_or_province),
256
+ from_string(data.postal_code),
257
+ from_string(data.country),
258
+ from_string(data.phone),
259
+ from_boolean(data.is_migrated),
260
+ from_boolean(data.is_notified_for_invoices))
261
+ end
262
+
263
+ def from_tag_definition(data)
264
+ Killbill::Plugin::Model::TagDefinition.new(from_uuid(data.id),
265
+ from_joda_date_time(data.created_date),
266
+ from_joda_date_time(data.updated_date),
267
+ from_string(data.name),
268
+ from_string(data.description),
269
+ from_boolean(data.is_control_tag),
270
+ nil)
271
+ end
272
+
273
+ def from_blocking_state(data)
274
+ if data.nil?
275
+ return nil
276
+ end
277
+ end
278
+
279
+
280
+ def from_tenant_context(context)
281
+ return Killbill::Plugin::Model::TenantContext.new(from_uuid(context.tenant_id))
282
+ end
283
+
284
+ def from_call_context(context)
285
+ return Killbill::Plugin::Model::CallContext.new(from_uuid(context.tenant_id),
286
+ from_uuid(context.user_token),
287
+ from_string(context.user_name),
288
+ from_call_origin(context.call_origin),
289
+ from_user_type(context.user_type),
290
+ from_string(context.reason_code),
291
+ from_string(context.comments),
292
+ from_joda_date_time(context.created_date),
293
+ from_joda_date_time(context.updated_date))
294
+ end
295
+
296
+
297
+ def from_uuid(uuid)
298
+ uuid.nil? ? nil : Killbill::Plugin::Model::UUID.new(uuid.to_s)
299
+ end
300
+
301
+ def from_joda_date_time(joda_time)
302
+ if joda_time.nil?
303
+ return nil
304
+ end
305
+
306
+ fmt = org.joda.time.format.ISODateTimeFormat.date_time
307
+ str = fmt.print(joda_time);
308
+ DateTime.iso8601(str)
309
+ end
310
+
311
+ def from_string(str)
312
+ str.nil? ? nil : str.to_s
313
+ end
314
+
315
+
316
+ def from_currency(currency)
317
+ if currency.nil?
318
+ return nil
319
+ end
320
+ if currency.to_s == Java::com.ning.billing.catalog.api.Currency::GBP.to_s
321
+ return Killbill::Plugin::Model::Currency.new(:GBP)
322
+ elsif currency.to_s == Java::com.ning.billing.catalog.api.Currency::MXN.to_s
323
+ return Killbill::Plugin::Model::Currency.new(:MXN)
324
+ elsif currency.to_s == Java::com.ning.billing.catalog.api.Currency::BRL.to_s
325
+ return Killbill::Plugin::Model::Currency.new(:BRL)
326
+ elsif currency.to_s == Java::com.ning.billing.catalog.api.Currency::EUR.to_s
327
+ return Killbill::Plugin::Model::Currency.new(:EUR)
328
+ elsif currency.to_s == Java::com.ning.billing.catalog.api.Currency::AUD.to_s
329
+ return Killbill::Plugin::Model::Currency.new(:AUD)
330
+ elsif currency.to_s == Java::com.ning.billing.catalog.api.Currency::USD.to_s
331
+ return Killbill::Plugin::Model::Currency.new(:USD)
332
+ end
333
+ nil
334
+ end
335
+
336
+ def from_call_origin(origin)
337
+ if origin.nil?
338
+ return nil
339
+ end
340
+
341
+ if origin.to_s == Java::com.ning.billing.util.callcontext.CallOrigin::INTERNAL.to_s
342
+ return Killbill::Plugin::Model::CallOrigin.new(:INTERNAL)
343
+ elsif origin.to_s == Java::com.ning.billing.util.callcontext.CallOrigin::EXTERNAL.to_s
344
+ return Killbill::Plugin::Model::CallOrigin.new(:EXTERNAL)
345
+ else
346
+ return Killbill::Plugin::Model::CallOrigin.new(:TEST)
347
+ end
348
+ end
349
+
350
+ def from_user_type(user)
351
+ if user.nil?
352
+ return nil
353
+ end
354
+
355
+ if user.to_s == Java::com.ning.billing.util.callcontext.UserType::SYSTEM.to_s
356
+ return Killbill::Plugin::Model::UserType.new(:SYSTEM)
357
+ elsif user.to_s == Java::com.ning.billing.util.callcontext.UserType::ADMIN.to_s
358
+ return Killbill::Plugin::Model::UserType.new(:ADMIN)
359
+ elsif user.to_s == Java::com.ning.billing.util.callcontext.UserType::CUSTOMER.to_s
360
+ return Killbill::Plugin::Model::UserType.new(:CUSTOMER)
361
+ elsif user.to_s == Java::com.ning.billing.util.callcontext.UserType::MIGRATION.to_s
362
+ return Killbill::Plugin::Model::UserType.new(:MIGRATION)
363
+ else # user == Java::com.ning.billing.util.callcontext.UserType::TEST
364
+ return Killbill::Plugin::Model::UserType.new(:TEST)
365
+ end
366
+ end
367
+
368
+ def from_date_time_zone(date_time_zone)
369
+ if date_time_zone.nil?
370
+ return nil
371
+ end
372
+ if date_time_zone.to_s == org.joda.time.DateTimeZone::UTC.to_s
373
+ return Killbill::Plugin::Model::DateTimeZone.new(:UTC)
374
+ end
375
+ nil
376
+ end
377
+
378
+
379
+ def from_payment_plugin_status(status)
380
+ if status.to_s == Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::PROCESSED.to_s
381
+ Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
382
+ elsif status.to_s == Java::com.ning.billing.payment.plugin.api.PaymentPluginStatus::ERROR.to_s
383
+ Killbill::Plugin::Model::PaymentPluginStatus.new(:ERROR)
384
+ else
385
+ Killbill::Plugin::Model::PaymentPluginStatus.new(:UNDEFINED)
386
+ end
387
+ end
388
+
389
+ def from_refund_plugin_status(status)
390
+ if status.to_s == Java::com.ning.billing.payment.plugin.api.RefundPluginStatus::PROCESSED.to_s
391
+ Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED)
392
+ elsif status.to_s == Java::com.ning.billing.payment.plugin.api.RefundPluginStatus::ERROR.to_s
393
+ Killbill::Plugin::Model::RefundPluginStatus.new(:ERROR)
394
+ else
395
+ Killbill::Plugin::Model::RefundPluginStatus.new(:UNDEFINED)
396
+ end
397
+ end
398
+
399
+ def from_big_decimal_with_cents_conversion(big_decimal)
400
+ big_decimal.nil? ? 0 : big_decimal.multiply(java.math.BigDecimal.valueOf(100)).to_s.to_i
401
+ end
402
+
403
+ def from_boolean(b)
404
+ if b.nil?
405
+ return false
406
+ end
407
+
408
+ b_value = (b.java_kind_of? java.lang.Boolean) ? b.boolean_value : b
409
+ return b_value ? true : false
410
+ end
411
+
412
+ def from_payment_method_plugin(pm)
413
+ props = Array.new
414
+ pm.properties.each do |p|
415
+ key = from_string(p.key)
416
+ value = from_string(p.value)
417
+ is_updatable = from_boolean(p.is_updatable)
418
+ props << Killbill::Plugin::Model::PaymentMethodKVInfo.new(is_updatable, key, value)
419
+ end
420
+
421
+ pmid = from_string(pm.external_payment_method_id)
422
+ default = from_boolean(pm.is_default_payment_method)
423
+ Killbill::Plugin::Model::PaymentMethodPlugin.new(from_string(pm.external_payment_method_id),
424
+ from_boolean(pm.is_default_payment_method),
425
+ props,
426
+ nil,
427
+ from_string(pm.type),
428
+ from_string(pm.cc_name),
429
+ from_string(pm.cc_type),
430
+ from_string(pm.cc_expiration_month),
431
+ from_string(pm.cc_expiration_year),
432
+ from_string(pm.cc_last4),
433
+ from_string(pm.address1),
434
+ from_string(pm.address2),
435
+ from_string(pm.city),
436
+ from_string(pm.state),
437
+ from_string(pm.zip),
438
+ from_string(pm.country))
439
+ end
440
+
441
+ def from_payment_method_info_plugin(pm)
442
+ Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(from_uuid(pm.account_id),
443
+ from_uuid(pm.payment_method_id),
444
+ from_boolean(pm.is_default),
445
+ from_string(pm.external_payment_method_id))
446
+ end
447
+
448
+
449
+ def from_ext_bus_event(event)
450
+ Killbill::Plugin::Model::ExtBusEvent.new(from_bus_event_type(event.event_type),
451
+ from_object_type(event.object_type),
452
+ from_uuid(event.object_id),
453
+ from_uuid(event.account_id),
454
+ from_uuid(event.tenant_id))
455
+ end
456
+
457
+ def from_object_type(type)
458
+
459
+ puts "from_object_type #{type.to_s}, type = #{type.inspect} #{Java::com.ning.billing.ObjectType::ACCOUNT.inspect} #{type.to_s == Java::com.ning.billing.ObjectType::ACCOUNT.to_s}"
460
+
461
+ if type.to_s == Java::com.ning.billing.ObjectType::ACCOUNT.to_s
462
+ Killbill::Plugin::Model::ObjectType.new(:ACCOUNT)
463
+ elsif type.to_s == Java::com.ning.billing.ObjectType::ACCOUNT_EMAIL.to_s
464
+ Killbill::Plugin::Model::ObjectType.new(:ACCOUNT_EMAIL)
465
+ elsif type.to_s == Java::com.ning.billing.ObjectType::BLOCKING_STATES.to_s
466
+ Killbill::Plugin::Model::ObjectType.new(:BLOCKING_STATES)
467
+ elsif type.to_s == Java::com.ning.billing.ObjectType::BUNDLE.to_s
468
+ Killbill::Plugin::Model::ObjectType.new(:BUNDLE)
469
+ elsif type.to_s == Java::com.ning.billing.ObjectType::CUSTOM_FIELD.to_s
470
+ Killbill::Plugin::Model::ObjectType.new(:CUSTOM_FIELD)
471
+ elsif type.to_s == Java::com.ning.billing.ObjectType::INVOICE.to_s
472
+ Killbill::Plugin::Model::ObjectType.new(:INVOICE)
473
+ elsif type.to_s == Java::com.ning.billing.ObjectType::PAYMENT.to_s
474
+ Killbill::Plugin::Model::ObjectType.new(:PAYMENT)
475
+ elsif type.to_s == Java::com.ning.billing.ObjectType::INVOICE_ITEM.to_s
476
+ Killbill::Plugin::Model::ObjectType.new(:INVOICE_ITEM)
477
+ elsif type.to_s == Java::com.ning.billing.ObjectType::INVOICE_PAYMENT.to_s
478
+ Killbill::Plugin::Model::ObjectType.new(:INVOICE_PAYMENT)
479
+ elsif type.to_s == Java::com.ning.billing.ObjectType::SUBSCRIPTION.to_s
480
+ Killbill::Plugin::Model::ObjectType.new(:SUBSCRIPTION)
481
+ elsif type.to_s == Java::com.ning.billing.ObjectType::SUBSCRIPTION_EVENT.to_s
482
+ Killbill::Plugin::Model::ObjectType.new(:SUBSCRIPTION_EVENT)
483
+ elsif type.to_s == Java::com.ning.billing.ObjectType::PAYMENT_ATTEMPT.to_s
484
+ Killbill::Plugin::Model::ObjectType.new(:PAYMENT_ATTEMPT)
485
+ elsif type.to_s == Java::com.ning.billing.ObjectType::PAYMENT_METHOD.to_s
486
+ Killbill::Plugin::Model::ObjectType.new(:PAYMENT_METHOD)
487
+ elsif type.to_s == Java::com.ning.billing.ObjectType::REFUND.to_s
488
+ Killbill::Plugin::Model::ObjectType.new(:REFUND)
489
+ elsif type.to_s == Java::com.ning.billing.ObjectType::TAG.to_s
490
+ Killbill::Plugin::Model::ObjectType.new(:TAG)
491
+ elsif type.to_s == Java::com.ning.billing.ObjectType::TAG_DEFINITION.to_s
492
+ Killbill::Plugin::Model::ObjectType.new(:TAG_DEFINITION)
493
+ elsif type.to_s == Java::com.ning.billing.ObjectType::TENANT.to_s
494
+ Killbill::Plugin::Model::ObjectType.new(:TENANT)
495
+ else
496
+ Killbill::Plugin::Model::ObjectType.new(:TENANT_KVS)
497
+ end
498
+ end
499
+
500
+ def from_bus_event_type(type)
501
+
502
+ if type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::ACCOUNT_CREATION.to_s
503
+ Killbill::Plugin::Model::ExtBusEventType.new(:ACCOUNT_CREATION)
504
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::ACCOUNT_CHANGE.to_s
505
+ Killbill::Plugin::Model::ExtBusEventType.new(:ACCOUNT_CHANGE)
506
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::SUBSCRIPTION_CREATION.to_s
507
+ Killbill::Plugin::Model::ExtBusEventType.new(:SUBSCRIPTION_CREATION)
508
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::SUBSCRIPTION_PHASE.to_s
509
+ Killbill::Plugin::Model::ExtBusEventType.new(:SUBSCRIPTION_PHASE)
510
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::SUBSCRIPTION_CHANGE.to_s
511
+ Killbill::Plugin::Model::ExtBusEventType.new(:SUBSCRIPTION_CHANGE)
512
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::SUBSCRIPTION_CANCEL.to_s
513
+ Killbill::Plugin::Model::ExtBusEventType.new(:SUBSCRIPTION_CANCEL)
514
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::SUBSCRIPTION_UNCANCEL.to_s
515
+ Killbill::Plugin::Model::ExtBusEventType.new(:SUBSCRIPTION_UNCANCEL)
516
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::OVERDUE_CHANGE.to_s
517
+ Killbill::Plugin::Model::ExtBusEventType.new(:OVERDUE_CHANGE)
518
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::INVOICE_CREATION.to_s
519
+ Killbill::Plugin::Model::ExtBusEventType.new(:INVOICE_CREATION)
520
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::INVOICE_ADJUSTMENT.to_s
521
+ Killbill::Plugin::Model::ExtBusEventType.new(:INVOICE_ADJUSTMENT)
522
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::PAYMENT_SUCCESS.to_s
523
+ Killbill::Plugin::Model::ExtBusEventType.new(:PAYMENT_SUCCESS)
524
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::PAYMENT_FAILED.to_s
525
+ Killbill::Plugin::Model::ExtBusEventType.new(:PAYMENT_FAILED)
526
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::TAG_CREATION.to_s
527
+ Killbill::Plugin::Model::ExtBusEventType.new(:TAG_CREATION)
528
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::TAG_DELETION.to_s
529
+ Killbill::Plugin::Model::ExtBusEventType.new(:TAG_DELETION)
530
+ elsif type.to_s == Java::com.ning.billing.beatrix.bus.api.ExtBusEventType::CUSTOM_FIELD_CREATION.to_s
531
+ Killbill::Plugin::Model::ExtBusEventType.new(:CUSTOM_FIELD_CREATION)
532
+ else
533
+ Killbill::Plugin::Model::ExtBusEventType.new(:CUSTOM_FIELD_DELETION)
534
+ end
535
+ end
536
+
537
+ end
538
+ end
539
+ end
540
+ end