Class: Spree::Api::V2::Storefront::TicketTransfersController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Api::V2::Storefront::TicketTransfersController
- Defined in:
- app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb
Instance Method Summary collapse
- #cancel ⇒ Object
- #create ⇒ Object
- #index ⇒ Object
- #preview_rule ⇒ Object
- #reject ⇒ Object
- #show ⇒ Object
Instance Method Details
#cancel ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 52 def cancel ticket_transfer = model_class.find_by!(token: params[:id]) result = SpreeCmCommissioner::TicketTransfers::Cancel.call( ticket_transfer: ticket_transfer, acting_user: spree_current_user ) if result.success? render_serialized_payload { serialize_resource(result.value[:ticket_transfer]) } else render_error_payload(result.error) end end |
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 34 def create result = SpreeCmCommissioner::TicketTransfers::Initiate.call( from_user_id: spree_current_user.id, to_user_id: ticket_transfer_params[:to_user_id], from_guest_id: ticket_transfer_params[:guest_id], price: ticket_transfer_params[:price] || 0, currency: ticket_transfer_params[:currency] || 'USD', expires_at: ticket_transfer_params[:expires_at], transfer_type: ticket_transfer_params[:transfer_type] || 'purchase' ) if result.success? render_serialized_payload(201) { serialize_resource(result.value[:ticket_transfer]) } else render_error_payload(result.error) end end |
#index ⇒ Object
8 9 10 11 12 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 8 def index render_serialized_payload do serialize_collection(paginated_collection) end end |
#preview_rule ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 21 def preview_rule result = SpreeCmCommissioner::TicketTransfers::PreviewRule.call( from_guest_id: params[:guest_id], currency: params[:currency] || 'USD' ) if result.success? render json: { data: result.value } else render_error_payload(result.error) end end |
#reject ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 67 def reject ticket_transfer = model_class.find_by!(token: params[:id]) result = SpreeCmCommissioner::TicketTransfers::Reject.call( ticket_transfer: ticket_transfer, acting_user: spree_current_user ) if result.success? render_serialized_payload { serialize_resource(result.value[:ticket_transfer]) } else render_error_payload(result.error) end end |
#show ⇒ Object
14 15 16 17 18 19 |
# File 'app/controllers/spree/api/v2/storefront/ticket_transfers_controller.rb', line 14 def show ticket_transfer = model_class.includes(:order, from_guest: [:event, { line_item: :product }]).find_by!(token: params[:id]) return render_error_payload(I18n.t('ticket_transfer.unauthorized_view'), 403) unless (ticket_transfer) render_serialized_payload { serialize_resource(ticket_transfer) } end |