Skip to content

Instantly share code, notes, and snippets.

@danielweinmann
Created August 2, 2011 12:12
Show Gist options
  • Save danielweinmann/1120070 to your computer and use it in GitHub Desktop.
Save danielweinmann/1120070 to your computer and use it in GitHub Desktop.
Using MoIP integration
def pay
backer = Backer.find params[:backer_id]
current_user.update_attributes params[:user]
current_user.reload
payer = {
:nome => current_user.full_name,
:email => current_user.email,
:logradouro => current_user.address_street,
:numero => current_user.address_number,
:complemento => current_user.address_complement,
:bairro => current_user.address_neighbourhood,
:cidade => current_user.address_city,
:estado => current_user.address_state,
:pais => "BRA",
:cep => current_user.address_zip_code,
:tel_fixo => current_user.phone_number
}
payment = {
:valor => "%0.0f" % (backer.value),
:id_proprio => backer.key,
:razao => "Apoio para o projeto '#{backer.project.name}'",
:forma => "BoletoBancario",
:dias_expiracao => 2,
:pagador => payer,
:url_retorno => thank_you_url
}
response = MoIP::Client.checkout(payment)
redirect_to MoIP::Client.moip_page(response["Token"])
end
def moip
key = params[:id_transacao]
status = params[:status_pagamento]
value = params[:valor]
backer = Backer.find_by_key key
return render :nothing => true, :status => 200 if status != '1'
return render :nothing => true, :status => 200 if backer.confirmed
return render :nothing => true, :status => 422 if backer.moip_value != value
backer.confirm!
return render :nothing => true, :status => 200
rescue => e
return render :nothing => true, :status => 422
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment