paysto-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +121 -0
- data/Rakefile +1 -0
- data/lib/generators/paysto/install_generator.rb +31 -0
- data/lib/generators/paysto/models_generator.rb +27 -0
- data/lib/generators/templates/config/paysto.en.yml +8 -0
- data/lib/generators/templates/config/paysto.rb +31 -0
- data/lib/generators/templates/config/paysto.ru.yml +8 -0
- data/lib/generators/templates/controllers/paysto_controller.rb +3 -0
- data/lib/generators/templates/migration.rb +28 -0
- data/lib/generators/templates/models/invoice.rb +54 -0
- data/lib/generators/templates/models/invoice_notification.rb +4 -0
- data/lib/generators/templates/models/payment.rb +11 -0
- data/lib/paysto-rails.rb +11 -0
- data/lib/paysto/base.rb +113 -0
- data/lib/paysto/controller.rb +40 -0
- data/lib/paysto/version.rb +3 -0
- data/paysto-rails.gemspec +24 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDc3NzBiMTNmOGFjNjgxNTZhMmRjODM2MTAzNzBmYmYwZGM1ZmNiYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGUwYjY1M2RmZTY0OGFjZWRkMmFjNjE5ZWE3ODg5MDI1MjdlMGNmNA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjNjYTVhODgyZDJlNThiMDU2M2EwODYxMzAzNzkyNmFmZmQ3MTQ5NmI4OTA4
|
10
|
+
NmRlMDk0YmZhYTdkNDg3NTZmZTg3MTk2OWNjZjAxMzFjNmNjOGJlYjY3MWNm
|
11
|
+
ZGFhMzFkZjRjMTM5N2I4YjI4ZTYxY2U4ZTc3NWNlNjUwYTIxOTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzFmNzY3NzZmYWM5YzFkNGZmNDc4YzZhNWYwMTc4NDg1MTk2NzFkZDg3OWFk
|
14
|
+
OWI1YWQxMzY4OGMzYjZhNWYyMzU4ODY2MzMxZTEzYjYzNzc1YjQ2YjZmNjA2
|
15
|
+
OGYwOGI2OWE0NGQ3NWVlYjcyNTQwNGJjMzU5NTc0Y2RkZWU1MWI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrey Baiburin
|
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,121 @@
|
|
1
|
+
# «paysto-rails»
|
2
|
+
[![GitHub version](https://badge.fury.io/gh/fbandrey%2Fpaysto-rails.svg)](http://badge.fury.io/gh/fbandrey%2Fpaysto-rails)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/fbandrey/paysto-rails/badges/gpa.svg)](https://codeclimate.com/github/fbandrey/paysto-rails)
|
4
|
+
|
5
|
+
This is first implementation of gateway for passing payments through [Paysto](https://paysto.com).
|
6
|
+
|
7
|
+
It works only with «[onlineMerchant](https://paysto.com/ru/products/onlineMerchant)», if you know what I mean. :)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'paysto-rails'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install paysto-rails
|
22
|
+
|
23
|
+
## Setup
|
24
|
+
|
25
|
+
After installation run this command:
|
26
|
+
```
|
27
|
+
rails generate paysto:install
|
28
|
+
```
|
29
|
+
|
30
|
+
It will create files for you:
|
31
|
+
```
|
32
|
+
create config/initializers/paysto.rb
|
33
|
+
create config/locales/paysto.en.yml
|
34
|
+
create config/locales/paysto.ru.yml
|
35
|
+
create app/controllers/paysto_controller.rb
|
36
|
+
```
|
37
|
+
and extend your routes with:
|
38
|
+
```
|
39
|
+
namespace :paysto do
|
40
|
+
post :success, :fail, :check, :callback
|
41
|
+
get :fail
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Right now you may to configure model names in ```config/initializers/paysto.rb``` file for payments, invoices and their notifications. By default they are ```Payment```, ```Invoice``` and ```InvoiceNotification``` respectively.
|
46
|
+
|
47
|
+
Then run this command:
|
48
|
+
```
|
49
|
+
rails generate paysto:models
|
50
|
+
```
|
51
|
+
It will create your models and migration:
|
52
|
+
|
53
|
+
```
|
54
|
+
create db/migrate/20140101000000_create_paysto_tables.rb
|
55
|
+
create app/models/payment.rb
|
56
|
+
create app/models/invoice.rb
|
57
|
+
create app/models/invoice_notification.rb
|
58
|
+
```
|
59
|
+
|
60
|
+
In the simple case only what you should to do:
|
61
|
+
|
62
|
+
1. Put your real credentials in ```config/initializers/paysto.rb``` as well
|
63
|
+
2. Run ```rake db:migrate```
|
64
|
+
|
65
|
+
That's all.
|
66
|
+
|
67
|
+
Now you may to customize models as you want, associate it with users or anything else...
|
68
|
+
|
69
|
+
For more information check [payment workflow](https://github.com/fbandrey/paysto-rails/wiki/Payment-workflow) wiki.
|
70
|
+
|
71
|
+
## Usage
|
72
|
+
|
73
|
+
You have 3 models and 1 controller now if you did everything right before. Check models and extend them with logic and associations, which you need in your application.
|
74
|
+
|
75
|
+
Controller by default [extended with concern](https://github.com/fbandrey/paysto-rails/blob/master/lib/paysto/controller.rb) and looks so:
|
76
|
+
```
|
77
|
+
class PaystoController < ApplicationController
|
78
|
+
include Paysto::Controller
|
79
|
+
end
|
80
|
+
```
|
81
|
+
But you may override methods here as you want. For example, if I want to redirect user to "/payments" URL when payment is passed:
|
82
|
+
```
|
83
|
+
class PaystoController < ApplicationController
|
84
|
+
include Paysto::Controller
|
85
|
+
|
86
|
+
def success
|
87
|
+
flash[:success] = I18n.t('paysto.success')
|
88
|
+
redirect_to custom_payments_path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
Also you can customize [check](https://github.com/fbandrey/paysto-rails/blob/master/lib/paysto/controller.rb#L9) or [callback](https://github.com/fbandrey/paysto-rails/blob/master/lib/paysto/controller.rb#L18) methods using Paysto module as you want, but we don't recommend it, do it only if you know what's going on there.
|
94
|
+
|
95
|
+
### Paysto methods
|
96
|
+
|
97
|
+
```Paysto.balance``` – current balance in Paysto.
|
98
|
+
|
99
|
+
```Paysto.currencies``` – available pay methods.
|
100
|
+
|
101
|
+
```Paysto.get_payments(from_date, to_date)``` – payments list between dates.
|
102
|
+
|
103
|
+
```Paysto.get_payment_type(invoice.id)``` – pay method for ```Invoice```.
|
104
|
+
|
105
|
+
```Paysto.invoice_valid?(invoice)``` – check whether the invoice is valid.
|
106
|
+
|
107
|
+
```Paysto.ip_valid?(request.remote_ip)``` – check whether the IP is permitted.
|
108
|
+
|
109
|
+
```Paysto.md5_valid?(params)``` – check whether the MD5 sign is valid.
|
110
|
+
|
111
|
+
```Paysto.pay_till``` – timestamp string in Paysto format.
|
112
|
+
|
113
|
+
```Paysto.real_amount(amount)``` – real income amount without Paysto tax.
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
1. Fork it
|
118
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
119
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
120
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
121
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Paysto
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
6
|
+
|
7
|
+
def add_paysto_routes
|
8
|
+
paysto_route = <<-PAYSTO_ROUTES
|
9
|
+
namespace :paysto do
|
10
|
+
post :success, :fail, :check, :callback
|
11
|
+
get :fail
|
12
|
+
end
|
13
|
+
PAYSTO_ROUTES
|
14
|
+
route paysto_route
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_config
|
18
|
+
template 'config/paysto.rb', 'config/initializers/paysto.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_locale
|
22
|
+
template 'config/paysto.en.yml', 'config/locales/paysto.en.yml'
|
23
|
+
template 'config/paysto.ru.yml', 'config/locales/paysto.ru.yml'
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_controller
|
27
|
+
template 'controllers/paysto_controller.rb', 'app/controllers/paysto_controller.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Paysto
|
5
|
+
class ModelsGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../../templates', __FILE__)
|
8
|
+
|
9
|
+
def self.next_migration_number(dirname)
|
10
|
+
if ActiveRecord::Base.timestamped_migrations
|
11
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
12
|
+
else
|
13
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_migration_file
|
18
|
+
migration_template 'migration.rb', 'db/migrate/create_paysto_tables.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_models
|
22
|
+
template 'models/payment.rb', "app/models/#{Paysto.payment_class_name.underscore}.rb"
|
23
|
+
template 'models/invoice.rb', "app/models/#{Paysto.invoice_class_name.underscore}.rb"
|
24
|
+
template 'models/invoice_notification.rb', "app/models/#{Paysto.invoice_notification_class_name.underscore}.rb"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Paysto.setup do |config|
|
2
|
+
|
3
|
+
# === Put your Paysto credentials here
|
4
|
+
config.id = 'SECRET-ID'
|
5
|
+
config.secret = 'SECRET-KEY'
|
6
|
+
config.description = 'CUSTOM-DESCRIPTION-FOR-PAYMENTS'
|
7
|
+
|
8
|
+
config.urls = {
|
9
|
+
payment: 'https://paysto.com/ru/pay',
|
10
|
+
currencies: 'https://paysto.com/api/Common/Currency',
|
11
|
+
balance: 'https://paysto.com/api/Common/Balance',
|
12
|
+
payments_list: 'https://paysto.com/api/Payment/GetList'
|
13
|
+
}
|
14
|
+
|
15
|
+
config.ips = [
|
16
|
+
'66.226.72.66',
|
17
|
+
'66.226.74.225',
|
18
|
+
'66.226.74.226',
|
19
|
+
'66.226.74.227',
|
20
|
+
'66.226.74.228'
|
21
|
+
]
|
22
|
+
|
23
|
+
# === Payments tax of your tariff plan in Paysto, default onlineMerchant "All inclusive" is 5%.
|
24
|
+
config.tax = 0.05
|
25
|
+
|
26
|
+
# === Customize model names as you want before they are will be generated
|
27
|
+
config.payment_class_name = 'Payment'
|
28
|
+
config.invoice_class_name = 'Invoice'
|
29
|
+
config.invoice_notification_class_name = 'InvoiceNotification'
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreatePaystoTables < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
|
4
|
+
create_table :<%= Paysto.payment_class_name.underscore.pluralize %> do |t|
|
5
|
+
t.float :amount, default: 0.0
|
6
|
+
t.float :real_amount
|
7
|
+
t.string :gateway_code
|
8
|
+
t.string :gateway_payment_method
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
create_table :<%= Paysto.invoice_class_name.underscore.pluralize %> do |t|
|
13
|
+
t.integer :<%= Paysto.payment_class_name.underscore %>_id
|
14
|
+
t.float :amount, default: 0.0
|
15
|
+
t.datetime :paid_at
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
add_index :<%= Paysto.invoice_class_name.underscore.pluralize %>, :<%= Paysto.payment_class_name.underscore %>_id
|
19
|
+
|
20
|
+
create_table :<%= Paysto.invoice_notification_class_name.underscore.pluralize %> do |t|
|
21
|
+
t.integer :<%= Paysto.invoice_class_name.underscore %>_id
|
22
|
+
t.text :pay_data
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
add_index :<%= Paysto.invoice_notification_class_name.underscore.pluralize %>, :<%= Paysto.invoice_class_name.underscore %>_id
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class <%= Paysto.invoice_class_name %> < ActiveRecord::Base
|
2
|
+
# attr_accessible :<%= Paysto.payment_class_name.underscore %>_id,
|
3
|
+
# :amount,
|
4
|
+
# :paid_at
|
5
|
+
|
6
|
+
belongs_to :<%= Paysto.payment_class_name.underscore %>, class_name: '<%= Paysto.payment_class_name %>'
|
7
|
+
has_many :<%= Paysto.invoice_notification_class_name.underscore.pluralize %>, class_name: '<%= Paysto.invoice_notification_class_name %>', dependent: :destroy
|
8
|
+
|
9
|
+
validates :amount, presence: true
|
10
|
+
|
11
|
+
SUCCESS_STATES = {
|
12
|
+
'paysto' => 'RES_PAID'
|
13
|
+
}
|
14
|
+
|
15
|
+
def notify(params, gateway)
|
16
|
+
self.<%= Paysto.invoice_notification_class_name.underscore.pluralize %>.create(pay_data: info_by_gateway(params, gateway))
|
17
|
+
end
|
18
|
+
|
19
|
+
def need_to_be_paid?(gateway, payment_status, amount)
|
20
|
+
!paid? && (payment_status == SUCCESS_STATES[gateway.to_s]) && (self.amount.to_f == amount.to_f)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_<%= Paysto.payment_class_name.underscore %>(payment_method, gateway_code, real_amount = nil)
|
24
|
+
self.<%= Paysto.payment_class_name.underscore %> = <%= Paysto.payment_class_name %>.new(amount: self.amount,
|
25
|
+
real_amount: real_amount,
|
26
|
+
gateway_code: gateway_code,
|
27
|
+
gateway_payment_method: payment_method)
|
28
|
+
|
29
|
+
if self.<%= Paysto.payment_class_name.underscore %>.save
|
30
|
+
self.paid_at = Time.zone.now
|
31
|
+
self.save
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def paid?
|
36
|
+
!!paid_at
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def info_by_gateway(_params, _gateway)
|
42
|
+
_keys = case _gateway
|
43
|
+
when :paysto
|
44
|
+
['PAYSTO_SUM', 'PAYSTO_INVOICE_ID', 'PAYSTO_SHOP_ID', 'PAYSTO_DESC', 'PAYSTO_TTL', 'PAYSTO_PAYMENT_ID', 'PAYSTO_REQUEST_MODE']
|
45
|
+
else
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
|
49
|
+
_keys.map do |_key|
|
50
|
+
[_key, _params[_key.to_sym]].join(':')
|
51
|
+
end.join(';')
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= Paysto.payment_class_name %> < ActiveRecord::Base
|
2
|
+
# attr_accessible :amount,
|
3
|
+
# :real_amount,
|
4
|
+
# :gateway_code,
|
5
|
+
# :gateway_payment_method
|
6
|
+
|
7
|
+
has_one :<%= Paysto.invoice_class_name.underscore %>, class_name: '<%= Paysto.invoice_class_name %>', dependent: :destroy
|
8
|
+
|
9
|
+
validates :amount, presence: true
|
10
|
+
validates :amount, exclusion: { in: [0] }, allow_nil: false
|
11
|
+
end
|
data/lib/paysto-rails.rb
ADDED
data/lib/paysto/base.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
module Paysto
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
mattr_accessor :id,
|
5
|
+
:secret,
|
6
|
+
:description,
|
7
|
+
:urls,
|
8
|
+
:ips,
|
9
|
+
:tax,
|
10
|
+
:payment_class_name,
|
11
|
+
:invoice_class_name,
|
12
|
+
:invoice_notification_class_name
|
13
|
+
|
14
|
+
class << self
|
15
|
+
|
16
|
+
def setup
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def payment_class
|
21
|
+
@@payment_class_name.constantize
|
22
|
+
end
|
23
|
+
|
24
|
+
def invoice_class
|
25
|
+
@@invoice_class_name.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
def invoice_notification_class
|
29
|
+
@@invoice_notification_class_name.constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
def currencies
|
33
|
+
https_request_to Paysto.urls[:currencies], base_params
|
34
|
+
end
|
35
|
+
|
36
|
+
def balance
|
37
|
+
https_request_to Paysto.urls[:balance], base_params
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_payments(from, to)
|
41
|
+
p = { 'PAYSTO_SHOP_ID' => Paysto.id,
|
42
|
+
'FROM' => from.strftime('%Y%m%d%H%M'),
|
43
|
+
'TO' => to.strftime('%Y%m%d%H%M') }
|
44
|
+
p.merge!('PAYSTO_MD5' => generate_md5(p))
|
45
|
+
|
46
|
+
res = https_request_to(Paysto.urls[:payments_list], p)
|
47
|
+
CSV.parse(res)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_payment_type(invoice_id, time = Time.zone.now)
|
51
|
+
_type = 'common'
|
52
|
+
_payments = get_payments(time.utc - 30.minutes, time.utc + 5.minutes)
|
53
|
+
if _payments.present?
|
54
|
+
p = _payments.select{|_p| _p[2].eql?(invoice_id.to_s)}.first
|
55
|
+
_type = p[7] if p
|
56
|
+
end
|
57
|
+
_type
|
58
|
+
end
|
59
|
+
|
60
|
+
def invoice_valid?(invoice)
|
61
|
+
invoice && invoice.payment_id.blank? && invoice.paid_at.blank?
|
62
|
+
end
|
63
|
+
|
64
|
+
def ip_valid?(ip)
|
65
|
+
Paysto.ips.include?(ip)
|
66
|
+
end
|
67
|
+
|
68
|
+
def md5_valid?(p)
|
69
|
+
generate_md5(p.reject{|k,v| ['action', 'controller', 'PAYSTO_MD5'].include?(k)}) == p['PAYSTO_MD5']
|
70
|
+
end
|
71
|
+
|
72
|
+
def pay_till
|
73
|
+
(Time.zone.now + 1.day + 1.minute).utc.strftime('%Y%m%d%H%M')
|
74
|
+
end
|
75
|
+
|
76
|
+
def real_amount(str)
|
77
|
+
amount = str.to_f
|
78
|
+
_tax = amount * Paysto.tax
|
79
|
+
_tax = 10 if _tax < 10
|
80
|
+
amount - _tax
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def generate_md5(p = {}, upcase = true)
|
86
|
+
hash_str = p.to_a.sort_by{|pair| pair.first.downcase}.map{|pair| pair.join('=')}.join('&')
|
87
|
+
md5 = Digest::MD5.hexdigest("#{hash_str}&#{Paysto.secret}")
|
88
|
+
if upcase
|
89
|
+
md5.upcase
|
90
|
+
else
|
91
|
+
md5
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def base_params
|
96
|
+
p = { 'PAYSTO_SHOP_ID' => Paysto.id }
|
97
|
+
p.merge!('PAYSTO_MD5' => generate_md5(p))
|
98
|
+
end
|
99
|
+
|
100
|
+
def https_request_to(url, params)
|
101
|
+
uri = URI.parse(url)
|
102
|
+
req = Net::HTTP::Post.new(uri.path)
|
103
|
+
req.set_form_data(params)
|
104
|
+
session = Net::HTTP.new(uri.hostname, 443)
|
105
|
+
session.use_ssl = true
|
106
|
+
res = session.start do |http|
|
107
|
+
http.request(req)
|
108
|
+
end
|
109
|
+
res.body.force_encoding('UTF-8')
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Paysto
|
2
|
+
module Controller
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
skip_before_filter :verify_authenticity_token, only: [:callback, :check]
|
7
|
+
end
|
8
|
+
|
9
|
+
def check
|
10
|
+
invoice = Paysto.invoice_class.find_by_id(params['PAYSTO_INVOICE_ID'])
|
11
|
+
if Paysto.invoice_valid?(invoice) && Paysto.ip_valid?(request.remote_ip) && Paysto.md5_valid?(params)
|
12
|
+
render text: invoice.id
|
13
|
+
else
|
14
|
+
render text: I18n.t('paysto.check.fail')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def callback
|
19
|
+
invoice = Paysto.invoice_class.find_by_id(params['PAYSTO_INVOICE_ID'])
|
20
|
+
if invoice && invoice.need_to_be_paid?(:paysto, params['PAYSTO_REQUEST_MODE'], params['PAYSTO_SUM']) && Paysto.ip_valid?(request.remote_ip) && Paysto.md5_valid?(params)
|
21
|
+
invoice.notify(params, :paysto)
|
22
|
+
invoice.send("create_#{Paysto.payment_class_name.underscore}", Paysto.get_payment_type(invoice.id), 'paysto', Paysto.real_amount(params['PAYSTO_SUM']))
|
23
|
+
render text: invoice.id
|
24
|
+
else
|
25
|
+
render text: I18n.t('paysto.callback.fail')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def success
|
30
|
+
flash[:success] = I18n.t('paysto.success')
|
31
|
+
redirect_to root_path
|
32
|
+
end
|
33
|
+
|
34
|
+
def fail
|
35
|
+
flash[:alert] = I18n.t('paysto.fail')
|
36
|
+
redirect_to root_path
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paysto/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'paysto-rails'
|
8
|
+
spec.version = Paysto::VERSION
|
9
|
+
spec.authors = ['Andrey Baiburin']
|
10
|
+
spec.email = ['fbandrey@gmail.com']
|
11
|
+
spec.description = %q{Payments gateway for Paysto.com}
|
12
|
+
spec.summary = %q{Payments gateway for Paysto.com}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'i18n'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paysto-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Baiburin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Payments gateway for Paysto.com
|
56
|
+
email:
|
57
|
+
- fbandrey@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/generators/paysto/install_generator.rb
|
68
|
+
- lib/generators/paysto/models_generator.rb
|
69
|
+
- lib/generators/templates/config/paysto.en.yml
|
70
|
+
- lib/generators/templates/config/paysto.rb
|
71
|
+
- lib/generators/templates/config/paysto.ru.yml
|
72
|
+
- lib/generators/templates/controllers/paysto_controller.rb
|
73
|
+
- lib/generators/templates/migration.rb
|
74
|
+
- lib/generators/templates/models/invoice.rb
|
75
|
+
- lib/generators/templates/models/invoice_notification.rb
|
76
|
+
- lib/generators/templates/models/payment.rb
|
77
|
+
- lib/paysto-rails.rb
|
78
|
+
- lib/paysto/base.rb
|
79
|
+
- lib/paysto/controller.rb
|
80
|
+
- lib/paysto/version.rb
|
81
|
+
- paysto-rails.gemspec
|
82
|
+
homepage: ''
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Payments gateway for Paysto.com
|
106
|
+
test_files: []
|