Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view for orders api (Fixes Issue #2512) #2513

Merged
merged 2 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions api/app/views/spree/api/orders/_big.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ json.payments(order.payments) do |payment|
json.(payment, *payment_attributes)
json.payment_method { json.(payment.payment_method, :id, :name) }
json.source do
if payment.source
json.(payment.source, *payment_source_attributes)
##
# payment.source could be a Spree::Payment. If it is then we need to call
# source twice.
# @see https://github.com/solidusio/solidus/blob/v2.4/backend/app/views/spree/admin/payments/show.html.erb#L16
#
payment_source = payment.source.is_a?(Spree::Payment) ? payment.source.source : payment.source

if @current_user_roles.include?("admin")
json.(payment.source, :gateway_customer_profile_id, :gateway_payment_profile_id)
end
if payment_source
json.partial!(
"spree/api/payments/source_views/#{payment.payment_method.partial_name}",
payment_source: payment_source
)
else
json.nil!
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.nil!
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
attrs = [:id, :month, :year, :cc_type, :last_digits, :name]
if @current_user_roles.include?("admin")
attrs += [:gateway_customer_profile_id, :gateway_payment_profile_id]
end

json.(payment_source, *attrs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
json.(payment_source, :id, :memo, :created_at)
json.created_by payment_source.created_by.email
json.category payment_source.category, :id, :name
15 changes: 15 additions & 0 deletions api/spec/requests/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ module Spree
expect(credit_cards[0]['id']).to eq payment.source.id
expect(credit_cards[0]['address']['id']).to eq credit_card.address_id
end

it 'renders the payment source view for gateway' do
subject
expect(response).to render_template partial: 'spree/api/payments/source_views/_gateway'
end
end

context 'when store credit is present' do
let!(:payment) { create(:store_credit_payment, order: order, source: store_credit) }
let(:store_credit) { create(:store_credit) }

it 'renders the payment source view for store credit' do
subject
expect(response).to render_template partial: 'spree/api/payments/source_views/_storecredit'
end
end
end

Expand Down