Module: Cybersourcery::PaymentsHelper

Defined in:
lib/cybersourcery/payments_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_expiry_date_fields(form, classes = 'select required form-control card-expiry') ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cybersourcery/payments_helper.rb', line 68

def add_expiry_date_fields(form, classes = 'select required form-control card-expiry')
  date_fields =  hidden_input form, :card_expiry_date
  date_fields << form.input(:card_expiry_dummy, label: field_label(:card_expiry_dummy)) do
    form.date_select(:card_expiry_dummy,
      {
        discard_day: true,
        order: [:month, :year],
        start_year: Date.today.year,
        end_year:  (Date.today.year + 19),
        use_two_digit_numbers: true,
        date_separator: ' / ',
        prompt: true
      },
      { class: classes }
    )
  end
end

#add_signed_fields(payment, form) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/cybersourcery/payments_helper.rb', line 3

def add_signed_fields(payment, form)
  signed_fields = ''

  payment.signed_fields.each do |field, value|
    signed_fields << hidden_input(form, field, value)
  end

  signed_fields
end

#card_typesObject



395
396
397
398
399
400
401
402
# File 'lib/cybersourcery/payments_helper.rb', line 395

def card_types
  {
    'Visa' => '001',
    'MasterCard' => '002',
    'American Express' => '003',
    'Discover' => '004'
  }
end

#countriesObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/cybersourcery/payments_helper.rb', line 86

def countries
  {
    "Afghanistan" => "AF",
    "Aland Islands" => "AX",
    "Albania" => "AL",
    "Algeria" => "DZ",
    "American Samoa (US)" => "AS",
    "Andorra" => "AD",
    "Angola" => "AO",
    "Anguilla (UK)" => "AI",
    "Antarctica" => "AQ",
    "Antigua and Barbuda" => "AG",
    "Argentina" => "AR",
    "Armenia" => "AM",
    "Aruba" => "AW",
    "Australia" => "AU",
    "Austria" => "AT",
    "Azerbaijan" => "AZ",
    "Bahamas" => "BS",
    "Bahrain" => "BH",
    "Bangladesh" => "BD",
    "Barbados" => "BB",
    "Belarus" => "BY",
    "Belgium" => "BE",
    "Belize" => "BZ",
    "Benin" => "BJ",
    "Bermuda (UK)" => "BM",
    "Bhutan" => "BT",
    "Bolivia" => "BO",
    "Bonaire, Sint Eustatius and Saba" => "BQ",
    "Bosnia and Herzegovina" => "BA",
    "Botswana" => "BW",
    "Brazil" => "BR",
    "British Indian Ocean Territory" => "IO",
    "British Virgin Islands (UK)" => "VG",
    "Brunei Darussalam" => "BN",
    "Bulgaria" => "BG",
    "Burkina Faso" => "BF",
    "Burundi" => "BI",
    "Cambodia" => "KH",
    "Cameroon" => "CM",
    "Canada" => "CA",
    "Cape Verde" => "CV",
    "Cayman Islands (UK)" => "KY",
    "Central African Republic" => "CF",
    "Chad" => "TD",
    "Chile" => "CL",
    "China" => "CN",
    "Christmas Island (AU)" => "CX",
    "Cocos (Keeling) Islands (AU)" => "CC",
    "Colombia" => "CO",
    "Comoros" => "KM",
    "Congo, Democratic Republic of the" => "CD",
    "Congo, Republic of the" => "CG",
    "Cook Islands (NZ)" => "CK",
    "Costa Rica" => "CR",
    "Côte D'Ivoire" => "CI",
    "Croatia" => "HR",
    "Cuba" => "CU",
    "Curaçao" => "CW",
    "Cyprus" => "CY",
    "Czech Republic" => "CZ",
    "Denmark" => "DK",
    "Djibouti" => "DJ",
    "Dominica" => "DM",
    "Dominican Republic" => "DO",
    "Ecuador" => "EC",
    "Egypt" => "EG",
    "El Salvador" => "SV",
    "Equatorial Guinea" => "GQ",
    "Eritrea" => "ER",
    "Estonia" => "EE",
    "Ethiopia" => "ET",
    "Falkland Islands (UK)" => "FK",
    "Faroe Islands (DK)" => "FO",
    "Fiji" => "FJ",
    "Finland" => "FI",
    "France" => "FR",
    "French Guiana (FR)" => "GF",
    "French Polynesia (FR)" => "PF",
    "French Southern Territories" => "TF",
    "Gabon" => "GA",
    "Gambia" => "GM",
    "Georgia" => "GE",
    "Germany" => "DE",
    "Ghana" => "GH",
    "Gibraltar (UK)" => "GI",
    "Greece" => "GR",
    "Greenland (DK)" => "GL",
    "Grenada" => "GD",
    "Guadeloupe (FR)" => "GP",
    "Guam (US)" => "GU",
    "Guatemala" => "GT",
    "Guernsey" => "GG",
    "Guinea" => "GN",
    "Guinea-Bissau" => "GW",
    "Guyana" => "GY",
    "Haiti" => "HT",
    "Heard Island and McDonald Islands" => "HM",
    "Holy See (Vatican City)" => "VA",
    "Honduras" => "HN",
    "Hong Kong (CN)" => "HK",
    "Hungary" => "HU",
    "Iceland" => "IS",
    "India" => "IN",
    "Indonesia" => "ID",
    "Iran" => "IR",
    "Iraq" => "IQ",
    "Ireland" => "IE",
    "Isle of Man" => "IM",
    "Israel" => "IL",
    "Italy" => "IT",
    "Jamaica" => "JM",
    "Japan" => "JP",
    "Jersey" => "JE",
    "Jordan" => "JO",
    "Kazakhstan" => "KZ",
    "Kenya" => "KE",
    "Kiribati" => "KI",
    "Korea, Democratic People's Republic (North)" => "KP",
    "Korea, Republic of (South)" => "KR",
    "Kuwait" => "KW",
    "Kyrgyzstan" => "KG",
    "Laos" => "LA",
    "Latvia" => "LV",
    "Lebanon" => "LB",
    "Lesotho" => "LS",
    "Liberia" => "LR",
    "Libya" => "LY",
    "Liechtenstein" => "LI",
    "Lithuania" => "LT",
    "Luxembourg" => "LU",
    "Macau (CN)" => "MO",
    "Macedonia" => "MK",
    "Madagascar" => "MG",
    "Malawi" => "MW",
    "Malaysia" => "MY",
    "Maldives" => "MV",
    "Mali" => "ML",
    "Malta" => "MT",
    "Marshall Islands" => "MH",
    "Martinique (FR)" => "MQ",
    "Mauritania" => "MR",
    "Mauritius" => "MU",
    "Mayotte (FR)" => "YT",
    "Mexico" => "MX",
    "Micronesia, Federated States of" => "FM",
    "Moldova Republic of" => "MD",
    "Monaco" => "MC",
    "Mongolia" => "MN",
    "Montenegro" => "ME",
    "Montserrat (UK)" => "MS",
    "Morocco" => "MA",
    "Mozambique" => "MZ",
    "Myanmar" => "MM",
    "Namibia" => "NA",
    "Nauru" => "NR",
    "Nepal" => "NP",
    "Netherlands" => "NL",
    "Netherlands Antilles (NL)" => "AN",
    "New Caledonia (FR)" => "NC",
    "New Zealand" => "NZ",
    "Nicaragua" => "NI",
    "Niger" => "NE",
    "Nigeria" => "NG",
    "Niue" => "NU",
    "Norfolk Island (AU)" => "NF",
    "Northern Mariana Islands (US)" => "MP",
    "Norway" => "NO",
    "Oman" => "OM",
    "Pakistan" => "PK",
    "Palau" => "PW",
    "Palestinian Territories" => "PS",
    "Panama" => "PA",
    "Papua New Guinea" => "PG",
    "Paraguay" => "PY",
    "Peru" => "PE",
    "Philippines" => "PH",
    "Pitcairn Islands (UK)" => "PN",
    "Poland" => "PL",
    "Portugal" => "PT",
    "Puerto Rico (US)" => "PR",
    "Qatar" => "QA",
    "Reunion (FR)" => "RE",
    "Romania" => "RO",
    "Russia" => "RU",
    "Rwanda" => "RW",
    "Saint Barthelemy" => "BL",
    "Saint Helena (UK)" => "SH",
    "Saint Kitts and Nevis" => "KN",
    "Saint Lucia" => "LC",
    "Saint Martin" => "MF",
    "Saint Pierre & Miquelon (FR)" => "PM",
    "Saint Vincent and the Grenadines" => "VC",
    "Samoa" => "WS",
    "San Marino" => "SM",
    "Sao Tome and Principe" => "ST",
    "Saudi Arabia" => "SA",
    "Senegal" => "SN",
    "Serbia" => "RS",
    "Seychelles" => "SC",
    "Sierra Leone" => "SL",
    "Singapore" => "SG",
    "Sint Maarten (Dutch Part)" => "SX",
    "Slovakia" => "SK",
    "Slovenia" => "SI",
    "Solomon Islands" => "SB",
    "Somalia" => "SO",
    "South Africa" => "ZA",
    "South Georgia & South Sandwich Islands (UK)" => "GS",
    "South Sudan" => "SS",
    "Spain" => "ES",
    "Sri Lanka" => "LK",
    "Sudan" => "SD",
    "Suriname" => "SR",
    "Svalbard and Jan Mayen" => "SJ",
    "Swaziland" => "SZ",
    "Sweden" => "SE",
    "Switzerland" => "CH",
    "Syria" => "SY",
    "Taiwan" => "TW",
    "Tajikistan" => "TJ",
    "Tanzania" => "TZ",
    "Thailand" => "TH",
    "Timor-Leste" => "TL",
    "Togo" => "TG",
    "Tokelau" => "TK",
    "Tonga" => "TO",
    "Trinidad and Tobago" => "TT",
    "Tunisia" => "TN",
    "Turkey" => "TR",
    "Turkmenistan" => "TM",
    "Turks and Caicos Islands (UK)" => "TC",
    "Tuvalu" => "TV",
    "Uganda" => "UG",
    "Ukraine" => "UA",
    "United Arab Emirates" => "AE",
    "United Kingdom" => "GB",
    "United States" => "US",
    "United States Minor Outlying Islands" => "UM",
    "Uruguay" => "UY",
    "Uzbekistan" => "UZ",
    "Vanuatu" => "VU",
    "Venezuela" => "VE",
    "Vietnam" => "VN",
    "Virgin Islands (US)" => "VI",
    "Wallis and Futuna (FR)" => "WF",
    "Western Sahara" => "EH",
    "Yemen" => "YE",
    "Zambia" => "ZM",
    "Zimbabwe" => "ZW"
  }
end

#field_label(field) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cybersourcery/payments_helper.rb', line 33

def field_label(field)
  labels = {
    bill_to_forename: 'First Name',
    bill_to_surname: 'Last Name',
    card_number: 'Card Number',
    card_cvn: 'Security Code',
    card_expiry_dummy: 'Expiration',
    bill_to_email: 'Email',
    bill_to_address_line1: 'Street Address (line 1)',
    bill_to_address_line2: 'Street Address (line 2)',
    bill_to_address_city: 'City',
    bill_to_address_state: 'State (Province)',
    bill_to_address_postal_code: 'Zip (Postal Code)'
  }
  labels[field]
end

#field_pattern(field) ⇒ Object



50
51
52
53
54
55
# File 'lib/cybersourcery/payments_helper.rb', line 50

def field_pattern(field)
  patterns = {
    card_number: "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$"
  }
  patterns[field]
end

#field_validation_message(field) ⇒ Object



57
58
59
60
61
62
# File 'lib/cybersourcery/payments_helper.rb', line 57

def field_validation_message(field)
  patterns = {
    card_number: 'Please enter a valid credit card number'
  }
  patterns[field]
end

#hidden_input(form, field, value = nil) ⇒ Object



64
65
66
# File 'lib/cybersourcery/payments_helper.rb', line 64

def hidden_input(form, field, value = nil)
  form.hidden_field field, value: value, name: field.to_s
end

#simple_form_input(form, field, value = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cybersourcery/payments_helper.rb', line 13

def simple_form_input(form, field, value = nil)
  form.input field, label: field_label(field), input_html: {
    name: field.to_s,
    value: value,
    pattern: field_pattern(field),
    title: field_validation_message(field)
  }
end

#simple_form_select(form, field, collection, selected = nil, prompt = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/cybersourcery/payments_helper.rb', line 22

def simple_form_select(form, field, collection, selected = nil, prompt = nil)
  form.input(
    field,
    label: field_label(field),
    collection: collection,
    selected: selected,
    prompt: prompt,
    input_html: { name: field.to_s }
  )
end

#us_statesObject



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/cybersourcery/payments_helper.rb', line 340

def us_states
  {
    "Alabama" => "AL",
    "Alaska" => "AK",
    "Arizona" => "AZ",
    "Arkansas" => "AR",
    "California" => "CA",
    "Colorado" => "CO",
    "Connecticut" => "CT",
    "Delaware" => "DE",
    "Florida" => "FL",
    "Georgia" => "GA",
    "Hawaii" => "HI",
    "Idaho" => "ID",
    "Illinois" => "IL",
    "Indiana" => "IN",
    "Iowa" => "IA",
    "Kansas" => "KS",
    "Kentucky" => "KY",
    "Louisiana" => "LA",
    "Maine" => "ME",
    "Maryland" => "MD",
    "Massachusetts" => "MA",
    "Michigan" => "MI",
    "Minnesota" => "MN",
    "Mississippi" => "MS",
    "Missouri" => "MO",
    "Montana" => "MT",
    "Nebraska" => "NE",
    "Nevada" => "NV",
    "New Hampshire" => "NH",
    "New Jersey" => "NJ",
    "New Mexico" => "NM",
    "New York" => "NY",
    "North Carolina" => "NC",
    "North Dakota" => "ND",
    "Ohio" => "OH",
    "Oklahoma" => "OK",
    "Oregon" => "OR",
    "Pennsylvania" => "PA",
    "Rhode Island" => "RI",
    "South Carolina" => "SC",
    "South Dakota" => "SD",
    "Tennessee" => "TN",
    "Texas" => "TX",
    "Utah" => "UT",
    "Vermont" => "VT",
    "Virginia" => "VA",
    "Washington" => "WA",
    "West Virginia" => "WV",
    "Wisconsin" => "WI",
    "Wyoming" => "WY"
  }
end