The Rubykassa gem

Gem Version Build Status Coverage Status Code Climate Dependency Status Inline docs

by Zero One

Yet another Ruby wrapper for Robokassa API. Make Robokassa to work with your Rails project without pain. Rubykassa took the best from robokassa gem and Active Merchant Robokassa integration but easier to use and setup.

Installation

Add to your Gemfile:

gem "rubykassa"

Usage

Run rails g rubykassa:install, get an initializer with the following code:

Rubykassa.configure do |config|
  config. = ENV["ROBOKASSA_LOGIN"]
  config.first_password = ENV["ROBOKASSA_FIRST_PASSWORD"]
  config.second_password = ENV["ROBOKASSA_SECOND_PASSWORD"]
  config.mode = :test # or :production
  config.http_method = :get # or :post
  config.xml_http_method = :get # or :post
end

and configure it with your credentials.

Also, you need to specify Result URL, Success URL and Fail URL at the "Technical Settings" (Технические настройки) in your Robokassa dashboard:

  • Result URL: http://<your_domain>/robokassa/paid
  • Success URL: http://<your_domain>/robokassa/success
  • Fail URL: http://<your_domain>/robokassa/fail

To define custom success/fail callbacks you can also use the initializer:

Rubykassa.configure do |config|
  ...
  config.success_callback = ->(notification) { render text: 'success' }
  config.fail_callback    = ->(notification) { redirect_to root_path }
  config.result_callback  = ->(notification) { render text: notification.success }
end

Lambdas are called in RobokassaController so you can respond with any kind that is supported by Rails.

NOTE: result_callback should always return "OK#{ invoice_id }" string. So, implement your custom logic above render text: notification.success line.

Mode is :test by default. For production you have to use :production. http_method and xml_http_method are :get by default but can be configured as :post

Once you are done, simply use pay_url helper in your view:

<%= pay_url "Pay with Robokassa", ivoice_id, total_sum %>

Additionally you may want to pass extra options. There is no problem:

<%= pay_url "Pay with Robokassa", ivoice_id, total_sum, { description: "Invoice description", email: "[email protected]", currency: "WMZM", culture: :ru } %>

Or if you would like to pass some custom params use custom key in options hash:

<%= pay_url "Pay with Robokassa", ivoice_id, total_sum, { description: "Invoice description", email: "[email protected]", currency: "WMZM", culture: :ru, custom: { param1: "value1", param2: "value2" }} %>      

You can also pass some HTML options with html key in options hash (Bootstrap 3 example):

<%= pay_url "Pay with Robokassa", ivoice_id, total_sum, { html: { class: 'btn btn-primary btn-bg' }}

If you need to implement Robokassa's XML interface functionality you have to the following:

xml_interface = Rubykassa::XmlInterface.new do
  self.invoice_id = your_invioce_id
  self.total = your_total_sum
  self.language = :ru # can be :en, :ru is default
end

then call whatever you need

xml_interface.get_currencies_list
xml_interface.get_payment_methods
xml_interface.get_rates
xml_interface.op_state

Supported Rubies and Rails versions

Rubies:

  • 1.9.3
  • 2.0.0
  • 2.1.0

Rails:

  • ~> 3.2.18
  • ~> 4.0.0
  • ~> 4.1.0

License

This project rocks and uses MIT-LICENSE Copyright (c) 2013-2014 Zero One

Bitdeli Badge