Last active
December 10, 2015 19:39
-
-
Save marcomoura/4482801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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