Skip to content

Commit

Permalink
add custom exceptions when webservice fail, add a sample when need pa…
Browse files Browse the repository at this point in the history
…y with html link
  • Loading branch information
danielvlopes committed Oct 31, 2009
1 parent d149d57 commit 22862e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
class PaymentsController < ApplicationController

def charge
response = Moip.authorize(:reason=>"Teste",:id=>"12", :value=>1)
def direct_charge
response = Moip.authorize(:reason=>"Teste",:id=>"15", :value=>1)
redirect_to Moip.charge_url(response)
end

def manual_charge
@response = Moip.authorize(:reason=>"Teste",:id=>"14", :value=>1)
end

end
Empty file removed app/views/payments/index.html.erb
Empty file.
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ActionController::Routing::Routes.draw do |map|

map.charge "/charge", :controller=>"payments", :action=>"charge"


map.charge "/manual_charge", :controller=>"payments", :action=>"manual_charge"
map.charge "/direct_charge", :controller=>"payments", :action=>"direct_charge"

end
3 changes: 2 additions & 1 deletion lib/moip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def self.authorize(attributes = {})
end

response = post('/EnviarInstrucao/Unica', :body => xml)["ns1:EnviarInstrucaoUnicaResponse"]
response["Resposta"]["Status"] == "Falha" ? raise(StandardError, response["Resposta"]["Erro"]) : response
raise(StandardError, "Webservice can't be reached") if response.nil?
(response["Resposta"]["Status"] == "Falha") ? raise(StandardError, response["Resposta"]["Erro"]) : response
end

def self.charge_url(response)
Expand Down

0 comments on commit 22862e8

Please sign in to comment.