conekta 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQ0MDY4MjFjZDhlMmJiNGE0ZjM4ODg1NTEzY2I1NjAxOGM4NTg0MA==
4
+ ODc4YjY0NDAxY2FkMjI4YWE0ZjA0ZDcyNDgyNzZmNzBmYjZkYzgyNw==
5
5
  data.tar.gz: !binary |-
6
- MGIwODM1ZWJjNWE4N2Y2OWM3MjcyNzIxOGJmZjcwNmY0MjA2YjcyOA==
6
+ MDAyYmE3ZjZiNmQ2NmExMTJjMjM4N2U5YmRhMTc5ZmY2NWZkNWU4NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTk3NDg4NDJkYWExOTgwZDM0ZTc5MzA0YWNlNWI4MWNmMzgxNTIyNTA0MmZm
10
- ODkyM2YwMGJlZTc3N2UxNDhjZjkwZTgwYmNjOWRmZDM4ZjFlMzU0MWIzNGU0
11
- NzgxODk4MjE3MGFjMjk3YzRhMzdjNmJjNzQ5MDIwZWNjYmE1NDk=
9
+ MGY0Y2FiYTJlYTg0ZDI4MjZmNDI3ZDgyZjlhYzY3ZjEzOTlhMjhhNTBkODEw
10
+ OTliMGY0N2JiMTZlMDkyODFlNzg3OTM5YTIxNjY3ZTgzMDMyNDhmZDNjNWY2
11
+ MGQ5NjE3YmM1MmYxMTI2YTM4N2U4ZjcyYzVkZmVkZjI1NzAzMWM=
12
12
  data.tar.gz: !binary |-
13
- ZmE1OTFjOTU4YWJhOTQwNDIxZWFiYWNiMzQ0ZTc2YTZhNjE0NzBkZDc2ZjQ3
14
- OWU5MmY4ZDM5YWJkNmRmMjQyOTVhZGM3MzgwYmJjNzBjM2Q4NmE5MDc0N2Ni
15
- M2U4NDlkNDI2OWIxMWU4MWYzNjhiYWVkMWFmNmY5N2YxNDlmNjk=
13
+ YmE0YTE5YmY2NjBmOTM1YmI5OThkZjE2NjFhMTM5YmZmMzQ5YjM0YmVjMDU5
14
+ NGZhNWE5ZWQ1ODUzMzAzMjNiMjk0NTljYmEzYWRlMzg4MTMxOGFiZjQwMjg5
15
+ NWM1MWFiOTUzYWM3M2Y2YjQzYjFiNjljYjkzZTA4YmJjYTE3Zjk=
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conekta (0.3.1)
4
+ conekta (0.3.2)
5
5
  multi_json (>= 1.0.4, < 2)
6
6
  rest-client (~> 1.4)
7
7
 
@@ -1,11 +1,15 @@
1
1
  = Conekta Ruby bindings
2
2
 
3
+ == Update
4
+
5
+ Update to latest version 0.3.2. Earlier versions are deprecated!
6
+
3
7
  == Installation
4
8
 
5
9
  You don't need this source code unless you want to modify the gem. If
6
10
  you want to install the gem via bundler you should add this line to your gemfile:
7
11
 
8
- gem "conekta", "~> 0.3.0"
12
+ gem "conekta", "~> 0.3.2"
9
13
 
10
14
  You can also install this gem by running:
11
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.3
@@ -0,0 +1,205 @@
1
+ Conekta.api_key="1tv5yJp3xnVZ7eK67m4h"
2
+ charge = Conekta::Charge.create({
3
+ "description"=>"Stogies",
4
+ "amount"=> 20000,
5
+ "currency"=>"MXN",
6
+ "reference_id"=>"9839-wolf_pack",
7
+ "card"=> "tok_test_visa_4242"
8
+ })
9
+ #<Conekta::Charge:0x4b8a584> JSON: {
10
+ "id": "529f5c51cfc26cd15f000001",
11
+ "livemode": false,
12
+ "created_at": 1386175569,
13
+ "status": "pending_payment",
14
+ "currency": "MXN",
15
+ "description": "Stogies",
16
+ "reference_id": "9839-wolf_pack",
17
+ "failure_code": null,
18
+ "failure_message": null,
19
+ "object": "charge",
20
+ "amount": 20000,
21
+ "fee": 998,
22
+ "payment_method": {"name":"Fulanito Lopez","exp_month":"12","exp_year":"19","auth_code":null,"object":"card_payment","last4":"4242","brand":"visa"},
23
+ "details": {"name":null,"phone":null,"email":null,"line_items":[]}
24
+ }
25
+ customer = Conekta::Customer.create({"cards"=> ["tok_test_visa_4242"]})
26
+ #<Conekta::Customer:0x4e2cf3a> JSON: {
27
+ "id": "cus_mvWeMJftBGnhuPzPQ",
28
+ "email": null,
29
+ "name": null,
30
+ "phone": null,
31
+ "livemode": false,
32
+ "default_card_id": "card_uHAemUaNvM2pa5Tf",
33
+ "object": "customer",
34
+ "created_at": 1386175612,
35
+ "cards": [
36
+ {"id":"card_uHAemUaNvM2pa5Tf","created_at":1386175612,"active":true,"last4":"4242","object":"card","exp_month":"12","exp_year":"19","brand":"VISA","name":"Fulanito Lopez"}
37
+ ],
38
+ "subscription": null
39
+ }
40
+ customer.cards[0].delete
41
+ #<Conekta::Card:0x4e2c724> JSON: {
42
+ "id": "card_uHAemUaNvM2pa5Tf",
43
+ "created_at": 1386175612,
44
+ "active": true,
45
+ "last4": "4242",
46
+ "object": "card",
47
+ "exp_month": "12",
48
+ "exp_year": "19",
49
+ "brand": "VISA",
50
+ "name": "Fulanito Lopez",
51
+ "deleted": true
52
+ }
53
+ customer.cards
54
+ []
55
+ customer.create_card({"token"=> "tok_test_visa_4242"})
56
+ #<Conekta::Card:0x4ed7b1a> JSON: {
57
+ "id": "card_sQJ67YasvBqywCez",
58
+ "created_at": 1386175697,
59
+ "active": true,
60
+ "last4": "4242",
61
+ "object": "card",
62
+ "exp_month": "12",
63
+ "exp_year": "19",
64
+ "brand": "VISA",
65
+ "name": "Fulanito Lopez"
66
+ }
67
+ customer.cards[0].update(:token => "tok_test_visa_1881")
68
+ #<Conekta::Card:0x4ed7b1a> JSON: {
69
+ "id": "card_sQJ67YasvBqywCez",
70
+ "created_at": 1386175697,
71
+ "active": true,
72
+ "last4": "1881",
73
+ "object": "card",
74
+ "exp_month": "12",
75
+ "exp_year": "19",
76
+ "brand": "VISA",
77
+ "name": "Fulanito Lopez"
78
+ }
79
+ customer.cards
80
+ [#<Conekta::Card:0x4ed7b1a> JSON: {
81
+ "id": "card_sQJ67YasvBqywCez",
82
+ "created_at": 1386175697,
83
+ "active": true,
84
+ "last4": "1881",
85
+ "object": "card",
86
+ "exp_month": "12",
87
+ "exp_year": "19",
88
+ "brand": "VISA",
89
+ "name": "Fulanito Lopez"
90
+ }]
91
+ plan = Conekta::Plan.retrieve("gold-plan")
92
+ #<Conekta::Plan:0x4ee1c00> JSON: {
93
+ "id": "gold-plan",
94
+ "livemode": false,
95
+ "created_at": 1385481591,
96
+ "name": "Gold Plan",
97
+ "amount": 10000,
98
+ "currency": "MXN",
99
+ "interval": "week",
100
+ "frequency": 1,
101
+ "expiry_count": null,
102
+ "trial_period_days": null,
103
+ "object": "plan"
104
+ }
105
+ plan.update({
106
+ :id => "gold-plan",
107
+ :name => "Gold Plan",
108
+ :amount => 20000,
109
+ :currency => "MXN",
110
+ :interval => "month",
111
+ :frequency => 1,
112
+ :trial_period_days => 15,
113
+ :expiry_count => 12})
114
+ #<Conekta::Plan:0x4ee1c00> JSON: {
115
+ "id": "gold-plan",
116
+ "livemode": false,
117
+ "created_at": 1385481591,
118
+ "name": "Gold Plan",
119
+ "amount": 20000,
120
+ "currency": "MXN",
121
+ "interval": "month",
122
+ "frequency": 1,
123
+ "expiry_count": 12,
124
+ "trial_period_days": 15,
125
+ "object": "plan"
126
+ }
127
+ plan
128
+ => #<Conekta::Plan:0x4ee1c00> JSON: {
129
+ "id": "gold-plan",
130
+ "livemode": false,
131
+ "created_at": 1385481591,
132
+ "name": "Gold Plan",
133
+ "amount": 20000,
134
+ "currency": "MXN",
135
+ "interval": "month",
136
+ "frequency": 1,
137
+ "expiry_count": 12,
138
+ "trial_period_days": 15,
139
+ "object": "plan"
140
+ }
141
+ subscription = customer.create_subscription({:plan => "gold-plan"})
142
+ #<Conekta::Subscription:0x4da1ea8> JSON: {
143
+ "id": "sub_GxJJGD5V2fez2sjKP",
144
+ "status": "in_trial",
145
+ "object": "subscription",
146
+ "created_at": 1386175781,
147
+ "start": 1386175781,
148
+ "billing_cycle_start": 1386175781,
149
+ "billing_cycle_end": 1388767781,
150
+ "plan_id": "gold-plan",
151
+ "card_id": "card_sQJ67YasvBqywCez"
152
+ }
153
+ subscription.cancel
154
+ #<Conekta::Subscription:0x4da1ea8> JSON: {
155
+ "id": "sub_GxJJGD5V2fez2sjKP",
156
+ "status": "canceled",
157
+ "object": "subscription",
158
+ "created_at": 1386175781,
159
+ "start": 1386175781,
160
+ "billing_cycle_start": 1386175781,
161
+ "billing_cycle_end": 1388767781,
162
+ "plan_id": "gold-plan",
163
+ "card_id": "card_sQJ67YasvBqywCez",
164
+ "canceled_at": 1386175791
165
+ }
166
+ subscription
167
+ #<Conekta::Subscription:0x4da1ea8> JSON: {
168
+ "id": "sub_GxJJGD5V2fez2sjKP",
169
+ "status": "canceled",
170
+ "object": "subscription",
171
+ "created_at": 1386175781,
172
+ "start": 1386175781,
173
+ "billing_cycle_start": 1386175781,
174
+ "billing_cycle_end": 1388767781,
175
+ "plan_id": "gold-plan",
176
+ "card_id": "card_sQJ67YasvBqywCez",
177
+ "canceled_at": 1386175791
178
+ }
179
+ subscription.pause
180
+ #<Conekta::Subscription:0x4da1ea8> JSON: {
181
+ "id": "sub_GxJJGD5V2fez2sjKP",
182
+ "status": "paused",
183
+ "object": "subscription",
184
+ "created_at": 1386175781,
185
+ "start": 1386175781,
186
+ "billing_cycle_start": 1386175781,
187
+ "plan_id": "gold-plan",
188
+ "card_id": "card_sQJ67YasvBqywCez",
189
+ "canceled_at": 1386175791,
190
+ "paused_at": 1386175833
191
+ }
192
+ subscription.resume
193
+ #<Conekta::Subscription:0x4da1ea8> JSON: {
194
+ "id": "sub_GxJJGD5V2fez2sjKP",
195
+ "status": "active",
196
+ "object": "subscription",
197
+ "created_at": 1386175781,
198
+ "start": 1386175781,
199
+ "billing_cycle_start": 1386175781,
200
+ "plan_id": "gold-plan",
201
+ "card_id": "card_sQJ67YasvBqywCez",
202
+ "canceled_at": 1386175791,
203
+ "billing_cycle_end": 1388767798
204
+ }
205
+
@@ -1,24 +1,17 @@
1
1
  module Conekta
2
2
  module APIOperations
3
3
  module CreateMember
4
- module ClassMethods
5
- def create_member(member, params={}, api_key=nil)
6
- path = "#{path}/#{member}"
7
- response, api_key = Conekta.request(:post, path, api_key, params)
8
- obj = Util.convert_to_conekta_object(response, api_key)
9
- obj.try("#{parent}".to_sym) = self
10
- if obj.class == ConektaObject
11
- count = self.try("#{member}".to_sym).count
12
- self.try("#{member}".to_sym)[count] = obj
13
- else
14
- self.try("#{member}".to_sym) = obj
15
- end
16
- obj
4
+ def create_member(member, params={}, api_key=nil)
5
+ path = "/customers/#{self.id}/#{member}"
6
+ response, api_key = Conekta.request(:post, path, api_key, params)
7
+ obj = Util.convert_to_conekta_object(response, api_key)
8
+ if obj.class == ConektaObject
9
+ count = self.cards.count
10
+ self.cards[count] = obj
11
+ else
12
+ self.subscription = obj
17
13
  end
18
- end
19
-
20
- def self.included(base)
21
- base.extend(ClassMethods)
14
+ obj
22
15
  end
23
16
  end
24
17
  end
@@ -1,17 +1,11 @@
1
1
  module Conekta
2
2
  module APIOperations
3
3
  module ModifyMember
4
- module ClassMethods
5
- def modify_member(parent, member, params={}, action, method, api_key=nil)
6
- path = "#{path}/#{member}/#{action}"
7
- response, api_key = Conekta.request(method.to_sym, path, api_key, params)
8
- self.try("#{parent}".to_sym).try("#{member}".to_sym) = self
9
- self
10
- end
11
- end
12
-
13
- def self.included(base)
14
- base.extend(ClassMethods)
4
+ def modify_member(member, action, params={}, api_key=nil)
5
+ path = "/customers/#{customer.id}/#{member}/#{action}"
6
+ response, api_key = Conekta.request("post", path, api_key, {:foo => "var"})
7
+ refresh_from(response, api_key)
8
+ self
15
9
  end
16
10
  end
17
11
  end
@@ -11,6 +11,12 @@ module Conekta
11
11
  end
12
12
  self
13
13
  end
14
+
15
+ def update(params={})
16
+ response, api_key = Conekta.request(:put, url, @api_key, params)
17
+ refresh_from(response, api_key)
18
+ self
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -2,6 +2,16 @@ module Conekta
2
2
  class Card < APIResource
3
3
  include Conekta::APIOperations::Update
4
4
 
5
+ attr_accessor :customer
6
+
7
+ def customer
8
+ @customer
9
+ end
10
+
11
+ def customer=(customer)
12
+ @customer = customer
13
+ end
14
+
5
15
  def delete
6
16
  response, api_key = Conekta.request(:delete, url, @api_key)
7
17
  refresh_from(response, api_key)
@@ -6,12 +6,29 @@ module Conekta
6
6
  include Conekta::APIOperations::List
7
7
  include Conekta::APIOperations::CreateMember
8
8
 
9
+ def refresh_from(values, api_key, partial=false)
10
+ super
11
+ customer = self
12
+ for i in 0..(customer.cards.count - 1)
13
+ customer.cards[i].customer = customer
14
+ end
15
+ if customer.subscription
16
+ customer.subscription.customer = customer
17
+ end
18
+ end
19
+
9
20
  def create_subscription(params={})
10
- self.create_member('subscription', params)
21
+ subscription = create_member('subscription', params)
22
+ subscription.customer = self
23
+ self.subscription = subscription
24
+ subscription
11
25
  end
12
26
 
13
27
  def create_card(params={})
14
- self.create_member('cards', params)
28
+ card = create_member('cards', params)
29
+ card.customer = self
30
+ self.cards << card
31
+ card
15
32
  end
16
33
  end
17
34
  end
@@ -3,16 +3,26 @@ module Conekta
3
3
  include Conekta::APIOperations::Update
4
4
  include Conekta::APIOperations::ModifyMember
5
5
 
6
+ attr_accessor :customer
7
+
8
+ def customer
9
+ @customer
10
+ end
11
+
12
+ def customer=(customer)
13
+ @customer = customer
14
+ end
15
+
6
16
  def cancel
7
- self.modify_member("customer", "subscription", nil, "cancel", "post")
17
+ self.modify_member("subscription", "cancel")
8
18
  end
9
19
 
10
20
  def pause
11
- self.modify_member("customer", "subscription", nil, "pause", "post")
21
+ subscription = self.modify_member("subscription", "pause")
12
22
  end
13
23
 
14
24
  def resume
15
- self.modify_member("customer", "subscription", nil, "resume", "post")
25
+ subscription = self.modify_member("subscription", "resume")
16
26
  end
17
27
 
18
28
  def url
@@ -18,7 +18,11 @@ module Conekta
18
18
  def self.object_classes
19
19
  @object_classes ||= {
20
20
  'charge' => Charge,
21
- 'list' => ListObject
21
+ 'list' => ListObject,
22
+ 'card' => Card,
23
+ 'subscription' => Subscription,
24
+ 'customer' => Customer,
25
+ 'plan' => Plan
22
26
  }
23
27
  end
24
28
 
@@ -1,3 +1,3 @@
1
1
  module Conekta
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conekta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Fischer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2013-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -93,6 +93,7 @@ email:
93
93
  - mauricio@conekta.com
94
94
  executables:
95
95
  - conekta-console
96
+ - test calls
96
97
  extensions: []
97
98
  extra_rdoc_files: []
98
99
  files:
@@ -106,6 +107,7 @@ files:
106
107
  - Rakefile
107
108
  - VERSION
108
109
  - bin/conekta-console
110
+ - bin/test calls
109
111
  - conekta.gemspec
110
112
  - gemfiles/default-with-activesupport.gemfile
111
113
  - gemfiles/json.gemfile
@@ -113,11 +115,15 @@ files:
113
115
  - lib/conekta.rb
114
116
  - lib/conekta/account.rb
115
117
  - lib/conekta/api_operations/create.rb
118
+ - lib/conekta/api_operations/create.rb~
116
119
  - lib/conekta/api_operations/create_member.rb
120
+ - lib/conekta/api_operations/create_member.rb~
117
121
  - lib/conekta/api_operations/delete.rb
118
122
  - lib/conekta/api_operations/list.rb
119
123
  - lib/conekta/api_operations/modify_member.rb
124
+ - lib/conekta/api_operations/modify_member.rb~
120
125
  - lib/conekta/api_operations/update.rb
126
+ - lib/conekta/api_operations/update.rb~
121
127
  - lib/conekta/api_resource.rb
122
128
  - lib/conekta/card.rb
123
129
  - lib/conekta/charge.rb