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
data/Jarfile CHANGED
@@ -1,3 +1,5 @@
1
- jar 'com.ning.billing:killbill-api', '0.1.76-SNAPSHOT'
2
- jar 'com.ning.billing:killbill-util:tests', '0.1.76-SNAPSHOT'
1
+ jar 'com.ning.billing:killbill-api', '0.1.77-SNAPSHOT'
2
+ jar 'com.ning.billing:killbill-util:tests', '0.1.77-SNAPSHOT'
3
+ jar 'com.ning.billing:killbill-api', '0.1.76'
4
+ jar 'com.ning.billing:killbill-util:tests', '0.1.76'
3
5
  jar 'javax.servlet:javax.servlet-api', '3.0.1'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.15
1
+ 1.0.16
data/lib/killbill.rb CHANGED
@@ -1,36 +1,91 @@
1
1
  begin
2
2
  require 'java'
3
3
 
4
- KILLBILL_APIS = %w(
4
+ # Add method snake_case to String as early as possible so all classes below can use it
5
+ class String
6
+ def snake_case
7
+ return downcase if match(/\A[A-Z]+\z/)
8
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
9
+ gsub(/([a-z])([A-Z])/, '\1_\2').
10
+ downcase
11
+ end
12
+ end
13
+
14
+
15
+ #
16
+ # The Killbill Java APIs imported into that jruby bridge
17
+ #
18
+ IMPORT_KILLBILL_APIS = %w(
5
19
  com.ning.billing.account.api.AccountUserApi
6
- com.ning.billing.analytics.api.sanity.AnalyticsSanityApi
7
- com.ning.billing.analytics.api.user.AnalyticsUserApi
8
20
  com.ning.billing.catalog.api.CatalogUserApi
9
- com.ning.billing.entitlement.api.migration.EntitlementMigrationApi
10
- com.ning.billing.entitlement.api.timeline.EntitlementTimelineApi
11
- com.ning.billing.entitlement.api.transfer.EntitlementTransferApi
12
21
  com.ning.billing.entitlement.api.user.EntitlementUserApi
13
- com.ning.billing.invoice.api.InvoiceMigrationApi
14
22
  com.ning.billing.invoice.api.InvoicePaymentApi
15
23
  com.ning.billing.invoice.api.InvoiceUserApi
16
24
  com.ning.billing.overdue.OverdueUserApi
17
25
  com.ning.billing.payment.api.PaymentApi
18
- com.ning.billing.tenant.api.TenantUserApi
19
- com.ning.billing.usage.api.UsageUserApi
20
- com.ning.billing.util.api.AuditUserApi
21
26
  com.ning.billing.util.api.CustomFieldUserApi
22
- com.ning.billing.util.api.ExportUserApi
23
27
  com.ning.billing.util.api.TagUserApi
24
28
  javax.servlet.http.HttpServlet
25
29
  )
26
30
 
31
+ #
32
+ # The Killbill ruby APIs exported for all the ruby plugins
33
+ #
34
+ EXPORT_KILLBILL_API = %w(
35
+ createAccount
36
+ updateAccount
37
+ getAccountById
38
+ getBundleFromId
39
+ getSubscriptionFromId
40
+ getBundlesForAccount
41
+ getSubscriptionsForBundle
42
+ getBaseSubscription
43
+ createBundleForAccount
44
+ createSubscription
45
+ getNextBillingDate
46
+ getAllInvoicesByAccount
47
+ getInvoice
48
+ getInvoicePayments
49
+ getInvoicePaymentForAttempt
50
+ getRemainingAmountPaid
51
+ getChargebacksByAccountId
52
+ getAccountIdFromInvoicePaymentId
53
+ getChargebacksByPaymentId
54
+ getChargebackById
55
+ getInvoicesByAccount
56
+ getAccountBalance
57
+ getAccountCBA
58
+ getInvoice
59
+ getUnpaidInvoicesByAccountId
60
+ getOverdueStateFor
61
+ getAccountRefunds
62
+ getPaymentRefunds
63
+ getInvoicePayments
64
+ getAccountPayments
65
+ getPayment
66
+ getPaymentMethods
67
+ getPaymentMethodById
68
+ addCustomFields
69
+ getCustomFieldsForAccount
70
+ getTagDefinitions
71
+ createTagDefinition
72
+ deleteTagDefinition
73
+ getTagDefinition
74
+ getTagDefinitions
75
+ addTags
76
+ addTag
77
+ removeTags
78
+ removeTag
79
+ getTagsForAccount
80
+ ).collect { |e| e.snake_case }
81
+
27
82
  begin
28
- KILLBILL_APIS.each { |api| java_import api }
83
+ IMPORT_KILLBILL_APIS.each { |api| java_import api }
29
84
  rescue NameError
30
85
  # killbill-api should be provided by the JRuby OSGI bundle. We default to using JBundler for development purposes only
31
86
  begin
32
87
  require 'jbundler'
33
- KILLBILL_APIS.each { |api| java_import api }
88
+ IMPORT_KILLBILL_APIS.each { |api| java_import api }
34
89
  warn 'Using JBundler to load killbill-api (see .jbundler/classpath.rb). This should only happen in development mode!'
35
90
  rescue LoadError => e
36
91
  warn 'Unable to load killbill-api. For development purposes, use JBundler (create the following Jarfile: http://git.io/eobYXA and run: `bundle install && jbundle install\')'
@@ -44,5 +99,6 @@ rescue LoadError => e
44
99
  warn "You need JRuby to run Killbill plugins #{e}"
45
100
  end
46
101
 
102
+ require 'killbill/gen/require_gen'
47
103
  require 'killbill/notification'
48
104
  require 'killbill/payment'
@@ -1,3 +1,9 @@
1
+ require 'java'
2
+
3
+ require 'killbill/jkillbill_api'
4
+ require 'killbill/killbill_api'
5
+
6
+ include Java
1
7
 
2
8
  module Killbill
3
9
  module Plugin
@@ -9,9 +15,17 @@ module Killbill
9
15
  @target_class_name = target_class_name
10
16
  end
11
17
 
12
- def create(*args)
18
+ def create(services)
19
+ japi_proxy = JKillbillApi.new(@target_class_name, services)
20
+
21
+ kb_apis = KillbillApi.new(japi_proxy)
13
22
  real_class = class_from_string
14
- args.nil? ? real_class.new : real_class.new(*args)
23
+ plugin_delegate = real_class.new
24
+ plugin_delegate.root = services["root"]
25
+ plugin_delegate.logger = services["logger"]
26
+ plugin_delegate.conf_dir = services["conf_dir"]
27
+ plugin_delegate.kb_apis = kb_apis
28
+ plugin_delegate
15
29
  end
16
30
 
17
31
  private
@@ -0,0 +1,72 @@
1
+ module Killbill
2
+ module Plugin
3
+
4
+ module Enum
5
+
6
+ class NameValuePair
7
+ attr_reader :label, :value
8
+
9
+ def initialize(label, value)
10
+ @label = label
11
+ @value = value
12
+ end
13
+
14
+ def first
15
+ @label
16
+ end
17
+
18
+ def last
19
+ @value
20
+ end
21
+ end
22
+
23
+ def const_missing(key)
24
+ @enum_hash[key]
25
+ end
26
+
27
+ def add_enum(key, value)
28
+ @enum_hash ||= {}
29
+ @enum_hash[key] = NameValuePair.new(value, key.to_s)
30
+ end
31
+
32
+ def each
33
+ @enum_hash.values.sort { |v1, v2| v1.label <=> v2.label }.each do |k|
34
+ yield(k)
35
+ end
36
+ end
37
+
38
+ def collect
39
+ @enum_hash.values.sort { |v1, v2| v1.label <=> v2.label }.collect do |k|
40
+ yield(k)
41
+ end
42
+ end
43
+
44
+ def each_with_index
45
+ @enum_hash.values.sort { |v1, v2| v1.label <=> v2.label }.each_with_index do |k, i|
46
+ yield(k, i)
47
+ end
48
+ end
49
+
50
+ def enums
51
+ @enum_hash.keys
52
+ end
53
+
54
+ def enum_values
55
+ @enum_hash.values
56
+ end
57
+
58
+ def get_enum_hash
59
+ @enum_hash
60
+ end
61
+
62
+ def find_by_key(key)
63
+ @enum_hash[key.upcase.to_sym]
64
+ end
65
+
66
+ def size
67
+ @enum_hash.keys.size
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,43 @@
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 Account
10
+
11
+ include com.ning.billing.account.api.Account
12
+
13
+ attr_reader :id, :blocking_state, :created_date, :updated_date, :external_key, :name, :first_name_length, :email, :bill_cycle_day_local, :currency, :payment_method_id, :time_zone, :locale, :address1, :address2, :company_name, :city, :state_or_province, :postal_code, :country, :phone, :is_migrated, :is_notified_for_invoices
14
+
15
+ def initialize(id, blocking_state, created_date, updated_date, external_key, name, first_name_length, email, bill_cycle_day_local, currency, payment_method_id, time_zone, locale, address1, address2, company_name, city, state_or_province, postal_code, country, phone, is_migrated, is_notified_for_invoices)
16
+ @id = id
17
+ @blocking_state = blocking_state
18
+ @created_date = created_date
19
+ @updated_date = updated_date
20
+ @external_key = external_key
21
+ @name = name
22
+ @first_name_length = first_name_length
23
+ @email = email
24
+ @bill_cycle_day_local = bill_cycle_day_local
25
+ @currency = currency
26
+ @payment_method_id = payment_method_id
27
+ @time_zone = time_zone
28
+ @locale = locale
29
+ @address1 = address1
30
+ @address2 = address2
31
+ @company_name = company_name
32
+ @city = city
33
+ @state_or_province = state_or_province
34
+ @postal_code = postal_code
35
+ @country = country
36
+ @phone = phone
37
+ @is_migrated = is_migrated
38
+ @is_notified_for_invoices = is_notified_for_invoices
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
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 AccountData
10
+
11
+ include com.ning.billing.account.api.AccountData
12
+
13
+ attr_reader :external_key, :name, :first_name_length, :email, :bill_cycle_day_local, :currency, :payment_method_id, :time_zone, :locale, :address1, :address2, :company_name, :city, :state_or_province, :postal_code, :country, :phone, :is_migrated, :is_notified_for_invoices
14
+
15
+ def initialize(external_key, name, first_name_length, email, bill_cycle_day_local, currency, payment_method_id, time_zone, locale, address1, address2, company_name, city, state_or_province, postal_code, country, phone, is_migrated, is_notified_for_invoices)
16
+ @external_key = external_key
17
+ @name = name
18
+ @first_name_length = first_name_length
19
+ @email = email
20
+ @bill_cycle_day_local = bill_cycle_day_local
21
+ @currency = currency
22
+ @payment_method_id = payment_method_id
23
+ @time_zone = time_zone
24
+ @locale = locale
25
+ @address1 = address1
26
+ @address2 = address2
27
+ @company_name = company_name
28
+ @city = city
29
+ @state_or_province = state_or_province
30
+ @postal_code = postal_code
31
+ @country = country
32
+ @phone = phone
33
+ @is_migrated = is_migrated
34
+ @is_notified_for_invoices = is_notified_for_invoices
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
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 AccountEmail
10
+
11
+ include com.ning.billing.account.api.AccountEmail
12
+
13
+ attr_reader :id, :created_date, :updated_date, :account_id, :email
14
+
15
+ def initialize(id, created_date, updated_date, account_id, email)
16
+ @id = id
17
+ @created_date = created_date
18
+ @updated_date = updated_date
19
+ @account_id = account_id
20
+ @email = email
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
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 AuditLog
10
+
11
+ include com.ning.billing.util.audit.AuditLog
12
+
13
+ attr_reader :id, :created_date, :updated_date, :change_type, :user_name, :reason_code, :user_token, :comment
14
+
15
+ def initialize(id, created_date, updated_date, change_type, user_name, reason_code, user_token, comment)
16
+ @id = id
17
+ @created_date = created_date
18
+ @updated_date = updated_date
19
+ @change_type = change_type
20
+ @user_name = user_name
21
+ @reason_code = reason_code
22
+ @user_token = user_token
23
+ @comment = comment
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
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 BlockingState
10
+
11
+ include com.ning.billing.junction.api.BlockingState
12
+
13
+ attr_reader :id, :created_date, :updated_date, :blocked_id, :state_name, :type, :timestamp, :is_block_change, :is_block_entitlement, :is_block_billing, :description, :service
14
+
15
+ def initialize(id, created_date, updated_date, blocked_id, state_name, type, timestamp, is_block_change, is_block_entitlement, is_block_billing, description, service)
16
+ @id = id
17
+ @created_date = created_date
18
+ @updated_date = updated_date
19
+ @blocked_id = blocked_id
20
+ @state_name = state_name
21
+ @type = type
22
+ @timestamp = timestamp
23
+ @is_block_change = is_block_change
24
+ @is_block_entitlement = is_block_entitlement
25
+ @is_block_billing = is_block_billing
26
+ @description = description
27
+ @service = service
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
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 CallContext
10
+
11
+ include com.ning.billing.util.callcontext.CallContext
12
+
13
+ attr_reader :tenant_id, :user_token, :user_name, :call_origin, :user_type, :reason_code, :comments, :created_date, :updated_date
14
+
15
+ def initialize(tenant_id, user_token, user_name, call_origin, user_type, reason_code, comments, created_date, updated_date)
16
+ @tenant_id = tenant_id
17
+ @user_token = user_token
18
+ @user_name = user_name
19
+ @call_origin = call_origin
20
+ @user_type = user_type
21
+ @reason_code = reason_code
22
+ @comments = comments
23
+ @created_date = created_date
24
+ @updated_date = updated_date
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -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 CallOrigin
10
+
11
+ @@admissible_values = [:INTERNAL, :EXTERNAL, :TEST]
12
+ attr_reader :enum
13
+
14
+ def initialize(value)
15
+ raise ArgumentError.new("Enum CallOrigin does not have such value : #{value}") if ! CallOrigin.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