From 00b67a16c807485e4a25412c1b521edb52d2892c Mon Sep 17 00:00:00 2001 From: Flavio Muller Date: Mon, 1 Apr 2024 18:37:00 -0400 Subject: [PATCH] Add net_terms_type to Invoices, Purchases, and Subscriptions --- lib/recurly/invoice.rb | 1 + lib/recurly/purchase.rb | 1 + lib/recurly/subscription.rb | 1 + .../purchases/invoice-with-eom-net-terms.xml | 161 ++++++++++++++++++ .../preview-201-with-eom-net-terms.xml | 67 ++++++++ .../preview-200-change-with-eom-net-terms.xml | 73 ++++++++ .../show-200-with-eom-net-terms.xml | 1 + spec/recurly/purchase_spec.rb | 31 ++++ spec/recurly/subscription_spec.rb | 22 +++ 9 files changed, 358 insertions(+) create mode 100644 spec/fixtures/purchases/invoice-with-eom-net-terms.xml create mode 100644 spec/fixtures/purchases/preview-201-with-eom-net-terms.xml create mode 100644 spec/fixtures/subscriptions/preview-200-change-with-eom-net-terms.xml create mode 100644 spec/fixtures/subscriptions/show-200-with-eom-net-terms.xml diff --git a/lib/recurly/invoice.rb b/lib/recurly/invoice.rb index 69edcd1f2..00851ebae 100644 --- a/lib/recurly/invoice.rb +++ b/lib/recurly/invoice.rb @@ -96,6 +96,7 @@ def invoice_number_with_prefix customer_notes address net_terms + net_terms_type collection_method tax_types refund_tax_date diff --git a/lib/recurly/purchase.rb b/lib/recurly/purchase.rb index 006edc802..b84b3b882 100644 --- a/lib/recurly/purchase.rb +++ b/lib/recurly/purchase.rb @@ -136,6 +136,7 @@ class Purchase < Resource collection_method po_number net_terms + net_terms_type coupon_codes terms_and_conditions customer_notes diff --git a/lib/recurly/subscription.rb b/lib/recurly/subscription.rb index 9f9c512d8..5eea3e49f 100644 --- a/lib/recurly/subscription.rb +++ b/lib/recurly/subscription.rb @@ -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 diff --git a/spec/fixtures/purchases/invoice-with-eom-net-terms.xml b/spec/fixtures/purchases/invoice-with-eom-net-terms.xml new file mode 100644 index 000000000..681eabb34 --- /dev/null +++ b/spec/fixtures/purchases/invoice-with-eom-net-terms.xml @@ -0,0 +1,161 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/invoices/3517 + + + + + + +
+ + Chickpea + Batard + + 11060 US-31 + + Elk Rapids + MI + 49629 + US + +
+ + Verena Example + Verena + Example + 400 Alabama St. + + San Francisco + CA + 94110 + US + 555-555-5555 + + + 63f7cd6612ef3c7befe2aa4432bd9426 + paid + + 1240 + + 0 + 7000 + USD + 2022-08-10T18:26:38Z + 2022-08-10T18:26:38Z + + 2022-08-10T18:26:38Z + + + + 7000 + 7000 + 0 + 2022-08-10T18:26:38Z + 0 + charge + purchase + + 7000 + + 30 + eom + automatic + + + + + + + + + + + + 7000 + 63f7cd6605de0c75fbdf8745b28f77a8 + invoiced + Setup fee: Byzantium Draw + + ramp-plan + setup_fee + 7000 + 1 + 0 + 0 + 7000 + USD + + 2022-08-10T18:26:35Z + + 2022-08-10T18:26:38Z + 2022-08-10T18:26:38Z + evenly + + + + + + + + 63f7cd6639e20788c87c164842872b85 + purchase + 7000 + 0 + USD + success + credit_card + 5654000 + subscription + false + true + true + true + + test + api + + Successful test transaction + + + + Match + Street address and postal code match. + + + 2022-08-10T18:26:35Z + 2022-08-10T18:26:35Z + 2022-08-10T18:26:38Z + false +
+ + periwinkleamaranth4 + Ruby + Playground + + + + Chickpea + Batard + 11060 US-31 + + Elk Rapids + MI + 49629 + US + + + Visa + 2045 + 12 + 411111 + 1111 + + +
+
+
+ +
+ +
diff --git a/spec/fixtures/purchases/preview-201-with-eom-net-terms.xml b/spec/fixtures/purchases/preview-201-with-eom-net-terms.xml new file mode 100644 index 000000000..aa2706980 --- /dev/null +++ b/spec/fixtures/purchases/preview-201-with-eom-net-terms.xml @@ -0,0 +1,67 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/invoices/3517 + + + + + +
+ 400 Alabama St + + San Francisco + CA + 94110 + US + +
+ 3cd86c538142718179ec4a4b4586efc4 + open + + + + + 1000 + 0 + 1000 + 1000 + USD + + + 2017-04-13T23:23:35Z + + + + + 30 + eom + automatic + + + + 3cd86c5379c19c7f92dca34d46846c46 + pending + + + c6b6ea2e-770d-4b1e-bdec-279d4be7e22f + debit + 1000 + 1 + 0 + 0 + 1000 + USD + false + false + + 2017-04-13T23:23:35Z + + + + at_invoice + + + + +
+
diff --git a/spec/fixtures/subscriptions/preview-200-change-with-eom-net-terms.xml b/spec/fixtures/subscriptions/preview-200-change-with-eom-net-terms.xml new file mode 100644 index 000000000..04ff1d7fc --- /dev/null +++ b/spec/fixtures/subscriptions/preview-200-change-with-eom-net-terms.xml @@ -0,0 +1,73 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + plan_code + A Man, a Plan, a Canal: Panama + + abcdef1234567890 + active + 1000 + USD + 5 + 2014-05-20T16:29:59Z + + + + + 2014-05-20T16:29:59Z + 2014-06-20T16:29:59Z + + + 5000 + + + + + + + abcdefg123 + open + + + + 60 + eom + + 5000 + 0 + 5000 + USD + + + + + + + abcdefg111 + pending + plan_code + + plan_code + plan + 5000 + 5 + 0 + 0 + 5000 + USD + false + false + 2014-05-20T18:14:08Z + 2014-06-20T16:29:59Z + + + + + + + + diff --git a/spec/fixtures/subscriptions/show-200-with-eom-net-terms.xml b/spec/fixtures/subscriptions/show-200-with-eom-net-terms.xml new file mode 100644 index 000000000..6987fee3d --- /dev/null +++ b/spec/fixtures/subscriptions/show-200-with-eom-net-terms.xml @@ -0,0 +1 @@ +123456789012345678901234567890abbasicplanBasic Planactive130eommanual1000EUR10002011-05-27T07:00:00Z2011-06-27T07:00:00Z2010-07-27T07:00:00Z
diff --git a/spec/recurly/purchase_spec.rb b/spec/recurly/purchase_spec.rb index 99f7f1500..5e37d9159 100644 --- a/spec/recurly/purchase_spec.rb +++ b/spec/recurly/purchase_spec.rb @@ -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 @@ -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 @@ -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) diff --git a/spec/recurly/subscription_spec.rb b/spec/recurly/subscription_spec.rb index 68bafe38a..d14845394 100644 --- a/spec/recurly/subscription_spec.rb +++ b/spec/recurly/subscription_spec.rb @@ -57,6 +57,13 @@ subscription.po_number.must_equal('1000') end + it "check deserialize for net_terms_type" do + subscription = Subscription.from_xml get_raw_xml("subscriptions/show-200-with-eom-net-terms.xml") + subscription.must_be_instance_of Subscription + subscription.net_terms.must_equal(30) + subscription.net_terms_type.must_equal('eom') + end + it 'can deserialize tax information' do stub_api_request :get, 'subscriptions/abc1234', 'subscriptions/show-200-taxed' subscription = Subscription.find 'abc1234' @@ -434,6 +441,21 @@ subscription.invoice_collection.must_be_instance_of InvoiceCollection subscription.invoice_collection.charge_invoice.must_be_instance_of Invoice end + + it 'previews subscription with net_terms_type' do + stub_api_request :get, 'subscriptions/abcdef1234567890', 'subscriptions/show-200-noinvoice' + stub_api_request :post, 'subscriptions/abcdef1234567890/preview', 'subscriptions/preview-200-change-with-eom-net-terms' + + subscription = Subscription.find 'abcdef1234567890' + subscription.net_terms = 60 + subscription.net_terms_type = 'eom' + subscription.preview + + subscription.invoice_collection.must_be_instance_of InvoiceCollection + subscription.invoice_collection.charge_invoice.must_be_instance_of Invoice + subscription.invoice_collection.net_terms.must_equal 60 + subscription.invoice_collection.net_terms_type.must_equal 'eom' + end end describe 'pausing and resuming' do