killbill-client 0.4.2 → 0.4.3
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.
- data/killbill_client.gemspec +2 -0
- data/lib/killbill_client.rb +26 -0
- data/lib/killbill_client/models/payment.rb +14 -0
- data/lib/killbill_client/models/refund.rb +7 -9
- data/lib/killbill_client/models/resource.rb +11 -1
- data/lib/killbill_client/version.rb +1 -1
- data/spec/killbill_client/remote/model_spec.rb +35 -1
- metadata +19 -3
data/killbill_client.gemspec
CHANGED
data/lib/killbill_client.rb
CHANGED
@@ -95,4 +95,30 @@ module KillBillClient
|
|
95
95
|
require 'killbill_client/version'
|
96
96
|
end
|
97
97
|
|
98
|
+
begin
|
99
|
+
require 'securerandom'
|
100
|
+
SecureRandom.uuid
|
101
|
+
rescue LoadError, NoMethodError
|
102
|
+
begin
|
103
|
+
# See http://jira.codehaus.org/browse/JRUBY-6176
|
104
|
+
module SecureRandom
|
105
|
+
def self.uuid
|
106
|
+
ary = self.random_bytes(16).unpack("NnnnnN")
|
107
|
+
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
108
|
+
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
109
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
110
|
+
end unless respond_to?(:uuid)
|
111
|
+
end
|
112
|
+
rescue TypeError
|
113
|
+
class SecureRandom
|
114
|
+
def self.uuid
|
115
|
+
ary = self.random_bytes(16).unpack("NnnnnN")
|
116
|
+
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
117
|
+
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
118
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
119
|
+
end unless respond_to?(:uuid)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
98
124
|
require 'rails/killbill_client' if defined? Rails::Railtie
|
@@ -8,6 +8,20 @@ module KillBillClient
|
|
8
8
|
has_many :audit_logs, KillBillClient::Model::AuditLog
|
9
9
|
|
10
10
|
create_alias :bundle_keys, :external_bundle_keys
|
11
|
+
|
12
|
+
def create(external_payment = false, user = nil, reason = nil, comment = nil, options = {})
|
13
|
+
# Nothing to return (nil)
|
14
|
+
self.class.post "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/payments",
|
15
|
+
to_json,
|
16
|
+
{
|
17
|
+
:externalPayment => external_payment
|
18
|
+
},
|
19
|
+
{
|
20
|
+
:user => user,
|
21
|
+
:reason => reason,
|
22
|
+
:comment => comment,
|
23
|
+
}.merge(options)
|
24
|
+
end
|
11
25
|
end
|
12
26
|
end
|
13
27
|
end
|
@@ -7,7 +7,6 @@ module KillBillClient
|
|
7
7
|
has_many :adjustments, KillBillClient::Model::InvoiceItem
|
8
8
|
|
9
9
|
class << self
|
10
|
-
|
11
10
|
def find_by_id refund_id, options = {}
|
12
11
|
get "#{KILLBILL_API_REFUNDS_PREFIX}/#{refund_id}",
|
13
12
|
{},
|
@@ -24,17 +23,16 @@ module KillBillClient
|
|
24
23
|
|
25
24
|
def create(user = nil, reason = nil, comment = nil, options = {})
|
26
25
|
created_refund = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/#{@payment_id}/refunds",
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
to_json,
|
27
|
+
{},
|
28
|
+
{
|
29
|
+
:user => user,
|
30
|
+
:reason => reason,
|
31
|
+
:comment => comment,
|
32
|
+
}.merge(options)
|
34
33
|
|
35
34
|
created_refund.refresh(options)
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -177,12 +177,22 @@ module KillBillClient
|
|
177
177
|
self.class.json_attributes.each do |name|
|
178
178
|
value = self.send(name)
|
179
179
|
unless value.nil?
|
180
|
-
json_hash[Utils.camelize name, :lower] = value
|
180
|
+
json_hash[Utils.camelize name, :lower] = _to_hash(value)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
json_hash
|
184
184
|
end
|
185
185
|
|
186
|
+
def _to_hash(value)
|
187
|
+
if value.is_a?(Resource)
|
188
|
+
value.to_hash
|
189
|
+
elsif value.is_a?(Array)
|
190
|
+
value.map { |v| _to_hash(v) }
|
191
|
+
else
|
192
|
+
value
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
186
196
|
def to_json
|
187
197
|
to_hash.to_json
|
188
198
|
end
|
@@ -88,7 +88,7 @@ describe KillBillClient::Model do
|
|
88
88
|
|
89
89
|
timeline.account.external_key.should == external_key
|
90
90
|
timeline.account.account_id.should_not be_nil
|
91
|
-
|
91
|
+
|
92
92
|
timeline.invoices.should be_a_kind_of Array
|
93
93
|
timeline.invoices.should_not be_empty
|
94
94
|
timeline.payments.should be_a_kind_of Array
|
@@ -104,6 +104,40 @@ describe KillBillClient::Model do
|
|
104
104
|
|
105
105
|
invoice_with_id.invoice_id.should == invoice_with_number.invoice_id
|
106
106
|
invoice_with_id.invoice_number.should == invoice_with_number.invoice_number
|
107
|
+
|
108
|
+
# Create an external payment
|
109
|
+
payment = KillBillClient::Model::Payment.new
|
110
|
+
payment.account_id = account.account_id
|
111
|
+
payment.create true, 'KillBill Spec test'
|
112
|
+
|
113
|
+
# Check the account balance
|
114
|
+
account = KillBillClient::Model::Account.find_by_id account.account_id, true
|
115
|
+
account.account_balance.should == 0
|
116
|
+
|
117
|
+
# Verify the timeline
|
118
|
+
timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
|
119
|
+
timeline.payments.should_not be_empty
|
120
|
+
payment = timeline.payments.first
|
121
|
+
payment.refunds.should be_empty
|
122
|
+
|
123
|
+
# Refund the payment (with item adjustment)
|
124
|
+
invoice_item = KillBillClient::Model::Invoice.find_by_id_or_number(invoice_number, true).items.first
|
125
|
+
refund = KillBillClient::Model::Refund.new
|
126
|
+
refund.payment_id = payment.payment_id
|
127
|
+
refund.amount = payment.amount
|
128
|
+
refund.adjusted = true
|
129
|
+
item = KillBillClient::Model::InvoiceItem.new
|
130
|
+
item.invoice_item_id = invoice_item.invoice_item_id
|
131
|
+
item.amount = invoice_item.amount
|
132
|
+
refund.adjustments = [item]
|
133
|
+
refund.create 'KillBill Spec test'
|
134
|
+
|
135
|
+
# Verify the refund
|
136
|
+
timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
|
137
|
+
timeline.payments.should_not be_empty
|
138
|
+
payment = timeline.payments.first
|
139
|
+
payment.refunds.should_not be_empty
|
140
|
+
payment.refunds.first.amount.should == invoice_item.amount
|
107
141
|
end
|
108
142
|
|
109
143
|
it 'should manipulate tag definitions' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.8.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.8.0
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rake
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
162
|
version: '0'
|
147
163
|
segments:
|
148
164
|
- 0
|
149
|
-
hash: -
|
165
|
+
hash: -442212084689921420
|
150
166
|
requirements: []
|
151
167
|
rubyforge_project:
|
152
168
|
rubygems_version: 1.8.25
|