Skip to content

Commit

Permalink
Add net_terms_type to Invoices, Purchases, and Subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviomuller committed Apr 1, 2024
1 parent 0dd5973 commit 00b67a1
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/recurly/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def invoice_number_with_prefix
customer_notes
address
net_terms
net_terms_type
collection_method
tax_types
refund_tax_date
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Purchase < Resource
collection_method
po_number
net_terms
net_terms_type
coupon_codes
terms_and_conditions
customer_notes
Expand Down
1 change: 1 addition & 0 deletions lib/recurly/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Subscription < Resource
total_billing_cycles
remaining_billing_cycles
net_terms
net_terms_type
collection_method
po_number
tax_in_cents
Expand Down
161 changes: 161 additions & 0 deletions spec/fixtures/purchases/invoice-with-eom-net-terms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/invoices/3517

<?xml version="1.0" encoding="UTF-8"?>
<invoice_collection>
<charge_invoice href="https://api.recurly.com/v2/invoices/1240">
<account href="https://api.recurly.com/v2/accounts/periwinkleamaranth4"/>
<dunning_campaign_id nil="nil"/>
<address>
<name_on_account nil="nil"/>
<first_name>Chickpea</first_name>
<last_name>Batard</last_name>
<company/>
<address1>11060 US-31</address1>
<address2 nil="nil"/>
<city>Elk Rapids</city>
<state>MI</state>
<zip>49629</zip>
<country>US</country>
<phone nil="nil"/>
</address>
<shipping_address>
<name>Verena Example</name>
<first_name>Verena</first_name>
<last_name>Example</last_name>
<address1>400 Alabama St.</address1>
<address2 nil="nil"/>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone>555-555-5555</phone>
</shipping_address>
<subscriptions href="https://api.recurly.com/v2/invoices/1240/subscriptions"/>
<uuid>63f7cd6612ef3c7befe2aa4432bd9426</uuid>
<state>paid</state>
<invoice_number_prefix/>
<invoice_number type="integer">1240</invoice_number>
<vat_number nil="nil"/>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">7000</total_in_cents>
<currency>USD</currency>
<created_at type="datetime">2022-08-10T18:26:38Z</created_at>
<updated_at type="datetime">2022-08-10T18:26:38Z</updated_at>
<attempt_next_collection_at nil="nil"/>
<closed_at type="datetime">2022-08-10T18:26:38Z</closed_at>
<customer_notes nil="nil"/>
<recovery_reason nil="nil"/>
<gateway_code nil="nil"/>
<subtotal_before_discount_in_cents type="integer">7000</subtotal_before_discount_in_cents>
<subtotal_in_cents type="integer">7000</subtotal_in_cents>
<discount_in_cents type="integer">0</discount_in_cents>
<due_on type="datetime">2022-08-10T18:26:38Z</due_on>
<balance_in_cents type="integer">0</balance_in_cents>
<type>charge</type>
<origin>purchase</origin>
<credit_invoices href="https://api.recurly.com/v2/invoices/1240/credit_invoices"/>
<refundable_total_in_cents type="integer">7000</refundable_total_in_cents>
<credit_payments type="array"/>
<net_terms type="integer">30</net_terms>
<net_terms_type type="string">eom</net_terms_type>
<collection_method>automatic</collection_method>
<po_number nil="nil"/>
<terms_and_conditions nil="nil"/>
<line_items type="array">
<adjustment href="https://api.recurly.com/v2/adjustments/63f7cd6605de0c75fbdf8745b28f77a8" type="charge">
<account href="https://api.recurly.com/v2/accounts/periwinkleamaranth4"/>
<bill_for_account href="https://api.recurly.com/v2/accounts/periwinkleamaranth4"/>
<item_code nil="nil"/>
<external_sku nil="nil"/>
<invoice href="https://api.recurly.com/v2/invoices/1240"/>
<subscription href="https://api.recurly.com/v2/subscriptions/63f7cd659ab7ad05401eff456dab46f8"/>
<credit_adjustments href="https://api.recurly.com/v2/adjustments/63f7cd6605de0c75fbdf8745b28f77a8/credit_adjustments"/>
<refundable_total_in_cents type="integer">7000</refundable_total_in_cents>
<uuid>63f7cd6605de0c75fbdf8745b28f77a8</uuid>
<state>invoiced</state>
<description>Setup fee: Byzantium Draw</description>
<accounting_code nil="nil"/>
<product_code>ramp-plan</product_code>
<origin>setup_fee</origin>
<unit_amount_in_cents type="integer">7000</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">7000</total_in_cents>
<currency>USD</currency>
<proration_rate nil="nil"/>
<start_date type="datetime">2022-08-10T18:26:35Z</start_date>
<end_date nil="nil"/>
<created_at type="datetime">2022-08-10T18:26:38Z</created_at>
<updated_at type="datetime">2022-08-10T18:26:38Z</updated_at>
<revenue_schedule_type>evenly</revenue_schedule_type>
</adjustment>
</line_items>
<transactions type="array">
<transaction href="https://api.recurly.com/v2/transactions/63f7cd6639e20788c87c164842872b85" type="credit_card">
<account href="https://api.recurly.com/v2/accounts/periwinkleamaranth4"/>
<invoice href="https://api.recurly.com/v2/invoices/1240"/>
<subscriptions href="https://api.recurly.com/v2/transactions/63f7cd6639e20788c87c164842872b85/subscriptions"/>
<uuid>63f7cd6639e20788c87c164842872b85</uuid>
<action>purchase</action>
<amount_in_cents type="integer">7000</amount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<currency>USD</currency>
<status>success</status>
<payment_method>credit_card</payment_method>
<reference>5654000</reference>
<source>subscription</source>
<recurring type="boolean">false</recurring>
<test type="boolean">true</test>
<voidable type="boolean">true</voidable>
<refundable type="boolean">true</refundable>
<ip_address nil="nil"/>
<gateway_type>test</gateway_type>
<origin>api</origin>
<description nil="nil"/>
<message>Successful test transaction</message>
<approval_code nil="nil"/>
<failure_type nil="nil"/>
<gateway_error_codes nil="nil"/>
<cvv_result code="M">Match</cvv_result>
<avs_result code="D">Street address and postal code match.</avs_result>
<avs_result_street nil="nil"/>
<avs_result_postal nil="nil"/>
<created_at type="datetime">2022-08-10T18:26:35Z</created_at>
<collected_at type="datetime">2022-08-10T18:26:35Z</collected_at>
<updated_at type="datetime">2022-08-10T18:26:38Z</updated_at>
<backup_payment_method_used type="boolean">false</backup_payment_method_used>
<details>
<account>
<account_code>periwinkleamaranth4</account_code>
<first_name>Ruby</first_name>
<last_name>Playground</last_name>
<company nil="nil"/>
<email nil="nil"/>
<billing_info type="credit_card">
<first_name>Chickpea</first_name>
<last_name>Batard</last_name>
<address1>11060 US-31</address1>
<address2 nil="nil"/>
<city>Elk Rapids</city>
<state>MI</state>
<zip>49629</zip>
<country>US</country>
<phone nil="nil"/>
<vat_number nil="nil"/>
<card_type>Visa</card_type>
<year type="integer">2045</year>
<month type="integer">12</month>
<first_six>411111</first_six>
<last_four>1111</last_four>
</billing_info>
</account>
</details>
</transaction>
</transactions>
<a name="refund" href="https://api.recurly.com/v2/invoices/1240/refund" method="post"/>
</charge_invoice>
<credit_invoices type="array"/>
</invoice_collection>
67 changes: 67 additions & 0 deletions spec/fixtures/purchases/preview-201-with-eom-net-terms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
HTTP/1.1 201 Created
Content-Type: application/xml; charset=utf-8
Location: https://api.recurly.com/v2/invoices/3517

<?xml version="1.0" encoding="UTF-8"?>
<invoice_collection>
<charge_invoice href="">
<account href="https://api.recurly.com/v2/accounts/e33a27ba-d040-4055-b792-7908f375519c"/>
<address>
<address1>400 Alabama St</address1>
<address2 nil="nil"></address2>
<city>San Francisco</city>
<state>CA</state>
<zip>94110</zip>
<country>US</country>
<phone nil="nil"></phone>
</address>
<uuid>3cd86c538142718179ec4a4b4586efc4</uuid>
<state>open</state>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number nil="nil"></invoice_number>
<po_number nil="nil"></po_number>
<vat_number nil="nil"></vat_number>
<subtotal_in_cents type="integer">1000</subtotal_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1000</total_in_cents>
<subtotal_after_discount_in_cents type="integer">1000</subtotal_after_discount_in_cents>
<currency>USD</currency>
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<attempt_next_collection_at type="datetime">2017-04-13T23:23:35Z</attempt_next_collection_at>
<closed_at nil="nil"></closed_at>
<terms_and_conditions nil="nil"></terms_and_conditions>
<customer_notes nil="nil"></customer_notes>
<recovery_reason nil="nil"></recovery_reason>
<net_terms type="integer">30</net_terms>
<net_terms_type type="string">eom</net_terms_type>
<collection_method>automatic</collection_method>
<line_items type="array">
<adjustment href="" type="charge">
<account href="https://api.recurly.com/v2/accounts/e33a27ba-d040-4055-b792-7908f375519c"/>
<uuid>3cd86c5379c19c7f92dca34d46846c46</uuid>
<state>pending</state>
<description nil="nil"></description>
<accounting_code nil="nil"></accounting_code>
<product_code>c6b6ea2e-770d-4b1e-bdec-279d4be7e22f</product_code>
<origin>debit</origin>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1000</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<tax_exempt type="boolean">false</tax_exempt>
<tax_code nil="nil"></tax_code>
<start_date type="datetime">2017-04-13T23:23:35Z</start_date>
<end_date nil="nil"></end_date>
<created_at nil="nil"></created_at>
<updated_at nil="nil"></updated_at>
<revenue_schedule_type>at_invoice</revenue_schedule_type>
</adjustment>
</line_items>
<transactions type="array">
</transactions>
</charge_invoice>
</invoice_collection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<subscription href="https://api.recurly.com/v2/subscriptions/abcdef1234567890">
<account href="https://api.recurly.com/v2/accounts/account_code"/>
<plan href="https://api.recurly.com/v2/plans/plan_code">
<plan_code>plan_code</plan_code>
<name>A Man, a Plan, a Canal: Panama</name>
</plan>
<uuid>abcdef1234567890</uuid>
<state>active</state>
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
<currency>USD</currency>
<quantity type="integer">5</quantity>
<activated_at type="datetime">2014-05-20T16:29:59Z</activated_at>
<canceled_at nil="nil"></canceled_at>
<expires_at nil="nil"></expires_at>
<total_billing_cycles nil="nil"></total_billing_cycles>
<remaining_billing_cycles nil="nil"></remaining_billing_cycles>
<current_period_started_at type="datetime">2014-05-20T16:29:59Z</current_period_started_at>
<current_period_ends_at type="datetime">2014-06-20T16:29:59Z</current_period_ends_at>
<trial_started_at nil="nil"></trial_started_at>
<trial_ends_at nil="nil"></trial_ends_at>
<cost_in_cents type="integer">5000</cost_in_cents>
<subscription_add_ons type="array">
</subscription_add_ons>
<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>
<net_terms type="integer">60</net_terms>
<net_terms_type>eom</net_terms_type>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<subscription href="https://api.recurly.com/v2/subscriptions/123456789012345678901234567890ab"><uuid>123456789012345678901234567890ab</uuid><account href="https://api.recurly.com/v2/accounts/subscribemock"/><plan href="https://api.recurly.com/v2/plans/basicplan"><plan_code>basicplan</plan_code><name>Basic Plan</name></plan><state>active</state><quantity type="integer">1</quantity><net_terms type="integer">30</net_terms><net_terms_type>eom</net_terms_type><collection_method>manual</collection_method><po_number>1000</po_number><currency>EUR</currency><unit_amount_in_cents type="integer">1000</unit_amount_in_cents><activated_at type="datetime">2011-05-27T07:00:00Z</activated_at><canceled_at nil="nil"></canceled_at><expires_at nil="nil"></expires_at><current_period_started_at type="datetime">2011-06-27T07:00:00Z</current_period_started_at><current_period_ends_at type="datetime">2010-07-27T07:00:00Z</current_period_ends_at><trial_started_at nil="nil"></trial_started_at><trial_ends_at nil="nil"></trial_ends_at><subscription_add_ons type="array"></subscription_add_ons><a name="cancel" href="https://api.recurly.com/v2/subscriptions/123456789012345678901234567890ab/cancel" method="put"/><a name="terminate" href="https://api.recurly.com/v2/subscriptions/123456789012345678901234567890ab/terminate" method="put"/><a name="notes" href="https://api.recurly.com/v2/subscriptions/123456789012345678901234567890ab/notes" method="put"/></subscription>
31 changes: 31 additions & 0 deletions spec/recurly/purchase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
}
)
end
let(:purchase_with_net_terms_type) do
Purchase.new(
account: {account_code: 'account123'},
net_terms: 30,
net_terms_type: 'eom',
transaction_type: 'moto',
subscriptions: [
{
plan_code: plan_code,
}
],
)
end

describe 'Purchase.invoice!' do
it 'should return an invoice_collection when valid' do
Expand Down Expand Up @@ -80,6 +93,16 @@
charge_invoice.transactions.first.amount_in_cents.must_equal 7000
end

it 'the first ramp interval unit amount is reflected in these expected attributes' do
stub_api_request(:post, 'purchase_with_net_terms_type', 'purchases/invoice-with-eom-net-terms')
collection = Purchase.invoice!(purchase)
charge_invoice = collection.charge_invoice

charge_invoice.total_in_cents.must_equal 7000
charge_invoice.net_terms.must_equal 30
charge_invoice.net_terms_typw.must_equal 'eom'
end

it 'should raise an Invalid error when data is invalid' do
stub_api_request(:post, 'purchases', 'purchases/invoice-422')
# ensure error is raised
Expand Down Expand Up @@ -129,6 +152,14 @@
preview_collection.charge_invoice.must_be_instance_of Invoice
end

it 'should return a preview invoice with net_terms_type when valid' do
stub_api_request(:post, 'purchases/preview', 'purchases/preview-201-with-eom-net-terms')
preview_collection = Purchase.preview!(purchase_with_net_terms_type)
preview_collection.charge_invoice.must_be_instance_of Invoice
preview_collection.net_terms.must_equal 30
preview_collection.net_terms_type.must_equal 'eom'
end

it 'the first ramp interval unit amount is reflected in these expected attributes' do
stub_api_request(:post, 'purchases/preview', 'purchases/preview-with-ramp-pricing-201')
collection = Purchase.preview!(purchase)
Expand Down
Loading

0 comments on commit 00b67a1

Please sign in to comment.