Class: CatarseDineromail::Payment::DineromailController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CatarseDineromail::Payment::DineromailController
- Defined in:
- app/controllers/catarse_dineromail/payment/dineromail_controller.rb
Constant Summary collapse
- SCOPE =
"projects.backers.checkout"
Instance Method Summary collapse
Instance Method Details
#error ⇒ Object
47 48 49 50 51 |
# File 'app/controllers/catarse_dineromail/payment/dineromail_controller.rb', line 47 def error backer = current_user.backs.find params[:id] flash[:failure] = t('dineromail_error', scope: SCOPE) redirect_to main_app.new_project_backer_path(backer.project) end |
#notifications ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/catarse_dineromail/payment/dineromail_controller.rb', line 53 def notifications notification = params[:Notificacion] Rails.logger.info params.inspect return render(status: 404, nothing: true) if notification.nil? xml = Nokogiri::XML(notification.downcase) ids = [] xml.xpath("//operacion//id").each {|o| ids << o.children.text} c = DineroMailIpn::Client.new(account: ::Configuration[:dineromail_merchant], password: ::Configuration[:dineromail_ipn_password], pais: DineroMailCheckout::Configuration.country_name(::Configuration[:dineromail_country_id].to_i)) reports = c.consulta_transacciones(ids).reports if reports reports.each do |report| begin backer = Backer.not_confirmed.where(payment_token: report.id).first backer.confirm! if backer and report.transaction_completed? rescue Exception => e Rails.logger.info "-----> #{e.inspect}" end end end render nothing: true end |
#pay ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/catarse_dineromail/payment/dineromail_controller.rb', line 10 def pay begin backer = current_user.backs.not_confirmed.find params[:id] if backer transaction_id = (Digest::MD5.hexdigest "#{SecureRandom.hex(5)}-#{DateTime.now.to_s}")[1..20].downcase backer.update_attribute :payment_method, 'Dineromail' backer.update_attribute :payment_token, transaction_id data = DineroMailCheckout::CheckoutData.validate({item_name_1: t('dineromail_description', scope: SCOPE), item_quantity_1: 1, item_currency_1: DineroMailCheckout.configuration.currency, change_quantity: 0, item_ammount_1: backer.moip_value, buyer_name: backer.user.full_name, buyer_phone: backer.user.phone_number, buyer_email: backer.user.email, ok_url: success_payment_dineromail_url(backer), error_url: error_payment_dineromail_url(backer), transaction_id: transaction_id}) redirect_to DineroMailCheckout::Client.get_uri(data) end rescue Exception => e Airbrake.notify({ :error_class => "Dineromail Error", :error_message => "Dineromail Error: #{e.inspect}", :parameters => params}) rescue nil Rails.logger.info "-----> #{e.inspect}" flash[:failure] = t('dineromail_error', scope: SCOPE) return redirect_to main_app.new_project_backer_path(backer.project) end end |
#success ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/controllers/catarse_dineromail/payment/dineromail_controller.rb', line 38 def success backer = current_user.backs.find params[:id] session[:thank_you_id] = backer.project.id session[:_payment_token] = backer.payment_token flash[:success] = t('success', scope: SCOPE) redirect_to main_app.thank_you_path end |