Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to credit memos feature #360

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/recurly/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ def mark_successful
end

# Marks an invoice as failing collection.
# Returns a new {InvoiceCollection} and does not
# reload this invoice.
#
# @return [true, false] +true+ when successful, +false+ when unable to
# @return [InvoiceCollection, false] InvoiceCollection when successful, +false+ when unable to
# (e.g., the invoice is no longer open).
def mark_failed
return false unless link? :mark_failed
reload follow_link :mark_failed
true
InvoiceCollection.from_response follow_link(:mark_failed)
rescue Recurly::API::UnprocessableEntity => e
raise Invalid, e.message
end

# Initiate a collection attempt on an invoice.
Expand Down
3 changes: 3 additions & 0 deletions lib/recurly/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Subscription < Resource
# @return [ShippingAddress, nil]
has_one :shipping_address, class_name: :ShippingAddress, readonly: false

# @return [InvoiceCollection, nil]
has_one :invoice_collection, class_name: :InvoiceCollection, readonly: true

define_attribute_methods %w(
uuid
state
Expand Down
84 changes: 43 additions & 41 deletions spec/fixtures/subscriptions/preview-200-change.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,47 @@ Content-Type: application/xml; charset=utf-8
<cost_in_cents type="integer">5000</cost_in_cents>
<subscription_add_ons type="array">
</subscription_add_ons>
<invoice href="">
<account href="https://api.recurly.com/v2/accounts/account_code"/>
<subscription href="https://api.recurly.com/v2/subscriptions/abcdef1234567890"/>
<uuid>abcdefg123</uuid>
<state>open</state>
<invoice_number nil="nil"></invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
<vat_number></vat_number>
<subtotal_in_cents type="integer">5000</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">5000</total_in_cents>
<currency>USD</currency>
<created_at nil="nil"></created_at>
<closed_at nil="nil"></closed_at>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/abcdefg111" type="charge">
<account href="https://api.recurly.com/v2/accounts/account_code"/>
<subscription href="https://api.recurly.com/v2/subscriptions/abcdef1234567890"/>
<uuid>abcdefg111</uuid>
<state>pending</state>
<description>plan_code</description>
<accounting_code></accounting_code>
<product_code>plan_code</product_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">5000</unit_amount_in_cents>
<quantity type="integer">5</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">5000</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<tax_exempt type="boolean">false</tax_exempt>
<start_date type="datetime">2014-05-20T18:14:08Z</start_date>
<end_date type="datetime">2014-06-20T16:29:59Z</end_date>
<created_at nil="nil"></created_at>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</invoice>
<invoice_collection>
<charge_invoice>
<account href="https://api.recurly.com/v2/accounts/account_code"/>
<subscription href="https://api.recurly.com/v2/subscriptions/abcdef1234567890"/>
<uuid>abcdefg123</uuid>
<state>open</state>
<invoice_number nil="nil"></invoice_number>
<invoice_number_prefix></invoice_number_prefix>
<po_number nil="nil"></po_number>
<vat_number></vat_number>
<subtotal_in_cents type="integer">5000</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">5000</total_in_cents>
<currency>USD</currency>
<created_at nil="nil"></created_at>
<closed_at nil="nil"></closed_at>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/abcdefg111" type="charge">
<account href="https://api.recurly.com/v2/accounts/account_code"/>
<subscription href="https://api.recurly.com/v2/subscriptions/abcdef1234567890"/>
<uuid>abcdefg111</uuid>
<state>pending</state>
<description>plan_code</description>
<accounting_code></accounting_code>
<product_code>plan_code</product_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">5000</unit_amount_in_cents>
<quantity type="integer">5</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">5000</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<tax_exempt type="boolean">false</tax_exempt>
<start_date type="datetime">2014-05-20T18:14:08Z</start_date>
<end_date type="datetime">2014-06-20T16:29:59Z</end_date>
<created_at nil="nil"></created_at>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</charge_invoice>
</invoice_collection>
</subscription>
3 changes: 2 additions & 1 deletion spec/recurly/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@
subscription.preview

subscription.cost_in_cents.must_equal subscription.unit_amount_in_cents * 5
subscription.invoice.must_be_instance_of Invoice
subscription.invoice_collection.must_be_instance_of InvoiceCollection
subscription.invoice_collection.charge_invoice.must_be_instance_of Invoice
end
end

Expand Down