recurly 2.12.2 → 2.13.0
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.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/recurly/account.rb +40 -4
- data/lib/recurly/adjustment.rb +5 -0
- data/lib/recurly/api.rb +1 -1
- data/lib/recurly/credit_payment.rb +28 -0
- data/lib/recurly/invoice.rb +48 -21
- data/lib/recurly/invoice_collection.rb +14 -0
- data/lib/recurly/purchase.rb +4 -4
- data/lib/recurly/resource.rb +36 -38
- data/lib/recurly/subscription.rb +2 -1
- data/lib/recurly/version.rb +2 -2
- data/lib/recurly/webhook/new_usage_notification.rb +8 -0
- data/lib/recurly/webhook.rb +1 -0
- data/lib/recurly/xml/nokogiri.rb +4 -1
- data/lib/recurly/xml.rb +17 -13
- data/lib/recurly.rb +2 -18
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce78f65370210f07aadec09d3ee7adc7914953c6
|
4
|
+
data.tar.gz: 3645d216c72e512ac2a9404524de84f051a581ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de8957a86ec7fa7d81af94bcc62fbcef07d8c4fb26c2ebc935c1f09fbf9a14fd9658c1be9c8fe51c4a45c570cb2256c5cfc65217f90c2f4e6ac3685b379d9a60
|
7
|
+
data.tar.gz: 3715c88543466b84c2e79d48fbadcbf04b1c4e0ddcce586356a3bfeea4fad2951eb01010aa9171abfa8f2bd8573ee23e316b83c18635fdd940b494a6e6509f1d
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Recurly is packaged as a Ruby gem. We recommend you install it with
|
|
14
14
|
[Bundler](http://gembundler.com/) by adding the following line to your Gemfile:
|
15
15
|
|
16
16
|
``` ruby
|
17
|
-
gem 'recurly', '~> 2.
|
17
|
+
gem 'recurly', '~> 2.13.0'
|
18
18
|
```
|
19
19
|
|
20
20
|
Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
|
data/lib/recurly/account.rb
CHANGED
@@ -39,6 +39,9 @@ module Recurly
|
|
39
39
|
# @return [AccountBalance, nil]
|
40
40
|
has_one :account_balance, readonly: true
|
41
41
|
|
42
|
+
# @return [Pager<CreditPayment>, []]
|
43
|
+
has_many :credit_payments, class_name: :CreditPayment, readonly: true
|
44
|
+
|
42
45
|
# Get's the first redemption given a coupon code
|
43
46
|
# @deprecated Use #{redemptions} instead
|
44
47
|
# @param coupon_code [String] The coupon code for the redemption
|
@@ -76,10 +79,10 @@ module Recurly
|
|
76
79
|
# Creates an invoice from the pending charges on the account.
|
77
80
|
# Raises an error if it fails.
|
78
81
|
#
|
79
|
-
# @return [
|
82
|
+
# @return [InvoiceCollection] A newly-created invoice.
|
80
83
|
# @raise [Invalid] Raised if the account cannot be invoiced.
|
81
84
|
def invoice!(attrs={})
|
82
|
-
|
85
|
+
InvoiceCollection.from_response API.post(invoices.uri, attrs.empty? ? nil : Invoice.to_xml(attrs))
|
83
86
|
rescue Recurly::API::UnprocessableEntity => e
|
84
87
|
raise Invalid, e.message
|
85
88
|
end
|
@@ -87,10 +90,10 @@ module Recurly
|
|
87
90
|
# Builds an invoice from the pending charges on the account but does not persist the invoice.
|
88
91
|
# Raises an error if it fails.
|
89
92
|
#
|
90
|
-
# @return [
|
93
|
+
# @return [InvoiceCollection] The newly-built invoice that has not been persisted.
|
91
94
|
# @raise [Invalid] Raised if the account cannot be invoiced.
|
92
95
|
def build_invoice
|
93
|
-
|
96
|
+
InvoiceCollection.from_response API.post("#{invoices.uri}/preview")
|
94
97
|
rescue Recurly::API::UnprocessableEntity => e
|
95
98
|
raise Invalid, e.message
|
96
99
|
end
|
@@ -106,6 +109,39 @@ module Recurly
|
|
106
109
|
true
|
107
110
|
end
|
108
111
|
|
112
|
+
# Verify a cvv code for the account's billing info.
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# acct = Recurly::Account.find('benjamin-du-monde')
|
116
|
+
# begin
|
117
|
+
# # If successful, returned billing_info will contain
|
118
|
+
# # updated billing info details.
|
119
|
+
# billing_info = acct.verify_cvv!("504")
|
120
|
+
# rescue Recurly::API::BadRequest => e
|
121
|
+
# e.message # => "This credit card has too many cvv check attempts."
|
122
|
+
# rescue Recurly::Transaction::Error => e
|
123
|
+
# # this will be the errors coming back from gateway
|
124
|
+
# e.transaction_error_code # => "fraud_security_code"
|
125
|
+
# e.gateway_error_code # => "fraud"
|
126
|
+
# rescue Recurly::Resource::Invalid => e
|
127
|
+
# e.message # => "verification_value must be three digits"
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
# @param [String] verification_value The CVV code to check
|
131
|
+
# @return [BillingInfo] The updated billing info
|
132
|
+
# @raise [Recurly::Transaction::Error] A Transaction Error will be raised if the gateway declines
|
133
|
+
# the cvv code.
|
134
|
+
# @raise [API::BadRequest] A BadRequest error will be raised if you attempt to check too many times
|
135
|
+
# and are locked out.
|
136
|
+
# @raise [Resource::Invalid] An Invalid Error will be raised if you send an invalid request (such as
|
137
|
+
# a value that is not a propert verification number).
|
138
|
+
def verify_cvv!(verification_value)
|
139
|
+
bi = BillingInfo.new(verification_value: verification_value)
|
140
|
+
bi.uri = "#{path}/billing_info/verify_cvv"
|
141
|
+
bi.save!
|
142
|
+
bi
|
143
|
+
end
|
144
|
+
|
109
145
|
def changed_attributes
|
110
146
|
attrs = super
|
111
147
|
if address.respond_to?(:changed?) && address.changed?
|
data/lib/recurly/adjustment.rb
CHANGED
@@ -18,6 +18,9 @@ module Recurly
|
|
18
18
|
# @return [Subscription, nil]
|
19
19
|
belongs_to :subscription
|
20
20
|
|
21
|
+
# @return [Pager<Adjustment>, []]
|
22
|
+
has_many :credit_adjustments, class_name: :Adjustment, readonly: true
|
23
|
+
|
21
24
|
define_attribute_methods %w(
|
22
25
|
uuid
|
23
26
|
state
|
@@ -45,6 +48,8 @@ module Recurly
|
|
45
48
|
tax_details
|
46
49
|
tax_types
|
47
50
|
proration_rate
|
51
|
+
credit_reason_code
|
52
|
+
original_adjustment_uuid
|
48
53
|
)
|
49
54
|
alias to_param uuid
|
50
55
|
|
data/lib/recurly/api.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Recurly
|
2
|
+
class CreditPayment < Resource
|
3
|
+
# @return [Account, nil]
|
4
|
+
belongs_to :account, class_name: :Account, readonly: true
|
5
|
+
|
6
|
+
# @return [Invoice, nil]
|
7
|
+
has_one :original_invoice, class_name: :Invoice, readonly: true
|
8
|
+
|
9
|
+
# @return [Invoice, nil]
|
10
|
+
has_one :applied_to_invoice, class_name: :Invoice, readonly: true
|
11
|
+
|
12
|
+
define_attribute_methods %w(
|
13
|
+
action
|
14
|
+
amount_in_cents
|
15
|
+
currency
|
16
|
+
created_at
|
17
|
+
original_credit_payment
|
18
|
+
refund_transaction
|
19
|
+
updated_at
|
20
|
+
uuid
|
21
|
+
voided_at
|
22
|
+
)
|
23
|
+
alias to_param uuid
|
24
|
+
|
25
|
+
# @return ["charge", "credit", nil] The type of credit payment.
|
26
|
+
attr_reader :type
|
27
|
+
end
|
28
|
+
end
|
data/lib/recurly/invoice.rb
CHANGED
@@ -10,20 +10,21 @@ module Recurly
|
|
10
10
|
# @macro [attach] scope
|
11
11
|
# @scope class
|
12
12
|
# @return [Pager<Invoice>] A pager that yields +$1+ invoices.
|
13
|
-
scope :
|
14
|
-
scope :
|
13
|
+
scope :pending, :state => :pending
|
14
|
+
scope :paid, :state => :paid
|
15
15
|
scope :failed, :state => :failed
|
16
16
|
scope :past_due, :state => :past_due
|
17
17
|
|
18
|
+
# These are deprecated as the states were renamed
|
19
|
+
scope :open, :state => :pending
|
20
|
+
scope :collected, :state => :paid
|
21
|
+
|
18
22
|
# @return [Account]
|
19
23
|
belongs_to :account
|
20
24
|
|
21
25
|
# @return [Pager<Subscription>, []]
|
22
26
|
has_many :subscriptions
|
23
27
|
|
24
|
-
# @return [Invoice]
|
25
|
-
belongs_to :original_invoice, class_name: :Invoice
|
26
|
-
|
27
28
|
# This will only be present if the invoice has > 500 line items
|
28
29
|
# @return [Pager<Adjustment>, []]
|
29
30
|
has_many :all_line_items, class_name: :Adjustment
|
@@ -32,7 +33,16 @@ module Recurly
|
|
32
33
|
has_many :redemptions
|
33
34
|
|
34
35
|
# @return [Pager<ShippingAddress>, [ShippingAddress], []]
|
35
|
-
has_one :shipping_address,
|
36
|
+
has_one :shipping_address, class_name: :ShippingAddress, readonly: true
|
37
|
+
|
38
|
+
# @return [Pager<Invoice>, []]
|
39
|
+
has_many :credit_invoices, class_name: :Invoice
|
40
|
+
|
41
|
+
# @return [[CreditPayment]]
|
42
|
+
has_many :credit_payments, class_name: :CreditPayment, readonly: true
|
43
|
+
|
44
|
+
# @return [Pager<Invoice>, []]
|
45
|
+
has_many :original_invoices, class_name: :Invoice, readonly: true
|
36
46
|
|
37
47
|
# Returns the first redemption in the Invoice's redemptions.
|
38
48
|
# This was placed here for backwards compatibility when we went from
|
@@ -76,9 +86,16 @@ module Recurly
|
|
76
86
|
tax_types
|
77
87
|
refund_tax_date
|
78
88
|
refund_geo_code
|
79
|
-
|
89
|
+
subtotal_before_discount_in_cents
|
80
90
|
attempt_next_collection_at
|
81
91
|
recovery_reason
|
92
|
+
discount_in_cents
|
93
|
+
balance_in_cents
|
94
|
+
due_on
|
95
|
+
type
|
96
|
+
origin
|
97
|
+
credit_customer_notes
|
98
|
+
refund_method
|
82
99
|
)
|
83
100
|
alias to_param invoice_number_with_prefix
|
84
101
|
|
@@ -110,13 +127,23 @@ module Recurly
|
|
110
127
|
# Initiate a collection attempt on an invoice.
|
111
128
|
#
|
112
129
|
# @return [true, false] +true+ when successful, +false+ when unable to
|
113
|
-
# (e.g., the invoice
|
130
|
+
# (e.g., the invoice is no longer open).
|
114
131
|
def force_collect
|
115
132
|
return false unless link? :force_collect
|
116
133
|
reload follow_link :force_collect
|
117
134
|
true
|
118
135
|
end
|
119
136
|
|
137
|
+
# Voids the invoice.
|
138
|
+
#
|
139
|
+
# @return [true, false] +true+ when successful, +false+ when unable to
|
140
|
+
# (e.g., the invoice is no longer open).
|
141
|
+
def void
|
142
|
+
return false unless link? :void
|
143
|
+
reload follow_link :void
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
120
147
|
# Posts an offline payment on this invoice
|
121
148
|
#
|
122
149
|
# @return [Transaction]
|
@@ -134,16 +161,16 @@ module Recurly
|
|
134
161
|
|
135
162
|
# Refunds specific line items on the invoice.
|
136
163
|
#
|
137
|
-
# @return [
|
164
|
+
# @return [InvoiceCollection, false] A new refund invoice, false if the invoice isn't
|
138
165
|
# refundable.
|
139
166
|
# @raise [Error] If the refund fails.
|
140
167
|
# @param line_items [Array, nil] An array of line items to refund.
|
141
|
-
|
168
|
+
# @param refund_method ["credit_first", "transaction_first"] The method used to refund.
|
169
|
+
def refund(line_items = nil, refund_method = 'credit_first')
|
142
170
|
return false unless link? :refund
|
143
|
-
|
144
|
-
follow_link :refund, :body => refund_line_items_to_xml(line_items,
|
171
|
+
InvoiceCollection.from_response(
|
172
|
+
follow_link :refund, :body => refund_line_items_to_xml(line_items, refund_method)
|
145
173
|
)
|
146
|
-
refund
|
147
174
|
end
|
148
175
|
|
149
176
|
# Refunds the invoice for a specific amount.
|
@@ -152,12 +179,12 @@ module Recurly
|
|
152
179
|
# refundable.
|
153
180
|
# @raise [Error] If the refund fails.
|
154
181
|
# @param amount_in_cents [Integer, nil] The amount (in cents) to refund.
|
155
|
-
|
182
|
+
# @param refund_method ["credit_first", "transaction_first"] The method used to refund.
|
183
|
+
def refund_amount amount_in_cents = nil, refund_method = 'credit_first'
|
156
184
|
return false unless link? :refund
|
157
|
-
|
158
|
-
follow_link :refund, :body => refund_amount_to_xml(amount_in_cents,
|
185
|
+
InvoiceCollection.from_response(
|
186
|
+
follow_link :refund, :body => refund_amount_to_xml(amount_in_cents, refund_method)
|
159
187
|
)
|
160
|
-
refund
|
161
188
|
end
|
162
189
|
|
163
190
|
def xml_keys
|
@@ -170,16 +197,16 @@ module Recurly
|
|
170
197
|
super({ :currency => Recurly.default_currency }.merge attributes)
|
171
198
|
end
|
172
199
|
|
173
|
-
def refund_amount_to_xml amount_in_cents = nil,
|
200
|
+
def refund_amount_to_xml amount_in_cents = nil, refund_method
|
174
201
|
builder = XML.new("<invoice/>")
|
175
|
-
builder.add_element '
|
202
|
+
builder.add_element 'refund_method', refund_method
|
176
203
|
builder.add_element 'amount_in_cents', amount_in_cents
|
177
204
|
builder.to_s
|
178
205
|
end
|
179
206
|
|
180
|
-
def refund_line_items_to_xml line_items = [],
|
207
|
+
def refund_line_items_to_xml line_items = [], refund_method
|
181
208
|
builder = XML.new("<invoice/>")
|
182
|
-
builder.add_element '
|
209
|
+
builder.add_element 'refund_method', refund_method
|
183
210
|
|
184
211
|
node = builder.add_element 'line_items'
|
185
212
|
line_items.each do |line_item|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Recurly
|
2
|
+
class InvoiceCollection < Resource
|
3
|
+
# @return [Invoice, nil]
|
4
|
+
has_one :charge_invoice, class_name: :Invoice, readonly: true
|
5
|
+
|
6
|
+
# @return [[Invoice], []]
|
7
|
+
has_many :credit_invoices, class_name: :Invoice, readonly: true
|
8
|
+
|
9
|
+
# These are readonly resources
|
10
|
+
embedded! true
|
11
|
+
undef save
|
12
|
+
undef destroy
|
13
|
+
end
|
14
|
+
end
|
data/lib/recurly/purchase.rb
CHANGED
@@ -105,7 +105,7 @@ module Recurly
|
|
105
105
|
# Generate an invoice for the purchase and run any needed transactions.
|
106
106
|
#
|
107
107
|
# @param purchase [Purchase] The purchase data for the request.
|
108
|
-
# @return [
|
108
|
+
# @return [InvoiceCollection] The saved invoice(s) representing this purchase.
|
109
109
|
# @raise [Invalid] Raised if the purchase cannot be invoiced.
|
110
110
|
# @raise [Transaction::Error] Raised if the transaction failed.
|
111
111
|
def invoice!(purchase)
|
@@ -116,7 +116,7 @@ module Recurly
|
|
116
116
|
# but does not run any transactions.
|
117
117
|
#
|
118
118
|
# @param purchase [Purchase] The purchase data for the request.
|
119
|
-
# @return [
|
119
|
+
# @return [InvoiceCollection] The preview invoice(s) representing this purchase.
|
120
120
|
# @raise [Invalid] Raised if the purchase cannot be invoiced.
|
121
121
|
def preview!(purchase)
|
122
122
|
post(purchase, "#{collection_path}/preview")
|
@@ -129,7 +129,7 @@ module Recurly
|
|
129
129
|
# Payment Pages).
|
130
130
|
#
|
131
131
|
# @param purchase [Purchase] The purchase data for the request.
|
132
|
-
# @return [
|
132
|
+
# @return [InvoiceCollection] The authorized invoice collection representing this purchase.
|
133
133
|
# @raise [Invalid] Raised if the purchase cannot be invoiced.
|
134
134
|
def authorize!(purchase)
|
135
135
|
post(purchase, "#{collection_path}/authorize")
|
@@ -137,7 +137,7 @@ module Recurly
|
|
137
137
|
|
138
138
|
def post(purchase, path)
|
139
139
|
response = API.send(:post, path, purchase.to_xml)
|
140
|
-
|
140
|
+
InvoiceCollection.from_response(response)
|
141
141
|
rescue API::UnprocessableEntity => e
|
142
142
|
purchase.apply_errors(e)
|
143
143
|
Transaction::Error.validate!(e, nil)
|
data/lib/recurly/resource.rb
CHANGED
@@ -391,18 +391,7 @@ module Recurly
|
|
391
391
|
# @see from_response
|
392
392
|
def from_xml(xml)
|
393
393
|
xml = XML.new xml
|
394
|
-
|
395
|
-
if self != Resource || xml.name == member_name
|
396
|
-
record = new
|
397
|
-
elsif Recurly.const_defined?(class_name = Helper.classify(xml.name), false)
|
398
|
-
klass = Recurly.const_get class_name, false
|
399
|
-
record = klass.send :new
|
400
|
-
elsif root = xml.root and root.elements.empty?
|
401
|
-
return XML.cast root
|
402
|
-
else
|
403
|
-
record = {}
|
404
|
-
end
|
405
|
-
klass ||= self
|
394
|
+
record = new
|
406
395
|
|
407
396
|
xml.root.attributes.each do |name, value|
|
408
397
|
record.instance_variable_set "@#{name}", value.to_s
|
@@ -425,26 +414,31 @@ module Recurly
|
|
425
414
|
# we dont care about text nodes, let's just skip them
|
426
415
|
next if defined?(Nokogiri::XML::Node::TEXT_NODE) && el.node_type == Nokogiri::XML::Node::TEXT_NODE
|
427
416
|
|
428
|
-
if
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
417
|
+
if association = find_association(el.name)
|
418
|
+
class_name = association_class_name(association, el.name)
|
419
|
+
resource_class = Recurly.const_get(class_name)
|
420
|
+
is_many = association.relation == :has_many
|
421
|
+
|
422
|
+
# Is this a link, or is it embedded data?
|
423
|
+
if el.children.empty? && href = el.attribute('href')
|
424
|
+
if is_many
|
425
|
+
record[el.name] = Pager.new(
|
426
|
+
resource_class, :uri => href.value, :parent => record
|
427
|
+
)
|
428
|
+
else
|
429
|
+
record.links[el.name] = {
|
430
|
+
:resource_class => resource_class,
|
431
|
+
:method => :get,
|
432
|
+
:href => href.value
|
433
|
+
}
|
434
|
+
end
|
435
|
+
else
|
436
|
+
if is_many
|
437
|
+
resources = el.elements.map { |e| resource_class.from_xml(e) }
|
438
|
+
record[el.name] = resources
|
439
|
+
else
|
440
|
+
record[el.name] = resource_class.from_xml(el)
|
441
|
+
end
|
448
442
|
end
|
449
443
|
else
|
450
444
|
# TODO name tax_type conflicts with the TaxType
|
@@ -484,12 +478,9 @@ module Recurly
|
|
484
478
|
associations.select{ |a| a.relation == relation }.map(&:resource_class)
|
485
479
|
end
|
486
480
|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
def association_class_name(resource_class)
|
491
|
-
association = find_association(resource_class)
|
492
|
-
association.class_name if association
|
481
|
+
def association_class_name(association, el_name)
|
482
|
+
return association.class_name if association.class_name
|
483
|
+
Helper.classify(el_name)
|
493
484
|
end
|
494
485
|
|
495
486
|
# @return [Association, nil] Find association for the current class
|
@@ -599,6 +590,13 @@ module Recurly
|
|
599
590
|
private_class_method(*%w(all find_each first paginate scoped where))
|
600
591
|
end
|
601
592
|
end
|
593
|
+
|
594
|
+
def find_resource_class(name)
|
595
|
+
resource_name = Helper.classify(name)
|
596
|
+
if Recurly.const_defined?(resource_name, false)
|
597
|
+
Recurly.const_get(resource_name, false)
|
598
|
+
end
|
599
|
+
end
|
602
600
|
end
|
603
601
|
|
604
602
|
# @return [Hash] The raw hash of record attributes.
|
data/lib/recurly/subscription.rb
CHANGED
@@ -33,7 +33,7 @@ module Recurly
|
|
33
33
|
has_one :gift_card
|
34
34
|
|
35
35
|
# @return [ShippingAddress, nil]
|
36
|
-
has_one :shipping_address,
|
36
|
+
has_one :shipping_address, class_name: :ShippingAddress, readonly: false
|
37
37
|
|
38
38
|
define_attribute_methods %w(
|
39
39
|
uuid
|
@@ -76,6 +76,7 @@ module Recurly
|
|
76
76
|
converted_at
|
77
77
|
no_billing_info_reason
|
78
78
|
imported_trial
|
79
|
+
credit_customer_notes
|
79
80
|
)
|
80
81
|
alias to_param uuid
|
81
82
|
|
data/lib/recurly/version.rb
CHANGED
data/lib/recurly/webhook.rb
CHANGED
@@ -47,6 +47,7 @@ module Recurly
|
|
47
47
|
autoload :ProcessingInvoiceNotification, 'recurly/webhook/processing_invoice_notification'
|
48
48
|
autoload :ScheduledPaymentNotification, 'recurly/webhook/scheduled_payment_notification'
|
49
49
|
autoload :NewDunningEventNotification, 'recurly/webhook/new_dunning_event_notification'
|
50
|
+
autoload :NewUsageNotification, 'recurly/webhook/new_usage_notification'
|
50
51
|
|
51
52
|
# This exception is raised if the Webhook Notification initialization fails
|
52
53
|
class NotificationError < Error
|
data/lib/recurly/xml/nokogiri.rb
CHANGED
@@ -46,7 +46,10 @@ module Recurly
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def to_s
|
49
|
-
root.to_xml(
|
49
|
+
root.to_xml(
|
50
|
+
indent: 0,
|
51
|
+
save_with: Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS
|
52
|
+
).gsub(/$\n/, '')
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
data/lib/recurly/xml.rb
CHANGED
@@ -1,38 +1,42 @@
|
|
1
1
|
module Recurly
|
2
2
|
class XML
|
3
3
|
class << self
|
4
|
-
def cast
|
4
|
+
def cast(el)
|
5
|
+
# return nil if the `nil` attribute is present
|
5
6
|
return if el.attribute 'nil'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
# get the type from the xml attribute but default to nil
|
9
|
+
type = if el.attribute('type')
|
10
|
+
el.attribute('type').value
|
11
|
+
end
|
10
12
|
|
13
|
+
# try to parse it as a known simple type
|
11
14
|
case type
|
12
|
-
when 'array' then el.elements.map { |e|
|
15
|
+
when 'array' then el.elements.map { |e| cast(e) }
|
13
16
|
when 'boolean' then el.text == 'true'
|
14
|
-
when 'date' then Date.parse
|
15
|
-
when 'datetime' then DateTime.parse
|
17
|
+
when 'date' then Date.parse(el.text)
|
18
|
+
when 'datetime' then DateTime.parse(el.text)
|
16
19
|
when 'float' then el.text.to_f
|
17
20
|
when 'integer' then el.text.to_i
|
18
21
|
else
|
19
|
-
#
|
22
|
+
# try to find a Resource class responsible for this element
|
20
23
|
[el.name, type].each do |name|
|
21
24
|
next unless name
|
22
|
-
|
23
|
-
|
24
|
-
return Recurly.const_get(resource_name, false).from_xml el
|
25
|
+
if resource = Recurly::Resource.find_resource_class(name)
|
26
|
+
return resource.from_xml(el)
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
# fallback to parsing it as a String or a Hash
|
27
31
|
if el.elements.empty?
|
28
32
|
el.text
|
29
33
|
else
|
30
|
-
Hash[el.elements.map { |e| [e.name,
|
34
|
+
Hash[el.elements.map { |e| [e.name, cast(e)] }]
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
35
|
-
def filter
|
39
|
+
def filter(text)
|
36
40
|
xml = XML.new text
|
37
41
|
xml.each do |el|
|
38
42
|
el = XML.new el
|
data/lib/recurly.rb
CHANGED
@@ -14,8 +14,10 @@ module Recurly
|
|
14
14
|
require 'recurly/juris_detail'
|
15
15
|
require 'recurly/adjustment'
|
16
16
|
require 'recurly/coupon'
|
17
|
+
require 'recurly/credit_payment'
|
17
18
|
require 'recurly/helper'
|
18
19
|
require 'recurly/invoice'
|
20
|
+
require 'recurly/invoice_collection'
|
19
21
|
require 'recurly/js'
|
20
22
|
require 'recurly/money'
|
21
23
|
require 'recurly/measured_unit'
|
@@ -87,8 +89,6 @@ module Recurly
|
|
87
89
|
end
|
88
90
|
|
89
91
|
# Assigns a logger to log requests/responses and more.
|
90
|
-
# The logger can only be set if the environment variable
|
91
|
-
# `RECURLY_INSECURE_DEBUG` equals `true`.
|
92
92
|
#
|
93
93
|
# @return [Logger, nil]
|
94
94
|
# @example
|
@@ -100,22 +100,6 @@ module Recurly
|
|
100
100
|
# Recurly.logger = nil # Or Recurly.logger = Logger.new nil
|
101
101
|
attr_accessor :logger
|
102
102
|
|
103
|
-
def logger=(logger)
|
104
|
-
if ENV['RECURLY_INSECURE_DEBUG'].to_s.downcase == 'true'
|
105
|
-
@logger = logger
|
106
|
-
puts <<-MSG
|
107
|
-
[WARNING] Recurly logger enabled. The logger has the potential to leak
|
108
|
-
PII and should never be used in production environments.
|
109
|
-
MSG
|
110
|
-
else
|
111
|
-
puts <<-MSG
|
112
|
-
[WARNING] Recurly logger has been disabled. If you wish to use it,
|
113
|
-
only do so in a non-production environment and make sure
|
114
|
-
the `RECURLY_INSECURE_DEBUG` environment variable is set to `true`.
|
115
|
-
MSG
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
103
|
# Convenience logging method includes a Logger#progname dynamically.
|
120
104
|
# @return [true, nil]
|
121
105
|
def log level, message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recurly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Recurly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.3.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: yard
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,11 +173,13 @@ files:
|
|
159
173
|
- lib/recurly/api/net_http_adapter.rb
|
160
174
|
- lib/recurly/billing_info.rb
|
161
175
|
- lib/recurly/coupon.rb
|
176
|
+
- lib/recurly/credit_payment.rb
|
162
177
|
- lib/recurly/delivery.rb
|
163
178
|
- lib/recurly/error.rb
|
164
179
|
- lib/recurly/gift_card.rb
|
165
180
|
- lib/recurly/helper.rb
|
166
181
|
- lib/recurly/invoice.rb
|
182
|
+
- lib/recurly/invoice_collection.rb
|
167
183
|
- lib/recurly/js.rb
|
168
184
|
- lib/recurly/juris_detail.rb
|
169
185
|
- lib/recurly/measured_unit.rb
|
@@ -199,6 +215,7 @@ files:
|
|
199
215
|
- lib/recurly/webhook/new_dunning_event_notification.rb
|
200
216
|
- lib/recurly/webhook/new_invoice_notification.rb
|
201
217
|
- lib/recurly/webhook/new_subscription_notification.rb
|
218
|
+
- lib/recurly/webhook/new_usage_notification.rb
|
202
219
|
- lib/recurly/webhook/notification.rb
|
203
220
|
- lib/recurly/webhook/past_due_invoice_notification.rb
|
204
221
|
- lib/recurly/webhook/processing_invoice_notification.rb
|
@@ -238,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
255
|
version: '0'
|
239
256
|
requirements: []
|
240
257
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.6.13
|
242
259
|
signing_key:
|
243
260
|
specification_version: 4
|
244
261
|
summary: Recurly API Client
|