diff --git a/lib/recurly.rb b/lib/recurly.rb index b29b89d84..28a5eaaf4 100644 --- a/lib/recurly.rb +++ b/lib/recurly.rb @@ -62,6 +62,8 @@ module Recurly require 'recurly/currency_percentage_tier' require 'recurly/sub_add_on_percentage_tier' require 'recurly/custom_field_definition' + require 'recurly/general_ledger_account' + require 'recurly/performance_obligation' @subdomain = nil diff --git a/lib/recurly/add_on.rb b/lib/recurly/add_on.rb index ab9d9e92b..822cb77db 100644 --- a/lib/recurly/add_on.rb +++ b/lib/recurly/add_on.rb @@ -31,7 +31,7 @@ class AddOn < Resource external_sku avalara_service_type avalara_transaction_type - ) + ) + RevRec::PRODUCT_ATTRIBUTES alias to_param add_on_code alias quantity default_quantity diff --git a/lib/recurly/adjustment.rb b/lib/recurly/adjustment.rb index 25572ea58..093f9d38c 100644 --- a/lib/recurly/adjustment.rb +++ b/lib/recurly/adjustment.rb @@ -68,7 +68,7 @@ class Adjustment < Resource avalara_transaction_type avalara_service_type refundable_total_in_cents - ] + ] + RevRec::ALL_ATTRIBUTES alias to_param uuid # @return ["charge", "credit", nil] The type of adjustment. diff --git a/lib/recurly/business_entity.rb b/lib/recurly/business_entity.rb index 17e178913..ce46f9b64 100644 --- a/lib/recurly/business_entity.rb +++ b/lib/recurly/business_entity.rb @@ -1,9 +1,10 @@ module Recurly class BusinessEntity < Resource belongs_to :site + belongs_to :default_revenue_gl_account, class_name: 'GeneralLedgerAccount' + belongs_to :default_liability_gl_account, class_name: 'GeneralLedgerAccount' has_many :invoices - has_many :accounts define_attribute_methods %w( @@ -15,6 +16,8 @@ class BusinessEntity < Resource subscriber_location_countries default_vat_number default_registration_number + default_revenue_gl_account_id + default_liability_gl_account_id created_at updated_at ) diff --git a/lib/recurly/general_ledger_account.rb b/lib/recurly/general_ledger_account.rb new file mode 100644 index 000000000..177c2e0bc --- /dev/null +++ b/lib/recurly/general_ledger_account.rb @@ -0,0 +1,16 @@ +module Recurly + class GeneralLedgerAccount < Resource + belongs_to :site + + define_attribute_methods %w( + id + code + description + account_type + ) + + def self.collection_path + "general_ledger_accounts" + end + end +end diff --git a/lib/recurly/gift_card.rb b/lib/recurly/gift_card.rb index 0864b2bcd..152abb45c 100644 --- a/lib/recurly/gift_card.rb +++ b/lib/recurly/gift_card.rb @@ -36,7 +36,7 @@ class GiftCard < Resource gifter_account_code recipient_account_code invoice_number - ) + ) + RevRec::PRODUCT_ATTRIBUTES alias to_param id # Preview a GiftCard given some attributes diff --git a/lib/recurly/item.rb b/lib/recurly/item.rb index e9d37216c..db567e654 100644 --- a/lib/recurly/item.rb +++ b/lib/recurly/item.rb @@ -16,7 +16,7 @@ class Item < Resource created_at updated_at deleted_at - ) + ) + RevRec::PRODUCT_ATTRIBUTES def changed_attributes attrs = super diff --git a/lib/recurly/performance_obligation.rb b/lib/recurly/performance_obligation.rb new file mode 100644 index 000000000..4cdee83fe --- /dev/null +++ b/lib/recurly/performance_obligation.rb @@ -0,0 +1,15 @@ +module Recurly + class PerformanceObligation < Resource + + define_attribute_methods %w( + id + name + created_at + updated_at + ) + + def self.collection_path + "performance_obligations" + end + end +end \ No newline at end of file diff --git a/lib/recurly/plan.rb b/lib/recurly/plan.rb index 2f6fa42b4..6162dad6d 100644 --- a/lib/recurly/plan.rb +++ b/lib/recurly/plan.rb @@ -1,6 +1,7 @@ module Recurly # Recurly Documentation: https://dev.recurly.com/docs/list-plans class Plan < Resource + # @return [Pager, []] has_many :add_ons @@ -13,6 +14,7 @@ class Plan < Resource # @return [[CustomField], []] has_many :custom_fields, class_name: :CustomField, readonly: false + # Define attribute methods define_attribute_methods %w( plan_code name @@ -50,7 +52,7 @@ class Plan < Resource custom_fields created_at updated_at - ) + ) + RevRec::PLAN_ATTRIBUTES alias to_param plan_code end end diff --git a/lib/recurly/resource.rb b/lib/recurly/resource.rb index 8d93bbb7e..d3c11653a 100644 --- a/lib/recurly/resource.rb +++ b/lib/recurly/resource.rb @@ -1,5 +1,6 @@ require 'date' require 'erb' +require_relative './rev_rec' module Recurly # The base class for all Recurly resources (e.g. {Account}, {Subscription}, diff --git a/lib/recurly/rev_rec.rb b/lib/recurly/rev_rec.rb new file mode 100644 index 000000000..3e91690d9 --- /dev/null +++ b/lib/recurly/rev_rec.rb @@ -0,0 +1,18 @@ +module Recurly + module RevRec + POB_ATTRIBUTE = %i(performance_obligation_id).freeze + POB_NATIVE_ATTRIBUTE = %i(performance_obligation_identifier).freeze + + GLA_ID_ATTRIBUTES = %i(liability_gl_account_id revenue_gl_account_id).freeze + GLA_CODE_ATTRIBUTES = %i(liability_gl_account_code revenue_gl_account_code).freeze + + PRODUCT_NATIVE_ATTRS = (POB_NATIVE_ATTRIBUTE + GLA_ID_ATTRIBUTES).freeze + PRODUCT_ATTRIBUTES = (POB_ATTRIBUTE + GLA_ID_ATTRIBUTES).freeze + + LINE_ITEM_ATTRIBUTES = (POB_ATTRIBUTE + GLA_CODE_ATTRIBUTES).freeze + ALL_ATTRIBUTES = (PRODUCT_ATTRIBUTES + LINE_ITEM_ATTRIBUTES).uniq.freeze + + SETUP_FEE_ATTRIBUTES = PRODUCT_ATTRIBUTES.map { |key| :"setup_fee_#{key}" }.freeze + PLAN_ATTRIBUTES = [*PRODUCT_ATTRIBUTES, *SETUP_FEE_ATTRIBUTES].freeze + end +end \ No newline at end of file diff --git a/lib/recurly/shipping_method.rb b/lib/recurly/shipping_method.rb index 76d915c14..2f1e45c2e 100644 --- a/lib/recurly/shipping_method.rb +++ b/lib/recurly/shipping_method.rb @@ -7,7 +7,7 @@ class ShippingMethod < Resource tax_code created_at updated_at - ) + ) + RevRec::PRODUCT_ATTRIBUTES alias to_param code end end diff --git a/lib/recurly/xml/rexml.rb b/lib/recurly/xml/rexml.rb index 6af6fc8c1..6d5135935 100644 --- a/lib/recurly/xml/rexml.rb +++ b/lib/recurly/xml/rexml.rb @@ -22,7 +22,7 @@ def each_element xpath = nil def each element = root element.each_element do |el| yield el - each el, &Proc.new + each el, &Proc.new { |e| yield e } end end diff --git a/spec/fixtures/adjustments/create-201-with-revrec.xml b/spec/fixtures/adjustments/create-201-with-revrec.xml new file mode 100644 index 000000000..6787490f1 --- /dev/null +++ b/spec/fixtures/adjustments/create-201-with-revrec.xml @@ -0,0 +1,39 @@ +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/adjustments/67360781108ceacd23dee747b7b1f5af + + + + + + + + 0 + 67360781108ceacd23dee747b7b1f5af + pending + + + + debit + 5000 + 1 + 0 + 0 + 5000 + USD + + 2023-01-18T23:34:52Z + + 2023-01-18T23:34:52Z + 2023-01-18T23:34:52Z + at_invoice + liability_gla + revenue_gla + 5 + + + field1 + priceless + + + \ No newline at end of file diff --git a/spec/fixtures/adjustments/show-200-with-revrec.xml b/spec/fixtures/adjustments/show-200-with-revrec.xml new file mode 100644 index 000000000..ea692785b --- /dev/null +++ b/spec/fixtures/adjustments/show-200-with-revrec.xml @@ -0,0 +1,64 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + + + + + plastic_gloves + plastic_gloves + abcdef1234567890 + pending + + plan + $12 Annual Subscription + 1200 + 1 + 1.2 + 0 + 5000 + usst + CA + 0.0875 + 1200 + USD + basic + evenly + 100 + 3 + 600 + liability_gla + revenue_gla + 5 + + + california + state + 0.065 + 3000 + state + true + + + san francisco + county + 0.02 + 2000 + + + 0.5 + abcdefg1234567 + 2011-04-30T07:00:00Z + 2011-04-30T07:00:00Z + 2011-08-31T03:30:00Z + + + field1 + priceless + + + diff --git a/spec/fixtures/business_entities/index-200.xml b/spec/fixtures/business_entities/index-200.xml index e455f83a2..a15a7e710 100644 --- a/spec/fixtures/business_entities/index-200.xml +++ b/spec/fixtures/business_entities/index-200.xml @@ -29,6 +29,8 @@ Link: + 12345 + 56789 2023-03-01T16:26:40Z 2023-04-01T16:26:40Z @@ -55,7 +57,8 @@ Link: - + abc123 + xyz789 2023-06-01T16:26:40Z 2023-07-01T16:26:40Z diff --git a/spec/fixtures/business_entities/show-200.xml b/spec/fixtures/business_entities/show-200.xml index d627ceae3..b43e34caa 100644 --- a/spec/fixtures/business_entities/show-200.xml +++ b/spec/fixtures/business_entities/show-200.xml @@ -1,35 +1,33 @@ HTTP/1.1 200 OK Content-Type: application/xml; charset=utf-8 -Link: ; rel="start", ; rel="next" - - - - sbup2j0fx800 - default - Default Business Entity - - 123 Main Ave - - San Francisco - CA - 90210 - US - - - - 123 Main Ave - - San Francisco - CA - 90210 - US - - - - - 2023-03-01T16:26:40Z - 2023-04-01T16:26:40Z - - \ No newline at end of file + + sbup2j0fx800 + default + Default Business Entity + + 123 Main Ave + + San Francisco + CA + 90210 + US + + + + 123 Main Ave + + San Francisco + CA + 90210 + US + + + + + 12345 + 56789 + 2023-03-01T16:26:40Z + 2023-04-01T16:26:40Z + \ No newline at end of file diff --git a/spec/fixtures/general_ledger_accounts/create-201.xml b/spec/fixtures/general_ledger_accounts/create-201.xml new file mode 100644 index 000000000..799effb08 --- /dev/null +++ b/spec/fixtures/general_ledger_accounts/create-201.xml @@ -0,0 +1,12 @@ +HTTP/1.1 201 Created + Content-Type: application/xml; charset=utf-8 + + + + u90r5deeaxix + code1 + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + \ No newline at end of file diff --git a/spec/fixtures/general_ledger_accounts/index-200-liability.xml b/spec/fixtures/general_ledger_accounts/index-200-liability.xml new file mode 100644 index 000000000..58b3f1b8c --- /dev/null +++ b/spec/fixtures/general_ledger_accounts/index-200-liability.xml @@ -0,0 +1,78 @@ +HTTP/1.1 200 OK + Content-Type: application/xml; charset=utf-8 + + + + + ty4utwr0mrgz + 90-557-279-6957 + liability + optimize rich content + 2023-11-22T16:36:34Z + 2023-11-22T16:36:34Z + + + twyyzw8vcm36 + 45-571-736-1179 + liability + incentivize sexy functionalities + 2023-11-16T19:45:05Z + 2023-11-16T19:45:05Z + + + twywtf01wkgb + 70-818-669-8644 + liability + generate transparent metrics + 2023-11-16T19:32:52Z + 2023-11-16T19:32:52Z + + + twywqfr48v9l + 7-271-680-5012 + liability + My main liability account + 2023-11-16T19:32:24Z + 2023-11-16T19:32:24Z + + + twyvjlhbnej2 + 1234 + liability + My main liability account + 2023-11-16T19:25:44Z + 2023-11-16T19:25:44Z + + + trkzlcm2pde8 + validategla + liability + HOWDY + 2023-10-20T15:22:49Z + 2023-10-20T15:22:49Z + + + trkzinjccchm + j + liability + HOWDY + 2023-10-20T15:22:24Z + 2023-10-20T15:22:24Z + + + tep8f2u4qq51 + get dat monayyy + liability + i can has money + 2023-08-16T15:45:40Z + 2023-08-16T15:45:40Z + + + tejv6lw4eovy + demo_liability + liability + i be descriptin' + 2023-08-15T21:42:35Z + 2023-09-13T15:38:04Z + + \ No newline at end of file diff --git a/spec/fixtures/general_ledger_accounts/index-200-revenue.xml b/spec/fixtures/general_ledger_accounts/index-200-revenue.xml new file mode 100644 index 000000000..5b5a91888 --- /dev/null +++ b/spec/fixtures/general_ledger_accounts/index-200-revenue.xml @@ -0,0 +1,38 @@ +HTTP/1.1 200 OK + Content-Type: application/xml; charset=utf-8 + + + + + u90r5deeaxix + string + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + + + trl0h3br1dl7 + 100 + revenue + HOWDY + 2023-10-20T15:27:46Z + 2023-10-20T15:27:46Z + + + trkz0atorlk3 + NEW code + revenue + NEW description + 2023-10-20T15:19:32Z + 2023-10-20T15:29:30Z + + + thproqnpcuwp + 303 + revenue + + 2023-08-31T20:46:04Z + 2023-08-31T20:46:04Z + + \ No newline at end of file diff --git a/spec/fixtures/general_ledger_accounts/index-200.xml b/spec/fixtures/general_ledger_accounts/index-200.xml new file mode 100644 index 000000000..c78664e2b --- /dev/null +++ b/spec/fixtures/general_ledger_accounts/index-200.xml @@ -0,0 +1,110 @@ +HTTP/1.1 200 OK + Content-Type: application/xml; charset=utf-8 + + + + + u90r5deeaxix + string + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + + + ty4utwr0mrgz + 90-557-279-6957 + liability + optimize rich content + 2023-11-22T16:36:34Z + 2023-11-22T16:36:34Z + + + twyyzw8vcm36 + 45-571-736-1179 + liability + incentivize sexy functionalities + 2023-11-16T19:45:05Z + 2023-11-16T19:45:05Z + + + twywtf01wkgb + 70-818-669-8644 + liability + generate transparent metrics + 2023-11-16T19:32:52Z + 2023-11-16T19:32:52Z + + + twywqfr48v9l + 7-271-680-5012 + liability + My main liability account + 2023-11-16T19:32:24Z + 2023-11-16T19:32:24Z + + + twyvjlhbnej2 + 1234 + liability + My main liability account + 2023-11-16T19:25:44Z + 2023-11-16T19:25:44Z + + + trl0h3br1dl7 + 100 + revenue + HOWDY + 2023-10-20T15:27:46Z + 2023-10-20T15:27:46Z + + + trkzlcm2pde8 + validategla + liability + HOWDY + 2023-10-20T15:22:49Z + 2023-10-20T15:22:49Z + + + trkzinjccchm + j + liability + HOWDY + 2023-10-20T15:22:24Z + 2023-10-20T15:22:24Z + + + trkz0atorlk3 + NEW code + revenue + NEW description + 2023-10-20T15:19:32Z + 2023-10-20T15:29:30Z + + + thproqnpcuwp + 303 + revenue + + 2023-08-31T20:46:04Z + 2023-08-31T20:46:04Z + + + tep8f2u4qq51 + get dat monayyy + liability + i can has money + 2023-08-16T15:45:40Z + 2023-08-16T15:45:40Z + + + tejv6lw4eovy + demo_liability + liability + i be descriptin' + 2023-08-15T21:42:35Z + 2023-09-13T15:38:04Z + + \ No newline at end of file diff --git a/spec/fixtures/general_ledger_accounts/show-200.xml b/spec/fixtures/general_ledger_accounts/show-200.xml new file mode 100644 index 000000000..a4010affe --- /dev/null +++ b/spec/fixtures/general_ledger_accounts/show-200.xml @@ -0,0 +1,12 @@ +HTTP/1.1 200 OK + Content-Type: application/xml; charset=utf-8 + + + + u90r5deeaxix + code1 + revenue + string + 2024-01-16T14:34:16Z + 2024-01-16T14:34:16Z + \ No newline at end of file diff --git a/spec/fixtures/gift_cards/show-200.xml b/spec/fixtures/gift_cards/show-200.xml index a1fc4fe75..05ee50baa 100644 --- a/spec/fixtures/gift_cards/show-200.xml +++ b/spec/fixtures/gift_cards/show-200.xml @@ -37,4 +37,7 @@ Content-Type: application/xml; charset=utf-8 2016-07-28T00:01:46Z + uf0jwj5zhclg + uf0jwincednb + 1 diff --git a/spec/fixtures/items/create-201.xml b/spec/fixtures/items/create-201.xml index 27671d40d..010ec19d4 100644 --- a/spec/fixtures/items/create-201.xml +++ b/spec/fixtures/items/create-201.xml @@ -9,6 +9,9 @@ Location: https://api.recurly.com/v2/items/plastic_gloves Sleek Plastic awesome-plastic-gloves 1569273944 + uf0jwj5zhclg + uf0jwincednb' + 1 never true diff --git a/spec/fixtures/items/show-200.xml b/spec/fixtures/items/show-200.xml index a2b0e965a..4372147fd 100644 --- a/spec/fixtures/items/show-200.xml +++ b/spec/fixtures/items/show-200.xml @@ -21,4 +21,7 @@ Content-Type: application/xml; charset=utf-8 2019-09-23T21:25:45Z 2019-09-23T21:25:45Z + uf0jwj5zhclg + uf0jwincednb + 1 diff --git a/spec/fixtures/performance_obligations/index-200.xml b/spec/fixtures/performance_obligations/index-200.xml new file mode 100644 index 000000000..258eb06a2 --- /dev/null +++ b/spec/fixtures/performance_obligations/index-200.xml @@ -0,0 +1,24 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + 6 + Over Time (Daily) + 2023-08-11T18:57:57Z + 2023-08-11T18:57:57Z + + + 5 + Over Time (Partial Monthly) + 2023-08-11T18:57:57Z + 2023-08-11T18:57:57Z + + + 4 + Point in Time + 2023-08-11T18:57:57Z + 2023-08-11T18:57:57Z + + \ No newline at end of file diff --git a/spec/fixtures/performance_obligations/show-200.xml b/spec/fixtures/performance_obligations/show-200.xml new file mode 100644 index 000000000..73af9fa1c --- /dev/null +++ b/spec/fixtures/performance_obligations/show-200.xml @@ -0,0 +1,10 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + 6 + Over Time (Daily) + 2023-08-11T18:57:57Z + 2023-08-11T18:57:57Z + \ No newline at end of file diff --git a/spec/fixtures/plans/add_ons/index-200.xml b/spec/fixtures/plans/add_ons/index-200.xml index 07414ec63..a2f0697e2 100644 --- a/spec/fixtures/plans/add_ons/index-200.xml +++ b/spec/fixtures/plans/add_ons/index-200.xml @@ -10,6 +10,9 @@ Content-Type: application/xml; charset=utf-8 1 false evenly + udexyr9hjgkc + uelq7rzkydlu + 6 5 diff --git a/spec/fixtures/plans/add_ons/show-200.xml b/spec/fixtures/plans/add_ons/show-200.xml new file mode 100644 index 000000000..22516d67e --- /dev/null +++ b/spec/fixtures/plans/add_ons/show-200.xml @@ -0,0 +1,22 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + marketing_email + Marketing Email + 1 + false + evenly + udexyr9hjgkc + uelq7rzkydlu + 6 + + 5 + + marketing-email + 600 + 3 + 2016-04-19T20:26:03Z + \ No newline at end of file diff --git a/spec/fixtures/plans/show-200.xml b/spec/fixtures/plans/show-200.xml index c98c3461f..2d9d942c6 100644 --- a/spec/fixtures/plans/show-200.xml +++ b/spec/fixtures/plans/show-200.xml @@ -22,6 +22,12 @@ Content-Type: application/xml; charset=utf-8 + udf6kuqq5rwr + udf6kubl7urs + 6 + udf6ktwsed99 + udf6ktdh636s + 4 evenly evenly false diff --git a/spec/fixtures/purchases/invoice-201-with-revrec.xml b/spec/fixtures/purchases/invoice-201-with-revrec.xml new file mode 100644 index 000000000..72ac9369c --- /dev/null +++ b/spec/fixtures/purchases/invoice-201-with-revrec.xml @@ -0,0 +1,228 @@ +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 + +
+ + 43d762734303e29025a8b64ef7953606 + paid + + 5333 + + 0 + 1013 + USD + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z + + 2018-03-27T17:52:42Z + Some notes for the customer. + + 1013 + 1013 + 0 + 2018-03-27T17:52:42Z + 0 + charge + purchase + + 1013 + + + 0 + automatic + + Our company terms and conditions. + + + + + + + 7 + 43d762733e47a12cf3dd7c47d9aed1c4 + invoiced + Setup fee: muWlYSa6U3 + + muwlysa6u3 + setup_fee + 7 + 1 + 0 + 0 + 7 + USD + + false + false + + 2018-03-27T17:52:42Z + + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z + evenly + liability_gla + revenue_gla + 5 + + 400 Alabama St + + San Francisco + CA + 94110 + US + + + + + + + + + 6 + 43d76273412274c8c041354ce7a27ee5 + invoiced + muWlYSa6U3 + + muwlysa6u3 + plan + 6 + 1 + 0 + 0 + 6 + USD + + false + false + + 2018-03-27T17:52:42Z + 2019-04-27T17:52:42Z + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z + evenly + + 400 Alabama St + + San Francisco + CA + 94110 + US + + + + + + + + 1000 + 43d76272fc2c59081d803145bbb017e4 + invoiced + + + 9d138ed5-7517-4984-b03d-a2116c0a714d + debit + 1000 + 1 + 0 + 0 + 1000 + USD + + false + false + + 2018-03-27T17:52:42Z + + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z + at_invoice + + 400 Alabama St + + San Francisco + CA + 94110 + US + + + + + + + + + + 43d762736a8c3f29413c0544ba92a44c + purchase + 1013 + 0 + USD + success + credit_card + 6871449 + subscription + false + true + true + true + + test + api + + Successful test transaction + + + + + Street address and postal code match. + + + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z + 2018-03-27T17:52:42Z +
+ + 7747ed3b-1771-4a03-b32a-503e9d65d3ad + Benjamin + Benjamin + + + + Benjamin + Du Monde + 400 Alabama St + + San Francisco + CA + 94110 + US + + + Visa + 2019 + 12 + 411111 + 1111 + + +
+
+
+ +
+ + +
diff --git a/spec/fixtures/purchases/preview-201-with-revrec.xml b/spec/fixtures/purchases/preview-201-with-revrec.xml new file mode 100644 index 000000000..34f0fa3fd --- /dev/null +++ b/spec/fixtures/purchases/preview-201-with-revrec.xml @@ -0,0 +1,69 @@ +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 + + + + + 0 + automatic + + + + 3cd86c5379c19c7f92dca34d46846c46 + pending + + + c6b6ea2e-770d-4b1e-bdec-279d4be7e22f + debit + 1000 + 1 + 0 + 0 + 1000 + USD + false + false + + 2017-04-13T23:23:35Z + + + + at_invoice + liability_gla + revenue_gla + 5 + + + + +
+
diff --git a/spec/fixtures/shipping_methods/show-200.xml b/spec/fixtures/shipping_methods/show-200.xml index faac8499b..966956cbe 100644 --- a/spec/fixtures/shipping_methods/show-200.xml +++ b/spec/fixtures/shipping_methods/show-200.xml @@ -6,6 +6,9 @@ Content-Type: application/xml; charset=utf-8 fedex_ground FedEx Ground + twywqfr48v9l + thproqnpcuwp + 4 2019-05-07T16:36:22Z 2019-05-07T16:36:22Z diff --git a/spec/recurly/add_on_spec.rb b/spec/recurly/add_on_spec.rb index ccc034e25..03901846d 100644 --- a/spec/recurly/add_on_spec.rb +++ b/spec/recurly/add_on_spec.rb @@ -1,6 +1,40 @@ require 'spec_helper' describe AddOn do + let(:add_on) do + AddOn.new( + add_on_code: 'pink_sweaters', + name: 'Pink Sweaters', + revenue_schedule_type: 'evenly', + unit_amount_in_cents: 200, + add_on_type: 'usage', + optional: false, + usage_type: 'price', + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1', + ) + end + + it 'must serialize' do + add_on.to_xml.must_equal <\ +pink_sweaters\ +usage\ +uf0jwj5zhclg\ +Pink Sweaters\ +false\ +1\ +uf0jwincednb\ +evenly\ +\ +200\ +\ +price\ + +XML + end + before do stub_api_request( :get, 'plans/gold', 'plans/show-200' @@ -26,6 +60,9 @@ stub_api_request( :get, 'plans/percentageplan/add_ons', 'plans/add_ons/index-200-tiered-percentage' ) + stub_api_request( + :get, 'plans/gold/add_ons/marketing_email', 'plans/add_ons/show-200' + ) end describe ".find" do @@ -85,5 +122,52 @@ add_on.percentage_tiers.first.tiers.count.must_equal 2 add_on.percentage_tiers.first.tiers.first.must_be_instance_of PercentageTier end + + it "returns RevRec attributes" do + plan = Plan.find 'gold' + add_ons = plan.add_ons + + add_on = add_ons.first + add_on.must_be_instance_of AddOn + add_on.liability_gl_account_id.must_equal "udexyr9hjgkc" + add_on.revenue_gl_account_id.must_equal "uelq7rzkydlu" + add_on.performance_obligation_id.must_equal "6" + end + end + + describe "create" do + it "must create a new add-on" do + stub_request(:post, "https://api.recurly.com/v2/plans/gold/add_ons"). + with(:body => "pink_sweatersusageuf0jwj5zhclgPink Sweatersfalse1uf0jwincednbevenly200price", + :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) + + plan = Plan.find 'gold' + add_on = plan.add_ons.create( + add_on_code: 'pink_sweaters', + name: 'Pink Sweaters', + revenue_schedule_type: 'evenly', + unit_amount_in_cents: 200, + add_on_type: 'usage', + optional: false, + usage_type: 'price', + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' + ) + add_on.must_be_instance_of AddOn + add_on.name.must_equal 'Pink Sweaters' + end + end + + describe "update" do + it "sends changed attributes to the server" do + plan = Plan.find 'gold' + add_on = plan.add_ons.find 'marketing_email' + stub_request(:put, "https://api.recurly.com/v2/plans/gold/add_ons/marketing_email"). + with(:body => "a8hkyaw9nmUpdated Emailsaksdfu48", + :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) + add_on.update_attributes({ name: 'Updated Emails', revenue_gl_account_id: 'aksdfu48', + liability_gl_account_id: 'a8hkyaw9nm', performance_obligation_id: '6'}) + end end end diff --git a/spec/recurly/adjustment_spec.rb b/spec/recurly/adjustment_spec.rb index 0c1c531d6..02f8354ab 100644 --- a/spec/recurly/adjustment_spec.rb +++ b/spec/recurly/adjustment_spec.rb @@ -92,6 +92,17 @@ stub_api_request :get, 'adjustments/abcdef1234567890', 'adjustments/show-404' proc { Adjustment.find 'abcdef1234567890' }.must_raise Resource::NotFound end + + describe 'with RevRec' do + it 'must return the RevRec details' do + stub_api_request :get, 'adjustments/abcdef1234567890', 'adjustments/show-200-with-revrec' + + adjustment = Adjustment.find 'abcdef1234567890' + adjustment.liability_gl_account_code.must_equal 'liability_gla' + adjustment.revenue_gl_account_code.must_equal 'revenue_gla' + adjustment.performance_obligation_id.must_equal '5' + end + end end describe "#subscription" do @@ -144,11 +155,11 @@ describe '#POST /accounts/{account_code}/adjustments' do let(:adjustment_body) do { - unit_amount_in_cents: 5000, - currency: 'USD', - quantity: 1, - accounting_code: 'bandwidth', - tax_exempt: false, + unit_amount_in_cents: 5000, + currency: 'USD', + quantity: 1, + accounting_code: 'bandwidth', + tax_exempt: false, custom_fields: [ { name: 'field1', @@ -187,4 +198,60 @@ charge.custom_fields.must_equal [CustomField.new(name: 'field1', value: 'priceless')] end end + + describe 'with RevRec #POST /accounts/{account_code}/adjustments' do + let(:adjustment_body) do + { + unit_amount_in_cents: 5000, + currency: 'USD', + quantity: 1, + accounting_code: 'bandwidth', + tax_exempt: false, + liability_gl_account_id: 'ad8h3layw', + revenue_gl_account_id: 'ydu5owk', + performance_obligation_id: '5', + custom_fields: [ + { + name: 'field1', + value: 'priceless' + } + ] + } + end + let(:adjustment) { Adjustment.new(adjustment_body) } + + it 'must serialize' do + adjustment.to_xml.must_equal <\ +bandwidth\ +USD\ +\ +\ +field1\ +priceless\ +\ +\ +ad8h3layw\ +5\ +1\ +ydu5owk\ +false\ +5000\ + +XML + end + + it 'it creates an adjustment with RevRec details on the account specified' do + stub_api_request :get, 'accounts/abcdef1234567890', 'accounts/show-200' + stub_api_request :post, 'accounts/abcdef1234567890/adjustments', 'adjustments/create-201-with-revrec' + + account = Account.find('abcdef1234567890') + + charge = account.adjustments.create(adjustment_body) + charge.custom_fields.must_equal [CustomField.new(name: 'field1', value: 'priceless')] + charge.liability_gl_account_code.must_equal 'liability_gla' + charge.revenue_gl_account_code.must_equal 'revenue_gla' + charge.performance_obligation_id.must_equal '5' + end + end end diff --git a/spec/recurly/business_entity_spec.rb b/spec/recurly/business_entity_spec.rb index dbad7a62f..7b8eabc80 100644 --- a/spec/recurly/business_entity_spec.rb +++ b/spec/recurly/business_entity_spec.rb @@ -1,6 +1,18 @@ require 'spec_helper' describe BusinessEntity do + let(:revenue_gla) { + GeneralLedgerAccount.new( + account_type: 'revenue', + code: '12345', + ) + } + let(:liablity_gla) { + GeneralLedgerAccount.new( + account_type: 'liability', + code: '56789' + ) + } let(:business_entity) { BusinessEntity.new( id: 'sokvpa93ztmm', @@ -31,6 +43,8 @@ subscriber_location_countries: ['US', 'AU'], default_vat_number: '12345', default_registration_number: '12345', + default_revenue_gl_account: revenue_gla, + default_liability_gl_account: liablity_gla, created_at: '2023-05-23T19:02:40Z', updated_at: '2023-06-23T19:02:40Z' ) @@ -41,38 +55,36 @@ expect(business_entity.code).must_equal('samplecode') expect(business_entity.id).must_equal('sokvpa93ztmm') expect(business_entity.subscriber_location_countries).must_equal(['US', 'AU']) + expect(business_entity.default_revenue_gl_account_id).must_equal(revenue_gla.id) + expect(business_entity.default_liability_gl_account_id).must_equal(liablity_gla.id) expect(business_entity.created_at).must_equal('2023-05-23T19:02:40Z') expect(business_entity.updated_at).must_equal('2023-06-23T19:02:40Z') end end - describe ".index" do - before do - stub_api_request( - :get, "https://api.recurly.com/v2/business_entities", - "business_entities/index-200" - ) - end + describe ".find" do + let(:business_entity) { + stub_api_request(:get, "business_entities/sbup2j0fx800", "business_entities/show-200") + Recurly::BusinessEntity.find 'sbup2j0fx800' + } it "returns a business entity" do business_entity.must_be_instance_of(BusinessEntity) - business_entity.id.must_equal('sokvpa93ztmm') - business_entity.code.must_equal('samplecode') + business_entity.id.must_equal('sbup2j0fx800') + business_entity.code.must_equal('default') + business_entity.default_liability_gl_account_id.must_equal('12345') + business_entity.default_revenue_gl_account_id.must_equal('56789') end end - describe ".find" do - before do - stub_api_request( - :get, "https://api.recurly.com/v2/business_entities/sokvpa93ztmm", - "business_entities/show-200" - ) - end + describe ".index" do + let(:business_entities) { + stub_api_request(:get, "business_entities", "business_entities/index-200") + Recurly::BusinessEntity.all + } - it "returns a business entity" do - business_entity.must_be_instance_of(BusinessEntity) - business_entity.id.must_equal('sokvpa93ztmm') - business_entity.code.must_equal('samplecode') + it "returns all business entities" do + expect(business_entities.count).must_equal(2) end end end diff --git a/spec/recurly/general_ledger_account_spec.rb b/spec/recurly/general_ledger_account_spec.rb new file mode 100644 index 000000000..d399b5944 --- /dev/null +++ b/spec/recurly/general_ledger_account_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +describe GeneralLedgerAccount do + let(:general_ledger_account) { + stub_api_request(:get, "general_ledger_accounts/u90r5deeaxix", "general_ledger_accounts/show-200") + Recurly::GeneralLedgerAccount.find 'u90r5deeaxix' + } + + let(:general_ledger_accounts) { + stub_api_request(:get, "general_ledger_accounts", "general_ledger_accounts/index-200") + Recurly::GeneralLedgerAccount.all + } + + describe "#find" do + it "returns a GeneralLedgerAccount" do + general_ledger_account.must_be_instance_of(GeneralLedgerAccount) + end + + it "has correct attributes" do + expect(general_ledger_account.id).must_equal('u90r5deeaxix') + expect(general_ledger_account.code).must_equal('code1') + expect(general_ledger_account.description).must_equal('string') + expect(general_ledger_account.account_type).must_equal('revenue') + end + end + + describe "#index" do + describe "when no params are passed" do + it "returns a list of general ledger accounts" do + expect(general_ledger_accounts.count).must_equal(13) + end + end + + describe "when account_type=revenue passed" do + let(:general_ledger_accounts) { + stub_api_request(:get, "general_ledger_accounts?account_type=revenue", "general_ledger_accounts/index-200-revenue") + Recurly::GeneralLedgerAccount.all(account_type: 'revenue') + } + + it "returns a list of general ledger accounts" do + expect(general_ledger_accounts.count).must_equal(4) + end + end + + describe "when account_type=liability passed" do + let(:general_ledger_accounts) { + stub_api_request(:get, "general_ledger_accounts?account_type=liability", "general_ledger_accounts/index-200-liability") + Recurly::GeneralLedgerAccount.all(account_type: 'liability') + } + + it "returns a list of general ledger accounts" do + expect(general_ledger_accounts.count).must_equal(9) + end + end + end + + describe "#save" do + let(:general_ledger_account) { GeneralLedgerAccount.new } + it "must return true when new and valid" do + stub_api_request :post, 'general_ledger_accounts', 'general_ledger_accounts/create-201' + general_ledger_account.save.must_equal true + general_ledger_account.code.must_equal 'code1' + end + end + + describe "#update" do + it "sends changed attributes to the server" do + stub_api_request :get, 'general_ledger_accounts/u90r5deeaxix', 'general_ledger_accounts/show-200' + stub_request(:put, "https://api.recurly.com/v2/general_ledger_accounts/u90r5deeaxix"). + with(:body => "new_string", + :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) + general_ledger_account.update_attributes({ description: 'new_string' }) + end + end +end diff --git a/spec/recurly/gift_card_spec.rb b/spec/recurly/gift_card_spec.rb index f10032bdf..68222ca3f 100644 --- a/spec/recurly/gift_card_spec.rb +++ b/spec/recurly/gift_card_spec.rb @@ -71,6 +71,12 @@ address.country.must_equal "US" address.phone.must_equal "337-555-5555" end + + it "should return RevRec settings" do + gift_card.revenue_gl_account_id.must_equal "uf0jwincednb" + gift_card.liability_gl_account_id.must_equal "uf0jwj5zhclg" + gift_card.performance_obligation_id.must_equal "1" + end end describe "#to_xml" do @@ -86,6 +92,7 @@ gift_card.to_xml.must_equal expected end end + describe "when creating the account with the gift card purchase" do let(:account_data) do { @@ -121,7 +128,10 @@ currency: 'USD', unit_amount_in_cents: 2000, gifter_account: account_data, - delivery: delivery_data + delivery: delivery_data, + liability_gl_account_id: "uf0jwj5zhclg", + revenue_gl_account_id: "uf0jwincednb", + performance_obligation_id: "1" ) } @@ -153,7 +163,10 @@ Sally Smith + uf0jwj5zhclg + 1 gift_card + uf0jwincednb 2000 XML diff --git a/spec/recurly/item_spec.rb b/spec/recurly/item_spec.rb index 7cfa5a2b1..02a1dd837 100644 --- a/spec/recurly/item_spec.rb +++ b/spec/recurly/item_spec.rb @@ -10,7 +10,10 @@ accounting_code: '1234', revenue_schedule_type: 'evenly', avalara_transaction_type: 600, - avalara_service_type: 3 + avalara_service_type: 3, + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' ) end @@ -23,7 +26,10 @@ Some Pink Sweaters\ ABC-123\ pink_sweaters\ +uf0jwj5zhclg\ Pink Sweaters\ +1\ +uf0jwincednb\ evenly\ XML @@ -32,13 +38,42 @@ describe "methods" do let(:item) { Item.find 'plastic_gloves' } + describe "create" do + it "must create a new item" do + stub_api_request :post, 'items', 'items/create-201' + item = Item.create( + item_code: 'pink_sweaters', + name: 'Pink Sweaters', + description: 'Some Pink Sweaters', + external_sku: 'ABC-123', + accounting_code: '1234', + revenue_schedule_type: 'evenly', + avalara_transaction_type: 600, + avalara_service_type: 3, + liability_gl_account_id: 'uf0jwj5zhclg', + revenue_gl_account_id: 'uf0jwincednb', + performance_obligation_id: '1' + ) + item.must_be_instance_of Item + item.description.must_equal 'Sleek Plastic' + end + end + describe ".find" do - it "must return an item when available" do + before do stub_api_request :get, 'items/plastic_gloves', 'items/show-200' + end + it "must return an item when available" do item.must_be_instance_of Item item.description.must_equal 'Sleek Plastic' end + + it "must return RevRec details when available" do + item.liability_gl_account_id.must_equal('uf0jwj5zhclg') + item.revenue_gl_account_id.must_equal('uf0jwincednb') + item.performance_obligation_id.must_equal('1') + end end describe "#save" do @@ -57,9 +92,10 @@ it "sends changed attributes to the server" do stub_api_request :get, 'items/plastic_gloves', 'items/show-200' stub_request(:put, "https://api.recurly.com/v2/items/plastic_gloves"). - with(:body => "Sleek Plastic Gloves", + with(:body => "a8hkyaw9nmSleek Plastic Gloves6aksdfu48", :headers => Recurly::API.headers).to_return(:status => 200, :body => "", :headers => {}) - item.update_attributes({ name: 'Sleek Plastic Gloves' }) + item.update_attributes({ name: 'Sleek Plastic Gloves', revenue_gl_account_id: 'aksdfu48', + liability_gl_account_id: 'a8hkyaw9nm', performance_obligation_id: '6'}) end end diff --git a/spec/recurly/performance_obligation_spec.rb b/spec/recurly/performance_obligation_spec.rb new file mode 100644 index 000000000..86ed2034f --- /dev/null +++ b/spec/recurly/performance_obligation_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe PerformanceObligation do + let(:performance_obligation) { + stub_api_request(:get, "performance_obligations/6", "performance_obligations/show-200") + Recurly::PerformanceObligation.find '6' + } + + let(:performance_obligations) { + stub_api_request(:get, "performance_obligations", "performance_obligations/index-200") + Recurly::PerformanceObligation.all + } + + describe "#find" do + it "returns a PerformanceObligation" do + performance_obligation.must_be_instance_of(PerformanceObligation) + end + + it "has correct attributes" do + expect(performance_obligation.id).must_equal('6') + expect(performance_obligation.name).must_equal('Over Time (Daily)') + expect(performance_obligation.created_at).wont_be_nil + end + end + + describe "#index" do + describe "when no params are passed" do + it "returns a list of performance obligations" do + expect(performance_obligations.count).must_equal(3) + end + end + end +end \ No newline at end of file diff --git a/spec/recurly/plan_spec.rb b/spec/recurly/plan_spec.rb index aa15be3e4..6caa935db 100644 --- a/spec/recurly/plan_spec.rb +++ b/spec/recurly/plan_spec.rb @@ -3,21 +3,21 @@ describe Plan do let(:plan) { Plan.new( - :plan_code => 'gold', - :name => 'The Gold Plan', - :unit_amount_in_cents => 79_00, - :description => 'The Gold Plan is for folks who love gold.', - :accounting_code => 'gold_plan_acc_code', - :setup_fee_accounting_code => 'setup_fee_ac', - :setup_fee_in_cents => 60_00, - :plan_interval_length => 1, - :plan_interval_unit => 'months', - :pricing_model => 'fixed', - :tax_exempt => false, - :revenue_schedule_type => 'evenly', - :avalara_transaction_type => 600, - :avalara_service_type => 3, - :custom_fields => [{ :name => 'color', value: 'Red' }] + :plan_code => 'gold', + :name => 'The Gold Plan', + :unit_amount_in_cents => 79_00, + :description => 'The Gold Plan is for folks who love gold.', + :accounting_code => 'gold_plan_acc_code', + :setup_fee_accounting_code => 'setup_fee_ac', + :setup_fee_in_cents => 60_00, + :plan_interval_length => 1, + :plan_interval_unit => 'months', + :pricing_model => 'fixed', + :tax_exempt => false, + :revenue_schedule_type => 'evenly', + :avalara_transaction_type => 600, + :avalara_service_type => 3, + :custom_fields => [{ :name => 'color', value: 'Red' }], ) } @@ -128,20 +128,72 @@ before do stub_api_request(:get, 'plans/gold', 'plans/show-200') end + let(:plan) { Plan.find 'gold' } it 'returns a plan when available' do - plan = Plan.find 'gold' - plan.must_be_instance_of Plan plan.plan_code.must_equal('gold') end it 'returns plan with the custom fields' do - plan = Plan.find 'gold' - plan.custom_fields[0].name.must_equal('color') plan.custom_fields[0].value.must_equal('Red') end + + it 'returns RevRec attributes' do + plan.setup_fee_performance_obligation_id.must_equal('4') + plan.performance_obligation_id.must_equal('6') + plan.setup_fee_liability_gl_account_id.must_equal('udf6ktwsed99') + plan.liability_gl_account_id.must_equal('udf6kuqq5rwr') + plan.setup_fee_revenue_gl_account_id.must_equal('udf6ktdh636s') + plan.revenue_gl_account_id.must_equal('udf6kubl7urs') + end + end + + describe 'RevRec attributes' do + let(:plan) { + Plan.new( + :plan_code => 'gold', + :name => 'The Gold Plan', + :unit_amount_in_cents => 79_00, + :description => 'The Gold Plan is for folks who love gold.', + :setup_fee_in_cents => 60_00, + :plan_interval_length => 1, + :plan_interval_unit => 'months', + :pricing_model => 'fixed', + :setup_fee_performance_obligation_id => '1', + :performance_obligation_id => '7uf', + :revenue_gl_account_id => '6t5', + :liability_gl_account_id => '8y7', + ) + } + + let(:expected_xml) do + <<~XML.gsub(' ', '').chomp + \ + The Gold Plan is for folks who love gold.\ + 8y7\ + The Gold Plan\ + 7uf\ + gold\ + 1\ + months\ + fixed\ + 6t5\ + \ + 6000\ + \ + 1\ + \ + 7900\ + \ + + XML + end + + it 'must serialize' do + plan.to_xml.must_equal expected_xml + end end describe '.save!' do @@ -159,4 +211,4 @@ plan.errors['setup_fee_in_cents'].must_equal ['is invalid'] end end -end +end \ No newline at end of file diff --git a/spec/recurly/purchase_spec.rb b/spec/recurly/purchase_spec.rb index 04c93df34..99f7f1500 100644 --- a/spec/recurly/purchase_spec.rb +++ b/spec/recurly/purchase_spec.rb @@ -2,23 +2,22 @@ describe Purchase do let(:plan_code) { 'plan_code' } + let(:adjustments) { [{ + product_code: 'product_code', + unit_amount_in_cents: 1_000, + quantity: 1, + custom_fields: [ + { + name: 'field1', + value: 'priceless' + } + ] + }]} let(:purchase) do Purchase.new( account: {account_code: 'account123'}, transaction_type: 'moto', - adjustments: [ - { - product_code: 'product_code', - unit_amount_in_cents: 1_000, - quantity: 1, - custom_fields: [ - { - name: 'field1', - value: 'priceless' - } - ] - } - ], + adjustments: adjustments, subscriptions: [ { plan_code: plan_code, @@ -101,6 +100,26 @@ purchase.adjustments.first.custom_fields.first.name.must_equal 'field1' purchase.adjustments.first.custom_fields.first.value.must_equal 'priceless' end + + describe 'with RevRec feature flag' do + let(:adjustments) { [{ + product_code: 'product_code', + unit_amount_in_cents: 1_000, + quantity: 1, + liability_gl_account_id: 'ad8h3layw', + revenue_gl_account_id: 'ydu5owk', + performance_obligation_id: '5', + }] + } + it 'should return RevRec details for an adjustment on a purchase that has RevRec details' do + stub_api_request(:post, 'purchases', 'purchases/invoice-201-with-revrec') + collection = Purchase.invoice!(purchase) + adjustment_list = collection.charge_invoice.line_items + adjustment_list.first.liability_gl_account_code.must_equal 'liability_gla' + adjustment_list.first.revenue_gl_account_code.must_equal 'revenue_gla' + adjustment_list.first.performance_obligation_id.must_equal '5' + end + end end describe 'Purchase.preview!' do @@ -132,6 +151,26 @@ # ensure error details are mapped back purchase.adjustments.first.errors['unit_amount_in_cents'].must_equal ['is not a number'] end + + describe 'with RevRec feature flag' do + let(:adjustments) { [{ + product_code: 'product_code', + unit_amount_in_cents: 1_000, + quantity: 1, + liability_gl_account_id: 'ad8h3layw', + revenue_gl_account_id: 'ydu5owk', + performance_obligation_id: '5', + }] + } + it 'should return RevRec details for an adjustment on a purchase that has RevRec details' do + stub_api_request(:post, 'purchases/preview', 'purchases/preview-201-with-revrec') + preview_collection = Purchase.preview!(purchase) + adjustment_list = preview_collection.charge_invoice.line_items + adjustment_list.first.liability_gl_account_code.must_equal 'liability_gla' + adjustment_list.first.revenue_gl_account_code.must_equal 'revenue_gla' + adjustment_list.first.performance_obligation_id.must_equal '5' + end + end end describe 'Purchase.authorize!' do @@ -166,6 +205,26 @@ # ensure error details are mapped back purchase.adjustments.first.errors['unit_amount_in_cents'].must_equal ['is not a number'] end + + describe 'with RevRec feature flag' do + let(:adjustments) { [{ + product_code: 'product_code', + unit_amount_in_cents: 1_000, + quantity: 1, + liability_gl_account_id: 'ad8h3layw', + revenue_gl_account_id: 'ydu5owk', + performance_obligation_id: '5', + }] + } + it 'should return RevRec details for an adjustment on a purchase that has RevRec details' do + stub_api_request(:post, 'purchases/authorize', 'purchases/preview-201-with-revrec') + authorized_collection = Purchase.authorize!(purchase) + adjustment_list = authorized_collection.charge_invoice.line_items + adjustment_list.first.liability_gl_account_code.must_equal 'liability_gla' + adjustment_list.first.revenue_gl_account_code.must_equal 'revenue_gla' + adjustment_list.first.performance_obligation_id.must_equal '5' + end + end end describe 'Purchase.pending!' do @@ -198,6 +257,26 @@ # ensure error details are mapped back purchase.adjustments.first.errors['unit_amount_in_cents'].must_equal ['is not a number'] end + + describe 'with RevRec feature flag' do + let(:adjustments) { [{ + product_code: 'product_code', + unit_amount_in_cents: 1_000, + quantity: 1, + liability_gl_account_id: 'ad8h3layw', + revenue_gl_account_id: 'ydu5owk', + performance_obligation_id: '5', + }] + } + it 'should return RevRec details for an adjustment on a purchase that has RevRec details' do + stub_api_request(:post, 'purchases/pending', 'purchases/preview-201-with-revrec') + pending_collection = Purchase.pending!(purchase) + adjustment_list = pending_collection.charge_invoice.line_items + adjustment_list.first.liability_gl_account_code.must_equal 'liability_gla' + adjustment_list.first.revenue_gl_account_code.must_equal 'revenue_gla' + adjustment_list.first.performance_obligation_id.must_equal '5' + end + end end describe "Purchase.capture!" do diff --git a/spec/recurly/shipping_method_spec.rb b/spec/recurly/shipping_method_spec.rb index 0e4094383..a805850a2 100644 --- a/spec/recurly/shipping_method_spec.rb +++ b/spec/recurly/shipping_method_spec.rb @@ -2,12 +2,21 @@ describe ShippingMethod do describe ".find" do - it "must return a shipping method when available" do + before do stub_api_request( :get, 'shipping_methods/fedex_ground', 'shipping_methods/show-200' - ) + ) + end + it "must return a shipping method when available" do shipping_method = ShippingMethod.find 'fedex_ground' shipping_method.must_be_instance_of ShippingMethod end + + it "returns RevRec values" do + shipping_method = ShippingMethod.find 'fedex_ground' + shipping_method.performance_obligation_id.must_equal('4') + shipping_method.revenue_gl_account_id.must_equal('thproqnpcuwp') + shipping_method.liability_gl_account_id.must_equal('twywqfr48v9l') + end end end \ No newline at end of file