payanyway 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 257f313795dce5796dc66612f46fa949cdb20e0c
4
+ data.tar.gz: f6fb7fdec9464461c7b33fa81a0857eead5f83f5
5
+ SHA512:
6
+ metadata.gz: 9e0de6dff4b65949d18b709cd12e7ba6f1ebf78927736b224d4b818b81c96b1ff33558688dcd8bf8058a932f2cc6e01f4b8c7d101757c6f0f041befccc3f9274
7
+ data.tar.gz: 4af175a8d83770dc55017f5866c3243ebe179a8bea4ce743beca6ab41841ef91f32e2403c2719cd2fb434c79e36a038bbcdcfaf480bbeed4e927f003952fb8ff
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/internal/log/*.log
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ .idea
17
+ .pumper.yml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --colour
3
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1
6
+ - 2.2
7
+
8
+ script:
9
+ - CODECLIMATE_REPO_TOKEN=41f20e51bdd84fed15a9717bd19c4aef62c96cd8be6e8fb61c08a69c840deb7a bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payanyway.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 ssnikolay
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ [![Build Status](https://travis-ci.org/ssnikolay/payanyway.svg?branch=master)](https://travis-ci.org/ssnikolay/payanyway)
2
+ [![Code Climate](https://codeclimate.com/github/ssnikolay/payanyway.svg)](https://codeclimate.com/github/ssnikolay/payanyway)
3
+ [![Test Coverage](https://codeclimate.com/github/ssnikolay/payanyway/badges/coverage.svg)](https://codeclimate.com/github/ssnikolay/payanyway)
4
+
5
+ # Payanyway
6
+
7
+ Этот gem предназначен для быстрой интеграции платежного шлюза [payanyway](http://payanyway.ru) в ваше ruby приложение.
8
+ При возникновенни вопросов следует ознакомиться с [http://moneta.ru/doc/MONETA.Assistant.ru.pdf](http://moneta.ru/doc/MONETA.Assistant.ru.pdf)
9
+ ## Установка
10
+
11
+ Добавьте эти строки в Gemfile вашего приложения:
12
+
13
+ ```ruby
14
+ gem 'payanyway'
15
+ ```
16
+
17
+ И выполните:
18
+
19
+ $ bundle
20
+
21
+ Или установки напрямую:
22
+
23
+ $ gem install payanyway
24
+
25
+ ## Подключение
26
+
27
+ Добавьте engine в `config/routes.rb`
28
+ ```ruby
29
+ Rails.application.routes.draw do
30
+ mount Payanyway::Engine => '/payanyway'
31
+ end
32
+ ```
33
+
34
+ Создайте `app/controllers/payanyway_controller.rb` со следующим кодом:
35
+
36
+ ```ruby
37
+ class PayanywayController
38
+ def success_implementation(order_id)
39
+ # вызывается при отправки шлюзом пользователя на Success URL.
40
+ #
41
+ # ВНИМАНИЕ: является незащищенным действием!
42
+ # Для выполнения действий после успешной оплаты используйте pay_implementation
43
+ end
44
+
45
+ def pay_implementation(params)
46
+ # вызывается при оповещении магазина об
47
+ # успешной оплате пользователем заказа.
48
+ #
49
+ # params[ KEY ], где KEY ∈ [ :moneta_id, :order_id, :operation_id,
50
+ # :amount, :currency, :subscriber_id, :test_mode, :user, :corraccount,
51
+ # :custom1, :custom2, :custom3 ]
52
+ end
53
+
54
+ def fail_implementation(order_id)
55
+ # вызывается при отправки шлюзом пользователя на Fail URL.
56
+ end
57
+ end
58
+ ```
59
+
60
+ Создайте конфигурационный файл: `config/payanyway.yml`
61
+
62
+
63
+ ```yml
64
+ development: &config
65
+ moneta_id: YOUR_MOTETA_ID
66
+ currency: RUB
67
+ payment_url: https://demo.moneta.ru/assistant.htm
68
+ test_mode: 1
69
+ token: secret_token
70
+ production: <<: *config
71
+ payment_url: https://moneta.ru/assistant.htm
72
+ test_mode: 0
73
+ ```
74
+ ## Использование
75
+
76
+ Что бы получить ссылку на платежный шлюз для оплаты заказа пользвателем, используйте `Payanyway::Gateway.payment_url(params, use_signature = true)`, где `params[ KEY ]` такой, что `KEY` ∈ `[:order_id, :amount, :test_mode, :description, :subscriber_id, :custom1, :custom2, :custom3]`
77
+
78
+ Пример:
79
+ ```ruby
80
+ class Order < ActiveRecord::Base; end
81
+
82
+ class OrdersController < AplicationController
83
+ def create
84
+ order = Order.create(params[:order])
85
+ redirect_to Payanyway::Gateway.payment_url(
86
+ order_id: order.id,
87
+ amount: order.total_amount
88
+ )
89
+ end
90
+ end
91
+ ```
92
+
93
+ ### Расшифровка параметров
94
+
95
+ params[ KEY ], где KEY | Описание
96
+ --------------------------|:-----------------------------------------------------------
97
+ `:moneta_id` | Идентификатор магазина в системе MONETA.RU.
98
+ `:order_id` | Внутренний идентификатор заказа, однозначно определяющий заказ в магазине.
99
+ `:operation_id` | Номер операции в системе MONETA.RU.
100
+ `:amount` | Фактическая сумма, полученная на оплату заказа.
101
+ `:currency` | ISO код валюты, в которой произведена оплата заказа в магазине.
102
+ `:test_mode` | Флаг оплаты в тестовом режиме (1 - да, 0 - нет).
103
+ `description` | Описание оплаты.
104
+ `:subscriber_id` | Внутренний идентификатор пользователя в системе магазина.
105
+ `:corraccount` | Номер счета плательщика.
106
+ `:custom[1|2|3]` | Поля произвольных параметров. Будут возращены магазину в параметрах отчета о проведенной оплате.
107
+ `:user` | Номер счета пользователя, если оплата производилась с пользовательского счета в системе «MONETA.RU».MONETA.Assistant.
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it ( https://github.com/ssnikolay/payanyway/fork )
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,3 @@
1
+ class PayanywayController < ApplicationController
2
+ include Payanyway::Controller
3
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Payanyway::Engine.routes.draw do
2
+ get 'success' => 'payanyway#success', as: :payanyway_on_success
3
+ get 'pay' => 'payanyway#pay', as: :payanyway_pay
4
+ get 'fail' => 'payanyway#fail', as: :payanyway_on_fail
5
+ end
data/lib/payanyway.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+ require 'active_support/core_ext'
3
+
4
+ require 'payanyway/helpers/settings'
5
+ require 'payanyway/helpers/signature_generator'
6
+
7
+ require 'payanyway/gateway'
8
+ require 'payanyway/engine'
9
+ require 'payanyway/controller'
@@ -0,0 +1,56 @@
1
+ module Payanyway
2
+ module Controller
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ skip_before_filter :verify_authenticity_token
7
+ end
8
+
9
+ def pay
10
+ service = Payanyway::Response::Pay.new(params)
11
+ service.perform
12
+ service.success? ?
13
+ pay_implementation(service.pretty_params) :
14
+ error_log(service.pretty_params)
15
+
16
+ render text: service.result
17
+ end
18
+
19
+ def success
20
+ service = Payanyway::Response::Base.new(params)
21
+ Rails.logger.info("Called success payment url for order '#{ service.pretty_params[:order_id] }'")
22
+
23
+ success_implementation(service.pretty_params)
24
+ end
25
+
26
+ def fail
27
+ service = Payanyway::Response::Base.new(params)
28
+ Rails.logger.error("Fail paid order '#{ service.pretty_params[:order_id] }'")
29
+
30
+ fail_implementation(service.pretty_params)
31
+ end
32
+
33
+ private
34
+
35
+ def error_log(params)
36
+ Rails.logger.error("ERROR! Invalid signature for order #{ params[:order_id] }. Params: #{ params.inspect }")
37
+ end
38
+
39
+ def pay_implementation(params)
40
+ # Вызывается после успешного прохождения
41
+ # запроса об оплате от payanyway.ru
42
+
43
+ Rails.logger.info("Success paid order #{ params[:order_id] }")
44
+ end
45
+
46
+ def success_implementation(params)
47
+ # Вызывается после успешной оплаты
48
+ render nothing: true
49
+ end
50
+
51
+ def fail_implementation(params)
52
+ # Вызывается после ошибки при оплате
53
+ render nothing: true
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module Payanyway
2
+ class Engine < Rails::Engine
3
+ config.autoload_paths += %W(#{ config.root }/lib)
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'singleton'
2
+ require 'yaml'
3
+ require 'forwardable'
4
+
5
+ module Payanyway
6
+ class Gateway
7
+ include Singleton
8
+ PARAMS = {
9
+ 'MNT_ID' => :moneta_id,
10
+ 'MNT_TEST_MODE' => :test_mode,
11
+ 'MNT_CURRENCY_CODE' => :currency
12
+ }.to_settings
13
+
14
+ attr_reader :config, :config_for_moneta
15
+
16
+ def initialize
17
+ @env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
18
+ @config = load_config
19
+ @config_for_moneta = PARAMS.configure_by(@config)
20
+ end
21
+
22
+ def payment_url(params, use_signature = true)
23
+ # Возвращает url на шлюз для входных параметров params
24
+ # * _params_ - параметры платежа.
25
+ # * _use_signature_ - отправить код для идентификации отправителя и проверки целостности данных.
26
+ #
27
+ # Обязателные:
28
+ # * _params[order_id]_ - номер заказа в магазине.
29
+ # * _params[amount]_ - сумма заказа.
30
+ #
31
+ # Необязательные:
32
+ # * _params[test_mode]_ - Указание, что запрос происходит в тестовом режиме.
33
+ # * _params[description]_ - Описание оплаты.
34
+ # * _params[subscriber_id]_ - Внутренний идентификатор пользователя в системе магазина.
35
+ # * _params[custom1]_ - Поля произвольных параметров.
36
+ # * _params[custom2]_ - Поля произвольных параметров.
37
+ # * _params[custom3]_ - Поля произвольных параметров.
38
+
39
+ Payanyway::Helpers::PaymentUrl.build(params, use_signature)
40
+ end
41
+
42
+ class << self
43
+ extend Forwardable
44
+ def_delegators(:instance, *Payanyway::Gateway.instance_methods(false))
45
+ end
46
+
47
+ private
48
+
49
+ def load_config
50
+ YAML.load(File.read(File.join(Rails.root, 'config/payanyway.yml')))[@env]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module Payanyway
2
+ module Helpers
3
+ class PaymentUrl
4
+ PARAMS = {
5
+ 'MNT_TRANSACTION_ID' => :order_id,
6
+ 'MNT_DESCRIPTION' => :description,
7
+ 'MNT_SUBSCRIBER_ID' => :subscriber_id,
8
+ 'MNT_AMOUNT' => :amount,
9
+ 'MNT_CUSTOM1' => :custom1,
10
+ 'MNT_CUSTOM2' => :custom2,
11
+ 'MNT_CUSTOM3' => :custom3
12
+ # 'MNT_SIGNATURE' => добавляется при use_signature == true
13
+ }.to_settings
14
+
15
+ class << self
16
+ def build(params, use_signature)
17
+ params_for_moneta = prepare_params(params, use_signature)
18
+ query_params = params_for_moneta.to_a.map { |option| option.map{ |opt| CGI::escape(opt.to_s) }.join('=') }.join('&')
19
+
20
+ "#{ Payanyway::Gateway.config['payment_url'] }?#{ query_params }"
21
+ end
22
+
23
+ private
24
+
25
+ def prepare_params(params, use_signature)
26
+ params_for_moneta = PARAMS.configure_by(params)
27
+ params_for_moneta = Payanyway::Gateway.config_for_moneta.merge(params_for_moneta)
28
+
29
+ use_signature ? add_signature(params_for_moneta) : params_for_moneta
30
+ end
31
+
32
+ def add_signature(params_for_moneta)
33
+ params_for_moneta.merge({
34
+ 'MNT_SIGNATURE' => Payanyway::Helpers::SignatureGenerate.for_url(params_for_moneta)
35
+ })
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ class Hash
2
+ def to_settings
3
+ Payanyway::Helpers::Settings.new(self)
4
+ end
5
+ end
6
+
7
+ module Payanyway
8
+ module Helpers
9
+ class Settings
10
+ delegate :[], to: '@settings'
11
+
12
+ def initialize(settings)
13
+ @settings = HashWithIndifferentAccess.new(settings.invert)
14
+ end
15
+
16
+ # Выбирает из настроек нужные
17
+ # и подставляет в переданный hash
18
+ #
19
+ # @settings = { 'MNT_ID' => :id, 'MNT_CURRENCY' => :currency }
20
+ # hash = { id: 1 }
21
+ # => { 'MNT_ID': 1 }
22
+ def configure_by(hash)
23
+ hash.each_with_object({}) do |(key, value), memo|
24
+ memo[ @settings[key] ] = value if @settings.has_key?(key)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'digest/md5'
2
+
3
+ module Payanyway
4
+ module Helpers
5
+ class SignatureGenerate
6
+ class << self
7
+ PAY_KEYS = %w(
8
+ MNT_TRANSACTION_ID
9
+ MNT_OPERATION_ID
10
+ MNT_AMOUNT
11
+ MNT_CURRENCY_CODE
12
+ MNT_SUBSCRIBER_ID
13
+ MNT_TEST_MODE
14
+ )
15
+
16
+ URL_KEYS = PAY_KEYS - [ 'MNT_OPERATION_ID' ]
17
+
18
+ def for_pay(params)
19
+ generate_by(params, PAY_KEYS)
20
+ end
21
+
22
+
23
+ def for_url(params)
24
+ generate_by(params, URL_KEYS)
25
+ end
26
+
27
+ private
28
+
29
+ def generate_by(params, keys)
30
+ values = keys.map { |key| get_value(params, key) }.join
31
+
32
+ md5(Payanyway::Gateway.config['moneta_id'].to_s + values + Payanyway::Gateway.config['token'])
33
+ end
34
+
35
+ def get_value(params, key)
36
+ (key == 'MNT_AMOUNT') ? '%.2f' % params[key] : params[key]
37
+ end
38
+
39
+ def md5(str)
40
+ Digest::MD5.hexdigest(str).downcase
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ module Payanyway
2
+ module Response
3
+ class Base
4
+ @@_params = { 'MNT_TRANSACTION_ID' => :order_id }.invert.to_settings
5
+
6
+ attr_reader :pretty_params
7
+
8
+ def initialize(params)
9
+ @params = params
10
+ @pretty_params = @@_params.configure_by(params)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ module Payanyway
2
+ module Response
3
+ class Pay < Base
4
+ @@_params = {
5
+ 'MNT_ID' => :moneta_id,
6
+ 'MNT_TRANSACTION_ID' => :order_id,
7
+ 'MNT_OPERATION_ID' => :operation_id,
8
+ 'MNT_AMOUNT' => :amount,
9
+ 'MNT_CURRENCY_CODE' => :currency,
10
+ 'MNT_SUBSCRIBER_ID' => :subscriber_id,
11
+ 'MNT_TEST_MODE' => :test_mode,
12
+ 'MNT_SIGNATURE' => :signature,
13
+ 'MNT_USER' => :user,
14
+ 'MNT_CORRACCOUNT' => :corraccount,
15
+ 'MNT_CUSTOM1' => :custom1,
16
+ 'MNT_CUSTOM2' => :custom2,
17
+ 'MNT_CUSTOM3' => :custom3
18
+ }.invert.to_settings
19
+
20
+ def perform
21
+ @valid_signature = (@pretty_params[:signature] == signature)
22
+ end
23
+
24
+ def success?
25
+ @valid_signature
26
+ end
27
+
28
+ def result
29
+ @valid_signature ? 'SUCCESS' : 'FAIL'
30
+ end
31
+
32
+ private
33
+
34
+ def signature
35
+ Payanyway::Helpers::SignatureGenerate.for_pay(@params)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Payanyway
2
+ VERSION = '1.0.0'
3
+ end
data/payanyway.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payanyway/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'payanyway'
8
+ spec.version = Payanyway::VERSION.dup
9
+ spec.authors = ['ssnikolay']
10
+ spec.email = ['ssnikolay@gmail.com']
11
+ spec.summary = 'simple gem for payanyway payment gateway'
12
+ spec.description = 'simple gem for payanyway payment gateway'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rails', '>= 3.2.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec-rails'
26
+ spec.add_development_dependency 'rspec-its'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'pumper'
29
+ spec.add_development_dependency 'combustion', '~> 0.5.3'
30
+ spec.add_development_dependency 'codeclimate-test-reporter'
31
+ end
@@ -0,0 +1,6 @@
1
+ describe Payanyway::Gateway do
2
+ subject { described_class.config }
3
+
4
+ its(['moneta_id']) { is_expected.to eq(141290) }
5
+ its(['currency']) { is_expected.to eq('RUB') }
6
+ end
@@ -0,0 +1,20 @@
1
+ describe Payanyway::Engine, type: :routing do
2
+ routes { Payanyway::Engine.routes }
3
+
4
+ context 'payanyway' do
5
+ specify { get('/success').should route_to(
6
+ controller: 'payanyway',
7
+ action: 'success'
8
+ )}
9
+
10
+ specify { get('/pay').should route_to(
11
+ controller: 'payanyway',
12
+ action: 'pay'
13
+ )}
14
+
15
+ specify { get('/fail').should route_to(
16
+ controller: 'payanyway',
17
+ action: 'fail'
18
+ )}
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ describe PayanywayController do
2
+ routes { Payanyway::Engine.routes }
3
+
4
+ describe 'GET #success' do
5
+ it 'should and message to logger' do
6
+ expect(Rails.logger).to receive(:info).with("Called success payment url for order '676'")
7
+
8
+ get :success, { 'MNT_TRANSACTION_ID' => 676 }
9
+ end
10
+ end
11
+
12
+ describe 'GET #fail' do
13
+ it 'should and message to logger' do
14
+ expect(Rails.logger).to receive(:error).with("Fail paid order '676'")
15
+
16
+ get :fail, { 'MNT_TRANSACTION_ID' => 676 }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ class ApplicationController < ActionController::Base; end
@@ -0,0 +1,6 @@
1
+ test:
2
+ moneta_id: 141290
3
+ currency: RUB
4
+ payment_url: https://demo.moneta.ru/assistant.htm
5
+ test_mode: 1
6
+ token: secret_token
@@ -0,0 +1,26 @@
1
+ describe Payanyway::Gateway do
2
+ describe '#payment_url' do
3
+ let(:use_signature) { false }
4
+ subject { described_class.payment_url(params, use_signature) }
5
+
6
+ context 'when min params' do
7
+ let(:params) { { amount: '120.25', order_id: 'FF790ABCD' } }
8
+
9
+ it { is_expected.to eq('https://demo.moneta.ru/assistant.htm?MNT_ID=141290&MNT_CURRENCY_CODE=RUB&MNT_TEST_MODE=1&MNT_AMOUNT=120.25&MNT_TRANSACTION_ID=FF790ABCD') }
10
+ it { is_expected.to_not be_include('MNT_SIGNATURE') }
11
+ end
12
+
13
+ context 'when have custom params' do
14
+ let(:params) { { amount: '120.25', order_id: 'FF790ABCD', custom1: 'utm_source' } }
15
+
16
+ it { is_expected.to eq('https://demo.moneta.ru/assistant.htm?MNT_ID=141290&MNT_CURRENCY_CODE=RUB&MNT_TEST_MODE=1&MNT_AMOUNT=120.25&MNT_TRANSACTION_ID=FF790ABCD&MNT_CUSTOM1=utm_source') }
17
+ end
18
+
19
+ context 'when use_signature == true' do
20
+ let(:use_signature) { true }
21
+ let(:params) { { amount: '120.25', order_id: 'FF790ABCD' } }
22
+
23
+ it { is_expected.to be_include('MNT_SIGNATURE') }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'digest/md5'
2
+
3
+ describe Payanyway::Helpers::SignatureGenerate do
4
+ describe '#for_pay' do
5
+ subject { described_class.for_pay(params) }
6
+
7
+ let(:params) {
8
+ {
9
+ 'MNT_ID' => 141290,
10
+ 'MNT_TRANSACTION_ID' => 2,
11
+ 'MNT_OPERATION_ID' => 3,
12
+ 'MNT_AMOUNT' => 10.20,
13
+ 'MNT_CURRENCY_CODE' => 'RUB',
14
+ 'MNT_TEST_MODE' => 1
15
+ }
16
+ }
17
+
18
+ it { should eq(Digest::MD5.hexdigest('1412902310.20RUB1secret_token').downcase) }
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ describe Payanyway::Response::Pay do
2
+ let(:service) { described_class.new(params) }
3
+ let(:params) do
4
+ {
5
+ 'MNT_ID' => 1,
6
+ 'MNT_TRANSACTION_ID' => 2,
7
+ 'MNT_OPERATION_ID' => 3,
8
+ 'MNT_AMOUNT' => 10.20,
9
+ 'MNT_CURRENCY_CODE' => 'RUB',
10
+ 'MNT_TEST_MODE' => 1,
11
+ 'MNT_SIGNATURE' => '2b7f8d7d00e8e980b3df95dc70d47461'# from spec/lib/payanyway/helpers/signature_generator_spec.rb
12
+ }
13
+ end
14
+
15
+ describe '#pretty_params' do
16
+ subject { service.pretty_params }
17
+
18
+ its([:moneta_id]) { is_expected.to eq(1) }
19
+ its([:amount]) { is_expected.to eq(10.20) }
20
+ end
21
+
22
+ describe '#perform' do
23
+ subject { service.success? }
24
+
25
+ context 'when success' do
26
+ before { service.perform }
27
+
28
+ it { is_expected.to be_truthy }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'combustion'
7
+ Bundler.require :default, :development
8
+
9
+ Combustion.initialize! :action_controller, :action_view
10
+
11
+ require 'payanyway'
12
+ require 'rspec/rails'
13
+ require 'pry'
14
+ require 'codeclimate-test-reporter'
15
+
16
+ CodeClimate::TestReporter.start
17
+
18
+
19
+ RSpec.configure do |config|
20
+ config.infer_spec_type_from_file_location!
21
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payanyway
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ssnikolay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pumper
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: combustion
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.5.3
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: simple gem for payanyway payment gateway
140
+ email:
141
+ - ssnikolay@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - .travis.yml
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - app/controllers/payanyway_controller.rb
154
+ - config/routes.rb
155
+ - lib/payanyway.rb
156
+ - lib/payanyway/controller.rb
157
+ - lib/payanyway/engine.rb
158
+ - lib/payanyway/gateway.rb
159
+ - lib/payanyway/helpers/payment_url.rb
160
+ - lib/payanyway/helpers/settings.rb
161
+ - lib/payanyway/helpers/signature_generator.rb
162
+ - lib/payanyway/response/base.rb
163
+ - lib/payanyway/response/pay.rb
164
+ - lib/payanyway/version.rb
165
+ - payanyway.gemspec
166
+ - spec/config/payanyway_spec.rb
167
+ - spec/config/routes_spec.rb
168
+ - spec/controllers/payanyway_controller_spec.rb
169
+ - spec/internal/app/controllers/application_controller.rb
170
+ - spec/internal/config/payanyway.yml
171
+ - spec/lib/payanyway/gateway_spec.rb
172
+ - spec/lib/payanyway/helpers/signature_generator_spec.rb
173
+ - spec/lib/payanyway/response/pay_spec.rb
174
+ - spec/spec_helper.rb
175
+ homepage: ''
176
+ licenses:
177
+ - MIT
178
+ metadata: {}
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubyforge_project:
195
+ rubygems_version: 2.4.3
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: simple gem for payanyway payment gateway
199
+ test_files:
200
+ - spec/config/payanyway_spec.rb
201
+ - spec/config/routes_spec.rb
202
+ - spec/controllers/payanyway_controller_spec.rb
203
+ - spec/internal/app/controllers/application_controller.rb
204
+ - spec/internal/config/payanyway.yml
205
+ - spec/lib/payanyway/gateway_spec.rb
206
+ - spec/lib/payanyway/helpers/signature_generator_spec.rb
207
+ - spec/lib/payanyway/response/pay_spec.rb
208
+ - spec/spec_helper.rb