rubykassa 0.2.5 → 0.2.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: 9853afe8fbe86ab00ff98d3dce3400f53ee12174
4
- data.tar.gz: 749c93e75d2f6aaf75e8b53d297aebe24cb1980c
3
+ metadata.gz: e32aed2ec5fcba1f0a2da295982531f30bc09639
4
+ data.tar.gz: 97b7a4036c09d345cd29becd995e259642786e37
5
5
  SHA512:
6
- metadata.gz: 1e54ae545570baecfab863f0044f120fe701b5eac77c516545e07d4918095c63703fdc9594fdad9ef1d2ea0161c4b23b57208421a841851b0a09deae0ea17d96
7
- data.tar.gz: 6890ca424c90fbe83e3dccedb894c2830a4d3ca2b54af7607691ad5bac78a4ab1926272da1bdce161ea5dbce73368bc31828f1ace981e5ec7cd791f4382f6935
6
+ metadata.gz: 780f5632372166c33f2eef59a63308a46ac87ad36a1f9db16e764763e42bf8acd7e1efeda195679435e45737cbd2972bad21e6ada74bdceec34114476d8102f2
7
+ data.tar.gz: 3402f01d6f369a09c850d5514941681367134c172516cf2f776d7c472cb6a99bf63446dcf67c010c80d0118a47e65005ed92bd93604d3b8d3b683dda5bd8ad3a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Edge (not released)
2
+
3
+ * Fix bug with wrong signature generating with custom user params
4
+
1
5
  ## 0.2.5
2
6
 
3
7
  * Fix bug with passing custom params
@@ -25,6 +25,6 @@ class RobokassaController < ApplicationController
25
25
  private
26
26
 
27
27
  def create_notification
28
- @notification = Rubykassa::Notification.new params
28
+ @notification = Rubykassa::Notification.new request.query_parameters
29
29
  end
30
30
  end
@@ -20,6 +20,7 @@ module Rubykassa
20
20
 
21
21
  def initialize &block
22
22
  instance_eval &block if block_given?
23
+ shpfy_params
23
24
  end
24
25
 
25
26
  def test_mode?
@@ -30,10 +31,10 @@ module Rubykassa
30
31
  test_mode? ? "http://test.robokassa.ru/Index.aspx" : "https://merchant.roboxchange.com/Index.aspx"
31
32
  end
32
33
 
33
- def pay_url(options = {})
34
- options = options.slice(:currency, :description, :email, :culture)
34
+ def pay_url(extra_params = {})
35
+ extra_params = extra_params.slice(:currency, :description, :email, :culture)
35
36
 
36
- "#{base_url}?" + initial_options.merge(options).map do |key, value|
37
+ "#{base_url}?" + initial_options.merge(extra_params).map do |key, value|
37
38
  if key =~ /^shp/
38
39
  "#{key}=#{value}"
39
40
  else
@@ -48,7 +49,13 @@ module Rubykassa
48
49
  total: @total,
49
50
  invoice_id: @invoice_id,
50
51
  signature: generate_signature_for(:payment)
51
- }.merge(Hash[@params.sort.map {|param_name| ["shp#{param_name[0]}".to_sym, param_name[1]]}])
52
+ }.merge(Hash[@params.sort.map {|param_name| [param_name[0], param_name[1]]}])
52
53
  end
54
+
55
+ private
56
+
57
+ def shpfy_params
58
+ @params = @params.map {|param_name| ["shp#{param_name[0]}".to_sym, param_name[1]]}
59
+ end
53
60
  end
54
61
  end
@@ -2,22 +2,26 @@
2
2
  module Rubykassa
3
3
  module SignatureGenerator
4
4
  def generate_signature_for kind
5
- raise ArgumentError, "Available kinds are only :payment, :result or :success" unless [:success, :payment, :result].include? kind
6
- custom_params = @params.keys.select {|key| key =~ /^shp/ }.sort.map {|key| "#{key}=#{params[key]}"}
7
- custom_params_string = custom_params.present? ? ":#{custom_params}" : ""
8
-
9
- Digest::MD5.hexdigest(params_string(kind, custom_params_string))
5
+ raise ArgumentError, "Available kinds are only :payment, :result or :success" unless [:success, :payment, :result].include? kind
6
+ Digest::MD5.hexdigest(params_string(kind))
10
7
  end
11
8
 
12
- def params_string kind, custom_params_string
9
+ def params_string kind
13
10
  string = case kind
14
11
  when :payment
15
- [Rubykassa.login, @total, @invoice_id, Rubykassa.first_password].join(":") + custom_params_string
12
+ [Rubykassa.login, @total, @invoice_id, Rubykassa.first_password, custom_params].flatten.join(":")
16
13
  when :result
17
- [@total, @invoice_id, Rubykassa.second_password].join(":") + custom_params_string
14
+ [@total, @invoice_id, Rubykassa.second_password, custom_params].flatten.join(":")
18
15
  when :success
19
- [@total, @invoice_id, Rubykassa.first_password].join(":") + custom_params_string
16
+ [@total, @invoice_id, Rubykassa.first_password, custom_params].flatten.join(":")
17
+ end
18
+ end
19
+
20
+ def custom_params
21
+ @params.sort.inject([]) do |result, element|
22
+ result << element.join("=") if element[0] =~ /^shp/
23
+ result
20
24
  end
21
25
  end
22
26
  end
23
- end
27
+ end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Rubykassa
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
data/lib/rubykassa.rb CHANGED
@@ -18,11 +18,11 @@ module Rubykassa
18
18
  end
19
19
  end
20
20
 
21
- def pay_url invoice_id, total, params, options = {}
21
+ def pay_url invoice_id, total, custom_params, extra_params = {}
22
22
  Rubykassa::PaymentInterface.new do
23
- self.total = total
24
- self.invoice_id = invoice_id
25
- self.params = params
26
- end.pay_url(options)
23
+ self.total = total
24
+ self.invoice_id = invoice_id
25
+ self.params = custom_params
26
+ end.pay_url(extra_params)
27
27
  end
28
28
  end
@@ -18,11 +18,11 @@ describe Rubykassa::PaymentInterface do
18
18
  end
19
19
 
20
20
  it "should return correct pay_url" do
21
- @payment_interface.pay_url.should == "http://test.robokassa.ru/Index.aspx?MrchLogin=your_login&OutSum=1200&InvId=12&SignatureValue=96c0bbd4fc8f365455e949b1fbf5e3f4&shpfoo=bar"
21
+ @payment_interface.pay_url.should == "http://test.robokassa.ru/Index.aspx?MrchLogin=your_login&OutSum=1200&InvId=12&SignatureValue=bf0504363d89638669e057932857316c&shpfoo=bar"
22
22
  end
23
23
 
24
24
  it "should return correct pay_url when additional options passed" do
25
- @payment_interface.pay_url({description: "desc", culture: "ru", email: "foo@bar.com", currency: ""}).should == "http://test.robokassa.ru/Index.aspx?MrchLogin=your_login&OutSum=1200&InvId=12&SignatureValue=96c0bbd4fc8f365455e949b1fbf5e3f4&shpfoo=bar&IncCurrLabel=&Desc=desc&Email=foo@bar.com&Culture=ru"
25
+ @payment_interface.pay_url({description: "desc", culture: "ru", email: "foo@bar.com", currency: ""}).should == "http://test.robokassa.ru/Index.aspx?MrchLogin=your_login&OutSum=1200&InvId=12&SignatureValue=bf0504363d89638669e057932857316c&shpfoo=bar&IncCurrLabel=&Desc=desc&Email=foo@bar.com&Culture=ru"
26
26
  end
27
27
 
28
28
  it "should return correct initial_options" do
@@ -30,7 +30,7 @@ describe Rubykassa::PaymentInterface do
30
30
  login: "your_login",
31
31
  total: 1200,
32
32
  invoice_id: 12,
33
- signature: "96c0bbd4fc8f365455e949b1fbf5e3f4",
33
+ signature: "bf0504363d89638669e057932857316c",
34
34
  shpfoo: "bar"
35
35
  }
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubykassa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Kishenin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails