conekta 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG +6 -0
- data/Gemfile +1 -0
- data/lib/conekta.rb +7 -1
- data/lib/conekta/conekta_object.rb +1 -1
- data/lib/conekta/util.rb +31 -6
- data/lib/conekta/version.rb +1 -1
- data/spec/conekta_spec.rb +67 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODc3YTc5NTUzOGQxMjgzMTk3YTNlMjA1NzJiOGIxODFjMDRjNjNjYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDllYzQyYWU4YTAyZWRjMmNlMDU0YjE3M2E1ZTFmYmMwMjIyZTg1ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjdlYzNjMWJhZWExNTllZTEzZDM3OGMxZTE5YjcwOGZiMTFlZWMyY2RmNDdj
|
10
|
+
OTIxYjNiZWRjODA3NGNkNTMxODIxYWIzOTc0YmUzMWZiMDVkZjkzZGZiMWE3
|
11
|
+
ZmM1YzJiZGMxZTcwYjhjZmRlYzc5MzFhZDEyMzIzZDhkNGUwMGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGMwYmNhM2FhZWM3YzlhYjUxZGE4ZDg4MTJjMmIyZmU3MjNkNGNhMzUwODY0
|
14
|
+
M2RmOGFiZDhhMjY2YjBmZmFjY2JiZDBhMjM5NzI2N2FlYzQ5MTc5NGZlNDU0
|
15
|
+
NjE2ZjFlMTViNTY1ZjE5MmY4MTRlMmVlMGQ5ZDEyOTg0MGU1ZWI=
|
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/lib/conekta.rb
CHANGED
@@ -23,9 +23,15 @@ require "conekta/subscription"
|
|
23
23
|
require "conekta/plan"
|
24
24
|
require "conekta/token"
|
25
25
|
require "conekta/event"
|
26
|
+
require "conekta/payee"
|
27
|
+
require "conekta/payout"
|
28
|
+
require "conekta/payout_method"
|
29
|
+
require "conekta/method"
|
30
|
+
require "conekta/webhook_log"
|
26
31
|
|
27
32
|
module Conekta
|
28
|
-
@api_base = 'https://api.conekta.io'
|
33
|
+
# @api_base = 'https://api.conekta.io'
|
34
|
+
@api_base = 'http://localhost:3000'
|
29
35
|
@api_version = '0.3.0'
|
30
36
|
def self.api_base
|
31
37
|
@api_base
|
@@ -73,7 +73,7 @@ module Conekta
|
|
73
73
|
end
|
74
74
|
def load_from_enumerable(k,v)
|
75
75
|
if v.respond_to? :each and !v.instance_of?(ConektaObject)
|
76
|
-
v = Conekta::Util.convert_to_conekta_object(v)
|
76
|
+
v = Conekta::Util.convert_to_conekta_object(k,v)
|
77
77
|
end
|
78
78
|
if self.instance_of?(ConektaObject)
|
79
79
|
self[k] = v
|
data/lib/conekta/util.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
require 'active_support/inflector'
|
1
2
|
module Conekta
|
2
3
|
module Util
|
3
4
|
def self.types
|
4
5
|
@types ||= {
|
6
|
+
'webhook_log' => WebhookLog,
|
7
|
+
'bank_transfer_payout_method' => Method,
|
8
|
+
'payout' => Payout,
|
9
|
+
'payee' => Payee,
|
10
|
+
'payout_method' => PayoutMethod,
|
5
11
|
'bank_transfer_payment' => PaymentMethod,
|
6
12
|
'card_payment' => PaymentMethod,
|
7
13
|
'cash_payment' => PaymentMethod,
|
@@ -14,15 +20,34 @@ module Conekta
|
|
14
20
|
'event' => Event
|
15
21
|
}
|
16
22
|
end
|
17
|
-
def self.convert_to_conekta_object(resp)
|
18
|
-
if resp.kind_of?(Hash)
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
def self.convert_to_conekta_object(name,resp)
|
24
|
+
if resp.kind_of?(Hash)
|
25
|
+
if resp.has_key?('object') and types[resp['object']]
|
26
|
+
instance = types[resp['object']].new()
|
27
|
+
instance.load_from(resp)
|
28
|
+
return instance
|
29
|
+
elsif name.instance_of? String
|
30
|
+
name = "event_data" if name.camelize == "Data"
|
31
|
+
name = "obj" if name.camelize == "Object"
|
32
|
+
if !Object.const_defined?(name.camelize)
|
33
|
+
instance = Object.const_set(name.camelize, Class.new(ConektaObject)).new
|
34
|
+
else
|
35
|
+
instance = name.camelize.constantize.new
|
36
|
+
end
|
37
|
+
instance.load_from(resp)
|
38
|
+
return instance
|
39
|
+
end
|
22
40
|
end
|
23
|
-
if resp.
|
41
|
+
if resp.kind_of?(Array)
|
24
42
|
instance = ConektaObject.new
|
25
43
|
instance.load_from(resp)
|
44
|
+
if !resp.empty? and resp.first.instance_of? Hash and !resp.first["object"]
|
45
|
+
resp.each_with_index do |r, i|
|
46
|
+
obj = convert_to_conekta_object(name,r)
|
47
|
+
instance.set_val(i,obj)
|
48
|
+
instance[i] = obj
|
49
|
+
end
|
50
|
+
end
|
26
51
|
return instance
|
27
52
|
end
|
28
53
|
return instance
|
data/lib/conekta/version.rb
CHANGED
data/spec/conekta_spec.rb
CHANGED
@@ -1,6 +1,66 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
describe :conekta_tests do
|
3
3
|
Conekta.api_key = '1tv5yJp3xnVZ7eK67m4h'
|
4
|
+
describe :payouts_tests do
|
5
|
+
p "payout 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 payout" do
|
12
|
+
payee = Conekta::Payee.create(name: "John Doe",
|
13
|
+
email: "j_d@radcorp.com",
|
14
|
+
phone: "555555555",
|
15
|
+
bank: {
|
16
|
+
account_number: '123456789012345678',
|
17
|
+
account_holder: 'J D - Radcorp',
|
18
|
+
bank: 'Banorte',
|
19
|
+
description: 'Conekta To JD',
|
20
|
+
statement_description: 'Conekta To JD 111111111',
|
21
|
+
statement_reference: '111111111'
|
22
|
+
},
|
23
|
+
billing_address:{
|
24
|
+
company_name: 'Rad Corp',
|
25
|
+
tax_id: 'tax121212abc',
|
26
|
+
street1: 'Guadalupe 73',
|
27
|
+
street2: 'Despacho 32',
|
28
|
+
street3: 'Condesa',
|
29
|
+
city: 'Cuauhtemoc',
|
30
|
+
state: 'DF',
|
31
|
+
country: 'MX',
|
32
|
+
zip: '06100'
|
33
|
+
})
|
34
|
+
payee.class.class_name.should eq("Payee")
|
35
|
+
|
36
|
+
payee.phone.should eq("555555555")
|
37
|
+
payee.payout_methods.first.account_number.should eq('123456789012345678')
|
38
|
+
payee.payout_methods.first.account_holder.should eq('J D - Radcorp')
|
39
|
+
payee.payout_methods.first.bank.should eq('Banorte')
|
40
|
+
payee.default_payout_method_id.should_not eq(nil)
|
41
|
+
|
42
|
+
payee.payout_methods.first.description.should eq('Conekta To JD')
|
43
|
+
payee.payout_methods.first.statement_description.should eq('Conekta To JD 111111111')
|
44
|
+
payee.payout_methods.first.statement_reference.should eq('111111111')
|
45
|
+
|
46
|
+
payee.billing_address.company_name.should eq('Rad Corp')
|
47
|
+
payee.billing_address.tax_id.should eq('tax121212abc')
|
48
|
+
payee.billing_address.zip.should eq('06100')
|
49
|
+
|
50
|
+
payout = Conekta::Payout.create(amount: 5000,
|
51
|
+
currency: "MXN",
|
52
|
+
payee: payee.id)
|
53
|
+
payout.class.class_name.should eq("Payout")
|
54
|
+
payout.amount.should eq(5000)
|
55
|
+
payout.currency.should eq("MXN")
|
56
|
+
|
57
|
+
payout.method.account_number.should eq('123456789012345678')
|
58
|
+
payout.method.account_holder.should eq('J D - Radcorp')
|
59
|
+
payout.method.bank.should eq('Banorte')
|
60
|
+
# payout.payout_transaction_id.should_not eq(nil)
|
61
|
+
payout.transactions.count.should eq(0)
|
62
|
+
end
|
63
|
+
end
|
4
64
|
describe :charge_tests do
|
5
65
|
p "charge tests"
|
6
66
|
before :each do
|
@@ -45,7 +105,7 @@ describe :conekta_tests do
|
|
45
105
|
begin
|
46
106
|
cpm = Conekta::Charge.create(pm.merge(card))
|
47
107
|
rescue Conekta::Error => e
|
48
|
-
e.message.should eq("The minimum
|
108
|
+
e.message.should eq("The minimum for card payments is 3 pesos. Check that the amount is in cents as explained in the documentation.")
|
49
109
|
end
|
50
110
|
end
|
51
111
|
it "test susccesful refund" do
|
@@ -117,7 +177,7 @@ describe :conekta_tests do
|
|
117
177
|
:cards => ["tok_test_visa_4241"],
|
118
178
|
})
|
119
179
|
rescue Conekta::Error => e
|
120
|
-
e.message.should eq("
|
180
|
+
e.message.should eq("Object tok_test_visa_4241 could not be found.")
|
121
181
|
end
|
122
182
|
end
|
123
183
|
it "add card to customer" do
|
@@ -178,7 +238,7 @@ describe :conekta_tests do
|
|
178
238
|
begin
|
179
239
|
subscription = customer.create_subscription({plan: 'unexistent-plan'})
|
180
240
|
rescue Conekta::Error => e
|
181
|
-
e.message.should eq("Plan
|
241
|
+
e.message.should eq("Object Plan unexistent-plan could not be found.")
|
182
242
|
end
|
183
243
|
end
|
184
244
|
it "test succesful pause subscription" do
|
@@ -279,14 +339,13 @@ describe :conekta_tests do
|
|
279
339
|
events = Conekta::Event.where
|
280
340
|
events.class_name.should eq("ConektaObject")
|
281
341
|
events[0].class_name.should eq("Event")
|
342
|
+
if !events[0].webhook_logs.empty?
|
343
|
+
events[0].webhook_logs.first.class_name.should eq("WebhookLog")
|
344
|
+
end
|
282
345
|
end
|
283
346
|
end
|
284
347
|
describe :token_tests do
|
285
348
|
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
349
|
end
|
291
350
|
describe :plan_tests do
|
292
351
|
p "plan tests"
|
@@ -304,7 +363,7 @@ describe :conekta_tests do
|
|
304
363
|
it "test succesful create plan" do
|
305
364
|
plans = Conekta::Plan.where
|
306
365
|
plan = Conekta::Plan.create({
|
307
|
-
id:
|
366
|
+
id: ((0...8).map { (65 + rand(26)).chr }.join),
|
308
367
|
name: "Gold Plan",
|
309
368
|
amount: 10000,
|
310
369
|
currency: "MXN",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conekta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MauricioMurga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|