paysto-rails 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 146fbeb3db8bf0d6dade99ab49918b88e0adf69a
4
- data.tar.gz: 3b495e18d3d3517f56a1fd67f5f8007726864023
3
+ metadata.gz: 7700a24bc357595d65d5bcf07880a171611f7635
4
+ data.tar.gz: 8dfd72717eaeae5936ff620c5a76feb3d5d2e190
5
5
  SHA512:
6
- metadata.gz: dde4877b7b7254f0a52f73759d4697d069b3534acc65bcf079402ef39d2aec1c4a4ee5e814e269d7b17348ad6b6ba024f185079e970219e3f0bba9090107f1b0
7
- data.tar.gz: 0c8359665d747d1f9032012019f60a33848187e7d2aafff5aae1c1b54827784be6e2f87a0aa1da3a93dbb2be7ebed216109f5d695decdb6dd5f1a2f9eb579be2
6
+ metadata.gz: 9716185ddc6a3691b9240eb189750d995f1a7401980422b9061093d2a13024a14421a669a3f8f569290c87a5b03e5f17dbc96eaaf888b2c24b545312663eb3e2
7
+ data.tar.gz: ff1a47758b4bde9ecdc77276be927191a110810b57b5ee67fa8dd381af3b8d110af4f6d529b32eaf6be316a926375080d8c18310ccf1bcfcf88c77bed085eb1c
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  This is quick implementation for passing payments through [Paysto](https://paysto.com) gateway. It works only with «[onlineMerchant](https://paysto.com/ru/products/onlineMerchant)». Your PRs are welcome.
10
10
 
11
- Check demo shop in action: [www.paysto.tk](http://www.paysto.tk/). And source code [here](http://github.com/fbandrey/paysto-demo).
11
+ Check demo shop in action: [ror.paysto.in](https://ror.paysto.in/). And source code [here](https://github.com/fbandrey/paysto-demo).
12
12
 
13
13
  ## Installation
14
14
 
@@ -82,7 +82,7 @@ But you may override methods as you want. For example, if you want to redirect u
82
82
  ```
83
83
  class PaystoController < ApplicationController
84
84
  include Paysto::Controller
85
-
85
+
86
86
  def success
87
87
  flash[:success] = I18n.t('paysto.success')
88
88
  redirect_to any_custom_payments_path
@@ -15,14 +15,10 @@ Paysto.setup do |config|
15
15
 
16
16
  # === Paysto server IPs.
17
17
  config.ips = [
18
- '66.226.72.66',
19
- '66.226.74.225',
20
- '66.226.74.226',
21
- '66.226.74.227',
22
- '66.226.74.228',
23
18
  '23.102.21.72',
19
+ '137.135.207.41',
24
20
  '23.102.17.162',
25
- '137.135.207.41'
21
+ '168.61.92.150'
26
22
  ]
27
23
 
28
24
  # === Payments tax of your tariff plan in Paysto. Default onlineMerchant "All inclusive" is 5%.
@@ -39,4 +35,4 @@ Paysto.setup do |config|
39
35
  config.invoice_class_name = 'Invoice'
40
36
  config.invoice_notification_class_name = 'InvoiceNotification'
41
37
 
42
- end
38
+ end
data/lib/paysto/base.rb CHANGED
@@ -14,6 +14,8 @@ module Paysto
14
14
  :invoice_class_name,
15
15
  :invoice_notification_class_name
16
16
 
17
+ RXP = Regexp.new('[^a-zA-Z0-9$&%;:?!\.,\s}(\[){\]"\'`\\/|^_~*+=<>@-]+')
18
+
17
19
  class << self
18
20
 
19
21
  # Configuring module.
@@ -65,7 +67,7 @@ module Paysto
65
67
  def get_payment_type(invoice_id, time = Time.zone.now)
66
68
  _payments = get_payments(time.utc - 30.minutes, time.utc + 5.minutes)
67
69
  if _payments.present?
68
- p = _payments.select{|_p| _p[2].eql?(invoice_id.to_s)}.first
70
+ p = _payments.select{ |_p| _p[2].eql?(invoice_id.to_s) }.first
69
71
  _type = p[7] if p
70
72
  end
71
73
  _type || 'common'
@@ -83,8 +85,8 @@ module Paysto
83
85
 
84
86
  # Check whether the MD5 sign is valid.
85
87
  def md5_valid?(p)
86
- except_keys = ['action', 'controller', 'PAYSTO_MD5']
87
- generate_md5(p.reject{|k,v| except_keys.include?(k)}) == p['PAYSTO_MD5']
88
+ hash = p.except('action', 'controller', 'PAYSTO_MD5')
89
+ generate_md5(hash) == p['PAYSTO_MD5']
88
90
  end
89
91
 
90
92
  # Timestamp string in Paysto format for payments expiration.
@@ -105,11 +107,17 @@ module Paysto
105
107
 
106
108
  # Generating MD5 sign according with received params.
107
109
  def generate_md5(p = {}, upcase = true)
108
- hash_str = p.to_a.sort_by{|pair| pair.first.downcase}.map{|pair| pair.join('=')}.join('&')
109
- md5 = Digest::MD5.hexdigest("#{hash_str}&#{@@secret}")
110
+ md5 = Digest::MD5.hexdigest(md5_string(p))
110
111
  upcase ? md5.upcase : md5
111
112
  end
112
113
 
114
+ # Final data string to gererane MD5.
115
+ def md5_string(p = {})
116
+ str = p.to_a.sort_by{ |pair| pair.first.downcase }.map{ |pair| pair.join('=') }.join('&')
117
+ str_with_secret = [str, @@secret].join('&')
118
+ str_with_secret.gsub(RXP, '')
119
+ end
120
+
113
121
  # Base set of params for requests.
114
122
  def base_params
115
123
  p = { 'PAYSTO_SHOP_ID' => @@id }
@@ -10,7 +10,7 @@ module Paysto
10
10
  # First step of payment workflow: Invoice, IP and MD5 verification.
11
11
  # Render invoice ID if everything right or anything else if not.
12
12
  def check
13
- invoice = Paysto.invoice_class.find_by_id(params['PAYSTO_INVOICE_ID'])
13
+ invoice = Paysto.invoice_class.find_by(id: params['PAYSTO_INVOICE_ID'])
14
14
  if Paysto.invoice_valid?(invoice) && Paysto.ip_valid?(request.remote_ip) && Paysto.md5_valid?(params)
15
15
  render text: invoice.id
16
16
  else
@@ -21,7 +21,7 @@ module Paysto
21
21
  # Second step of payment workflow: Payment creation.
22
22
  # Render invoice ID if everything right or anything else if not.
23
23
  def callback
24
- invoice = Paysto.invoice_class.find_by_id(params['PAYSTO_INVOICE_ID'])
24
+ invoice = Paysto.invoice_class.find_by(id: params['PAYSTO_INVOICE_ID'])
25
25
  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)
26
26
  invoice.notify(params, :paysto)
27
27
  invoice.send("create_#{Paysto.payment_class_name.underscore}", Paysto.get_payment_type(invoice.id), 'paysto', Paysto.real_amount(params['PAYSTO_SUM']))
@@ -1,3 +1,3 @@
1
1
  module Paysto
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.6'
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paysto-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Baiburin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: i18n
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Paysto.com implementation for Ruby on Rails applications
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -90,17 +90,17 @@ require_paths:
90
90
  - lib
91
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - '>='
98
+ - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.0.14
103
+ rubygems_version: 2.5.1
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Paysto.com implementation for Ruby on Rails applications