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/invoice.rb b/lib/recurly/invoice.rb
index 69edcd1f2..00a554607 100644
--- a/lib/recurly/invoice.rb
+++ b/lib/recurly/invoice.rb
@@ -122,7 +122,7 @@ def invoice_number_with_prefix
refundable_total_in_cents
used_tax_service
business_entity_id
- )
+ ) + RevRec::PRODUCT_ATTRIBUTES
alias to_param invoice_number_with_prefix
def self.to_xml(attrs)
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/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
+
+ 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/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/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