killbill-client 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -13
  2. data/lib/killbill_client/api/api.rb +2 -2
  3. data/lib/killbill_client/api/errors.rb +1 -1
  4. data/lib/killbill_client/api/net_http_adapter.rb +21 -1
  5. data/lib/killbill_client/models/account.rb +60 -112
  6. data/lib/killbill_client/models/account_timeline.rb +1 -1
  7. data/lib/killbill_client/models/bundle.rb +35 -34
  8. data/lib/killbill_client/models/catalog.rb +34 -0
  9. data/lib/killbill_client/models/custom_field.rb +3 -11
  10. data/lib/killbill_client/models/gen/account_attributes.rb +3 -3
  11. data/lib/killbill_client/models/gen/account_email_attributes.rb +3 -3
  12. data/lib/killbill_client/models/gen/account_timeline_attributes.rb +3 -3
  13. data/lib/killbill_client/models/gen/audit_log_attributes.rb +3 -3
  14. data/lib/killbill_client/models/gen/billing_exception_attributes.rb +3 -3
  15. data/lib/killbill_client/models/gen/bundle_attributes.rb +3 -3
  16. data/lib/killbill_client/models/gen/bundle_timeline_attributes.rb +3 -3
  17. data/lib/killbill_client/models/gen/catalog_attributes_simple.rb +3 -3
  18. data/lib/killbill_client/models/gen/credit_attributes.rb +3 -3
  19. data/lib/killbill_client/models/gen/custom_field_attributes.rb +3 -3
  20. data/lib/killbill_client/models/gen/deleted_event_subscription_attributes.rb +3 -3
  21. data/lib/killbill_client/models/gen/direct_payment_attributes.rb +45 -0
  22. data/lib/killbill_client/models/gen/direct_transaction_attributes.rb +47 -0
  23. data/lib/killbill_client/models/gen/event_subscription_attributes.rb +3 -3
  24. data/lib/killbill_client/models/gen/{chargeback_attributes.rb → gateway_notification_attributes.rb} +9 -12
  25. data/lib/killbill_client/models/gen/{refund_attributes.rb → hosted_payment_page_billing_address_attributes.rb} +10 -14
  26. data/lib/killbill_client/models/gen/hosted_payment_page_customer_attributes.rb +36 -0
  27. data/lib/killbill_client/models/gen/hosted_payment_page_fields_attributes.rb +33 -0
  28. data/lib/killbill_client/models/gen/hosted_payment_page_form_descriptor_attributes.rb +37 -0
  29. data/lib/killbill_client/models/gen/invoice_attributes.rb +3 -3
  30. data/lib/killbill_client/models/gen/invoice_email_attributes.rb +3 -3
  31. data/lib/killbill_client/models/gen/invoice_item_attributes.rb +3 -3
  32. data/lib/killbill_client/models/gen/invoice_payment_attributes.rb +46 -0
  33. data/lib/killbill_client/models/gen/invoice_payment_transaction_attributes.rb +49 -0
  34. data/lib/killbill_client/models/gen/new_event_subscription_attributes.rb +3 -3
  35. data/lib/killbill_client/models/gen/notification_attributes.rb +3 -3
  36. data/lib/killbill_client/models/gen/overdue_state_attributes.rb +3 -3
  37. data/lib/killbill_client/models/gen/payment_attributes.rb +11 -16
  38. data/lib/killbill_client/models/gen/payment_method_attributes.rb +4 -3
  39. data/lib/killbill_client/models/gen/payment_method_plugin_detail_attributes.rb +3 -15
  40. data/lib/killbill_client/models/gen/payment_transaction_attributes.rb +47 -0
  41. data/lib/killbill_client/models/gen/phase_attributes.rb +3 -3
  42. data/lib/killbill_client/models/gen/plan_attributes.rb +3 -3
  43. data/lib/killbill_client/models/gen/plan_detail_attributes.rb +3 -3
  44. data/lib/killbill_client/models/gen/{payment_method_properties.rb → plugin_property_attributes.rb} +4 -4
  45. data/lib/killbill_client/models/gen/price_attributes.rb +3 -3
  46. data/lib/killbill_client/models/gen/product_attributes.rb +3 -3
  47. data/lib/killbill_client/models/gen/require_gen.rb +12 -6
  48. data/lib/killbill_client/models/gen/session_attributes.rb +3 -3
  49. data/lib/killbill_client/models/gen/stack_trace_element_attributes.rb +3 -3
  50. data/lib/killbill_client/models/gen/subject_attributes.rb +3 -3
  51. data/lib/killbill_client/models/gen/subscription_attributes.rb +3 -3
  52. data/lib/killbill_client/models/gen/tag_attributes.rb +3 -3
  53. data/lib/killbill_client/models/gen/tag_definition_attributes.rb +3 -3
  54. data/lib/killbill_client/models/gen/tenant_attributes.rb +3 -3
  55. data/lib/killbill_client/models/gen/tenant_key_attributes.rb +3 -3
  56. data/lib/killbill_client/models/gen/usage_attributes.rb +3 -3
  57. data/lib/killbill_client/models/helpers/custom_field_helper.rb +51 -0
  58. data/lib/killbill_client/models/helpers/tag_helper.rb +112 -0
  59. data/lib/killbill_client/models/invoice.rb +30 -13
  60. data/lib/killbill_client/models/invoice_item.rb +37 -5
  61. data/lib/killbill_client/models/invoice_payment.rb +67 -0
  62. data/lib/killbill_client/models/models.rb +10 -2
  63. data/lib/killbill_client/models/payment.rb +5 -32
  64. data/lib/killbill_client/models/payment_method.rb +5 -6
  65. data/lib/killbill_client/models/phase.rb +9 -0
  66. data/lib/killbill_client/models/plan.rb +9 -0
  67. data/lib/killbill_client/models/plan_detail.rb +9 -0
  68. data/lib/killbill_client/models/product.rb +9 -0
  69. data/lib/killbill_client/models/resource.rb +22 -5
  70. data/lib/killbill_client/models/subscription.rb +28 -30
  71. data/lib/killbill_client/models/tag.rb +7 -11
  72. data/lib/killbill_client/models/tag_definition.rb +27 -6
  73. data/lib/killbill_client/models/transaction.rb +104 -0
  74. data/lib/killbill_client/version.rb +1 -1
  75. data/spec/killbill_client/remote/api_spec.rb +1 -1
  76. data/spec/killbill_client/remote/model_spec.rb +38 -23
  77. data/spec/killbill_client/resource_spec.rb +18 -0
  78. data/spec/spec_helper.rb +12 -0
  79. metadata +36 -19
  80. data/lib/killbill_client/models/chargeback.rb +0 -36
  81. data/lib/killbill_client/models/refund.rb +0 -55
@@ -0,0 +1,67 @@
1
+ module KillBillClient
2
+ module Model
3
+ class InvoicePayment < InvoicePaymentAttributes
4
+ KILLBILL_API_INVOICE_PAYMENTS_PREFIX = "#{KILLBILL_API_PREFIX}/invoicePayments"
5
+
6
+ has_many :transactions, KillBillClient::Model::Transaction
7
+ has_many :audit_logs, KillBillClient::Model::AuditLog
8
+
9
+ class << self
10
+ def find_by_id(payment_id, with_plugin_info = false, options = {})
11
+ get "#{KILLBILL_API_INVOICE_PAYMENTS_PREFIX}/#{payment_id}",
12
+ {
13
+ :withPluginInfo => with_plugin_info
14
+ },
15
+ options
16
+ end
17
+
18
+ def refund(payment_id, amount, adjustments = nil, user = nil, reason = nil, comment = nil, options = {})
19
+ payload = InvoicePaymentTransactionAttributes.new
20
+ payload.amount = amount
21
+ payload.is_adjusted = !adjustments.nil?
22
+ payload.adjustments = adjustments
23
+
24
+ invoice_payment = post "#{KILLBILL_API_INVOICE_PAYMENTS_PREFIX}/#{payment_id}/refunds",
25
+ payload.to_json,
26
+ {},
27
+ {
28
+ :user => user,
29
+ :reason => reason,
30
+ :comment => comment,
31
+ }.merge(options)
32
+
33
+ invoice_payment.refresh(options)
34
+ end
35
+ end
36
+
37
+ def create(external_payment = false, user = nil, reason = nil, comment = nil, options = {})
38
+ created_invoice_payment = self.class.post "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/#{target_invoice_id}/payments",
39
+ to_json,
40
+ {
41
+ :externalPayment => external_payment
42
+ },
43
+ {
44
+ :user => user,
45
+ :reason => reason,
46
+ :comment => comment,
47
+ }.merge(options)
48
+ created_invoice_payment.refresh(options)
49
+ end
50
+
51
+ def bulk_create(external_payment = false, user = nil, reason = nil, comment = nil, options = {})
52
+ # Nothing to return (nil)
53
+ self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/invoicePayments",
54
+ {},
55
+ {
56
+ :externalPayment => external_payment,
57
+ :paymentAmount => purchased_amount
58
+ },
59
+ {
60
+ :user => user,
61
+ :reason => reason,
62
+ :comment => comment,
63
+ }.merge(options)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -3,17 +3,25 @@ require 'killbill_client/models/resources'
3
3
 
4
4
  require 'killbill_client/models/gen/require_gen'
5
5
 
6
+ require 'killbill_client/models/helpers/tag_helper'
7
+ require 'killbill_client/models/helpers/custom_field_helper'
8
+
6
9
  require 'killbill_client/models/audit_log'
7
10
  require 'killbill_client/models/event_subscription'
11
+ require 'killbill_client/models/phase'
12
+ require 'killbill_client/models/plan'
13
+ require 'killbill_client/models/plan_detail'
14
+ require 'killbill_client/models/product'
15
+ require 'killbill_client/models/catalog'
8
16
  require 'killbill_client/models/credit'
9
17
  require 'killbill_client/models/invoice_item'
10
- require 'killbill_client/models/chargeback'
11
18
  require 'killbill_client/models/custom_field'
12
19
  require 'killbill_client/models/subscription'
13
20
  require 'killbill_client/models/bundle'
14
- require 'killbill_client/models/refund'
15
21
  require 'killbill_client/models/account'
16
22
  require 'killbill_client/models/invoice'
23
+ require 'killbill_client/models/transaction'
24
+ require 'killbill_client/models/invoice_payment'
17
25
  require 'killbill_client/models/payment'
18
26
  require 'killbill_client/models/payment_method'
19
27
  require 'killbill_client/models/security'
@@ -3,26 +3,13 @@ module KillBillClient
3
3
  class Payment < PaymentAttributes
4
4
  KILLBILL_API_PAYMENTS_PREFIX = "#{KILLBILL_API_PREFIX}/payments"
5
5
 
6
- has_many :refunds, KillBillClient::Model::Refund
7
- has_many :chargebacks, KillBillClient::Model::Chargeback
6
+ has_many :transactions, KillBillClient::Model::Transaction
8
7
  has_many :audit_logs, KillBillClient::Model::AuditLog
9
8
 
10
- create_alias :bundle_keys, :external_bundle_keys
11
-
12
9
  class << self
13
- def find_by_id(payment_id, with_refunds_and_chargebacks = false, options = {})
10
+ def find_by_id(payment_id, options = {})
14
11
  get "#{KILLBILL_API_PAYMENTS_PREFIX}/#{payment_id}",
15
- {
16
- :withRefundsAndChargebacks => with_refunds_and_chargebacks
17
- },
18
- options
19
- end
20
-
21
- def find_all_by_invoice_id(invoice_id, with_refunds_and_chargebacks = false, options = {})
22
- get "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/#{invoice_id}/payments",
23
- {
24
- :withRefundsAndChargebacks => with_refunds_and_chargebacks
25
- },
12
+ {},
26
13
  options
27
14
  end
28
15
 
@@ -30,7 +17,7 @@ module KillBillClient
30
17
  get "#{KILLBILL_API_PAYMENTS_PREFIX}/#{Resource::KILLBILL_API_PAGINATION_PREFIX}",
31
18
  {
32
19
  :offset => offset,
33
- :limit => limit
20
+ :limit => limit
34
21
  },
35
22
  options
36
23
  end
@@ -39,25 +26,11 @@ module KillBillClient
39
26
  get "#{KILLBILL_API_PAYMENTS_PREFIX}/search/#{search_key}",
40
27
  {
41
28
  :offset => offset,
42
- :limit => limit
29
+ :limit => limit
43
30
  },
44
31
  options
45
32
  end
46
33
  end
47
-
48
- def create(external_payment = false, user = nil, reason = nil, comment = nil, options = {})
49
- # Nothing to return (nil)
50
- self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
51
- to_json,
52
- {
53
- :externalPayment => external_payment
54
- },
55
- {
56
- :user => user,
57
- :reason => reason,
58
- :comment => comment,
59
- }.merge(options)
60
- end
61
34
  end
62
35
  end
63
36
  end
@@ -53,6 +53,7 @@ module KillBillClient
53
53
 
54
54
  def destroy(payment_method_id, set_auto_pay_off = false, user = nil, reason = nil, comment = nil, options = {})
55
55
  delete "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/#{payment_method_id}",
56
+ {},
56
57
  {
57
58
  :deleteDefaultPmWithAutoPayOff => set_auto_pay_off
58
59
  },
@@ -64,11 +65,11 @@ module KillBillClient
64
65
  end
65
66
  end
66
67
 
67
- def create(set_default = true, user = nil, reason = nil, comment = nil, options = {})
68
+ def create(user = nil, reason = nil, comment = nil, options = {})
68
69
  created_pm = self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/paymentMethods",
69
70
  to_json,
70
71
  {
71
- :isDefault => set_default
72
+ :isDefault => is_default
72
73
  },
73
74
  {
74
75
  :user => user,
@@ -87,12 +88,10 @@ module KillBillClient
87
88
  @plugin_info.properties = []
88
89
  return if info.nil?
89
90
 
90
- info.each { |k, v| @plugin_info.send("#{Utils.underscore k}=", v) unless k == 'properties' }
91
-
92
91
  if info['properties'].nil?
93
92
  # Convenience method to create properties to add a payment method
94
93
  info.each do |key, value|
95
- property = PaymentMethodProperties.new
94
+ property = PluginPropertyAttributes.new
96
95
  property.key = key
97
96
  property.value = value
98
97
  property.is_updatable = false
@@ -101,7 +100,7 @@ module KillBillClient
101
100
  else
102
101
  # De-serialization from JSON payload
103
102
  info['properties'].each do |property_json|
104
- property = PaymentMethodProperties.new
103
+ property = PluginPropertyAttributes.new
105
104
  property.key = property_json['key']
106
105
  property.value = property_json['value']
107
106
  property.is_updatable = property_json['isUpdatable']
@@ -0,0 +1,9 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Phase < PhaseAttributes
4
+
5
+ has_many :prices, KillBillClient::Model::PriceAttributes
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Plan < PlanAttributes
4
+
5
+ has_many :phases, KillBillClient::Model::Phase
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module KillBillClient
2
+ module Model
3
+ class PlanDetail < PlanDetailAttributes
4
+
5
+ has_many :prices, KillBillClient::Model::PriceAttributes
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Product < ProductAttributes
4
+
5
+ has_many :plans, KillBillClient::Model::Plan
6
+
7
+ end
8
+ end
9
+ end
@@ -14,6 +14,15 @@ module KillBillClient
14
14
 
15
15
  @@attribute_names = {}
16
16
 
17
+ def initialize(hash = nil)
18
+ # Make sure we support ActiveSupport::HashWithIndifferentAccess for Kaui
19
+ if hash.respond_to?(:each)
20
+ hash.each do |key,value|
21
+ send("#{Utils.underscore key.to_s}=", value)
22
+ end
23
+ end
24
+ end
25
+
17
26
  class << self
18
27
  def head(uri, params = {}, options = {}, clazz = self)
19
28
  response = KillBillClient::API.head uri, params, options
@@ -35,8 +44,8 @@ module KillBillClient
35
44
  from_response clazz, response
36
45
  end
37
46
 
38
- def delete(uri, params = {}, options = {}, clazz = self)
39
- response = KillBillClient::API.delete uri, params, options
47
+ def delete(uri, body = nil, params = {}, options = {}, clazz = self)
48
+ response = KillBillClient::API.delete uri, body, params, options
40
49
  from_response clazz, response
41
50
  end
42
51
 
@@ -49,6 +58,7 @@ module KillBillClient
49
58
  def from_response(resource_class, response)
50
59
  case response['Content-Type']
51
60
  when %r{application/pdf}
61
+ when %r{text/html}
52
62
  response.body
53
63
  when %r{application/json}
54
64
  record = from_json resource_class, response.body
@@ -105,7 +115,13 @@ module KillBillClient
105
115
 
106
116
  data.each do |name, value|
107
117
  name = Utils.underscore name
108
- attr_desc = @@attribute_names[record.class.name][name.to_sym] rescue nil
118
+ attr_desc = nil
119
+
120
+ # Allow for inheritance. TODO What's the performance hit?
121
+ resource_class.ancestors.each do |ancestor|
122
+ attr_desc = @@attribute_names[ancestor.name][name.to_sym] rescue nil
123
+ break unless attr_desc.nil?
124
+ end
109
125
 
110
126
  unless attr_desc.nil?
111
127
  type = attr_desc[:type]
@@ -124,7 +140,8 @@ module KillBillClient
124
140
  end
125
141
  end #end unless attr_desc.nil? or data_elem.blank?
126
142
 
127
- record.send("#{Utils.underscore name}=", value )
143
+ # TODO Be lenient for now to support different API formats
144
+ record.send("#{Utils.underscore name}=", value) rescue nil
128
145
 
129
146
  end #end data.each
130
147
 
@@ -230,6 +247,6 @@ module KillBillClient
230
247
  def hash
231
248
  to_hash.hash
232
249
  end
233
- end
250
+ end
234
251
  end
235
252
  end
@@ -21,8 +21,8 @@ module KillBillClient
21
21
  to_json,
22
22
  {},
23
23
  {
24
- :user => user,
25
- :reason => reason,
24
+ :user => user,
25
+ :reason => reason,
26
26
  :comment => comment,
27
27
  }.merge(options)
28
28
  created_entitlement.refresh(options)
@@ -37,19 +37,19 @@ module KillBillClient
37
37
  # @ call_completion : whether the call should wait for invoice/payment to be completed before calls return
38
38
  #
39
39
  def change_plan(input, user = nil, reason = nil, comment = nil,
40
- requested_date = nil, billing_policy = nil, call_completion = false, options = {})
40
+ requested_date = nil, billing_policy = nil, call_completion = false, options = {})
41
41
 
42
- params = {}
42
+ params = {}
43
43
  params[:callCompletion] = call_completion
44
- params[:requestedDate] = requested_date unless requested_date.nil?
45
- params[:billingPolicy] = billing_policy unless billing_policy.nil?
44
+ params[:requestedDate] = requested_date unless requested_date.nil?
45
+ params[:billingPolicy] = billing_policy unless billing_policy.nil?
46
46
 
47
47
  return self.class.put "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{@subscription_id}",
48
48
  input.to_json,
49
49
  params,
50
50
  {
51
- :user => user,
52
- :reason => reason,
51
+ :user => user,
52
+ :reason => reason,
53
53
  :comment => comment,
54
54
  }.merge(options)
55
55
  end
@@ -61,37 +61,35 @@ module KillBillClient
61
61
  # @billing_policy : the override for the billing policy {END_OF_TERM, IMMEDIATE}
62
62
  #
63
63
  def cancel(user = nil, reason = nil, comment = nil, requested_date = nil, entitlementPolicy = nil, billing_policy = nil, use_requested_date_for_billing = nil, options = {})
64
-
65
- params = {}
66
- params[:requestedDate] = requested_date unless requested_date.nil?
67
- params[:billingPolicy] = billing_policy unless billing_policy.nil?
68
- params[:entitlementPolicy] = entitlementPolicy unless entitlementPolicy.nil?
64
+ params = {}
65
+ params[:requestedDate] = requested_date unless requested_date.nil?
66
+ params[:billingPolicy] = billing_policy unless billing_policy.nil?
67
+ params[:entitlementPolicy] = entitlementPolicy unless entitlementPolicy.nil?
69
68
  params[:useRequestedDateForBilling] = use_requested_date_for_billing unless use_requested_date_for_billing.nil?
70
69
 
71
- return self.class.delete "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{@subscription_id}",
72
- params,
73
- {
74
- :user => user,
75
- :reason => reason,
76
- :comment => comment,
77
- }.merge(options)
70
+ self.class.delete "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{subscription_id}",
71
+ {},
72
+ params,
73
+ {
74
+ :user => user,
75
+ :reason => reason,
76
+ :comment => comment,
77
+ }.merge(options)
78
78
  end
79
79
 
80
80
  #
81
81
  # Uncancel a future cancelled entitlement
82
82
  #
83
- #
84
83
  def uncancel(user = nil, reason = nil, comment = nil, options = {})
85
-
86
84
  params = {}
87
- return self.class.put "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{@subscription_id}/uncancel",
88
- nil,
89
- params,
90
- {
91
- :user => user,
92
- :reason => reason,
93
- :comment => comment,
94
- }.merge(options)
85
+ self.class.put "#{KILLBILL_API_ENTITLEMENT_PREFIX}/#{subscription_id}/uncancel",
86
+ nil,
87
+ params,
88
+ {
89
+ :user => user,
90
+ :reason => reason,
91
+ :comment => comment,
92
+ }.merge(options)
95
93
  end
96
94
 
97
95
  end
@@ -1,25 +1,17 @@
1
1
  module KillBillClient
2
2
  module Model
3
3
  class Tag < TagAttributes
4
+
4
5
  KILLBILL_API_TAGS_PREFIX = "#{KILLBILL_API_PREFIX}/tags"
5
6
 
6
7
  has_many :audit_logs, KillBillClient::Model::AuditLog
7
8
 
8
9
  class << self
9
- def find_all_by_account_id(account_id, included_deleted = false, audit = "NONE", options = {})
10
- get "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/tags",
11
- {
12
- :includedDeleted => included_deleted,
13
- :audit => audit
14
- },
15
- options
16
- end
17
-
18
10
  def find_in_batches(offset = 0, limit = 100, options = {})
19
11
  get "#{KILLBILL_API_TAGS_PREFIX}/#{Resource::KILLBILL_API_PAGINATION_PREFIX}",
20
12
  {
21
13
  :offset => offset,
22
- :limit => limit
14
+ :limit => limit
23
15
  },
24
16
  options
25
17
  end
@@ -28,11 +20,15 @@ module KillBillClient
28
20
  get "#{KILLBILL_API_TAGS_PREFIX}/search/#{search_key}",
29
21
  {
30
22
  :offset => offset,
31
- :limit => limit
23
+ :limit => limit
32
24
  },
33
25
  options
34
26
  end
35
27
  end
28
+
29
+ def <=>(tag)
30
+ tag_definition_name.downcase <=> tag.tag_definition_name.downcase
31
+ end
36
32
  end
37
33
  end
38
34
  end
@@ -4,14 +4,24 @@ module KillBillClient
4
4
  KILLBILL_API_TAG_DEFINITIONS_PREFIX = "#{KILLBILL_API_PREFIX}/tagDefinitions"
5
5
 
6
6
  class << self
7
- def all(options = {})
7
+ def all(audit = 'NONE', options = {})
8
8
  get KILLBILL_API_TAG_DEFINITIONS_PREFIX,
9
- {},
9
+ {
10
+ :audit => audit
11
+ },
10
12
  options
11
13
  end
12
14
 
13
- def find_by_name(name, options = {})
14
- self.all(options).select { |tag_definition| tag_definition.name == name }.first
15
+ def find_by_id(id, audit = 'NONE', options = {})
16
+ get "#{KILLBILL_API_TAG_DEFINITIONS_PREFIX}/#{id}",
17
+ {
18
+ :audit => audit
19
+ },
20
+ options
21
+ end
22
+
23
+ def find_by_name(name, audit = 'NONE', options = {})
24
+ self.all(audit, options).select { |tag_definition| tag_definition.name == name }.first
15
25
  end
16
26
  end
17
27
 
@@ -20,12 +30,23 @@ module KillBillClient
20
30
  to_json,
21
31
  {},
22
32
  {
23
- :user => user,
24
- :reason => reason,
33
+ :user => user,
34
+ :reason => reason,
25
35
  :comment => comment,
26
36
  }.merge(options)
27
37
  created_tag_definition.refresh(options)
28
38
  end
39
+
40
+ def delete(user = nil, reason = nil, comment = nil, options = {})
41
+ self.class.delete "#{KILLBILL_API_TAG_DEFINITIONS_PREFIX}/#{id}",
42
+ to_json,
43
+ {},
44
+ {
45
+ :user => user,
46
+ :reason => reason,
47
+ :comment => comment,
48
+ }.merge(options)
49
+ end
29
50
  end
30
51
  end
31
52
  end
@@ -0,0 +1,104 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Transaction < PaymentTransactionAttributes
4
+
5
+ has_many :audit_logs, KillBillClient::Model::AuditLog
6
+
7
+ def auth(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
8
+ query_map = {}
9
+ query_map[:paymentMethodId] = payment_method_id unless payment_method_id.nil?
10
+
11
+ @transaction_type = 'AUTHORIZE'
12
+ created_transaction = self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
13
+ to_json,
14
+ query_map,
15
+ {
16
+ :user => user,
17
+ :reason => reason,
18
+ :comment => comment,
19
+ }.merge(options)
20
+ created_transaction.refresh(options, Payment)
21
+ end
22
+
23
+ def purchase(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
24
+ query_map = {}
25
+ query_map[:paymentMethodId] = payment_method_id unless payment_method_id.nil?
26
+
27
+ @transaction_type = 'PURCHASE'
28
+ created_transaction = self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
29
+ to_json,
30
+ query_map,
31
+ {
32
+ :user => user,
33
+ :reason => reason,
34
+ :comment => comment,
35
+ }.merge(options)
36
+ created_transaction.refresh(options, Payment)
37
+ end
38
+
39
+ def credit(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
40
+ query_map = {}
41
+ query_map[:paymentMethodId] = payment_method_id unless payment_method_id.nil?
42
+
43
+ @transaction_type = 'CREDIT'
44
+ created_transaction = self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
45
+ to_json,
46
+ query_map,
47
+ {
48
+ :user => user,
49
+ :reason => reason,
50
+ :comment => comment,
51
+ }.merge(options)
52
+ created_transaction.refresh(options, Payment)
53
+ end
54
+
55
+ def capture(user = nil, reason = nil, comment = nil, options = {})
56
+ created_transaction = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/#{payment_id}",
57
+ to_json,
58
+ {},
59
+ {
60
+ :user => user,
61
+ :reason => reason,
62
+ :comment => comment,
63
+ }.merge(options)
64
+ created_transaction.refresh(options, Payment)
65
+ end
66
+
67
+ def refund(user = nil, reason = nil, comment = nil, options = {})
68
+ created_transaction = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/#{payment_id}/refunds",
69
+ to_json,
70
+ {},
71
+ {
72
+ :user => user,
73
+ :reason => reason,
74
+ :comment => comment,
75
+ }.merge(options)
76
+ created_transaction.refresh(options, Payment)
77
+ end
78
+
79
+ def void(user = nil, reason = nil, comment = nil, options = {})
80
+ created_transaction = self.class.delete "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/#{payment_id}",
81
+ to_json,
82
+ {},
83
+ {
84
+ :user => user,
85
+ :reason => reason,
86
+ :comment => comment,
87
+ }.merge(options)
88
+ created_transaction.refresh(options, Payment)
89
+ end
90
+
91
+ def chargeback(user = nil, reason = nil, comment = nil, options = {})
92
+ created_transaction = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/#{payment_id}/chargebacks",
93
+ to_json,
94
+ {},
95
+ {
96
+ :user => user,
97
+ :reason => reason,
98
+ :comment => comment,
99
+ }.merge(options)
100
+ created_transaction.refresh(options, Payment)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -2,7 +2,7 @@ module KillBillClient
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 7
5
- PATCH = 2
5
+ PATCH = 3
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe KillBillClient::API do
4
- it 'should get all tag definitions' do
4
+ it 'should get all tag definitions', :integration => true do
5
5
  response = KillBillClient::API.get '/1.0/kb/tagDefinitions'
6
6
  response.code.to_i.should == 200
7
7
  tag_definitions = KillBillClient::Model::Resource.from_response KillBillClient::Model::TagDefinition, response