Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created February 20, 2014 01:34
Show Gist options
  • Save zaneclaes/9105339 to your computer and use it in GitHub Desktop.
Save zaneclaes/9105339 to your computer and use it in GitHub Desktop.
module Api
module V2
class TripInvoicesPresenter < BasePresenter
def initialize(trip_invoice, current_user)
@trip_invoice = trip_invoice
@current_user = current_user
end
def to_json_default
invoice_items = @trip_invoice.trip_invoice.trip_invoice_items.map do |item|
item.trip_product = TripProduct.find_by_id(item.trip_product_id)
binding.pry
item
end
json = {
:id => @trip_invoice.trip_invoice.id,
:open => @trip_invoice.trip_invoice.open?,
:parent_type => @trip_invoice.trip_invoice.parent_type,
:parent_id => @trip_invoice.trip_invoice.parent_id,
:payment_instrument_id => @trip_invoice.trip_invoice.payment_instrument_id,
:created_at => @trip_invoice.trip_invoice.created_at,
:updated_at => @trip_invoice.trip_invoice.updated_at,
:consumer_currency => @trip_invoice.trip_invoice.consumer_currency,
:consumer_balance_native => @trip_invoice.trip_invoice.consumer_balance_native,
:consumer_balance_usd => @trip_invoice.trip_invoice.consumer_balance_usd,
:consumer_total_native => @trip_invoice.trip_invoice.consumer_total_native,
:consumer => @trip_invoice.trip_invoice.consumer,
:providers => @trip_invoice.trip_invoice.providers,
:trip_invoice_items => invoice_items,
}
end
end
end
end
"trip_invoice_items"=>
[{"trip_invoice_item"=>
{"canceled_at"=>nil,
"consumer_amount_native"=>20,
"consumer_currency"=>"USD",
"consumer_currency_rate"=>1.0,
"consumer_currency_spread"=>0.0,
"consumer_fee_native"=>1,
"consumer_settled_at"=>nil,
"created_at"=>"2014-02-20T01:34:08Z",
"dispute_status"=>0,
"id"=>1,
"item_type"=>"Purchase",
"line_item_id"=>nil,
"lock_version"=>0,
"payment2_id"=>nil,
"provider_amount_native"=>20,
"provider_currency"=>"USD",
"provider_currency_rate"=>1.0,
"provider_fee_native"=>1,
"provider_reference"=>nil,
"provider_settled_at"=>nil,
"refunded_at"=>nil,
"trip_invoice_id"=>5,
"trip_product_id"=>5,
"updated_at"=>"2014-02-20T01:34:08Z"}}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment