conekta 0.3.3 → 0.3.5
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 +8 -8
- data/.gitignore +5 -11
- data/CHANGELOG +5 -0
- data/Gemfile +6 -1
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +1 -14
- data/conekta.gemspec +22 -22
- data/lib/conekta.rb +36 -290
- data/lib/conekta/card.rb +10 -34
- data/lib/conekta/charge.rb +14 -38
- data/lib/conekta/conekta_object.rb +64 -136
- data/lib/conekta/customer.rb +23 -25
- data/lib/conekta/error.rb +65 -0
- data/lib/conekta/event.rb +2 -2
- data/lib/conekta/operations/create.rb +19 -0
- data/lib/conekta/operations/create_member.rb +30 -0
- data/lib/conekta/operations/custom_action.rb +17 -0
- data/lib/conekta/operations/delete.rb +43 -0
- data/lib/conekta/operations/find.rb +28 -0
- data/lib/conekta/operations/update.rb +13 -0
- data/lib/conekta/operations/where.rb +28 -0
- data/lib/conekta/payment_method.rb +4 -0
- data/lib/conekta/plan.rb +8 -5
- data/lib/conekta/requestor.rb +55 -0
- data/lib/conekta/resource.rb +13 -0
- data/lib/conekta/subscription.rb +12 -26
- data/lib/conekta/token.rb +3 -2
- data/lib/conekta/util.rb +19 -91
- data/lib/conekta/version.rb +1 -1
- data/lib/ssl_data/ca_bundle.crt +66 -0
- data/spec/conekta_spec.rb +299 -808
- data/spec/spec_helper.rb +12 -0
- metadata +55 -72
- data/CONTRIBUTORS +0 -9
- data/Gemfile.lock +0 -57
- data/History.txt +0 -4
- data/LICENSE +0 -23
- data/README.rdoc +0 -30
- data/VERSION +0 -1
- data/bin/conekta-console +0 -7
- data/bin/test calls +0 -205
- data/gemfiles/default-with-activesupport.gemfile +0 -3
- data/gemfiles/json.gemfile +0 -4
- data/gemfiles/yajl.gemfile +0 -4
- data/lib/conekta/account.rb +0 -4
- data/lib/conekta/api_operations/create.rb +0 -16
- data/lib/conekta/api_operations/create_member.rb +0 -18
- data/lib/conekta/api_operations/delete.rb +0 -11
- data/lib/conekta/api_operations/list.rb +0 -16
- data/lib/conekta/api_operations/modify_member.rb +0 -12
- data/lib/conekta/api_operations/update.rb +0 -22
- data/lib/conekta/api_resource.rb +0 -33
- data/lib/conekta/errors/api_connection_error.rb +0 -4
- data/lib/conekta/errors/api_error.rb +0 -4
- data/lib/conekta/errors/authentication_error.rb +0 -4
- data/lib/conekta/errors/card_error.rb +0 -11
- data/lib/conekta/errors/conekta_error.rb +0 -20
- data/lib/conekta/errors/malformed_request_error.rb +0 -10
- data/lib/conekta/errors/parameter_validation_error.rb +0 -10
- data/lib/conekta/errors/resource_not_found_error.rb +0 -10
- data/lib/conekta/json.rb +0 -21
- data/lib/conekta/list_object.rb +0 -35
- data/lib/conekta/log.rb +0 -5
- data/lib/conekta/singleton_api_resource.rb +0 -20
- data/lib/data/ca-certificates.crt +0 -3918
- data/spec/conekta_with_active_support_spec.rb +0 -3
- data/spec/test_helper.rb +0 -338
data/lib/conekta/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
#Bundled Digicerts
|
2
|
+
DigiCert Assured ID Root CA
|
3
|
+
===========================
|
4
|
+
-----BEGIN CERTIFICATE-----
|
5
|
+
MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBlMQswCQYDVQQG
|
6
|
+
EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSQw
|
7
|
+
IgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzEx
|
8
|
+
MTEwMDAwMDAwWjBlMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQL
|
9
|
+
ExB3d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1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vcNAQEF
|
39
|
+
BQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/EsrhMAtudXH/vTBH1jLuG2cenTnmCmr
|
40
|
+
EbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIt
|
41
|
+
tep3Sp+dWOIrWcBAI+0tKIJFPnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886
|
42
|
+
UAb3LujEV0lsYSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
|
43
|
+
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
44
|
+
-----END CERTIFICATE-----
|
45
|
+
|
46
|
+
DigiCert High Assurance EV Root CA
|
47
|
+
==================================
|
48
|
+
-----BEGIN CERTIFICATE-----
|
49
|
+
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
|
50
|
+
EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
|
51
|
+
KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
|
52
|
+
MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
|
53
|
+
MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
|
54
|
+
Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
|
55
|
+
Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT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|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
describe :conekta_tests do
|
3
|
+
Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
4
|
+
describe :charge_tests do
|
5
|
+
p "charge tests"
|
6
|
+
before :each do
|
7
|
+
@valid_payment_method = {amount: 2000, currency: 'mxn', description: 'Some desc'}
|
8
|
+
@invalid_payment_method = {amount: 10, currency: 'mxn', description: 'Some desc'}
|
9
|
+
@valid_visa_card = {card: 'tok_test_visa_4242'}
|
10
|
+
end
|
11
|
+
it "succesful get charge" do
|
12
|
+
pm = @valid_payment_method
|
13
|
+
card = @valid_visa_card
|
14
|
+
cpm = Conekta::Charge.create(pm.merge(card))
|
15
|
+
cpm.status.should eq("paid")
|
16
|
+
pm = Conekta::Charge.find(cpm.id)
|
17
|
+
pm.class.class_name.should eq("Charge")
|
18
|
+
end
|
19
|
+
it "test succesful where" do
|
20
|
+
charges = Conekta::Charge.where
|
21
|
+
charges.class.class_name.should eq("ConektaObject")
|
22
|
+
charges[0].class.class_name.should eq("Charge")
|
23
|
+
end
|
24
|
+
it "tests succesful bank pm create" do
|
25
|
+
pm = @valid_payment_method
|
26
|
+
bank = {bank: {'type' => 'banorte'}}
|
27
|
+
bpm = Conekta::Charge.create(pm.merge(bank))
|
28
|
+
bpm.status.should eq("pending_payment")
|
29
|
+
end
|
30
|
+
it "tests succesful card pm create" do
|
31
|
+
pm = @valid_payment_method
|
32
|
+
card = @valid_visa_card
|
33
|
+
cpm = Conekta::Charge.create(pm.merge(card))
|
34
|
+
cpm.status.should eq("paid")
|
35
|
+
end
|
36
|
+
it "tests succesful oxxo pm create" do
|
37
|
+
pm = @valid_payment_method
|
38
|
+
oxxo = {cash: {'type' => 'oxxo'}}
|
39
|
+
bpm = Conekta::Charge.create(pm.merge(oxxo))
|
40
|
+
bpm.status.should eq("pending_payment")
|
41
|
+
end
|
42
|
+
it "test unsuccesful pm create" do
|
43
|
+
pm = @invalid_payment_method
|
44
|
+
card = @valid_visa_card
|
45
|
+
begin
|
46
|
+
cpm = Conekta::Charge.create(pm.merge(card))
|
47
|
+
rescue Conekta::Error => e
|
48
|
+
e.message.should eq("The minimum purchase is 3 MXN pesos for card payments")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
it "test susccesful refund" do
|
52
|
+
pm = @valid_payment_method
|
53
|
+
card = @valid_visa_card
|
54
|
+
cpm = Conekta::Charge.create(pm.merge(card))
|
55
|
+
cpm.status.should eq("paid")
|
56
|
+
cpm.refund
|
57
|
+
cpm.status.should eq("refunded")
|
58
|
+
end
|
59
|
+
it "test unsusccesful refund" do
|
60
|
+
pm = @valid_payment_method
|
61
|
+
card = @valid_visa_card
|
62
|
+
cpm = Conekta::Charge.create(pm.merge(card))
|
63
|
+
cpm.status.should eq("paid")
|
64
|
+
begin
|
65
|
+
cpm.refund(3000)
|
66
|
+
rescue Conekta::Error => e
|
67
|
+
e.message.should eq("The order does not exist or the amount to refund is invalid")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
it "tests succesful card pm create" do
|
71
|
+
pm = @valid_payment_method
|
72
|
+
card = @valid_visa_card
|
73
|
+
capture = {capture: false}
|
74
|
+
cpm = Conekta::Charge.create(pm.merge(card).merge(capture))
|
75
|
+
cpm.status.should eq("pre_authorized")
|
76
|
+
cpm.capture
|
77
|
+
cpm.status.should eq("paid")
|
38
78
|
end
|
39
79
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Conekta.mock_rest_client = @mock
|
46
|
-
@mock.expects(:get).never
|
47
|
-
@mock.expects(:post).never
|
48
|
-
c = Conekta::Charge.new("someid")
|
49
|
-
Conekta.mock_rest_client = nil
|
50
|
-
end
|
51
|
-
|
52
|
-
it "creating a new APIResource from a hash should not fetch over the network" do
|
53
|
-
@mock = double
|
54
|
-
Conekta.mock_rest_client = @mock
|
55
|
-
|
56
|
-
@mock.expects(:get).never
|
57
|
-
@mock.expects(:post).never
|
58
|
-
c = Conekta::Charge.construct_from({
|
59
|
-
id: "somecharge",
|
60
|
-
amount: 10000,
|
61
|
-
currency: 'MXN',
|
62
|
-
card: {
|
63
|
-
number: '4242424242424242',
|
64
|
-
cvc:'123',
|
65
|
-
exp_month:12,
|
66
|
-
exp_year:19,
|
67
|
-
name:'Sebastian Q.'
|
68
|
-
}
|
80
|
+
describe :customer_tests do
|
81
|
+
p "customer tests"
|
82
|
+
it "successful customer create" do
|
83
|
+
customer = Conekta::Customer.create({
|
84
|
+
:cards => ["tok_test_visa_4242"],
|
69
85
|
})
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
@mock = double
|
76
|
-
Conekta.mock_rest_client = @mock
|
77
|
-
|
78
|
-
@mock.expects(:get).never
|
79
|
-
@mock.expects(:post).never
|
80
|
-
c = Conekta::Charge.new("test_charge");
|
81
|
-
c = Conekta::Charge.construct_from({
|
82
|
-
id: "somecharge",
|
83
|
-
amount: 10000,
|
84
|
-
card: {
|
85
|
-
number: '4242424242424242',
|
86
|
-
cvc:'123',
|
87
|
-
exp_month:12,
|
88
|
-
exp_year:19,
|
89
|
-
name:'Sebastian Q.'
|
90
|
-
}
|
86
|
+
customer.class.class_name.should eq("Customer")
|
87
|
+
end
|
88
|
+
it "successful customer get" do
|
89
|
+
c = Conekta::Customer.create({
|
90
|
+
:cards => ["tok_test_visa_4242"],
|
91
91
|
})
|
92
|
-
|
93
|
-
|
94
|
-
Conekta.mock_rest_client = nil
|
95
|
-
end
|
96
|
-
|
97
|
-
it "accessing id should not issue a fetch" do
|
98
|
-
@mock = double
|
99
|
-
Conekta.mock_rest_client = @mock
|
100
|
-
|
101
|
-
@mock.expects(:get).never
|
102
|
-
c = Conekta::Charge.new("test_charge");
|
103
|
-
c.id
|
104
|
-
|
105
|
-
Conekta.mock_rest_client = nil
|
92
|
+
customer = Conekta::Customer.find(c.id)
|
93
|
+
customer.class.class_name.should eq("Customer")
|
106
94
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
Conekta.api_key = nil
|
112
|
-
expect{Conekta::Charge.new("test_charge").refresh}.to raise_error(Conekta::AuthenticationError)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "specifying api credentials containing whitespace should raise an exception" do
|
116
|
-
Conekta.api_key = "key "
|
117
|
-
expect{Conekta::Charge.new("test_charge").refresh}.to raise_error(Conekta::AuthenticationError)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "specifying invalid api credentials should raise an exception" do
|
121
|
-
@mock = double
|
122
|
-
Conekta.mock_rest_client = @mock
|
123
|
-
|
124
|
-
Conekta.api_key = "invalid"
|
125
|
-
response = test_response(test_invalid_api_key_error, 401)
|
126
|
-
|
127
|
-
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
128
|
-
expect{Conekta::Charge.retrieve("failing_charge")}.to raise_error(Conekta::AuthenticationError)
|
129
|
-
|
130
|
-
Conekta.mock_rest_client = nil
|
131
|
-
end
|
132
|
-
|
133
|
-
it "AuthenticationErrors should have an http status, http body, and JSON body" do
|
134
|
-
@mock = double
|
135
|
-
Conekta.mock_rest_client = @mock
|
136
|
-
|
137
|
-
Conekta.api_key = "invalid"
|
138
|
-
response = test_response(test_invalid_api_key_error, 401)
|
139
|
-
|
140
|
-
begin
|
141
|
-
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
142
|
-
Conekta::Charge.retrieve("failing_charge")
|
143
|
-
rescue Conekta::AuthenticationError => e
|
144
|
-
401.should eq(e.http_status)
|
145
|
-
true.should_not eq(e.http_body)
|
146
|
-
true.should_not eq(e.json_body[:message])
|
147
|
-
test_invalid_api_key_error['message'].should eq(e.json_body[:message])
|
148
|
-
end
|
149
|
-
|
150
|
-
Conekta.mock_rest_client = nil
|
95
|
+
it "successful customer where" do
|
96
|
+
customers = Conekta::Customer.where
|
97
|
+
customers.class.class_name.should eq("ConektaObject")
|
98
|
+
customers[0].class.class_name.should eq("Customer")
|
151
99
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
Conekta.should_receive(:execute_request){|opts|
|
160
|
-
opts[:headers][:authorization].should eq("Basic c2tfdGVzdF9sb2NhbDo=\n")
|
161
|
-
test_response(test_charge)
|
162
|
-
}
|
163
|
-
|
164
|
-
Conekta::Charge.create({:card => {:number => '4242424242424242'}},
|
165
|
-
'sk_test_local')
|
166
|
-
end
|
167
|
-
|
168
|
-
it "when specifying per-object credentials with global API key set, use the per-object credential when creating" do
|
169
|
-
Conekta.api_key = "global"
|
170
|
-
|
171
|
-
Conekta.should_receive(:execute_request){|opts|
|
172
|
-
opts[:headers][:authorization].should eq("Basic c2tfdGVzdF9sb2NhbDo=\n")
|
173
|
-
test_response(test_charge)
|
174
|
-
}
|
175
|
-
|
176
|
-
Conekta::Charge.create({:card => {:number => '4242424242424242'}},
|
177
|
-
'sk_test_local')
|
178
|
-
end
|
179
|
-
|
180
|
-
it "when specifying per-object credentials with a global API key set, use the per-object credential when retrieving and making other calls" do
|
181
|
-
Conekta.api_key = "global"
|
182
|
-
|
183
|
-
Conekta.should_receive(:execute_request){|opts|
|
184
|
-
opts[:url].should eq("#{Conekta.api_base}/charges/ch_test_charge.json")
|
185
|
-
opts[:headers][:authorization].should eq("Basic c2tfdGVzdF9sb2NhbDo=\n")
|
186
|
-
test_response(test_charge)
|
187
|
-
}
|
188
|
-
Conekta.should_receive(:execute_request){|opts|
|
189
|
-
opts[:url].should eq("#{Conekta.api_base}/charges/ch_test_charge/refund.json")
|
190
|
-
opts[:headers][:authorization].should eq("Basic c2tfdGVzdF9sb2NhbDo=\n")
|
191
|
-
test_response(test_charge)
|
192
|
-
}
|
193
|
-
|
194
|
-
ch = Conekta::Charge.retrieve('ch_test_charge', 'sk_test_local')
|
195
|
-
ch.refund
|
100
|
+
it "successful customer delete" do
|
101
|
+
customer = Conekta::Customer.create({
|
102
|
+
:cards => ["tok_test_visa_4242"],
|
103
|
+
})
|
104
|
+
customer.delete
|
105
|
+
customer.deleted.should eq(true)
|
196
106
|
end
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
response = test_response(test_charge_array)
|
206
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
207
|
-
|
208
|
-
arg1.should eq("#{Conekta.api_base}/charges.json?amount=500")
|
209
|
-
arg2.should eq(nil)
|
210
|
-
arg3.should eq(nil)
|
211
|
-
response
|
212
|
-
}
|
213
|
-
charges = Conekta::Charge.all(amount: 500).data
|
214
|
-
charges.should be_kind_of(Array)
|
215
|
-
|
216
|
-
Conekta.mock_rest_client = nil
|
217
|
-
end
|
218
|
-
|
219
|
-
it "with valid credential, construct URL properly with base query parameters" do
|
220
|
-
@mock = double
|
221
|
-
Conekta.mock_rest_client = @mock
|
222
|
-
|
223
|
-
response = test_response(test_charge_array)
|
224
|
-
|
225
|
-
Conekta.api_key = 'foo'
|
226
|
-
response = test_response(test_charge_array_filtered)
|
227
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
228
|
-
arg1.should eq("#{Conekta.api_base}/charges.json?amount=500")
|
229
|
-
arg2.should eq(nil)
|
230
|
-
arg3.should eq(nil)
|
231
|
-
response
|
232
|
-
}
|
233
|
-
charges = Conekta::Charge.all(amount: 500)
|
234
|
-
|
235
|
-
response = test_response(test_charge_array_filtered)
|
236
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
237
|
-
arg1.should eq("#{Conekta.api_base}/charges.json?amount=500&status=paid")
|
238
|
-
arg2.should eq(nil)
|
239
|
-
arg3.should eq(nil)
|
240
|
-
response
|
241
|
-
}
|
242
|
-
charges.all(:status=>'paid')
|
243
|
-
|
244
|
-
Conekta.mock_rest_client = nil
|
245
|
-
end
|
246
|
-
|
247
|
-
it "with valid credential, a 401 should give an AuthenticationError with http status, body, and JSON body" do
|
248
|
-
@mock = double
|
249
|
-
Conekta.mock_rest_client = @mock
|
250
|
-
|
251
|
-
response = test_response(test_missing_id_error, 401)
|
252
|
-
@mock.should_receive(:get){|args|
|
253
|
-
raise RestClient::ExceptionWithResponse.new(response, 401)
|
254
|
-
}.once
|
255
|
-
|
256
|
-
begin
|
257
|
-
Conekta::Charge.retrieve("foo")
|
258
|
-
rescue Conekta::AuthenticationError => e
|
259
|
-
e.http_status.should eq(401)
|
260
|
-
e.http_body.should_not eq(true)
|
261
|
-
e.json_body.should be_kind_of(Hash)
|
262
|
-
end
|
263
|
-
|
264
|
-
Conekta.mock_rest_client = nil
|
265
|
-
end
|
266
|
-
|
267
|
-
it "with valid credential, a 402 should give an CardError with http status, body, and JSON body" do
|
268
|
-
@mock = double
|
269
|
-
Conekta.mock_rest_client = @mock
|
270
|
-
|
271
|
-
response = test_response(test_missing_id_error, 402)
|
272
|
-
@mock.should_receive(:post){|args|
|
273
|
-
raise RestClient::ExceptionWithResponse.new(response, 402)
|
274
|
-
}.once
|
275
|
-
|
107
|
+
it "successful customer update" do
|
108
|
+
customer = Conekta::Customer.create({
|
109
|
+
:cards => ["tok_test_visa_4242"],
|
110
|
+
})
|
111
|
+
customer.update({name: 'Logan', email: 'logan@x-men.org'})
|
112
|
+
customer.name.should eq('Logan')
|
113
|
+
end
|
114
|
+
it "successful customer update" do
|
276
115
|
begin
|
277
|
-
Conekta::
|
278
|
-
|
279
|
-
description:'Test',
|
280
|
-
card: {
|
281
|
-
name:'Leo Fischer',
|
282
|
-
number:4000000000000119,
|
283
|
-
cvc:123,
|
284
|
-
exp_month:8,
|
285
|
-
exp_year:19
|
286
|
-
}
|
116
|
+
customer = Conekta::Customer.create({
|
117
|
+
:cards => ["tok_test_visa_4241"],
|
287
118
|
})
|
288
|
-
|
289
|
-
|
290
|
-
e.http_status.should eq(402)
|
291
|
-
e.http_body.should_not eq(true)
|
292
|
-
e.json_body.should be_kind_of(Hash)
|
119
|
+
rescue Conekta::Error => e
|
120
|
+
e.message.should eq("Token 'tok_test_visa_4241' could not be found.")
|
293
121
|
end
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
122
|
+
end
|
123
|
+
it "add card to customer" do
|
124
|
+
customer = Conekta::Customer.create({
|
125
|
+
:cards => ["tok_test_visa_4242"],
|
126
|
+
})
|
127
|
+
card = customer.create_card(:token => 'tok_test_visa_1881')
|
128
|
+
customer.cards.count.should eq(2)
|
129
|
+
customer.cards.last.last4.should eq('1881')
|
130
|
+
end
|
131
|
+
it "test delete card" do
|
132
|
+
customer = Conekta::Customer.create({
|
133
|
+
:cards => ["tok_test_visa_4242"],
|
134
|
+
})
|
135
|
+
card = customer.cards[0].delete
|
136
|
+
card.deleted.should eq(true)
|
137
|
+
end
|
138
|
+
it "test update card" do
|
139
|
+
customer = Conekta::Customer.create({
|
140
|
+
:cards => ["tok_test_visa_4242"],
|
141
|
+
})
|
142
|
+
customer.cards[0].update({token: 'tok_test_mastercard_4444', active: false})
|
143
|
+
customer.cards[0].last4.should eq('4444')
|
144
|
+
end
|
145
|
+
it "test succesful create subscription" do
|
146
|
+
customer = Conekta::Customer.create({
|
147
|
+
:cards => ["tok_test_visa_4242"],
|
148
|
+
})
|
149
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
150
|
+
subscription.class.class_name.should eq('Subscription')
|
151
|
+
end
|
152
|
+
it "test succesful update subscription" do
|
153
|
+
customer = Conekta::Customer.create({
|
154
|
+
:cards => ["tok_test_visa_4242"],
|
155
|
+
})
|
156
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
307
157
|
begin
|
308
|
-
Conekta::
|
309
|
-
rescue Conekta::
|
310
|
-
|
311
|
-
|
312
|
-
|
158
|
+
plan = Conekta::Plan.find('gold-plan2')
|
159
|
+
rescue Conekta::Error => e
|
160
|
+
plan = Conekta::Plan.create({
|
161
|
+
id: "gold-plan2",
|
162
|
+
name: "Gold Plan",
|
163
|
+
amount: 10000,
|
164
|
+
currency: "MXN",
|
165
|
+
interval: "month",
|
166
|
+
frequency: 1,
|
167
|
+
trial_period_days: 15,
|
168
|
+
expiry_count: 12
|
169
|
+
})
|
313
170
|
end
|
314
|
-
|
315
|
-
|
316
|
-
end
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
response = test_response(test_missing_id_error, 422)
|
323
|
-
@mock.should_receive(:post){|args|
|
324
|
-
raise RestClient::ExceptionWithResponse.new(response, 422)
|
325
|
-
}.once
|
326
|
-
|
171
|
+
subscription.update({plan: plan.id})
|
172
|
+
subscription.plan_id.should eq('gold-plan2')
|
173
|
+
end
|
174
|
+
it "test unsuccesful create subscription" do
|
175
|
+
customer = Conekta::Customer.create({
|
176
|
+
:cards => ["tok_test_visa_4242"],
|
177
|
+
})
|
327
178
|
begin
|
328
|
-
|
329
|
-
rescue Conekta::
|
330
|
-
e.
|
331
|
-
e.http_body.should_not eq(true)
|
332
|
-
e.json_body.should be_kind_of(Hash)
|
179
|
+
subscription = customer.create_subscription({plan: 'unexistent-plan'})
|
180
|
+
rescue Conekta::Error => e
|
181
|
+
e.message.should eq("Plan 'unexistent-plan' does not exist and cannot be used to create a new subsription.")
|
333
182
|
end
|
334
|
-
|
335
|
-
Conekta.mock_rest_client = nil
|
336
|
-
end
|
337
|
-
|
338
|
-
it "with valid credential, setting a nil value for a param should exclude that param from the request" do
|
339
|
-
@mock = double
|
340
|
-
Conekta.mock_rest_client = @mock
|
341
|
-
|
342
|
-
@mock.should_receive(:get){|url, api_key, params|
|
343
|
-
uri = URI(url)
|
344
|
-
query = CGI.parse(uri.query)
|
345
|
-
url.should match(%r{^#{Conekta.api_base}/charges?})
|
346
|
-
query.keys.sort.should eq(['offset', 'sad'])
|
347
|
-
|
348
|
-
test_response({ :count => 1, :data => [test_charge] })
|
349
|
-
}
|
350
|
-
c = Conekta::Charge.all(:count => nil, :offset => 5, :sad => false)
|
351
|
-
|
352
|
-
@mock.should_receive(:post){|url, api_key, params|
|
353
|
-
"#{Conekta.api_base}/charges.json".should eq(url)
|
354
|
-
api_key.should eq(nil)
|
355
|
-
{:amount => 50, :currency=>'usd', :card=>{}}.should eq(JSON.parse(params).symbolize_keys)
|
356
|
-
|
357
|
-
test_response({ :count => 1, :data => [test_charge] })
|
358
|
-
}
|
359
|
-
c = Conekta::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
360
|
-
Conekta.mock_rest_client = nil
|
361
|
-
end
|
362
|
-
|
363
|
-
it "requesting with a unicode ID should result in a request" do
|
364
|
-
@mock = double
|
365
|
-
Conekta.mock_rest_client = @mock
|
366
|
-
|
367
|
-
response = test_response(test_missing_id_error, 400)
|
368
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
369
|
-
arg1.should eq("#{Conekta.api_base}/charges/%E2%98%83.json")
|
370
|
-
arg2.should eq(nil)
|
371
|
-
arg3.should eq(nil)
|
372
|
-
raise RestClient::ExceptionWithResponse.new(response, 400)
|
373
|
-
}.once
|
374
|
-
c = Conekta::Charge.new("☃")
|
375
|
-
expect{c.refresh}.to raise_error(Conekta::MalformedRequestError)
|
376
|
-
|
377
|
-
Conekta.mock_rest_client = nil
|
378
|
-
end
|
379
|
-
|
380
|
-
it "requesting with no ID should result in an ParameterValidationError with no request" do
|
381
|
-
c = Conekta::Charge.new
|
382
|
-
expect{c.refresh}.to raise_error(Conekta::ParameterValidationError)
|
383
|
-
end
|
384
|
-
|
385
|
-
it "making a GET request with parameters should have a query string and no body" do
|
386
|
-
@mock = double
|
387
|
-
Conekta.mock_rest_client = @mock
|
388
|
-
|
389
|
-
params = { :limit => 1 }
|
390
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
391
|
-
arg1.should eq("#{Conekta.api_base}/charges.json?limit=1")
|
392
|
-
arg2.should eq(nil)
|
393
|
-
arg3.should eq(nil)
|
394
|
-
test_response([test_charge])
|
395
|
-
}.once
|
396
|
-
c = Conekta::Charge.all(params)
|
397
|
-
|
398
|
-
Conekta.mock_rest_client = nil
|
399
|
-
end
|
400
|
-
|
401
|
-
it "making a POST request with parameters should have a body and no query string" do
|
402
|
-
@mock = double
|
403
|
-
Conekta.mock_rest_client = @mock
|
404
|
-
|
405
|
-
params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
|
406
|
-
@mock.should_receive(:post){|url, get, post|
|
407
|
-
get.should eq(nil)
|
408
|
-
JSON.parse(post).symbolize_keys.should eq({:amount => 100, :currency => 'usd', :card => 'sc_token'})
|
409
|
-
test_response(test_charge)
|
410
|
-
}
|
411
|
-
c = Conekta::Charge.create(params)
|
412
|
-
|
413
|
-
Conekta.mock_rest_client = nil
|
414
|
-
end
|
415
|
-
|
416
|
-
it "loading an object should issue a GET request" do
|
417
|
-
@mock = double
|
418
|
-
Conekta.mock_rest_client = @mock
|
419
|
-
|
420
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
421
|
-
test_response(test_charge)
|
422
|
-
}.once
|
423
|
-
c = Conekta::Charge.new("test_charge")
|
424
|
-
c.refresh
|
425
|
-
|
426
|
-
Conekta.mock_rest_client = nil
|
427
|
-
end
|
428
|
-
|
429
|
-
it "using array accessors should be the same as the method interface" do
|
430
|
-
@mock = double
|
431
|
-
Conekta.mock_rest_client = @mock
|
432
|
-
|
433
|
-
@mock.should_receive(:get){|arg1, arg2, arg3|
|
434
|
-
test_response(test_charge)
|
435
|
-
}.once
|
436
|
-
c = Conekta::Charge.new("test_charge")
|
437
|
-
c.refresh
|
438
|
-
c.created.should eq(c[:created])
|
439
|
-
c.created.should eq(c['created'])
|
440
|
-
c['created'] = 12345
|
441
|
-
c.created.should eq(12345)
|
442
|
-
|
443
|
-
Conekta.mock_rest_client = nil
|
444
|
-
end
|
445
|
-
|
446
|
-
# it "accessing a property other than id or parent on an unfetched object should fetch it" do
|
447
|
-
# @mock = double
|
448
|
-
# Conekta.mock_rest_client = @mock
|
449
|
-
#
|
450
|
-
# @mock.should_receive(:get){
|
451
|
-
# test_response(test_charge)
|
452
|
-
# }.once
|
453
|
-
# c = Conekta::Charge.new("test_charge")
|
454
|
-
# c.card
|
455
|
-
#
|
456
|
-
# Conekta.mock_rest_client = nil
|
457
|
-
# end
|
458
|
-
|
459
|
-
it "updating an object should issue a POST request with only the changed properties" do
|
460
|
-
@mock = double
|
461
|
-
Conekta.mock_rest_client = @mock
|
462
|
-
|
463
|
-
@mock.should_receive(:post){|url, api_key, params|
|
464
|
-
url.should eq("#{Conekta.api_base}/charges/ch_test_charge.json")
|
465
|
-
api_key.should eq(nil)
|
466
|
-
JSON.parse(params).symbolize_keys.should eq({:mnemonic => 'another_mn'})
|
467
|
-
test_response(test_charge)
|
468
|
-
}.once
|
469
|
-
c = Conekta::Charge.construct_from(test_charge)
|
470
|
-
c.mnemonic = "another_mn"
|
471
|
-
c.save
|
472
|
-
|
473
|
-
Conekta.mock_rest_client = nil
|
474
|
-
end
|
475
|
-
|
476
|
-
it "updating should merge in returned properties" do
|
477
|
-
@mock = double
|
478
|
-
Conekta.mock_rest_client = @mock
|
479
|
-
|
480
|
-
@mock = double
|
481
|
-
Conekta.mock_rest_client = @mock
|
482
|
-
|
483
|
-
@mock.should_receive(:post){
|
484
|
-
test_response(test_charge)
|
485
|
-
}.once
|
486
|
-
c = Conekta::Charge.new("c_test_charge")
|
487
|
-
c.mnemonic = "another_mn"
|
488
|
-
c.save
|
489
|
-
c.livemode.should eq(false)
|
490
|
-
|
491
|
-
Conekta.mock_rest_client = nil
|
492
|
-
end
|
493
|
-
|
494
|
-
# it "deleting should send no props and result in an object that has no props other deleted" do
|
495
|
-
# @mock = double
|
496
|
-
# Conekta.mock_rest_client = @mock
|
497
|
-
#
|
498
|
-
# @mock.expects(:get).never
|
499
|
-
# @mock.expects(:post).never
|
500
|
-
# @mock.should_receive(:delete){|arg1, arg2, arg3|
|
501
|
-
# arg1.should eq("#{Conekta.api_base}/v1/charges/ch_test_charge")
|
502
|
-
# arg2.should eq(nil)
|
503
|
-
# arg3.should eq(nil)
|
504
|
-
#
|
505
|
-
# test_response({ "id" => "test_charge", "deleted" => true })
|
506
|
-
# }.once
|
507
|
-
#
|
508
|
-
# c = Conekta::Customer.construct_from(test_charge)
|
509
|
-
# c.delete
|
510
|
-
# c.deleted.should eq(true)
|
511
|
-
#
|
512
|
-
# c.livemode.to raise_error(NoMethodError)
|
513
|
-
# end
|
514
|
-
|
515
|
-
it "loading an object with properties that have specific types should instantiate those classes" do
|
516
|
-
@mock = double
|
517
|
-
Conekta.mock_rest_client = @mock
|
518
|
-
|
519
|
-
@mock.should_receive(:get){
|
520
|
-
test_response(test_charge)
|
521
|
-
}.once
|
522
|
-
|
523
|
-
c = Conekta::Charge.retrieve("test_charge")
|
524
|
-
c.card.should be_kind_of(Conekta::ConektaObject)
|
525
|
-
#c.card.object == 'card'
|
526
|
-
|
527
|
-
Conekta.mock_rest_client = nil
|
528
|
-
end
|
529
|
-
|
530
|
-
it "loading all of an APIResource should return an array of recursively instantiated objects" do
|
531
|
-
@mock = double
|
532
|
-
Conekta.mock_rest_client = @mock
|
533
|
-
|
534
|
-
@mock.should_receive(:get){
|
535
|
-
test_response(test_charge_array)
|
536
|
-
}.once
|
537
|
-
c = Conekta::Charge.all
|
538
|
-
c = c.data
|
539
|
-
c.should be_kind_of(Array)
|
540
|
-
c[0].should be_kind_of(Conekta::Charge)
|
541
|
-
c[0].card.should be_kind_of(Conekta::ConektaObject)
|
542
|
-
#c[0].card.object == 'card'
|
543
|
-
|
544
|
-
Conekta.mock_rest_client = nil
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
describe Conekta::Account, "#retrieve" do
|
549
|
-
it "account should be retrievable" do
|
550
|
-
@mock = double
|
551
|
-
Conekta.mock_rest_client = @mock
|
552
|
-
|
553
|
-
resp = {:email => "test+bindings@conekta.com", :charge_enabled => false, :details_submitted => false}
|
554
|
-
@mock.should_receive(:get){test_response(resp)}.once
|
555
|
-
a = Conekta::Account.retrieve
|
556
|
-
"test+bindings@conekta.com".should eq(a.email)
|
557
|
-
a.charge_enabled.should eq(false)
|
558
|
-
a.details_submitted.should eq(false)
|
559
|
-
|
560
|
-
Conekta.mock_rest_client = nil
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
describe Conekta::ListObject, "#all" do
|
565
|
-
it "be able to retrieve full lists given a listobject" do
|
566
|
-
@mock = double
|
567
|
-
Conekta.mock_rest_client = @mock
|
568
|
-
|
569
|
-
@mock.should_receive(:get){
|
570
|
-
test_response(test_charge_array)
|
571
|
-
}.twice
|
572
|
-
|
573
|
-
c = Conekta::Charge.all
|
574
|
-
c.should be_kind_of(Conekta::ListObject)
|
575
|
-
'/charges'.should eq(c.url)
|
576
|
-
all = c.all
|
577
|
-
all.should be_kind_of(Conekta::ListObject)
|
578
|
-
'/charges'.should eq(all.url)
|
579
|
-
all.data.should be_kind_of(Array)
|
580
|
-
|
581
|
-
Conekta.mock_rest_client = nil
|
582
183
|
end
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
it "execute should return a new customer" do
|
587
|
-
@mock = double
|
588
|
-
Conekta.mock_rest_client = @mock
|
589
|
-
|
590
|
-
@mock.should_receive(:post){|url, api_key, params|
|
591
|
-
url.should eq("#{Conekta.api_base}/customers.json")
|
592
|
-
api_key.should eq(nil)
|
593
|
-
JSON.parse(params).symbolize_keys.should eq({
|
594
|
-
:cards=>["TOKEN_ID"]
|
595
|
-
})
|
596
|
-
|
597
|
-
test_response(test_customer)
|
598
|
-
}.once
|
599
|
-
|
600
|
-
c = Conekta::Customer.create({
|
601
|
-
:cards => ["TOKEN_ID"],
|
184
|
+
it "test succesful pause subscription" do
|
185
|
+
customer = Conekta::Customer.create({
|
186
|
+
:cards => ["tok_test_visa_4242"],
|
602
187
|
})
|
603
|
-
|
604
|
-
|
605
|
-
|
188
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
189
|
+
subscription.pause
|
190
|
+
subscription.status.should eq('paused')
|
606
191
|
end
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
it "execute should return a new plan" do
|
611
|
-
@mock = double
|
612
|
-
Conekta.mock_rest_client = @mock
|
613
|
-
|
614
|
-
@mock.should_receive(:post){|url, api_key, params|
|
615
|
-
url.should eq("#{Conekta.api_base}/plans.json")
|
616
|
-
api_key.should eq(nil)
|
617
|
-
JSON.parse(params).symbolize_keys.should eq({
|
618
|
-
:id => "gold-plan",
|
619
|
-
:name => "Gold Plan",
|
620
|
-
:amount => 10000,
|
621
|
-
:currency => "MXN",
|
622
|
-
:interval => "month",
|
623
|
-
:frequency => 1,
|
624
|
-
:trial_period_days => 15,
|
625
|
-
:expiry_count => 12
|
626
|
-
})
|
627
|
-
|
628
|
-
test_response(test_plan)
|
629
|
-
}.once
|
630
|
-
|
631
|
-
p = Conekta::Plan.create({
|
632
|
-
:id => "gold-plan",
|
633
|
-
:name => "Gold Plan",
|
634
|
-
:amount => 10000,
|
635
|
-
:currency => "MXN",
|
636
|
-
:interval => "month",
|
637
|
-
:frequency => 1,
|
638
|
-
:trial_period_days => 15,
|
639
|
-
:expiry_count => 12
|
192
|
+
it "test succesful resume subscription" do
|
193
|
+
customer = Conekta::Customer.create({
|
194
|
+
:cards => ["tok_test_visa_4242"],
|
640
195
|
})
|
641
|
-
|
642
|
-
|
643
|
-
|
196
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
197
|
+
subscription.resume
|
198
|
+
subscription.status.should eq('active')
|
644
199
|
end
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
it "execute should return a new token" do
|
649
|
-
@mock = double
|
650
|
-
Conekta.mock_rest_client = @mock
|
651
|
-
|
652
|
-
@mock.should_receive(:post){|url, api_key, params|
|
653
|
-
url.should eq("#{Conekta.api_base}/tokens.json")
|
654
|
-
api_key.should eq(nil)
|
655
|
-
params = JSON.parse(params).symbolize_keys
|
656
|
-
params[:card] = params[:card].symbolize_keys
|
657
|
-
params.should eq({
|
658
|
-
:card => {
|
659
|
-
:number => "4242424242424242",
|
660
|
-
:exp_month => 11,
|
661
|
-
:exp_year => 2012,
|
662
|
-
}
|
663
|
-
})
|
664
|
-
|
665
|
-
test_response(test_token)
|
666
|
-
}.once
|
667
|
-
|
668
|
-
t = Conekta::Token.create({
|
669
|
-
:card => {
|
670
|
-
:number => "4242424242424242",
|
671
|
-
:exp_month => 11,
|
672
|
-
:exp_year => 2012,
|
673
|
-
}
|
200
|
+
it "test succesful cancel subscription" do
|
201
|
+
customer = Conekta::Customer.create({
|
202
|
+
:cards => ["tok_test_visa_4242"],
|
674
203
|
})
|
675
|
-
|
676
|
-
|
677
|
-
|
204
|
+
subscription = customer.create_subscription({plan: 'gold-plan'})
|
205
|
+
subscription.cancel
|
206
|
+
subscription.status.should eq('canceled')
|
678
207
|
end
|
679
208
|
end
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
Conekta
|
686
|
-
|
687
|
-
@mock.should_receive(:get){
|
688
|
-
test_response(test_charge_array)
|
689
|
-
}.once
|
690
|
-
c = Conekta::Charge.all
|
691
|
-
c.data.should be_kind_of(Array)
|
692
|
-
c.each do |charge|
|
693
|
-
charge.should be_kind_of(Conekta::Charge)
|
209
|
+
describe :error_tests do
|
210
|
+
p "error tests"
|
211
|
+
it "test no id error" do
|
212
|
+
begin
|
213
|
+
charge = Conekta::Charge.find(nil)
|
214
|
+
rescue Conekta::Error => e
|
215
|
+
e.message.should eq('Could not get the id of Charge instance.')
|
694
216
|
end
|
695
|
-
|
696
|
-
Conekta.mock_rest_client = nil
|
697
|
-
end
|
698
|
-
|
699
|
-
it "charges should be refundable" do
|
700
|
-
@mock = double
|
701
|
-
Conekta.mock_rest_client = @mock
|
702
|
-
|
703
|
-
@mock.expects(:get).never
|
704
|
-
@mock.should_receive(:post){test_response({:id => "ch_test_charge", :refunded => true})}.once
|
705
|
-
c = Conekta::Charge.new("test_charge")
|
706
|
-
c.refund
|
707
|
-
c.refunded.should eq(true)
|
708
|
-
|
709
|
-
Conekta.mock_rest_client = nil
|
710
|
-
end
|
711
|
-
|
712
|
-
it "charges should not be deletable" do
|
713
|
-
@mock = double
|
714
|
-
Conekta.mock_rest_client = @mock
|
715
|
-
|
716
|
-
@mock.should_receive(:get){test_response(test_charge)}.once
|
717
|
-
c = Conekta::Charge.retrieve("test_charge")
|
718
|
-
expect{c.delete}.to raise_error(NoMethodError)
|
719
|
-
|
720
|
-
Conekta.mock_rest_client = nil
|
721
|
-
end
|
722
|
-
|
723
|
-
|
724
|
-
it "charges should be updateable" do
|
725
|
-
@mock = double
|
726
|
-
Conekta.mock_rest_client = @mock
|
727
|
-
|
728
|
-
@mock.should_receive(:get){test_response(test_charge)}.once
|
729
|
-
@mock.should_receive(:post){test_response(test_charge)}.once
|
730
|
-
c = Conekta::Charge.new("test_charge")
|
731
|
-
c.refresh
|
732
|
-
c.mnemonic = "New charge description"
|
733
|
-
c.save
|
734
|
-
|
735
|
-
Conekta.mock_rest_client = nil
|
736
|
-
end
|
737
|
-
|
738
|
-
it "charges should have Card objects associated with their Card property" do
|
739
|
-
@mock = double
|
740
|
-
Conekta.mock_rest_client = @mock
|
741
|
-
|
742
|
-
@mock.should_receive(:get){test_response(test_charge)}.once
|
743
|
-
c = Conekta::Charge.retrieve("test_charge")
|
744
|
-
c.card.should be_kind_of(Conekta::ConektaObject)
|
745
|
-
#&& c.card.object == 'card'
|
746
|
-
|
747
|
-
Conekta.mock_rest_client = nil
|
748
|
-
end
|
749
|
-
|
750
|
-
it "execute should return a new, fully executed charge when passed correct parameters" do
|
751
|
-
@mock = double
|
752
|
-
Conekta.mock_rest_client = @mock
|
753
|
-
|
754
|
-
@mock.should_receive(:post){|url, api_key, params|
|
755
|
-
url.should eq("#{Conekta.api_base}/charges.json")
|
756
|
-
api_key.should eq(nil)
|
757
|
-
params = JSON.parse(params).symbolize_keys
|
758
|
-
params[:card] = params[:card].symbolize_keys
|
759
|
-
params.should eq({
|
760
|
-
:currency => 'usd',
|
761
|
-
:amount => 100,
|
762
|
-
:card=>{
|
763
|
-
:number => '4242424242424242',
|
764
|
-
:exp_month => 11,
|
765
|
-
:exp_year => 2012
|
766
|
-
}
|
767
|
-
})
|
768
|
-
|
769
|
-
test_response(test_charge)
|
770
|
-
}.once
|
771
|
-
|
772
|
-
c = Conekta::Charge.create({
|
773
|
-
:amount => 100,
|
774
|
-
:card => {
|
775
|
-
:number => "4242424242424242",
|
776
|
-
:exp_month => 11,
|
777
|
-
:exp_year => 2012,
|
778
|
-
},
|
779
|
-
:currency => "usd"
|
780
|
-
})
|
781
|
-
c.paid.should eq(true)
|
782
|
-
|
783
|
-
Conekta.mock_rest_client = nil
|
784
217
|
end
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
218
|
+
it "test no connection error" do
|
219
|
+
api_url = Conekta::api_base
|
220
|
+
Conekta::api_base = 'http://localhost:3001'
|
221
|
+
begin
|
222
|
+
customer = Conekta::Customer.create({cards: ["tok_test_visa_4242"]})
|
223
|
+
rescue Exception => e
|
224
|
+
e.class_name.should eq("NoConnectionError")
|
225
|
+
end
|
226
|
+
Conekta::api_base = api_url
|
227
|
+
end
|
228
|
+
it "test api error" do
|
229
|
+
begin
|
230
|
+
customer = Conekta::Customer.create({cards: {0=>"tok_test_visa_4242"}})
|
231
|
+
rescue Conekta::Error => e
|
232
|
+
e.class_name.should eq("ApiError")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
it "test authentication error" do
|
236
|
+
Conekta::api_key = ""
|
795
237
|
begin
|
796
|
-
Conekta::
|
797
|
-
rescue Conekta::
|
798
|
-
e.should
|
799
|
-
|
800
|
-
|
238
|
+
customer = Conekta::Customer.create({cards: ["tok_test_visa_4242"]})
|
239
|
+
rescue Conekta::Error => e
|
240
|
+
e.class_name.should eq("AuthenticationError")
|
241
|
+
end
|
242
|
+
Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
243
|
+
end
|
244
|
+
it "test parameter validation error" do
|
245
|
+
begin
|
246
|
+
plan = Conekta::Plan.create({id: 'gold-plan'})
|
247
|
+
rescue Conekta::Error => e
|
248
|
+
e.class_name.should eq("ParameterValidationError")
|
249
|
+
end
|
250
|
+
end
|
251
|
+
it "test processing error" do
|
252
|
+
charge = nil
|
253
|
+
charges = Conekta::Charge.where()
|
254
|
+
charges.each do |(k,v)|
|
255
|
+
if v.status == "pre_authorized"
|
256
|
+
charge = v
|
257
|
+
break
|
258
|
+
end
|
801
259
|
end
|
802
|
-
|
803
|
-
Conekta.mock_rest_client = nil
|
804
|
-
end
|
805
|
-
|
806
|
-
it "5XXs should raise an APIError" do
|
807
|
-
@mock = double
|
808
|
-
Conekta.mock_rest_client = @mock
|
809
|
-
|
810
|
-
response = test_response(test_api_error, 500)
|
811
|
-
@mock.should_receive(:get){raise RestClient::ExceptionWithResponse.new(response, 500)}.once
|
812
|
-
|
813
260
|
begin
|
814
|
-
|
815
|
-
|
816
|
-
|
261
|
+
if charge
|
262
|
+
charge.capture
|
263
|
+
end
|
264
|
+
rescue Conekta::Error => e
|
265
|
+
e.class_name.should eq("ProcessingError")
|
817
266
|
end
|
818
|
-
|
819
|
-
|
820
|
-
end
|
821
|
-
|
822
|
-
it "402s should raise a CardError" do
|
823
|
-
@mock = double
|
824
|
-
Conekta.mock_rest_client = @mock
|
825
|
-
|
826
|
-
response = test_response(test_invalid_exp_year_error, 402)
|
827
|
-
@mock.should_receive(:get){raise RestClient::ExceptionWithResponse.new(response, 402)}.once
|
828
|
-
|
267
|
+
end
|
268
|
+
it "test resource not found error" do
|
829
269
|
begin
|
830
|
-
Conekta::Charge.
|
831
|
-
rescue Conekta::
|
832
|
-
e.should
|
833
|
-
"invalid_expiry_year".should eq(e.code)
|
834
|
-
"exp_year".should eq(e.param)
|
835
|
-
"Your card's expiration year is invalid".should eq(e.message)
|
270
|
+
charge = Conekta::Charge.find(1)
|
271
|
+
rescue Conekta::Error => e
|
272
|
+
e.class_name.should eq("ResourceNotFoundError")
|
836
273
|
end
|
837
|
-
|
838
|
-
|
274
|
+
end
|
275
|
+
end
|
276
|
+
describe :event_tests do
|
277
|
+
p "event tests"
|
278
|
+
it "test succesful where" do
|
279
|
+
events = Conekta::Event.where
|
280
|
+
events.class_name.should eq("ConektaObject")
|
281
|
+
events[0].class_name.should eq("Event")
|
282
|
+
end
|
283
|
+
end
|
284
|
+
describe :token_tests do
|
285
|
+
p "token tests"
|
286
|
+
it "test succesful where" do
|
287
|
+
token = Conekta::Token.find("tok_test_visa_4242")
|
288
|
+
token.class_name.should eq("Token")
|
289
|
+
end
|
290
|
+
end
|
291
|
+
describe :plan_tests do
|
292
|
+
p "plan tests"
|
293
|
+
it "test succesful get plan" do
|
294
|
+
plans = Conekta::Plan.where
|
295
|
+
p = plans.first;
|
296
|
+
plan = Conekta::Plan.find(p.id)
|
297
|
+
plan.class_name.should eq("Plan")
|
298
|
+
end
|
299
|
+
it "test succesful where" do
|
300
|
+
plans = Conekta::Plan.where
|
301
|
+
plans.class_name.should eq("ConektaObject")
|
302
|
+
plans.first.class_name.should eq("Plan")
|
303
|
+
end
|
304
|
+
it "test succesful create plan" do
|
305
|
+
plans = Conekta::Plan.where
|
306
|
+
plan = Conekta::Plan.create({
|
307
|
+
id: "gold-plan#{plans.count}",
|
308
|
+
name: "Gold Plan",
|
309
|
+
amount: 10000,
|
310
|
+
currency: "MXN",
|
311
|
+
interval: "month",
|
312
|
+
frequency: 10,
|
313
|
+
trial_period_days: 15,
|
314
|
+
expiry_count: 12
|
315
|
+
}
|
316
|
+
)
|
317
|
+
plan.class_name.should eq("Plan")
|
318
|
+
end
|
319
|
+
it "test update plan" do
|
320
|
+
plans = Conekta::Plan.where
|
321
|
+
plan = plans.first
|
322
|
+
plan.update({name: "Silver Plan"})
|
323
|
+
plan.name.should eq("Silver Plan")
|
324
|
+
end
|
325
|
+
it "test delete plan" do
|
326
|
+
plans = Conekta::Plan.where
|
327
|
+
plan = plans.first
|
328
|
+
plan.delete
|
329
|
+
plan.deleted.should eq(true)
|
839
330
|
end
|
840
331
|
end
|
841
332
|
end
|