pay_simple 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +35 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +100 -0
  8. data/Rakefile +1 -0
  9. data/lib/ps.rb +32 -0
  10. data/lib/ps/api.rb +80 -0
  11. data/lib/ps/api/json.rb +78 -0
  12. data/lib/ps/base.rb +22 -0
  13. data/lib/ps/enumerations.rb +191 -0
  14. data/lib/ps/exceptions.rb +5 -0
  15. data/lib/ps/object.rb +48 -0
  16. data/lib/ps/objects/ach_account.rb +34 -0
  17. data/lib/ps/objects/credit_card_account.rb +38 -0
  18. data/lib/ps/objects/customer.rb +79 -0
  19. data/lib/ps/objects/customer_account.rb +25 -0
  20. data/lib/ps/objects/payment.rb +73 -0
  21. data/lib/ps/objects/payment_status_filter.rb +6 -0
  22. data/lib/ps/objects/recurring_payment.rb +60 -0
  23. data/lib/ps/objects/recurring_payment_filter.rb +26 -0
  24. data/lib/ps/objects/user.rb +10 -0
  25. data/lib/ps/response.rb +83 -0
  26. data/lib/ps/util.rb +28 -0
  27. data/lib/ps/util/hash.rb +17 -0
  28. data/lib/ps/util/state.rb +15 -0
  29. data/lib/ps/util/states.yml +263 -0
  30. data/lib/ps/util/string.rb +15 -0
  31. data/paysimple.gemspec +19 -0
  32. data/spec/config.yml.example +13 -0
  33. data/spec/factories/ach_account.rb +11 -0
  34. data/spec/factories/credit_card_accounts.rb +11 -0
  35. data/spec/factories/customer_accounts.rb +7 -0
  36. data/spec/factories/customers.rb +18 -0
  37. data/spec/factories/payment.rb +12 -0
  38. data/spec/factories/recurring_payment.rb +25 -0
  39. data/spec/ps/api/json_spec.rb +12 -0
  40. data/spec/ps/api_spec.rb +53 -0
  41. data/spec/ps/base_spec.rb +40 -0
  42. data/spec/ps/format_spec.rb +16 -0
  43. data/spec/ps/object_spec.rb +35 -0
  44. data/spec/ps/objects/ach_account_spec.rb +57 -0
  45. data/spec/ps/objects/credit_card_account_spec.rb +69 -0
  46. data/spec/ps/objects/customer_account_spec.rb +43 -0
  47. data/spec/ps/objects/customer_spec.rb +153 -0
  48. data/spec/ps/objects/payment_spec.rb +98 -0
  49. data/spec/ps/objects/recurring_payment_spec.rb +145 -0
  50. data/spec/ps/objects/user_spec.rb +14 -0
  51. data/spec/ps/response_spec.rb +39 -0
  52. data/spec/ps/util/hash_spec.rb +33 -0
  53. data/spec/ps/util/states_spec.rb +25 -0
  54. data/spec/ps/util/string_spec.rb +21 -0
  55. data/spec/ps/util_spec.rb +30 -0
  56. data/spec/spec_functions.rb +155 -0
  57. data/spec/spec_helper.rb +22 -0
  58. metadata +156 -0
data/lib/ps/util.rb ADDED
@@ -0,0 +1,28 @@
1
+ module PS
2
+ module Util
3
+ ##
4
+ # objects contained within PS::Response.ps_object have a '__type' attribute
5
+ # that signals the subclass of PS::Object they represent. This constant
6
+ # provides access to what class needs to be instantiated relative to what
7
+ # paysimple return.
8
+ PS_OBJECTS = {
9
+ "PsCustomer" => PS::Customer,
10
+ "PsCustomerAccount" => PS::CustomerAccount,
11
+ "PsCreditCardAccount" => PS::CreditCardAccount,
12
+ "PsAchAccount" => PS::AchAccount,
13
+ "PsPayment" => PS::Payment,
14
+ "PsDefaultCustomerAccount" => PS::CustomerAccount,
15
+ "PsRecurringPayment" => PS::RecurringPayment
16
+ }
17
+
18
+ def self.instantiate_ps_objects(ps_objects)
19
+ case ps_objects
20
+ when Array
21
+ ps_objects.map { |obj| instantiate_ps_objects(obj) }
22
+ when Hash
23
+ klass_name = ps_objects.delete("__type").scan(/[a-zA-Z]+:/)[0].delete(":")
24
+ PS_OBJECTS[klass_name].new(ps_objects.symbolize_keys)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ class Hash
2
+ def camel_case_keys
3
+ camel_case_hash = {}
4
+ self.each do |key, value|
5
+ camel_case_hash[key.to_s.to_camel_case] = value
6
+ end
7
+ self.replace(camel_case_hash)
8
+ end
9
+
10
+ def snake_case_keys
11
+ snake_case_hash = {}
12
+ self.each do |key, value|
13
+ snake_case_hash[key.to_s.to_snake_case] = value
14
+ end
15
+ self.replace(snake_case_hash)
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module PS
2
+ module State
3
+ class << self
4
+ YAML.load_file(File.dirname(__FILE__)+"/states.yml").each do |k,state|
5
+ define_method state["abbreviation"].downcase.to_s do
6
+ PS::States.const_get("#{state["abbreviation"].upcase}")
7
+ end
8
+
9
+ define_method state["name"].gsub(/ /, '_').downcase do
10
+ PS::States.const_get("#{state["abbreviation"].upcase}")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,263 @@
1
+ AK:
2
+ name: Alaska
3
+ abbreviation: AK
4
+
5
+ AL:
6
+ name: Alabama
7
+ abbreviation: AL
8
+
9
+ AS:
10
+ name: American Samoa
11
+ abbreviation: AS
12
+
13
+ AZ:
14
+ name: Arizona
15
+ abbreviation: AZ
16
+
17
+ AR:
18
+ name: Arkansas
19
+ abbreviation: AR
20
+
21
+ CA:
22
+ name: California
23
+ abbreviation: CA
24
+
25
+ CO:
26
+ name: Colorado
27
+ abbreviation: CO
28
+
29
+ CT:
30
+ name: Connecticut
31
+ abbreviation: CT
32
+
33
+ DE:
34
+ name: Delaware
35
+ abbreviation: DE
36
+
37
+ DC:
38
+ name: District of Columbia
39
+ abbreviation: DC
40
+
41
+ FM:
42
+ name: Federated States of Micronesia
43
+ abbreviation: FM
44
+
45
+ FL:
46
+ name: Florida
47
+ abbreviation: FL
48
+
49
+ GA:
50
+ name: Georgia
51
+ abbreviation: GA
52
+
53
+ GU:
54
+ name: Guam
55
+ abbreviation: GU
56
+
57
+ HI:
58
+ name: Hawaii
59
+ abbreviation: HI
60
+
61
+ ID:
62
+ name: Idaho
63
+ abbreviation: ID
64
+
65
+ IL:
66
+ name: Illinois
67
+ abbreviation: IL
68
+
69
+ IN:
70
+ name: Indiana
71
+ abbreviation: IN
72
+
73
+ IA:
74
+ name: Iowa
75
+ abbreviation: IA
76
+
77
+ KS:
78
+ name: Kansas
79
+ abbreviation: KS
80
+
81
+ KY:
82
+ name: Kentucky
83
+ abbreviation: KY
84
+
85
+ LA:
86
+ name: Louisiana
87
+ abbreviation: LA
88
+
89
+ ME:
90
+ name: Maine
91
+ abbreviation: ME
92
+
93
+ MH:
94
+ name: Marshall Islands
95
+ abbreviation: MH
96
+
97
+ MD:
98
+ name: Maryland
99
+ abbreviation: MD
100
+
101
+ MA:
102
+ name: Massachusetts
103
+ abbreviation: MA
104
+
105
+ MI:
106
+ name: Michigan
107
+ abbreviation: MI
108
+
109
+ MN:
110
+ name: Minnesota
111
+ abbreviation: MN
112
+
113
+ MS:
114
+ name: Mississippi
115
+ abbreviation: MS
116
+
117
+ MO:
118
+ name: Missouri
119
+ abbreviation: MO
120
+
121
+ MT:
122
+ name: Montana
123
+ abbreviation: MT
124
+
125
+ NE:
126
+ name: Nebraska
127
+ abbreviation: NE
128
+
129
+ NV:
130
+ name: Nevada
131
+ abbreviation: NV
132
+
133
+ NH:
134
+ name: New Hampshire
135
+ abbreviation: NH
136
+
137
+ NJ:
138
+ name: New Jersey
139
+ abbreviation: NJ
140
+
141
+ NM:
142
+ name: New Mexico
143
+ abbreviation: NM
144
+
145
+ NY:
146
+ name: New York
147
+ abbreviation: NY
148
+
149
+ NC:
150
+ name: North Carolina
151
+ abbreviation: NC
152
+
153
+ ND:
154
+ name: North Dakota
155
+ abbreviation: ND
156
+
157
+ MP:
158
+ name: Northern Mariana Islands
159
+ abbreviation: MP
160
+
161
+ OH:
162
+ name: Ohio
163
+ abbreviation: OH
164
+
165
+ OK:
166
+ name: Oklahoma
167
+ abbreviation: OK
168
+
169
+ OR:
170
+ name: Oregon
171
+ abbreviation: OR
172
+
173
+ PW:
174
+ name: Palau
175
+ abbreviation: PW
176
+
177
+ PA:
178
+ name: Pennsylvania
179
+ abbreviation: PA
180
+
181
+ PR:
182
+ name: Puerto Rico
183
+ abbreviation: PR
184
+
185
+ RI:
186
+ name: Rhode Island
187
+ abbreviation: RI
188
+
189
+ SC:
190
+ name: South Carolina
191
+ abbreviation: SC
192
+
193
+ SD:
194
+ name: South Dakota
195
+ abbreviation: SD
196
+
197
+ TN:
198
+ name: Tennessee
199
+ abbreviation: TN
200
+
201
+ TX:
202
+ name: Texas
203
+ abbreviation: TX
204
+
205
+ UT:
206
+ name: Utah
207
+ abbreviation: UT
208
+
209
+ VT:
210
+ name: Vermont
211
+ abbreviation: VT
212
+
213
+ VI:
214
+ name: Virgin Islands
215
+ abbreviation: VI
216
+
217
+ VA:
218
+ name: Virginia
219
+ abbreviation: VA
220
+
221
+ WA:
222
+ name: Washington
223
+ abbreviation: WA
224
+
225
+ WV:
226
+ name: West Virginia
227
+ abbreviation: WV
228
+
229
+ WI:
230
+ name: Wisconsin
231
+ abbreviation: WI
232
+
233
+ WY:
234
+ name: Wyoming
235
+ abbreviation: WY
236
+
237
+ AE:
238
+ name: Armed Forces Africa
239
+ abbreviation: AE
240
+
241
+ AA:
242
+ name: Armed Forces Americas (except Canada)
243
+ abbreviation: AA
244
+
245
+ AE:
246
+ name: Armed Forces Canada
247
+ abbreviation: AE
248
+
249
+ AE:
250
+ name: Armed Forces Europe
251
+ abbreviation: AE
252
+
253
+ AE:
254
+ name: Armed Forces Middle East
255
+ abbreviation: AE
256
+
257
+ AP:
258
+ name: Armed Forces Pacific
259
+ abbreviation: AP
260
+
261
+ OTHER:
262
+ name: Other
263
+ abbreviation: Other
@@ -0,0 +1,15 @@
1
+ class String
2
+ def to_snake_case
3
+ gsub(/::/, '/')
4
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
5
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
6
+ .tr("-", "_")
7
+ .downcase
8
+ end
9
+
10
+ def to_camel_case
11
+ split("_")
12
+ .map(&:capitalize)
13
+ .join
14
+ end
15
+ end
data/paysimple.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |s|
3
+ s.name = 'pay_simple'
4
+ s.version = '0.0.1'
5
+ s.date = '2013-11-13'
6
+ s.summary = "Multiformat paysimple api integration"
7
+ s.description = ""
8
+ s.author = [ "Kyle Carter", "Kevin Collette" ]
9
+ s.email = [ 'seijounai@gmail.com', "kevcollette@gmail.com" ]
10
+ s.homepage = 'http://github.com/CTA/PSJ'
11
+ s.files = `git ls-files`.split($/)
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+ s.require_paths = ["lib"]
16
+ s.license = "MIT"
17
+ s.add_dependency('httparty')
18
+ s.add_dependency('json')
19
+ end
@@ -0,0 +1,13 @@
1
+ ---
2
+ :development:
3
+ :apikey: ""
4
+ :userkey: ""
5
+ :env: "development"
6
+ :format: "json"
7
+ :company_name: ""
8
+ :production:
9
+ :apikey: ""
10
+ :userkey: ""
11
+ :company_name: ""
12
+ :env: "production"
13
+ :format: "json"
@@ -0,0 +1,11 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :ach_account, class: PS::AchAccount do
5
+ is_checking_account true
6
+ routing_number "307075259"
7
+ account_number "751111111"
8
+ bank_name "Simply Bank"
9
+ customer_id 0
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :credit_card_account, :class => PS::CreditCardAccount do
5
+ customer_id 0
6
+ #ps_reference_id please derive
7
+ account_number "4111111111111111"
8
+ c_c_expiry "12/2015"
9
+ c_c_type CreditCardIssuer::VISA
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :customer_account, :class => PS::CustomerAccount do
5
+ customer_id 0
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :customer, class: PS::Customer do
5
+ first_name "test"
6
+ middle_name "e"
7
+ last_name "name"
8
+ email "example@test.com"
9
+ phone "0000000000"
10
+ billing_address1 "1600 Pennslyvania Ave NW"
11
+ billing_city "Seattle"
12
+ billing_state 8
13
+ billing_postal_code 20500
14
+ billing_country_code "USA"
15
+ shipping_same_as_billing 1
16
+ company_name "USA"
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :payment, class: PS::Payment do
5
+ customer_id 0
6
+ customer_account_id 0
7
+ amount 199.99
8
+ payment_date Time.now
9
+ is_debit true
10
+ recurring_schedule_id 0
11
+ end
12
+ end