Fingertips-internetkassa 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'abn-amro/internetkassa/response'
2
2
  require "digest/sha1"
3
+ require "cgi"
3
4
 
4
5
  module AbnAmro
5
6
  class Internetkassa
@@ -26,17 +27,20 @@ module AbnAmro
26
27
  PRODUCTION_URL = "https://internetkassa.abnamro.nl/ncol/prod/orderstandard.asp"
27
28
  TEST_URL = "https://internetkassa.abnamro.nl/ncol/test/orderstandard.asp"
28
29
 
30
+ attr_reader :params
31
+
29
32
  attr_accessor :order_id, :amount, :description, :currency, :language
30
33
  attr_accessor :accept_url, :decline_url, :exception_url, :cancel_url
34
+ attr_accessor :url_variable, :endpoint_params
31
35
 
32
- def initialize(options = {})
33
- @options = {}
36
+ def initialize(params = {})
37
+ @params = {}
34
38
 
35
- DEFAULT_VALUES.merge(options).each do |k,v|
39
+ DEFAULT_VALUES.merge(params).each do |k,v|
36
40
  if respond_to?("#{k}=")
37
41
  send("#{k}=", v)
38
42
  else
39
- @options[k] = v
43
+ @params[k] = v
40
44
  end
41
45
  end
42
46
  end
@@ -49,7 +53,7 @@ module AbnAmro
49
53
 
50
54
  def data
51
55
  verify_values!
52
- @options.merge(
56
+ @params.merge(
53
57
  :PSPID => merchant_id,
54
58
  :orderID => @order_id,
55
59
  :amount => @amount,
@@ -57,11 +61,13 @@ module AbnAmro
57
61
  :language => @language,
58
62
  :COM => @description,
59
63
  :SHASign => signature,
64
+ :PARAMVAR => @url_variable,
65
+ :PARAMPLUS => url_encoded_endpoint_params,
60
66
  :accepturl => @accept_url,
61
67
  :declineurl => @decline_url,
62
68
  :exceptionurl => @exception_url,
63
69
  :cancelurl => @cancel_url
64
- )
70
+ ).delete_if { |key, value| value.nil? || value.to_s.empty? }
65
71
  end
66
72
 
67
73
  private
@@ -83,5 +89,10 @@ module AbnAmro
83
89
  def signature
84
90
  Digest::SHA1.hexdigest("#{@order_id}#{@amount}#{@currency}#{merchant_id}#{passphrase}").upcase
85
91
  end
92
+
93
+ def url_encoded_endpoint_params
94
+ return unless @endpoint_params
95
+ @endpoint_params.map { |k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
96
+ end
86
97
  end
87
98
  end
@@ -44,7 +44,9 @@ describe "AbnAmro::Internetkassa, an instance" do
44
44
  :order_id => 123,
45
45
  :amount => 1000,
46
46
  :description => "HappyHardcore vol. 123 - the ballads",
47
- :endpoint_url => "http://example.com/payments"
47
+ :endpoint_url => "http://example.com/payments",
48
+ :url_variable => ":id",
49
+ :endpoint_params => [[:session_id, 'abcde12345'], [:message, '“Thanks for your purchase”']]
48
50
  }
49
51
  @instance = AbnAmro::Internetkassa.new(@valid_attributes)
50
52
  end
@@ -67,6 +69,14 @@ describe "AbnAmro::Internetkassa, an instance" do
67
69
  @instance.language.should == 'nl_NL'
68
70
  end
69
71
 
72
+ it "should return the url_variable" do
73
+ @instance.url_variable.should == ":id"
74
+ end
75
+
76
+ it "should return the extra params" do
77
+ @instance.endpoint_params.should == [[:session_id, 'abcde12345'], [:message, '“Thanks for your purchase”']]
78
+ end
79
+
70
80
  it "should have access to the pspid/merchant_id" do
71
81
  @instance.send(:merchant_id).should == AbnAmro::Internetkassa.merchant_id
72
82
  end
@@ -97,6 +107,8 @@ describe "AbnAmro::Internetkassa, an instance" do
97
107
  :language => @instance.language,
98
108
  :COM => @instance.description,
99
109
  :SHASign => @instance.send(:signature),
110
+ :PARAMVAR => @instance.url_variable,
111
+ :PARAMPLUS => "session_id=abcde12345&message=%E2%80%9CThanks+for+your+purchase%E2%80%9D",
100
112
  :accepturl => @valid_attributes[:endpoint_url],
101
113
  :declineurl => @valid_attributes[:endpoint_url],
102
114
  :exceptionurl => @valid_attributes[:endpoint_url],
@@ -119,6 +131,8 @@ describe "AbnAmro::Internetkassa, an instance" do
119
131
  :language => @instance.language,
120
132
  :COM => @instance.description,
121
133
  :SHASign => @instance.send(:signature),
134
+ :PARAMVAR => @instance.url_variable,
135
+ :PARAMPLUS => "session_id=abcde12345&message=%E2%80%9CThanks+for+your+purchase%E2%80%9D",
122
136
  :accepturl => @valid_attributes[:endpoint_url],
123
137
  :declineurl => @valid_attributes[:endpoint_url],
124
138
  :exceptionurl => @valid_attributes[:endpoint_url],
@@ -126,4 +140,12 @@ describe "AbnAmro::Internetkassa, an instance" do
126
140
  :TITLE => 'My Transaction'
127
141
  }
128
142
  end
143
+
144
+ it "should not return blank values in the `data'" do
145
+ @instance.url_variable = nil
146
+ @instance.data.should.not.has_key :PARAMVAR
147
+
148
+ @instance.url_variable = ''
149
+ @instance.data.should.not.has_key :PARAMVAR
150
+ end
129
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Fingertips-internetkassa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Duran