conekta 0.3.7 → 0.4.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODIyZjJhMjlmZWQ2M2I5OWZiNjFhMzNkZjk3YzY2NTQxZTMxZjg2Yg==
4
+ ODc3YTc5NTUzOGQxMjgzMTk3YTNlMjA1NzJiOGIxODFjMDRjNjNjYw==
5
5
  data.tar.gz: !binary |-
6
- ODdiODQ1MzBiN2QyZDU3MjdiZWVhZTBhMTE2ZTYyY2Y1OGI0ZTMyYw==
6
+ NDllYzQyYWU4YTAyZWRjMmNlMDU0YjE3M2E1ZTFmYmMwMjIyZTg1ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjljY2QzODlkZjFhMjIxOWY2NWU5YWFmM2JkZDg4YmNkYzNjMjQxYTRlZjRl
10
- YjMzYjY3Mzg5ZDdlZmMyMzQwZWFkNDUzZmQ3M2UxNjc0YTg2MDQyMWFlZDI4
11
- NDhhNjJhZTM0MGZlNDdkZDdkNDUwMDFiODhlOTJkODRkMWQ1OGM=
9
+ MjdlYzNjMWJhZWExNTllZTEzZDM3OGMxZTE5YjcwOGZiMTFlZWMyY2RmNDdj
10
+ OTIxYjNiZWRjODA3NGNkNTMxODIxYWIzOTc0YmUzMWZiMDVkZjkzZGZiMWE3
11
+ ZmM1YzJiZGMxZTcwYjhjZmRlYzc5MzFhZDEyMzIzZDhkNGUwMGE=
12
12
  data.tar.gz: !binary |-
13
- YzMwMWYyMDhhNjIxMDMxNjRlMDRiZDU3NDRiZDI2MmVmY2ZhOTExYmE1NWQy
14
- ZTk4YzlkOGU5MGM4MjFlMDA3ZWFjODFkNjBhMGJhY2I0NDc0YWUwMmNlZDg0
15
- YTgyMjM1ZTZhY2ZkOTI4NDAxZTRlMTdiNDJjNGY2MDEwYzRlYmI=
13
+ ZGMwYmNhM2FhZWM3YzlhYjUxZGE4ZDg4MTJjMmIyZmU3MjNkNGNhMzUwODY0
14
+ M2RmOGFiZDhhMjY2YjBmZmFjY2JiZDBhMjM5NzI2N2FlYzQ5MTc5NGZlNDU0
15
+ NjE2ZjFlMTViNTY1ZjE5MmY4MTRlMmVlMGQ5ZDEyOTg0MGU1ZWI=
data/CHANGELOG CHANGED
@@ -10,3 +10,9 @@
10
10
  === 0.3.7 2013-01-27
11
11
 
12
12
  * Add api_version= method.
13
+
14
+ === 0.4.0 2014-04-16
15
+
16
+ * Add payout and payee models with specs.
17
+ * Add webhook logs for events.
18
+ * Ameliorate convert_to_conekta_object logic.
data/Gemfile CHANGED
@@ -3,5 +3,6 @@ gem 'sys-uname'
3
3
  gem 'rspec'
4
4
  gem 'faraday'
5
5
  gem 'json'
6
+ gem 'active_support'
6
7
  # Specify your gem's dependencies in conekta.gemspec
7
8
  gemspec
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) and resp.has_key?('object') and types[resp['object']]
19
- instance = types[resp['object']].new()
20
- instance.load_from(resp)
21
- return instance
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.respond_to? :each
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
@@ -1,3 +1,3 @@
1
1
  module Conekta
2
- VERSION = '0.3.7'
2
+ VERSION = '0.4.0'
3
3
  end
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 purchase is 3 MXN pesos for card payments")
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("Token 'tok_test_visa_4241' could not be found.")
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 'unexistent-plan' does not exist and cannot be used to create a new subsription.")
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: "gold-plan#{plans.count}",
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.3.7
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-01-28 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler