Skip to content

Instantly share code, notes, and snippets.

@marcomoura
Last active December 10, 2015 19:39
Show Gist options
  • Save marcomoura/4482801 to your computer and use it in GitHub Desktop.
Save marcomoura/4482801 to your computer and use it in GitHub Desktop.
class OrdersController < ApplicationController
def confirm
order = OrderResource.confirm(params)
redirect_to payment_on_external_service_url(order.number)
end
end
class Order
def final_message
if items.any?{ |item| item == :paper }
"
Os seus impressos serão entregues via transportadora,
os itens digitais estão disponíveis para download no android,
exceto os epub que estão disponíveis no applicativo Ipad
"
else
""
end
end
end
class OrderResource
def self.confirm(params)
order = Order.find(params[:id])
order.update_attribute(:number, create_on_external_service(order).order_number)
order
end
def self.create_on_external_service(order)
order_external = ServiceExternal::Order.new(order, messagem: order.final_message)
if order_external.save
order_external
else
raise InvalidOrderOnExternalService
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment