conekta 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/CONTRIBUTORS +9 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +57 -0
- data/History.txt +4 -0
- data/LICENSE +23 -0
- data/README.rdoc +22 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/bin/conekta-console +7 -0
- data/conekta.gemspec +27 -0
- data/gemfiles/default-with-activesupport.gemfile +3 -0
- data/gemfiles/json.gemfile +4 -0
- data/gemfiles/yajl.gemfile +4 -0
- data/lib/conekta.rb +292 -0
- data/lib/conekta/account.rb +4 -0
- data/lib/conekta/api_operations/create.rb +16 -0
- data/lib/conekta/api_operations/delete.rb +11 -0
- data/lib/conekta/api_operations/list.rb +16 -0
- data/lib/conekta/api_operations/update.rb +16 -0
- data/lib/conekta/api_resource.rb +33 -0
- data/lib/conekta/charge.rb +43 -0
- data/lib/conekta/conekta_object.rb +158 -0
- data/lib/conekta/errors/api_connection_error.rb +4 -0
- data/lib/conekta/errors/api_error.rb +4 -0
- data/lib/conekta/errors/authentication_error.rb +4 -0
- data/lib/conekta/errors/card_error.rb +11 -0
- data/lib/conekta/errors/conekta_error.rb +20 -0
- data/lib/conekta/errors/malformed_request_error.rb +10 -0
- data/lib/conekta/errors/parameter_validation_error.rb +10 -0
- data/lib/conekta/errors/resource_not_found_error.rb +10 -0
- data/lib/conekta/event.rb +5 -0
- data/lib/conekta/json.rb +21 -0
- data/lib/conekta/list_object.rb +35 -0
- data/lib/conekta/log.rb +5 -0
- data/lib/conekta/singleton_api_resource.rb +20 -0
- data/lib/conekta/util.rb +99 -0
- data/lib/conekta/version.rb +3 -0
- data/lib/data/ca-certificates.crt +3918 -0
- data/spec/conekta_spec.rb +743 -0
- data/spec/conekta_with_active_support_spec.rb +3 -0
- data/spec/test_helper.rb +302 -0
- metadata +177 -0
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'conekta'
|
4
|
+
require 'mocha/setup'
|
5
|
+
include Mocha
|
6
|
+
|
7
|
+
#monkeypatch request methods
|
8
|
+
module Conekta
|
9
|
+
@mock_rest_client = nil
|
10
|
+
|
11
|
+
def self.mock_rest_client=(mock_client)
|
12
|
+
@mock_rest_client = mock_client
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.execute_request(opts)
|
16
|
+
get_params = (opts[:headers] || {})[:params]
|
17
|
+
post_params = opts[:payload]
|
18
|
+
case opts[:method]
|
19
|
+
when :get then @mock_rest_client.get opts[:url], get_params, post_params
|
20
|
+
when :post then @mock_rest_client.post opts[:url], get_params, post_params
|
21
|
+
when :delete then @mock_rest_client.delete opts[:url], get_params, post_params
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_response(body, code=200)
|
27
|
+
# When an exception is raised, restclient clobbers method_missing. Hence we
|
28
|
+
# can't just use the stubs interface.
|
29
|
+
body = MultiJson.dump(body) if !(body.kind_of? String)
|
30
|
+
m = double
|
31
|
+
m.instance_variable_set('@conekta_values', { :body => body, :code => code })
|
32
|
+
def m.body; @conekta_values[:body]; end
|
33
|
+
def m.code; @conekta_values[:code]; end
|
34
|
+
m
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_customer(params={})
|
38
|
+
{
|
39
|
+
:subscription_history => [],
|
40
|
+
:bills => [],
|
41
|
+
:charges => [],
|
42
|
+
:livemode => false,
|
43
|
+
:object => "customer",
|
44
|
+
:id => "c_test_customer",
|
45
|
+
:default_card => "cc_test_card",
|
46
|
+
:created => 1304114758,
|
47
|
+
:cards => test_card_array('c_test_customer')
|
48
|
+
}.merge(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_customer_array
|
52
|
+
{
|
53
|
+
:data => [test_customer, test_customer, test_customer],
|
54
|
+
:object => 'list',
|
55
|
+
:url => '/customers'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_charge(params={})
|
60
|
+
{
|
61
|
+
:refunded => false,
|
62
|
+
:paid => true,
|
63
|
+
:amount => 100,
|
64
|
+
:card => {
|
65
|
+
:type => "Visa",
|
66
|
+
:last4 => "4242",
|
67
|
+
:exp_month => 11,
|
68
|
+
:country => "US",
|
69
|
+
:exp_year => 2012,
|
70
|
+
:id => "cc_test_card",
|
71
|
+
:object => "card"
|
72
|
+
},
|
73
|
+
:id => "ch_test_charge",
|
74
|
+
:reason => "execute_charge",
|
75
|
+
:livemode => false,
|
76
|
+
:currency => "usd",
|
77
|
+
:object => "charge",
|
78
|
+
:created => 1304114826
|
79
|
+
}.merge(params)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_charge_array_filtered
|
83
|
+
{
|
84
|
+
:data => [test_charge, test_charge, test_charge],
|
85
|
+
:object => 'list',
|
86
|
+
:url => '/charges.json?amount=500'
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_charge_array
|
91
|
+
{
|
92
|
+
:data => [test_charge, test_charge, test_charge],
|
93
|
+
:object => 'list',
|
94
|
+
:url => '/charges'
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_card_array(customer_id)
|
99
|
+
{
|
100
|
+
:data => [test_card, test_card, test_card],
|
101
|
+
:object => 'list',
|
102
|
+
:url => '/customers/' + customer_id + '/cards'
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_card(params={})
|
107
|
+
{
|
108
|
+
:type => "Visa",
|
109
|
+
:last4 => "4242",
|
110
|
+
:exp_month => 11,
|
111
|
+
:country => "US",
|
112
|
+
:exp_year => 2012,
|
113
|
+
:id => "cc_test_card",
|
114
|
+
:customer => 'c_test_customer',
|
115
|
+
:object => "card"
|
116
|
+
}.merge(params)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_coupon(params={})
|
120
|
+
{
|
121
|
+
:duration => 'repeating',
|
122
|
+
:duration_in_months => 3,
|
123
|
+
:percent_off => 25,
|
124
|
+
:id => "co_test_coupon",
|
125
|
+
:object => "coupon"
|
126
|
+
}.merge(params)
|
127
|
+
end
|
128
|
+
|
129
|
+
#FIXME nested overrides would be better than hardcoding plan_id
|
130
|
+
def test_subscription(plan_id="gold")
|
131
|
+
{
|
132
|
+
:current_period_end => 1308681468,
|
133
|
+
:status => "trialing",
|
134
|
+
:plan => {
|
135
|
+
:interval => "month",
|
136
|
+
:amount => 7500,
|
137
|
+
:trial_period_days => 30,
|
138
|
+
:object => "plan",
|
139
|
+
:identifier => plan_id
|
140
|
+
},
|
141
|
+
:current_period_start => 1308595038,
|
142
|
+
:start => 1308595038,
|
143
|
+
:object => "subscription",
|
144
|
+
:trial_start => 1308595038,
|
145
|
+
:trial_end => 1308681468,
|
146
|
+
:customer => "c_test_customer"
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_invoice
|
151
|
+
{
|
152
|
+
:id => 'in_test_invoice',
|
153
|
+
:object => 'invoice',
|
154
|
+
:livemode => false,
|
155
|
+
:amount_due => 1000,
|
156
|
+
:attempt_count => 0,
|
157
|
+
:attempted => false,
|
158
|
+
:closed => false,
|
159
|
+
:currency => 'usd',
|
160
|
+
:customer => 'c_test_customer',
|
161
|
+
:date => 1349738950,
|
162
|
+
:lines => {
|
163
|
+
"invoiceitems" => [
|
164
|
+
{
|
165
|
+
:id => 'ii_test_invoice_item',
|
166
|
+
:object => '',
|
167
|
+
:livemode => false,
|
168
|
+
:amount => 1000,
|
169
|
+
:currency => 'usd',
|
170
|
+
:customer => 'c_test_customer',
|
171
|
+
:date => 1349738950,
|
172
|
+
:description => "A Test Invoice Item",
|
173
|
+
:invoice => 'in_test_invoice'
|
174
|
+
},
|
175
|
+
],
|
176
|
+
},
|
177
|
+
:paid => false,
|
178
|
+
:period_end => 1349738950,
|
179
|
+
:period_start => 1349738950,
|
180
|
+
:starting_balance => 0,
|
181
|
+
:subtotal => 1000,
|
182
|
+
:total => 1000,
|
183
|
+
:charge => nil,
|
184
|
+
:discount => nil,
|
185
|
+
:ending_balance => nil,
|
186
|
+
:next_payemnt_attempt => 1349825350,
|
187
|
+
}
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_paid_invoice
|
191
|
+
test_invoice.merge({
|
192
|
+
:attempt_count => 1,
|
193
|
+
:attempted => true,
|
194
|
+
:closed => true,
|
195
|
+
:paid => true,
|
196
|
+
:charge => 'ch_test_charge',
|
197
|
+
:ending_balance => 0,
|
198
|
+
:next_payment_attempt => nil,
|
199
|
+
})
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_invoice_customer_array
|
203
|
+
{
|
204
|
+
:data => [test_invoice],
|
205
|
+
:object => 'list',
|
206
|
+
:url => '/invoices?customer=test_customer'
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_recipient(params={})
|
211
|
+
{
|
212
|
+
:name => "Conekta User",
|
213
|
+
:type => "individual",
|
214
|
+
:livemode => false,
|
215
|
+
:object => "recipient",
|
216
|
+
:id => "rp_test_recipient",
|
217
|
+
:active_account => {
|
218
|
+
:last4 => "6789",
|
219
|
+
:bank_name => "STRIPE TEST BANK",
|
220
|
+
:country => "US",
|
221
|
+
:object => "bank_account"
|
222
|
+
},
|
223
|
+
:created => 1304114758,
|
224
|
+
:verified => true
|
225
|
+
}.merge(params)
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_recipient_array
|
229
|
+
{
|
230
|
+
:data => [test_recipient, test_recipient, test_recipient],
|
231
|
+
:object => 'list',
|
232
|
+
:url => '/recipients'
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_transfer(params={})
|
237
|
+
{
|
238
|
+
:status => 'pending',
|
239
|
+
:amount => 100,
|
240
|
+
:account => {
|
241
|
+
:object => 'bank_account',
|
242
|
+
:country => 'US',
|
243
|
+
:bank_name => 'STRIPE TEST BANK',
|
244
|
+
:last4 => '6789'
|
245
|
+
},
|
246
|
+
:recipient => 'test_recipient',
|
247
|
+
:fee => 0,
|
248
|
+
:fee_details => [],
|
249
|
+
:id => "tr_test_transfer",
|
250
|
+
:livemode => false,
|
251
|
+
:currency => "usd",
|
252
|
+
:object => "transfer",
|
253
|
+
:date => 1304114826
|
254
|
+
}.merge(params)
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_transfer_array
|
258
|
+
{
|
259
|
+
:data => [test_transfer, test_transfer, test_transfer],
|
260
|
+
:object => 'list',
|
261
|
+
:url => '/transfers'
|
262
|
+
}
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_invalid_api_key_error
|
266
|
+
{
|
267
|
+
"error" => {
|
268
|
+
"type" => "invalid_request_error",
|
269
|
+
"message" => "Invalid API Key provided: invalid"
|
270
|
+
}
|
271
|
+
}
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_invalid_exp_year_error
|
275
|
+
{
|
276
|
+
"code" => "invalid_expiry_year",
|
277
|
+
"param" => "exp_year",
|
278
|
+
"type" => "card_error",
|
279
|
+
"message" => "Your card's expiration year is invalid"
|
280
|
+
}
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_missing_id_error
|
284
|
+
{
|
285
|
+
:param => "id",
|
286
|
+
:type => "parameter_validation_error",
|
287
|
+
:message => "Invalid id value"
|
288
|
+
}
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_api_error
|
292
|
+
{
|
293
|
+
:type => "api_error"
|
294
|
+
}
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_delete_discount_response
|
298
|
+
{
|
299
|
+
:deleted => true,
|
300
|
+
:id => "di_test_coupon"
|
301
|
+
}
|
302
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conekta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leo Fischer
|
9
|
+
- Mauricio Murga
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.4'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.4'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: multi_json
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.0.4
|
39
|
+
- - <
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2'
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.0.4
|
50
|
+
- - <
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: shoulda
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.4.0
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rake
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
description: Easy payments and shipping, see http://conekta.mx for details.
|
102
|
+
email:
|
103
|
+
- leo@conekta.mx
|
104
|
+
- mauricio@conekta.com
|
105
|
+
executables:
|
106
|
+
- conekta-console
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- .gitignore
|
111
|
+
- CONTRIBUTORS
|
112
|
+
- Gemfile
|
113
|
+
- Gemfile.lock
|
114
|
+
- History.txt
|
115
|
+
- LICENSE
|
116
|
+
- README.rdoc
|
117
|
+
- Rakefile
|
118
|
+
- VERSION
|
119
|
+
- bin/conekta-console
|
120
|
+
- conekta.gemspec
|
121
|
+
- gemfiles/default-with-activesupport.gemfile
|
122
|
+
- gemfiles/json.gemfile
|
123
|
+
- gemfiles/yajl.gemfile
|
124
|
+
- lib/conekta.rb
|
125
|
+
- lib/conekta/account.rb
|
126
|
+
- lib/conekta/api_operations/create.rb
|
127
|
+
- lib/conekta/api_operations/delete.rb
|
128
|
+
- lib/conekta/api_operations/list.rb
|
129
|
+
- lib/conekta/api_operations/update.rb
|
130
|
+
- lib/conekta/api_resource.rb
|
131
|
+
- lib/conekta/charge.rb
|
132
|
+
- lib/conekta/conekta_object.rb
|
133
|
+
- lib/conekta/errors/api_connection_error.rb
|
134
|
+
- lib/conekta/errors/api_error.rb
|
135
|
+
- lib/conekta/errors/authentication_error.rb
|
136
|
+
- lib/conekta/errors/card_error.rb
|
137
|
+
- lib/conekta/errors/conekta_error.rb
|
138
|
+
- lib/conekta/errors/malformed_request_error.rb
|
139
|
+
- lib/conekta/errors/parameter_validation_error.rb
|
140
|
+
- lib/conekta/errors/resource_not_found_error.rb
|
141
|
+
- lib/conekta/event.rb
|
142
|
+
- lib/conekta/json.rb
|
143
|
+
- lib/conekta/list_object.rb
|
144
|
+
- lib/conekta/log.rb
|
145
|
+
- lib/conekta/singleton_api_resource.rb
|
146
|
+
- lib/conekta/util.rb
|
147
|
+
- lib/conekta/version.rb
|
148
|
+
- lib/data/ca-certificates.crt
|
149
|
+
- spec/conekta_spec.rb
|
150
|
+
- spec/conekta_with_active_support_spec.rb
|
151
|
+
- spec/test_helper.rb
|
152
|
+
homepage: http://conekta.mx/doc
|
153
|
+
licenses: []
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ! '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ! '>='
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 1.8.23
|
173
|
+
signing_key:
|
174
|
+
specification_version: 3
|
175
|
+
summary: Ruby bindings for the Conekta API
|
176
|
+
test_files: []
|
177
|
+
has_rdoc:
|