diff --git a/app/controllers/nonprofits/payments_controller.rb b/app/controllers/nonprofits/payments_controller.rb index 8bea6257..63a03ab7 100644 --- a/app/controllers/nonprofits/payments_controller.rb +++ b/app/controllers/nonprofits/payments_controller.rb @@ -42,6 +42,7 @@ module Nonprofits def show @nonprofit = current_nonprofit @payment = @nonprofit.payments.find(params[:id]) + render locals: {payment: @payment} end # def show def update diff --git a/app/views/nonprofits/payments/show.jbuilder b/app/views/nonprofits/payments/show.jbuilder new file mode 100644 index 00000000..f2f63a89 --- /dev/null +++ b/app/views/nonprofits/payments/show.jbuilder @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later +json.data do + json.extract! @payment, :id, :gross_amount, + :towards, :net_amount, + :fee_total, :date, + :refund_total, :kind + + d_anonymous = @payment.donation.nil? ? false : @payment.donation.anonymous + json.consider_donation_anonymous (!!d_anonymous || !!@payment.supporter.anonymous) + + json.charge do + json.extract! @payment.charge, :created_at, :id, :status + end + + json.donation do + d = @payment.donation + json.extract! d, :designation, :dedication, :origin_url, :id, :comment + + + json.campaign do + c = d.campaign + json.extract! c, :name, :id + json.url campaign_locateable_url(c) + end if d.campaign + + + json.campaign_gift do + json.name(d.campaign_gifts.any? ? d.campaign_gifts.last.campaign_gift_option.name : nil) + end + + json.event(d.event, partial: "events/event", as: :event) if d.event + + json.recurring_donation do + rd = d.recurring_donation + json.extract! rd, :interval, :time_unit, :created_at + end if d.recurring_donation + end if @payment.donation + + json.dispute do + dis =@payment.dispute + json.extract! dis, :id, :status, :reason + end if @payment.dispute + + json.refund do + ref = @payment.refund + json.extract! ref, :reason, :comment, :disbursed + end if @payment.refund + + json.offsite_payment do + off_p = @payment.offsite_payment + json.extract! off_p, :check_number, :kind + end if @payment.offsite_payment + + json.ticket do + event = @payment.tickets.last.event + json.event do + json.extract! event, :name, :id + json.url event_locateable_url(event) + end + json.levels @payment.tickets.map { |t| "#{GetData.chain(t.ticket_level, :name)} (#{t.quantity}x)" }.join(', ') + json.discount @payment.tickets.map { |t| t.event_discount ? "#{t.event_discount.name} (#{t.event_discount.percent}%)" : nil }.compact.join(', ') + end if @payment&.tickets&.last&.event + + json.tickets @payment.tickets do |t| + json.id t.id + json.ticket_level t.ticket_level, :name + end if @payment.tickets.any? + + json.supporter do + json.extract! @payment.supporter, :name, :email, :city, :state_code, :address, :zip_code, :phone, :id, :country + end + + json.nonprofit do + json.id @payment.nonprofit.id + end +end \ No newline at end of file diff --git a/app/views/nonprofits/payments/show.rabl b/app/views/nonprofits/payments/show.rabl deleted file mode 100644 index c63e7e72..00000000 --- a/app/views/nonprofits/payments/show.rabl +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -object @payment => :data - -attributes :gross_amount, :towards, :net_amount, :fee_total, :id, :date, :refund_total, :kind - -node(:consider_donation_anonymous) do |p| - d_anonymous = p.donation.nil? ? false : p.donation.anonymous - - !!d_anonymous || !!p.supporter.anonymous -end - -child :charge do - attributes :created_at, :id, :status -end - -child :donation, object_root: false do - attributes :designation, :dedication, :origin_url, :id, :comment - - child :campaign, object_root: false do - attributes :name, :url, :id - end - - node(:campaign_gift) { |d| { name: d.campaign_gifts.any? ? d.campaign_gifts.last.campaign_gift_option.name : nil } } - - child :event, object_root: false do - attributes :name, :url, :id - end - - child :recurring_donation, object_root: false do - attributes :interval, :time_unit, :created_at - end -end - -child :dispute, object_root: false do - attributes :id, :status, :reason -end - -child :refund do - attributes :reason, :comment, :disbursed -end - -child :offsite_payment do - attributes :check_number, :kind -end - -node(:ticket) do |payment| - event = payment&.tickets&.last&.event - h = { - event: { name: event&.name, url: event&.url, id: event&.id }, - levels: payment.tickets.map { |t| "#{GetData.chain(t.ticket_level, :name)} (#{t.quantity}x)" }.join(', '), - discount: payment.tickets.map { |t| t.event_discount ? "#{t.event_discount.name} (#{t.event_discount.percent}%)" : nil }.compact.join(', ') - } - event ? h : nil -end - -child :tickets, object_root: false do - attributes :id - - child :ticket_level do - attributes :name - end -end - -child :supporter do - attributes :name, :email, :city, :state_code, :address, :zip_code, :phone, :id, :country -end - -child :nonprofit do - attributes :id -end diff --git a/spec/controllers/nonprofits/payments_spec.rb b/spec/controllers/nonprofits/payments_spec.rb index dad9a4f4..ed3696f2 100644 --- a/spec/controllers/nonprofits/payments_spec.rb +++ b/spec/controllers/nonprofits/payments_spec.rb @@ -16,7 +16,7 @@ describe Nonprofits::PaymentsController, type: :controller do end describe 'show payments' do - include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1', without_json_view: true + include_context :open_to_np_associate, :get, :show, nonprofit_id: :__our_np, id: '1', with_status: 200 end describe 'update' do