offsite_payments 2.7.20 → 2.7.21

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
  SHA256:
3
- metadata.gz: 52bf59c63646b7d0fd207a51bb3e977e14234edd0d7b4d494967ebde13ead384
4
- data.tar.gz: 97d45379f6df925b274285ebec7f7b8380396dd3c46162734191b7a6ac03d83b
3
+ metadata.gz: 11d3af9b6ea7b963a53bba9b38c1c0495aa8a676a5d15a081fff92461ea7848c
4
+ data.tar.gz: d68bbaabd36c6e31f4ccdd9c77245dfb8adc1596dd9e8b71ba2042f1de010760
5
5
  SHA512:
6
- metadata.gz: 85fc3bf1c22cdf71b0a4497b44eecb9406f5ff1538eb4d50ea9a26212a13002f8b8a59fc71e5ac2d7d037dda6a39ef7dbae4ec10d2faed2431d736c95565240e
7
- data.tar.gz: ba78f07a16f201b9607a98088c4c9173d855ef59ce34e7086334380ff5349d9a6772aea721f2be5bf1b99529061ad10347c9f97ff78e2a80145e0a78378cd051
6
+ metadata.gz: 57c6f0dda0656e8a528eec91ff862d7580c2603559011d0ee2ddc7fbb437244ef2c3ee111fcf2b7a35ca34c68235a85debc77f33477b5bdb7b07beaa3b759db6
7
+ data.tar.gz: 50b50027b8cd16ed325e3e12692f775d615d32f6caa187882e89dfedb10cbdc63c4170278e8ae20ddd5e5ea056c1feaa85292efe4290bb4066204d25825b68d5
data/README.md CHANGED
@@ -67,6 +67,7 @@ one.
67
67
  * [Dwolla](https://www.dwolla.com/default.aspx)
68
68
  * [ePay](http://www.epay.dk/epay-payment-solutions/)
69
69
  * [First Data](https://firstdata.zendesk.com/entries/407522-first-data-global-gateway-e4sm-payment-pages-integration-manual)
70
+ * [Realex](https://www.globalpaymentsinc.com)
70
71
  * [HiTRUST](http://www.hitrust.com.hk/)
71
72
  * [MOLPay](http://www.molpay.com/v2/) - MY, SG, ID, TH, VN, PH, CN, AU
72
73
  * [Moneybookers](http://www.moneybookers.com)
@@ -77,7 +78,6 @@ one.
77
78
  * [PayDollar](http://www.paydollar.com)
78
79
  * [Paysbuy](https://www.paysbuy.com/) - TH
79
80
  * [Platron](https://www.platron.ru/) - RU
80
- * [Realex](http://www.realexpayments.com)
81
81
  * [RBK Money](https://rbkmoney.ru/) - RU
82
82
  * [Robokassa](http://robokassa.ru/) - RU
83
83
  * [SagePay Form](http://www.sagepay.com/products_services/sage_pay_go/integration/form)
@@ -63,6 +63,85 @@ module OffsitePayments #:nodoc:
63
63
  'COU' => 4
64
64
  }
65
65
 
66
+ CANADIAN_STATES = {
67
+ 'AB' => 'Alberta',
68
+ 'BC' => 'British Columbia',
69
+ 'MB' => 'Manitoba',
70
+ 'NB' => 'New Brunswick',
71
+ 'NL' => 'Newfoundland',
72
+ 'NS' => 'Nova Scotia',
73
+ 'NU' => 'Nunavut',
74
+ 'NT' => 'Northwest Territories',
75
+ 'ON' => 'Ontario',
76
+ 'PE' => 'Prince Edward Island',
77
+ 'QC' => 'Quebec',
78
+ 'SK' => 'Saskatchewan',
79
+ 'YT' => 'Yukon'
80
+ }
81
+
82
+ US_STATES = {
83
+ 'AL' => 'Alabama',
84
+ 'AK' => 'Alaska',
85
+ 'AS' => 'American Samoa',
86
+ 'AZ' => 'Arizona',
87
+ 'AR' => 'Arkansas',
88
+ 'CA' => 'California',
89
+ 'CO' => 'Colorado',
90
+ 'CT' => 'Connecticut',
91
+ 'DE' => 'Delaware',
92
+ 'DC' => 'District Of Columbia',
93
+ 'FM' => 'Federated States Of Micronesia',
94
+ 'FL' => 'Florida',
95
+ 'GA' => 'Georgia',
96
+ 'GU' => 'Guam',
97
+ 'HI' => 'Hawaii',
98
+ 'ID' => 'Idaho',
99
+ 'IL' => 'Illinois',
100
+ 'IN' => 'Indiana',
101
+ 'IA' => 'Iowa',
102
+ 'KS' => 'Kansas',
103
+ 'KY' => 'Kentucky',
104
+ 'LA' => 'Louisiana',
105
+ 'ME' => 'Maine',
106
+ 'MH' => 'Marshall Islands',
107
+ 'MD' => 'Maryland',
108
+ 'MA' => 'Massachusetts',
109
+ 'MI' => 'Michigan',
110
+ 'MN' => 'Minnesota',
111
+ 'MS' => 'Mississippi',
112
+ 'MO' => 'Missouri',
113
+ 'MT' => 'Montana',
114
+ 'NE' => 'Nebraska',
115
+ 'NV' => 'Nevada',
116
+ 'NH' => 'New Hampshire',
117
+ 'NJ' => 'New Jersey',
118
+ 'NM' => 'New Mexico',
119
+ 'NY' => 'New York',
120
+ 'NC' => 'North Carolina',
121
+ 'ND' => 'North Dakota',
122
+ 'MP' => 'Northern Mariana Islands',
123
+ 'OH' => 'Ohio',
124
+ 'OK' => 'Oklahoma',
125
+ 'OR' => 'Oregon',
126
+ 'PW' => 'Palau',
127
+ 'PA' => 'Pennsylvania',
128
+ 'PR' => 'Puerto Rico',
129
+ 'RI' => 'Rhode Island',
130
+ 'SC' => 'South Carolina',
131
+ 'SD' => 'South Dakota',
132
+ 'TN' => 'Tennessee',
133
+ 'TX' => 'Texas',
134
+ 'UT' => 'Utah',
135
+ 'VT' => 'Vermont',
136
+ 'VI' => 'Virgin Islands',
137
+ 'VA' => 'Virginia',
138
+ 'WA' => 'Washington',
139
+ 'WV' => 'West Virginia',
140
+ 'WI' => 'Wisconsin',
141
+ 'WY' => 'Wyoming'
142
+ }
143
+
144
+
66
145
  def create_signature(fields, secret)
67
146
  data = fields.join('.')
68
147
  digest = Digest::SHA1.hexdigest(data)
@@ -96,11 +175,51 @@ module OffsitePayments #:nodoc:
96
175
  [extract_digits(params[:zip]), extract_digits(params[:address1])].join('|')
97
176
  end
98
177
 
178
+ def extract_address_match_indicator(value)
179
+ value ? 'TRUE' : 'FALSE'
180
+ end
181
+
182
+ # The home phone number provided by the Cardholder. Should be In format:
183
+ # of 'CountryCallingCode|Number' for example, '1|123456789'.
184
+ def format_phone_number(phone_number)
185
+ return nil if phone_number.nil?
186
+
187
+ clean_number = phone_number.gsub(/\D/, '')
188
+
189
+ return phone_number if clean_number.length < 10
190
+
191
+ country_code = clean_number[0, clean_number.length - 9]
192
+ number = clean_number[clean_number.length - 9, clean_number.length]
193
+
194
+ "#{country_code}|#{number}"
195
+ end
196
+
197
+ def lookup_state_code(country_code, state)
198
+ case country_code
199
+ when 'CA'
200
+ state_code = CANADIAN_STATES.find { |code, state_name| state_name.downcase == state.downcase}
201
+ state_code ? state_code.first : state
202
+ when 'US'
203
+ state_code = US_STATES.find { |code, state_name| state_name.downcase == state.downcase}
204
+ state_code ? state_code.first : state
205
+ end
206
+ end
207
+
208
+ # if HPP_ADDRESS_MATCH_INDICATOR is set to TRUE
209
+ # HPP requires the shipping address to be sent from the billing address
210
+ def copy_billing_address
211
+ @fields.select { |k, _| k.start_with? 'HPP_BILLING_' }
212
+ .each do |k, v|
213
+ add_field("HPP_SHIPPING_#{k.split('HPP_BILLING_')[1]}", v)
214
+ end
215
+ end
99
216
  end
100
217
 
101
218
  class Helper < OffsitePayments::Helper
102
219
  include Common
103
220
 
221
+ self.country_format = :numeric
222
+
104
223
  def initialize(order, account, options = {})
105
224
  @timestamp = Time.now.strftime('%Y%m%d%H%M%S')
106
225
  @currency = options[:currency]
@@ -115,11 +234,13 @@ module OffsitePayments #:nodoc:
115
234
  add_field 'AUTO_SETTLE_FLAG', '1'
116
235
  add_field 'RETURN_TSS', '1'
117
236
  add_field 'TIMESTAMP', @timestamp
237
+ add_field 'HPP_VERSION', '2'
118
238
  # Realex does not send back CURRENCY param in response
119
239
  # however it does echo any other param so we send it twice.
120
240
  add_field 'X-CURRENCY', @currency
121
241
  add_field 'X-TEST', @test.to_s
122
242
  add_field 'ORDER_ID', "#{order}#{@timestamp.to_i}"
243
+ add_field 'COMMENT1', application_id
123
244
  end
124
245
 
125
246
  def form_fields
@@ -131,13 +252,59 @@ module OffsitePayments #:nodoc:
131
252
  end
132
253
 
133
254
  def billing_address(params={})
255
+ country = params[:country]
256
+ country_code = lookup_country_code(country, :alpha2)
257
+ super
258
+
134
259
  add_field(mappings[:billing_address][:zip], extract_avs_code(params))
135
- add_field(mappings[:billing_address][:country], lookup_country_code(params[:country]))
260
+ add_field(mappings[:billing_address][:country], lookup_country_code(country))
261
+
262
+ if ['US', 'CA'].include?(country_code) && params[:state].length > 2
263
+ add_field(mappings[:billing_address][:state], lookup_state_code(country_code, params[:state]))
264
+ end
136
265
  end
137
266
 
138
267
  def shipping_address(params={})
268
+ country = params[:country]
269
+ country_code = lookup_country_code(country, :alpha2)
270
+ super
271
+
139
272
  add_field(mappings[:shipping_address][:zip], extract_avs_code(params))
140
273
  add_field(mappings[:shipping_address][:country], lookup_country_code(params[:country]))
274
+
275
+ if ['US', 'CA'].include?(country_code) && params[:state].length > 2
276
+ add_field(mappings[:shipping_address][:state], lookup_state_code(country_code, params[:state]))
277
+ end
278
+ end
279
+
280
+ def customer(params={})
281
+ super
282
+ add_field(mappings[:customer][:phone], format_phone_number(params[:phone]))
283
+ end
284
+
285
+ def addresses_match(address_match = nil)
286
+ return if address_match.nil?
287
+
288
+ add_field(
289
+ mappings[:addresses_match],
290
+ extract_address_match_indicator(address_match)
291
+ )
292
+
293
+ copy_billing_address if address_match
294
+ end
295
+
296
+ def comment(comment = nil)
297
+ add_field(mappings[:comment], comment)
298
+ end
299
+
300
+ # HPP does not want shipping address and HPP_ADDRESS_MATCH_INDICATOR to be sent
301
+ # if the product does not require shipping
302
+ def require_shipping(require_shipping = nil)
303
+ return unless require_shipping == false
304
+
305
+ @fields.delete_if do |k, _|
306
+ k.start_with?('HPP_SHIPPING_') || k == 'HPP_ADDRESS_MATCH_INDICATOR'
307
+ end
141
308
  end
142
309
 
143
310
  def sign_fields
@@ -161,13 +328,29 @@ module OffsitePayments #:nodoc:
161
328
  mapping :notify_url, 'MERCHANT_RESPONSE_URL'
162
329
  mapping :return_url, 'MERCHANT_RETURN_URL'
163
330
 
164
- # Realex Optional fields
165
- mapping :customer, :email => 'CUST_NUM'
166
331
 
167
- mapping :shipping_address, :zip => 'SHIPPING_CODE',
168
- :country => 'SHIPPING_CO'
169
- mapping :billing_address, :zip => 'BILLING_CODE',
170
- :country => 'BILLING_CO'
332
+ # Realex Optional fields
333
+ mapping :customer, :email => 'HPP_CUSTOMER_EMAIL',
334
+ :phone => 'HPP_CUSTOMER_PHONENUMBER_MOBILE'
335
+
336
+ mapping :shipping_address, :zip => 'HPP_SHIPPING_POSTALCODE',
337
+ :country => 'HPP_SHIPPING_COUNTRY',
338
+ :address1 => 'HPP_SHIPPING_STREET1',
339
+ :address2 => 'HPP_SHIPPING_STREET2',
340
+ :address3 => 'HPP_SHIPPING_STREET3',
341
+ :city => 'HPP_SHIPPING_CITY',
342
+ :state => 'HPP_SHIPPING_STATE'
343
+
344
+ mapping :billing_address, :zip => 'HPP_BILLING_POSTALCODE',
345
+ :country => 'HPP_BILLING_COUNTRY',
346
+ :address1 => 'HPP_BILLING_STREET1',
347
+ :address2 => 'HPP_BILLING_STREET2',
348
+ :address3 => 'HPP_BILLING_STREET3',
349
+ :city => 'HPP_BILLING_CITY',
350
+ :state => 'HPP_BILLING_STATE'
351
+
352
+ mapping :addresses_match, 'HPP_ADDRESS_MATCH_INDICATOR'
353
+ mapping :comment, 'COMMENT2'
171
354
  end
172
355
 
173
356
  class Notification < OffsitePayments::Notification
@@ -1,3 +1,3 @@
1
1
  module OffsitePayments
2
- VERSION = "2.7.20"
2
+ VERSION = "2.7.21"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: offsite_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.20
4
+ version: 2.7.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-16 00:00:00.000000000 Z
11
+ date: 2019-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport