diff --git a/app/doc/open_api/v1/accounting_doc.rb b/app/doc/open_api/v1/accounting_doc.rb index 43d82d879..a022ba21c 100644 --- a/app/doc/open_api/v1/accounting_doc.rb +++ b/app/doc/open_api/v1/accounting_doc.rb @@ -14,8 +14,15 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc doc_for :index do api :GET, "/#{API_VERSION}/accounting", 'Accounting lines' description 'All accounting lines, paginated (necessarily becauce there is a lot of data) with optional dates filtering. ' \ - 'Ordered by *date* descendant.

The field *status* indicates if the accounting data is being built ' \ - 'or if the build is over. Possible status are: building or built.' + 'Ordered by *date* descendant.
' \ + 'The field *status* indicates if the accounting data is being built or if the build is over. ' \ + 'Possible status are: building or built.
' \ + 'The field *invoice.payment_details* is available if line_type=client. It will contain the following data:
' \ + '· *payment_mean*, possible status are: card, wallet or other. *WARNING*: If an invoice was settled ' \ + 'using multiple payment means, this will only report the payment mean applicable to current line.
' \ + '· *gateway_object_id*, if payment_mean=card, report the ID of the payment gateway related object
' \ + '· *gateway_object_type*, if payment_mean=card, report the type of the payment gateway related object
' \ + '· *wallet_transaction_id*, if payment_mean=wallet, report the ID of the wallet transaction
' param_group :pagination param :after, DateTime, optional: true, desc: 'Filter accounting lines to lines after the given date.' param :before, DateTime, optional: true, desc: 'Filter accounting lines to lines before the given date.' @@ -38,9 +45,17 @@ class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc "reference": "22010009/VL", "id": 274, "label": "Subscription of Dupont Marcel for 1 month starting from 2022, january 2nd", - "url": "/open_api/v1/invoices/247/download" + "url": "/open_api/v1/invoices/247/download", + "payment_details": { + "payment_mean": "card", + "gateway_object_id": "pi_3MA2PPW4kx8QemzC02ABBEbo", + "gateway_object_type": "Stripe::PaymentIntent" + } + }, + "user": { + "invoicing_profile_id": 6512, + "external_id": "U52-ALC4" }, - "user_invoicing_profile_id": 6512, "debit": 1400, "credit": 0 "currency": "EUR", diff --git a/app/models/invoice.rb b/app/models/invoice.rb index e94c3a65d..3edc9f54b 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -161,14 +161,15 @@ class Invoice < PaymentDocument when :card if paid_by_card? { + payment_mean: mean, gateway_object_id: payment_gateway_object.gateway_object_id, gateway_object_type: payment_gateway_object.gateway_object_type } end when :wallet - { wallet_transaction_id: wallet_transaction_id } if paid_by_wallet? + { payment_mean: mean, wallet_transaction_id: wallet_transaction_id } if paid_by_wallet? else - {} + { payment_mean: mean } end end diff --git a/app/views/open_api/v1/accounting/index.json.jbuilder b/app/views/open_api/v1/accounting/index.json.jbuilder index ddaa73e88..b0061e1eb 100644 --- a/app/views/open_api/v1/accounting/index.json.jbuilder +++ b/app/views/open_api/v1/accounting/index.json.jbuilder @@ -7,7 +7,7 @@ json.lines @lines do |line| json.extract! line.invoice, :reference, :id json.label Invoices::LabelService.build(line.invoice) json.url download_open_api_v1_invoice_path(line.invoice) - if @codes.values.include?(line.account_code) + if @codes.values.include?(line.account_code) # if this is a 'client' line mean = @codes.select { |_key, value| value == line.account_code } json.payment_details line.invoice.payment_details(mean.keys[0]) end diff --git a/test/integration/open_api/accounting_test.rb b/test/integration/open_api/accounting_test.rb index 0d3ebb3fb..42c264a38 100644 --- a/test/integration/open_api/accounting_test.rb +++ b/test/integration/open_api/accounting_test.rb @@ -92,6 +92,7 @@ class OpenApi::AccountingTest < ActionDispatch::IntegrationTest assert lines[:lines].count.positive? assert(lines[:lines].all? { |line| line[:line_type] == 'client' }) assert(lines[:lines].all? { |line| !line[:invoice][:payment_details].nil? }) + assert(lines[:lines].all? { |line| %w[card wallet other].include?(line[:invoice][:payment_details][:payment_mean]) }) assert(lines[:lines].filter { |line| line[:account_code] == card_code } .none? { |line| line[:invoice][:payment_details][:gateway_object_id].nil? }) assert(lines[:lines].filter { |line| line[:account_code] == card_code }