so_paid 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDBjM2UyM2M5NTQzMzg3OTRjOWVjZGNhMmE1MGU3YjZjODFlZjFiNw==
4
+ NTQ1MjljMjAwYzgzNGM2NTg1NjkyYzlhY2EwNTZkMDRlYzk0ZTBmMw==
5
5
  data.tar.gz: !binary |-
6
- ZGZhNzQ2YWE3MjZiMzhmNjM4NzI2M2U2ZTZmNjBhYTZlM2NjZGZkZg==
6
+ NjNmOGViNWIyM2VhZDQxYjczZTdjNzg0NTUwZjllYjJiNjAyZTU4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTI2MzIwNmYwMjcxOTZiOTYyNWI3ZDVlYmI0ZWQ4MTFlNmY3MzRkZmJjODNk
10
- ZGYyMGQ5ZDNkOGFjNDk4YmZhMzQzODFiMjI3OGUwNTk4YTQzMmM4MDY2YzU3
11
- NGM3NDA0NjA0MzE3Mzc1MDA1YzAxNTY2MDAyYTE4ZTYwNDc3MGU=
9
+ ZjZlZmVkNWI4YTUzM2E3MmRkYTQ3Yzc1NWZhOTFjYzQ3ODYxMmZmODYyZDZj
10
+ NjU1Y2UxNGIwOWRhNTExMzA2MTk0ZDIxN2JlODkzNTZjNDA3NjlkZTA5YWI5
11
+ MzFiZWQ5OTk5OWFhMzVlY2E3OWUyZWYwOWEyNDhlMTRjZDEwMTU=
12
12
  data.tar.gz: !binary |-
13
- NDg1ZmJkNmE3OGViNDFkMzNjMGQ5NDUwOGFiMWNkZWE1NGFlYjI3OTg4YjBj
14
- MmE5NGU2MWQ5NjI2MTQ5NzNlZGMyZDM3MGU0YjJjMmFjMTM3MjFmY2M3YzQx
15
- MDc0Yjk0OTRmMjkxZTI2NTFjMDJjN2IxMzViMGU4NmQxYzQ0YTk=
13
+ ZDczNGRhODkxMDJkNTJhZjQzMjUzNmEzOWZmYjZjODFmNmM0ZTM2MWJlZDFm
14
+ YjBiODJkNjMyNjAzMGJhZWJiZDdjOTRjMTY4ZWM2NTYyZTRhZjQyNmNmY2Fj
15
+ YTU5NGJmMGZjYzI1ZTkzODNlMDQ5Zjg4OTJiNDA2NTcxYzI2ZDU=
@@ -23,7 +23,7 @@ class PaymentsController < ApplicationController
23
23
  if @order.save
24
24
  # specific payment vendor, ex: cybersource...
25
25
  #...or not if you only have one defined in config
26
- #ex: @payment_vendor = SoPaid.vendor(:cybersource).new(@order, {override_defaults_hash}, {override_config_defaults_hash})
26
+ #ex: @payment_vendor = SoPaid.vendor(:cybersource).new(@order, {override_order_defaults_hash}, {override_config_defaults_hash})
27
27
  @payment_vendor = SoPaid.vendor.new(@order)
28
28
  else
29
29
  flash[:error] = "Please fix all errors with your account and your order. If you are having trouble making a purchase, contact the administrator."
@@ -1,4 +1,4 @@
1
- <form action="<%=@payment_vendor.hop_url(current_user)%>" method="post" >
1
+ <form action="<%=@payment_vendor.hop_url%>" method="post" >
2
2
  <% @payment_vendor.generate_params.each_pair do |key, value| %>
3
3
  <input type="hidden" name="<%=key%>" value="<%=value%>" >
4
4
  <%end%>
@@ -64,6 +64,11 @@ SoPaid.configure do |config|
64
64
  # config options
65
65
  # if mode
66
66
  :config_options=>{
67
+ :use_post_url=>:iframe #:webmobile
68
+ # the purpose of the test_user_email
69
+ # is to trump the test_mode set here
70
+ # essentially forcing test_mode to true
71
+ # for that user only
67
72
  :test_user_email=>"payment_tester@gmail.com",
68
73
  :test_mode=>false
69
74
  }
data/lib/.DS_Store CHANGED
Binary file
@@ -5,9 +5,17 @@ module SoPaid
5
5
 
6
6
 
7
7
  @@pv_defaults = {
8
- :live=>{
9
- },
10
8
  :test=>{
9
+ :post_urls=>{
10
+ :webmobile=>"https://testsecureacceptance.cybersource.com/pay",
11
+ :iframe=>"https://testsecureacceptance.cybersource.com/embedded/pay"
12
+ }
13
+ },
14
+ :live=>{
15
+ :post_urls=>{
16
+ :webmobile=>"https://secureacceptance.cybersource.com/pay",
17
+ :iframe=>"https://secureacceptance.cybersource.com/embedded/pay"
18
+ }
11
19
  },
12
20
  :secret_key=>"",
13
21
  :profile_id=>"",
@@ -39,8 +47,7 @@ module SoPaid
39
47
 
40
48
  @@config_defaults = {
41
49
  # optional for gem
42
- :test_mode=>false,
43
- :test_user_email=>"payment_tester@gmail.com"
50
+ :use_post_url=>:iframe
44
51
  }
45
52
 
46
53
 
@@ -61,27 +68,20 @@ module SoPaid
61
68
  end
62
69
 
63
70
 
64
- def hop_url(user_email)
65
- # test mode true or specific test email gets access to test page
66
- if test? or @config_options[:test_user_email] == @current_user_email
67
- test_hop_url
68
- else
69
- live_hop_url
70
- end
71
+ def hop_url(use_post_url=nil)
72
+ # test/live url has already been determined by test_mode or user_email
73
+ @merged_pv_opts[:post_urls][ use_post_url.presence || @config_options[:use_post_url]]
71
74
  end
72
75
 
73
76
 
74
77
  private
75
78
 
76
-
77
-
78
-
79
-
80
79
  def set_pv_fields
80
+ @pv_order_params = {}
81
81
  if live?
82
- @pv_order_params = @pv_options[:live].presence || @pv_options
82
+ pv_opts = @pv_options[:live].presence || @pv_options
83
83
  else
84
- @pv_order_params = @pv_options[:test].presence || @pv_options
84
+ pv_opts = @pv_options[:test].presence || @pv_options
85
85
  end
86
86
 
87
87
  # we just set them above and are done with them
@@ -89,7 +89,13 @@ module SoPaid
89
89
  @pv_options.delete(:test)
90
90
  # merge pv_order_params on top of pv_options which is
91
91
  # the combination of the class defaults and the configuration file defaults
92
- @pv_order_params = merge_defaults(nil, @pv_order_params, @pv_options)
92
+ @merged_pv_opts = merge_defaults(pv_opts, @pv_options)
93
+ order_keys = @merged_pv_opts[:signed_field_names] + @merged_pv_opts[:unsigned_field_names]
94
+
95
+ order_keys.each do |o_key|
96
+ @pv_order_params[o_key] = @merged_pv_opts[o_key]
97
+ end
98
+
93
99
  end
94
100
 
95
101
 
@@ -117,30 +123,22 @@ module SoPaid
117
123
 
118
124
  def sign_params
119
125
  data = []
120
- @pv_options[:signed_field_names].each do |key|
126
+ @pv_order_params[:signed_field_names].each do |key|
121
127
  data << key.to_s + "=" + @pv_order_params[key].to_s
122
128
  end
123
- @pv_options[:signed_field_names] = @pv_options[:signed_field_names].join(",")
129
+ @pv_order_params[:signed_field_names] = @pv_order_params[:signed_field_names].join(",")
124
130
  data = data.join(",")
125
131
 
126
- encode_hop(data, @pv_order_params[:secret_key])
132
+ encode_hop(data, @merged_pv_opts[:secret_key])
127
133
  end
128
134
 
129
135
 
130
136
  def test?
131
- @config_options[:test_mode]
137
+ @config_options[:test_mode] or (@config_options[:test_user_email].present? and @config_options[:test_user_email] == @current_user_email)
132
138
  end
133
139
 
134
140
  def live?
135
141
  !test?
136
142
  end
137
-
138
- def test_hop_url
139
- "https://testsecureacceptance.cybersource.com/pay"
140
- end
141
-
142
- def live_hop_url
143
- "https://secureacceptance.cybersource.com/pay"
144
- end
145
143
  end
146
144
  end
data/lib/so_paid/hop.rb CHANGED
@@ -24,8 +24,8 @@ module SoPaid
24
24
 
25
25
 
26
26
  def self.payment_options(pv_options={}, config_options={})
27
- @@pv_defaults = self.merge_defaults([:live, :test], pv_options, @@pv_defaults)
28
- @@config_defaults = self.merge_defaults(nil, config_options, @@config_defaults)
27
+ @@pv_defaults = self.merge_defaults(pv_options, @@pv_defaults)
28
+ @@config_defaults = self.merge_defaults(config_options, @@config_defaults)
29
29
 
30
30
  return self
31
31
  end
@@ -33,11 +33,13 @@ module SoPaid
33
33
 
34
34
  def initialize(order, pv_options={}, config_options={})
35
35
  @pv_order_params = {}.with_indifferent_access
36
- @pv_options = self.merge_defaults([:live, :test], pv_options, @@pv_defaults)
37
- @config_options = self.merge_defaults(nil, config_options, @@config_defaults)
36
+ @pv_options = self.merge_defaults(pv_options, @@pv_defaults)
37
+ @config_options = self.merge_defaults(config_options, @@config_defaults)
38
38
 
39
39
  @order = order
40
40
  @current_user_email = @config_options[:current_user_email] || @config_options[:current_user].try(:email) || (@order.user.try(:email) if @order.respond_to?(:user))
41
+ generate_params
42
+ return self
41
43
  end
42
44
 
43
45
 
@@ -61,142 +63,29 @@ module SoPaid
61
63
  verify_signature(message[:signed_field_names], message[:signature])
62
64
  end
63
65
 
64
- def merge_defaults(modes=[], opts={}, default_opts={})
65
- SoPaid::Hop.merge_defaults(modes, opts, default_opts)
66
+ def merge_defaults(opts={}, default_opts={})
67
+ SoPaid::Hop.merge_defaults(opts, default_opts)
66
68
  end
67
69
 
68
70
 
69
- def self.merge_defaults(modes=[], opts={}, default_opts={})
70
- modes ||= []
71
- new_opts = opts.clone.with_indifferent_access
72
- new_default_opts = default_opts.clone.with_indifferent_access
73
- modes.each do |mode|
74
- new_default_opts[mode] ||= {}
75
- new_opts_mode = new_opts[mode].is_a?(Hash) ? new_opts[mode] : {}
76
- new_opts_mode.each_pair do |key, value|
77
- if value.is_a?(Array)
78
- new_default_opts[mode][key] = ((new_default_opts[mode][key] || []) + value).uniq
79
- else
80
- new_default_opts[mode][key] = value
71
+
72
+ def self.merge_defaults(main_hash, defaults_hash)
73
+ target = main_hash.dup
74
+ (defaults_hash.keys + main_hash.keys).uniq.each do |key|
75
+ if defaults_hash[key].is_a? Hash and main_hash[key].is_a? Hash
76
+ target[key] = merge_defaults(target[key], defaults_hash[key])
77
+ next
78
+ end
79
+ #target[key] = hash[key]
80
+ # if the defaults_hash value is an array, make sure just to
81
+ # append new uniq values, not overwrite default
82
+ target.update(defaults_hash) do |key, tv, dv|
83
+ ntv = tv.is_a?(Array) ? tv.clone : tv
84
+ dv.is_a?(Array) ? (dv.clone << ntv ).flatten.uniq : ntv
81
85
  end
82
86
  end
83
- new_opts.delete(mode)
84
- end
85
-
86
- # if mode was not provided via configuration file,
87
- # this defaults to the opposite/non-provided mode,
88
- # or uses the defaults set up in this file
89
- new_opts.each_pair do |key, value|
90
- if value.is_a?(Array)
91
- new_default_opts[key] = ((new_default_opts[key] || []) + value).uniq
92
- else
93
- new_default_opts[key] = value
94
- end
95
- end
96
-
97
- return new_default_opts
98
- end
99
-
100
-
101
- # def get_microtime
102
- # t = Time.now
103
- # sprintf("%d%03d", t.to_i, t.usec / 1000)
104
- # end
105
-
106
- # def encode_hop(data, key)
107
- # Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, data)).chomp.gsub(/\n/,'')
108
- # end
109
-
110
-
111
- # def insert_signature3(amount="0.00",currency="usd",orderPage_transactionType='sale')
112
- # profile_id = get_profile_id
113
- # timestamp = get_microtime
114
- # data = profile_id + amount + currency + timestamp + orderPage_transactionType
115
- # pub = get_secret_key
116
- # serial_number = get_serial_number
117
- # pub_digest = encode_hop(data,pub)
118
-
119
- # sig = "<input type='hidden' name='orderPage_transactionType' value='#{orderPage_transactionType}'>\n"
120
- # sig << "<input type='hidden' name='amount' value='#{amount}'>\n"
121
- # sig << "<input type='hidden' name='currency' value='#{currency}'>\n"
122
- # sig << "<input type='hidden' name='orderPage_timestamp' value='#{timestamp}'>\n"
123
- # sig << "<input type='hidden' name='merchantID' value='#{profile_id}'>\n"
124
- # sig << "<input type='hidden' name='orderPage_signaturePublic' value='#{pub_digest}'>\n"
125
- # sig << "<input type='hidden' name='orderPage_version' value='4'>\n"
126
- # sig << "<input type='hidden' name='orderPage_serialNumber' value='#{serial_number}'>\n"
127
- # sig
128
- # end
129
-
130
-
131
-
132
- # def insert_map_signature(assoc_array)
133
- # assoc_array['mechantID'] = get_profile_id
134
- # assoc_array['orderPage_timestamp'] = get_microtime
135
- # assoc_array['orderPage_version'] = "4"
136
- # assoc_array['orderPage_serialNumber'] = getSerialNumber
137
-
138
- # fields = []
139
- # values = ''
140
- # inputs = ''
141
- # assoc_array.each do |key,value|
142
- # fields << key
143
- # values << value
144
- # inputs << '<input type="hidden" name="'+key+'" value="'+value+'">'+"\n"
145
- # end
146
-
147
- # pub = get_secret_key
148
- # pub_digest = hop_hash(values,pub)
149
- # inputs << '<input type="hidden" name="orderPage_signaturePublic" value="'+pub_digest+'">'+"\n"
150
- # inputs << '<input type="hidden" name="orderPage_signedFields" value="'+fields+'">'+"\n"
151
- # inputs
152
- # end
153
-
154
- # def insert_signature(amount="0.00",currency="usd")
155
- # merchant_id = get_merchant_id
156
- # timestamp = get_microtime
157
- # data = merchant_id + amt + curr + timestamp
158
- # serial_number = get_serial_number
159
- # pub_digest = hop_hash(data, get_shared_secret)
160
-
161
- # sig = "<input type='hidden' name='amount' value='#{amount}'>\n"
162
- # sig << "<input type='hidden' name='currency' value='#{currency}'>\n"
163
- # sig << "<input type='hidden' name='orderPage_timestamp' value='#{timestamp}'>\n"
164
- # sig << "<input type='hidden' name='merchantID' value='#{merchant_id}'>\n"
165
- # sig << "<input type='hidden' name='orderPage_signaturePublic' value='#{sig_hash}'>\n"
166
- # sig << "<input type='hidden' name='orderPage_version' value='4'>\n"
167
- # sig << "<input type='hidden' name='orderPage_serialNumber' value='#{serial_number}'>\n"
168
- # sig
169
- # end
170
-
171
-
172
- # def insert_subscription_signature(subscription_amount="0.00",
173
- # subscription_start_date="00000000",
174
- # subscription_frequency=nil,
175
- # subscription_number_of_payments="0",
176
- # subscription_automatic_renew="true"
177
- # )
178
- # if subscription_frequency.nil? then return end
179
-
180
- # data = subscription_amount + subscription_start_date + subscription_frequency + subscription_number_of_payments + subscription_automatic_renew
181
- # pub = get_shared_secret
182
- # pub_digest = hop_hash(data, pub)
183
- # sign = '<input type="hidden" name="recurringSubscriptionInfo_amount" value="' + subscriptionAmount + '">' + "\n"
184
- # sig << '<input type="hidden" name="recurringSubscriptionInfo_numberOfPayments" value="' + subscriptionNumberOfPayments + '">' + "\n"
185
- # sig << '<input type="hidden" name="recurringSubscriptionInfo_frequency" value="' + subscriptionFrequency + '">' + "\n"
186
- # sig << '<input type="hidden" name="recurringSubscriptionInfo_automaticRenew" value="' + subscriptionAutomaticRenew + '">' + "\n"
187
- # sig << '<input type="hidden" name="recurringSubscriptionInfo_startDate" value="' + subscriptionStartDate + '">' + "\n"
188
- # sig << '<input type="hidden" name="recurringSubscriptionInfo_signaturePublic" value="' + pub_digest + '">' + "\n"
189
- # sig
190
- # end
191
-
192
- # def insert_subscription_id_signature(subscription_id)
193
- # if subscription_id.nil? then return end
194
-
195
- # pub_digest = hop_hash(subscription_id, get_shared_secret)
196
- # str = '<input type="hidden" name="paySubscriptionCreateReply_subscriptionID" value="' + subscription_id + '">' + "\n"
197
- # str << '<input type="hidden" name="paySubscriptionCreateReply_subscriptionIDPublicSignature" value="' + pub_digest + '">' + "\n"
198
- # str
199
- # end
87
+ target
88
+ end
200
89
 
201
90
 
202
91
  end
@@ -1,3 +1,3 @@
1
1
  module SoPaid
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: so_paid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkralla11
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler