gem 'activemerchant', :require => 'active_merchant'
require 'active_merchant' require 'active_merchant/billing/integrations/action_view_helper' ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)
ActiveMerchant::Billing::Base.integration_mode = :production # :test for sandbox
scope 'robokassa' do match 'paid' => 'robokassa#paid', :as => :robokassa_paid # to handle Robokassa push request match 'success' => 'robokassa#success', :as => :robokassa_success # to handle Robokassa success redirect match 'fail' => 'robokassa#fail', :as => :robokassa_fail # to handle Robokassa fail redirect end
class RobokassaController < ApplicationController include ActiveMerchant::Billing::Integrations skip_before_filter :verify_authenticity_token # skip before filter if you chosen POST request for callbacks before_filter :create_notification before_filter :find_payment # Robokassa call this action after transaction def paid if @notification.acknowledge # check if it's genuine Robokassa request @payment.approve! # project-specific code render :text => @notification.success_response else head :bad_request end end # Robokassa redirect user to this action if it's all ok def success if !@payment.approved? && @notification.acknowledge @payment.approve! end redirect_to @payment, :notice => I18n.t("notice.robokassa.success") end # Robokassa redirect user to this action if it's not def fail redirect_to @payment, :notice => I18n.t("notice.robokassa.fail") end private def create_notification @notification = Robokassa::Notification.new(request.raw_post, :secret => AppConfig.robokassa_secret) end def find_payment @payment = Payment.find(@notification.item_id) end end
<%= payment_service_for @payment.id, AppConfig.robokassa_login, :amount => @payment.amount, :service => :robokassa, :secret => AppConfig.robokassa_secret do |s| %> <%= submit_tag "Submit" %> <% end %>
@payment
object @payment
, then after submitting the form, a redirect will occur to the Robokassa website, where you can make a payment for the amount specified in @payment.amount
.Source: https://habr.com/ru/post/147435/
All Articles