robokassa_api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 21ae1e9fc2286e894d47c681a6578cef7221e5eeca125477553a34ed85914864
4
+ data.tar.gz: 68e5e9a388bd908e4be3fa9ed59d1b3c7dfff99735606a0d6bb4eb30db93d883
5
+ SHA512:
6
+ metadata.gz: d7c5ed548231b4a7713866110893939b553e9fc9b70027958a68de5245a5976b75f692c92f7d7eb203934deb1b5f4a749308b048d1e621706349615fac8fb156
7
+ data.tar.gz: f301cac359e1b780e65e5b59e5975ffa878735a3fceaf18697d140ef8fea09ab9e7156e7b9f14ecf2c77294c00a1c0c5f33fb3a6b016e062bae567e20bf0560c
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ usage.rb
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # Gemfile
2
+ source 'https://rubygems.org'
3
+ ruby '2.4.1'
4
+
5
+ gem 'rspec'
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Robokassa API
2
+
3
+ Гем для работы с API Robokassa
@@ -0,0 +1,25 @@
1
+ class PaymentsController < ApplicationController
2
+ def result
3
+ out_sum = params['OutSum']
4
+ invoice_id = params['InvId']
5
+ user = params['Shp_user']
6
+ signature_1 = params['SignatureValue']
7
+
8
+ signature_2 = RobokassaApi.create_signature(args = {
9
+ out_sum: out_sum,
10
+ invoice_id: invoice_id,
11
+ user: user
12
+ })
13
+
14
+ # Сравниваем подписи (свою и чужую)
15
+ @result = RobokassaApi.check_signatures(signature1, signature2, invoice_id)
16
+ end
17
+
18
+ def success
19
+ redirect_to pay_path, notice: 'Success'
20
+ end
21
+
22
+ def failed
23
+ redirect_to pay_path, alert: 'Failed'
24
+ end
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ scope 'payments' do
3
+ post 'result', to: 'payments#result' # to handle Robokassa push request
4
+ get 'success', to: 'payments#success' # to handle Robokassa success redirect
5
+ get 'failed', to: 'payments#failed' # to handle Robokassa fail redirect
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators'
2
+
3
+ module Robokassa
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def create_initializer_file
8
+ template 'robokassa.rb',
9
+ File.join('config', 'initializers', 'robokassa.rb')
10
+ template 'payments_helper.rb',
11
+ File.join('app', 'helpers', 'payments_helper.rb')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module PaymentsHelper
2
+ def payment_link(out_sum, description)
3
+ user = set_user
4
+ signature = set_signature_one(user, out_sum)
5
+ payment_link = RobokassaApi.create_pay_url(signature, user, out_sum, description)
6
+ end
7
+
8
+ private
9
+
10
+ def set_user
11
+ current_user
12
+ end
13
+
14
+ def set_signature_one(user, out_sum)
15
+ RobokassaApi.create_signature_one(args = {
16
+ user: user,
17
+ out_sum: out_sum
18
+ })
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ Robokassa.configure do |config|
2
+ config.login = ENV['MERCHANT_LOGIN']
3
+ config.first_password = ENV['FIRST_PASSWORD']
4
+ config.second_password = ENV['SECOND_PASSWORD']
5
+ config.mode = :test # или :production
6
+ end
@@ -0,0 +1,12 @@
1
+ module RobokassaApi
2
+ module Data
3
+ MERCHANT_LOGIN = Robokassa.login
4
+
5
+ PASS_1 = Robokassa.first_password
6
+ PASS_2 = Robokassa.second_password
7
+
8
+ INVOICE_ID = '0'
9
+ ENCODING = 'utf-8'
10
+ CULTURE = 'ru'
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ module RobokassaApi
2
+ module PaymentUrl
3
+ include SignatureGenerator
4
+
5
+ URL = 'https://auth.robokassa.ru/Merchant/Index.aspx?'
6
+
7
+ def self.create_pay_url(signature, user, out_sum, description)
8
+ url = pay_link(signature, user, out_sum, description)
9
+
10
+ url += "&IsTest=1" if test_mode?
11
+ end
12
+
13
+ def test_mode?
14
+ Robokassa.mode == :test
15
+ end
16
+
17
+ private
18
+
19
+ def pay_link(signature, user, out_sum, description)
20
+ URL + "MerchantLogin=#{MERCHANT_LOGIN}" +
21
+ "&OutSum=#{out_sum}" + "&InvId=#{INVOICE_ID}" +
22
+ "&Desc=#{description}" + "&SignatureValue=#{signature}" +
23
+ "&Culture=#{CULTURE}" + "&Encoding=#{ENCODING}" + "&Shp_user=#{user.id}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'digest/md5'
2
+
3
+ module RobokassaApi
4
+ module SignatureGenerator
5
+ include Data
6
+
7
+ def self.create_signature(args)
8
+ if args.include?(:invoice_id)
9
+ create_signature_two(
10
+ user = args[:user],
11
+ out_sum = args[:out_sum]
12
+ invoice_id = args[:invoice_id]
13
+ )
14
+ else
15
+ create_signature_one(
16
+ user = args[:user],
17
+ out_sum = args[:out_sum]
18
+ )
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def create_signature_one(user, out_sum)
25
+ data = "#{MERCHANT_LOGIN}:#{out_sum}:#{INVOICE_ID}:#{PASS_1}:Shp_user=#{user.id}"
26
+ md5(data)
27
+ end
28
+
29
+ def create_signature_two(out_sum, invoice_id, user_id)
30
+ data = "#{out_sum}:#{invoice_id}:#{PASS_2}:Shp_user=#{user_id}"
31
+ md5(data).upcase
32
+ end
33
+
34
+ def md5(data)
35
+ Digest::MD5.hexdigest(data)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'robokassa_api/payment'
2
+
3
+ module RobokassaApi
4
+ extend self
5
+
6
+ def create_pay_url(signature, user, out_sum)
7
+ RobokassaApi::PaymentUrl.create_pay_url(signature, user, out_sum, description)
8
+ end
9
+
10
+ def create_signature(args)
11
+ RobokassaApi::SignatureGenerator.create_signature(args)
12
+ end
13
+
14
+ def check_signatures(signature1, signature2, invoice_id)
15
+ if signature_valid?(signature1, signature2)
16
+ "OK#{invoice_id}"
17
+ else
18
+ "bad sign"
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def signature_valid?(signature1, signature2)
25
+ (!signature_1.blank?) && (signature_1 == signature_2)
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'robokassa_api'
5
+ s.version = '0.0.1'
6
+ s.date = '2019-01-08'
7
+ s.summary = 'Robokassa API - Robokassa API wrapper gem'
8
+ s.description = 'Simple gem for Robokassa payments. This gem can work with Robokassa API.'
9
+ s.author = 'Alexander Levashov'
10
+ s.email = 'alevash1@gmail.com'
11
+ s.homepage = 'https://github.com/alexlev1/robokassa_api'
12
+ s.license = 'MIT'
13
+ s.files = `git ls-files`.split("\n")
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ require 'rails'
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :active_record, :action_controller
9
+
10
+ require 'rspec/rails'
11
+
12
+ RSpec.configure do |config|
13
+ config.use_transactional_fixtures = true
14
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robokassa_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Levashov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple gem for Robokassa payments. This gem can work with Robokassa API.
14
+ email: alevash1@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - Gemfile
21
+ - README.md
22
+ - app/controllers/payments_controller.rb
23
+ - config/routes.rb
24
+ - lib/generators/robokassa/install_generator.rb
25
+ - lib/generators/robokassa/templates/payments_helper.rb
26
+ - lib/generators/robokassa/templates/robokassa.rb
27
+ - lib/robokassa_api.rb
28
+ - lib/robokassa_api/data.rb
29
+ - lib/robokassa_api/payment_url.rb
30
+ - lib/robokassa_api/signature_generator.rb
31
+ - robokassa_api.gemspec
32
+ - spec/spec_helper.rb
33
+ homepage: https://github.com/alexlev1/robokassa_api
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.7.6
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Robokassa API - Robokassa API wrapper gem
57
+ test_files: []