openpay 0.9.8 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/.rakeTasks +1 -1
  3. data/.idea/OpenPay.iml +76 -79
  4. data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +1 -1
  5. data/.idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml +39 -0
  6. data/.idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml +37 -0
  7. data/.idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml +37 -0
  8. data/.idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml +37 -0
  9. data/.idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml +39 -0
  10. data/.idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml +37 -0
  11. data/.idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml +37 -0
  12. data/.idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml +37 -0
  13. data/.idea/runConfigurations/all_specs.xml +1 -1
  14. data/.idea/runConfigurations/install_open_pay.xml +26 -0
  15. data/.idea/runConfigurations/scrapbook.xml +26 -0
  16. data/.travis.yml +3 -0
  17. data/Gemfile +0 -1
  18. data/README.md +398 -28
  19. data/Rakefile +12 -1
  20. data/lib/OpenPay/Charges.rb +1 -3
  21. data/lib/OpenPay/errors/openpay_connection_exception.rb +1 -1
  22. data/lib/OpenPay/errors/{open_pay_exception.rb → openpay_exception.rb} +2 -24
  23. data/lib/OpenPay/errors/{open_pay_exception_factory.rb → openpay_exception_factory.rb} +0 -0
  24. data/lib/OpenPay/errors/openpay_transaction_exception.rb +1 -1
  25. data/lib/OpenPay/openpay_api.rb +2 -2
  26. data/lib/openpay.rb +4 -4
  27. data/lib/version.rb +6 -0
  28. data/{OpenPay.gemspec → openpay.gemspec} +5 -3
  29. data/test/Factories.rb +3 -3
  30. data/test/spec/bankaccounts_spec.rb +1 -1
  31. data/test/spec/cards_spec.rb +43 -8
  32. data/test/spec/charges_spec.rb +29 -17
  33. data/test/spec/customers_spec.rb +1 -1
  34. data/test/spec/exceptions_spec.rb +1 -1
  35. data/test/spec/fees_spec.rb +5 -2
  36. data/test/spec/payouts_spec.rb +2 -2
  37. data/test/spec/plans_spec.rb +2 -56
  38. data/test/spec/subscriptions_spec.rb +1 -1
  39. data/test/spec/transfers_spec.rb +1 -3
  40. data/test/spec_helper.rb +1 -1
  41. metadata +19 -7
  42. data/lib/OpenPay/version.rb +0 -3
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+
5
+
6
+ task :default => [:spec]
7
+
8
+ desc 'run specifications'
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = 'test/spec/*'
11
+ end
12
+
@@ -37,13 +37,11 @@ class Charges < OpenPayResource
37
37
  customers=@api_hook.create(:customers)
38
38
  customers.capture_charge(customer_id,transaction_id )
39
39
  else
40
- post(description, transaction_id+'/capture')
40
+ post( '',transaction_id+'/capture')
41
41
  end
42
42
  end
43
43
 
44
44
 
45
-
46
-
47
45
  def each(customer_id=nil)
48
46
  if customer_id
49
47
  all(customer_id).each do |card|
@@ -1,3 +1,3 @@
1
- require 'openpay/errors/open_pay_exception'
1
+ require 'openpay/errors/openpay_exception'
2
2
  class OpenpayConnectionException < OpenpayException
3
3
  end
@@ -1,4 +1,5 @@
1
1
  class OpenpayException < StandardError
2
+
2
3
  attr_reader :description
3
4
  attr_reader :http_code
4
5
  attr_reader :http_body
@@ -6,11 +7,10 @@ class OpenpayException < StandardError
6
7
  attr_reader :error_code
7
8
  attr_reader :category
8
9
 
9
-
10
10
  def initialize(message=nil,json_message=true)
11
11
  #openpay errors have a json error string
12
12
  if json_message
13
- json= JSON.parse message
13
+ json= JSON.parse message
14
14
  @description = json['description']
15
15
  @http_code = json['http_code']
16
16
  @error_code = json['error_code']
@@ -26,26 +26,4 @@ class OpenpayException < StandardError
26
26
  end
27
27
  end
28
28
 
29
-
30
-
31
- =begin
32
- rescue RestClient::BadRequest => e
33
- oe=OpenpayTransactionException.new(e.message,e.http_code,e.http_body,e.http_body)
34
- LOG.warn e.http_body
35
- @errors=true
36
- raise oe
37
- rescue RestClient::BadGateway => e
38
- oe=OpenpayConnectionException.new(e.message,e.http_code,e.http_body,e.http_body)
39
- LOG.warn e.http_body
40
- @errors=true
41
- raise oe
42
- rescue RestClient::Exception => e
43
- oe=OpenpayApiError.new(e.message,e.http_code,e.http_body,e.http_body)
44
- LOG.warn e.http_body
45
- @errors=true
46
- raise oe
47
- =end
48
-
49
-
50
-
51
29
  end
@@ -1,4 +1,4 @@
1
- require 'openpay/errors/open_pay_exception'
1
+ require 'openpay/errors/openpay_exception'
2
2
 
3
3
  class OpenpayTransactionException < OpenpayException
4
4
 
@@ -3,14 +3,14 @@ require 'open_pay_resource_factory'
3
3
  require 'base64'
4
4
  require 'rest-client'
5
5
  require 'uri'
6
- require 'errors/open_pay_exception'
6
+ require 'openpay/errors/openpay_exception'
7
7
 
8
8
 
9
9
  LOG= Logger.new(STDOUT)
10
10
 
11
11
  #change to Logger::DEBUG if need trace information
12
12
  #due the nature of the information, we recommend to never use a log file when in debug
13
- LOG.level=Logger::DEBUG
13
+ LOG.level=Logger::INFO
14
14
 
15
15
 
16
16
  class OpenpayApi
@@ -1,5 +1,5 @@
1
1
  #openpay version
2
- require 'openpay/version'
2
+ require 'version'
3
3
 
4
4
  #external dependencies
5
5
  require 'rest-client'
@@ -26,9 +26,9 @@ module Openpay
26
26
  require 'openpay/charges'
27
27
 
28
28
  #exceptions
29
- require 'openpay/errors/open_pay_exception_factory'
30
- require 'openpay/errors/open_pay_exception'
29
+ require 'openpay/errors/openpay_exception_factory'
30
+ require 'openpay/errors/openpay_exception'
31
31
  require 'openpay/errors/openpay_transaction_exception'
32
32
  require 'openpay/errors/openpay_connection_exception'
33
33
 
34
- end
34
+ end
@@ -0,0 +1,6 @@
1
+ module Openpay
2
+
3
+ # Dec 31 2014, 6:00 PM Qro Local time.
4
+ # 97 test cases passed / 275.232 secs
5
+ VERSION = '1.0.1'
6
+ end
@@ -1,14 +1,16 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'openpay/version'
4
+
5
+ require 'version'
6
+
5
7
 
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = "openpay"
8
10
  spec.version = Openpay::VERSION
9
11
  spec.authors = ["ronnie_bermejo"]
10
12
  spec.email = ["ronnie.bermejo.mx@gmail.com"]
11
- spec.description = %q{ruby client for Openpay API services (version 1.0.0)}
13
+ spec.description = %q{ruby client for Openpay API services (version 1.0.1)}
12
14
  spec.summary = %q{ruby api for openpay resources}
13
15
  spec.homepage = "http://openpay.mx/"
14
16
  spec.license = "Apache"
@@ -16,7 +18,7 @@ Gem::Specification.new do |spec|
16
18
  spec.files = `git ls-files`.split($/)
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
20
  spec.test_files = spec.files.grep(%r{^(test|spec)/})
19
- spec.require_paths = ["lib","lib/openpay"]
21
+ spec.require_paths = ["lib","lib/openpay",'openpay']
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
@@ -165,8 +165,8 @@ FactoryGirl.define do
165
165
 
166
166
 
167
167
  factory :refund_description, class:Hash do
168
- description 'A petición del cliente'
169
- initialize_with { attributes }
168
+ description 'A peticion del cliente'
169
+ initialize_with { attributes }
170
170
 
171
171
  end
172
172
 
@@ -174,7 +174,7 @@ FactoryGirl.define do
174
174
  factory :fee, class:Hash do
175
175
  customer_id 'dvocf97jd20es3tw5laz'
176
176
  amount '12.50'
177
- description 'Cobro de Comisión'
177
+ description 'Cobro de Comision'
178
178
  initialize_with { attributes }
179
179
 
180
180
  end
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
 
4
4
  describe Bankaccounts do
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
 
4
4
  describe Cards do
@@ -13,6 +13,9 @@ describe Cards do
13
13
  @cards=@openpay.create(:cards)
14
14
  @customers=@openpay.create(:customers)
15
15
 
16
+ @cards.delete_all
17
+
18
+
16
19
  end
17
20
 
18
21
  after(:all) do
@@ -140,20 +143,53 @@ describe Cards do
140
143
 
141
144
  describe '.each' do
142
145
 
143
- it 'list all existing merchant cards' do
146
+ it 'iterates over all existing merchant cards' do
144
147
  @cards.each do |card|
145
148
  expect(card['expiration_year']).to match '14'
146
149
  end
147
150
  end
148
151
 
149
152
 
153
+ it 'iterates over all existing customer cards' do
154
+
155
+
156
+
157
+ #creates a customer
158
+ card_hash = FactoryGirl.build(:valid_card, holder_name: 'Pepe')
159
+ customers=@openpay.create(:customers)
160
+ customer_hash = FactoryGirl.build(:customer)
161
+ customer=customers.create(customer_hash)
162
+
163
+ #creates a customer card
164
+ card=@cards.create(card_hash, customer['id'])
165
+ expect(card).to be_a(Hash)
166
+
167
+ @cards.each(customer['id']) do |c|
168
+ expect(c['expiration_year']).to match '14'
169
+ end
170
+
171
+
172
+ #cleanup
173
+ @cards.delete(card['id'],customer['id'])
174
+ @customers.delete(customer['id'])
175
+
176
+
177
+
178
+
179
+ end
180
+
181
+
182
+
183
+
184
+
150
185
  end
151
186
 
152
187
 
153
188
  describe '.delete' do
154
189
 
155
190
 
156
- it 'deletes a customer card' do
191
+ it 'deletes a merchant card' do
192
+
157
193
  #creates merchant card
158
194
  card_hash = FactoryGirl.build(:valid_card)
159
195
  cards=@cards.create(card_hash)
@@ -163,12 +199,11 @@ describe Cards do
163
199
  name='Vicente Olmos'
164
200
 
165
201
  #perform check
166
- card=@cards.get(id)
167
- expect(card['holder_name']).to match(name)
168
- expect(card['card_number']).to match('1111')
169
202
 
170
- #cleanup
171
- @cards.delete(card['id'])
203
+ card=@cards.delete(id)
204
+ expect { @cards.get(id) }.to raise_exception(OpenpayTransactionException)
205
+
206
+
172
207
  end
173
208
 
174
209
 
@@ -1,5 +1,5 @@
1
1
 
2
- require '../spec_helper'
2
+ require './test/spec_helper'
3
3
 
4
4
  describe Charges do
5
5
 
@@ -198,7 +198,31 @@ describe Charges do
198
198
 
199
199
  describe '.capture' do
200
200
 
201
- it 'captures an existing merchant charge' do
201
+
202
+ it 'captures a merchant card charge' do
203
+
204
+ #create new customer
205
+ customer_hash= FactoryGirl.build(:customer)
206
+ customer=@customers.create(customer_hash)
207
+
208
+ #create merchant card
209
+ card_hash=FactoryGirl.build(:valid_card)
210
+ card=@cards.create(card_hash)
211
+
212
+ #create merchant charge
213
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000,capture:'false')
214
+ charge=@charges.create(charge_hash)
215
+
216
+ #capture merchant charge
217
+ @charges.capture(charge['id'])
218
+
219
+ #clean up
220
+ @cards.delete(card['id'])
221
+ @customers.delete(customer['id'])
222
+
223
+ end
224
+
225
+ it 'captures an customer card charge' do
202
226
  #create new customer
203
227
  customer_hash= FactoryGirl.build(:customer)
204
228
  customer=@customers.create(customer_hash)
@@ -208,14 +232,11 @@ describe Charges do
208
232
  card=@cards.create(card_hash,customer['id'])
209
233
 
210
234
  #create charge
211
- charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000)
235
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'],amount: 4000,capture:'false')
212
236
  charge=@charges.create(charge_hash,customer['id'])
213
237
 
214
- #capture charge
215
- captured_charge=@charges.capture(charge['id'],customer['id'])
216
- p captured_charge
217
-
218
-
238
+ #capture customer charge
239
+ @charges.capture(charge['id'],customer['id'])
219
240
 
220
241
  #clean up
221
242
  @cards.delete(card['id'],customer['id'])
@@ -223,15 +244,6 @@ describe Charges do
223
244
  end
224
245
 
225
246
 
226
- it 'fails to capture an non existing merchant charge' do
227
- pending 'check if the cancel method in reality works, documentation has some discrepancies'
228
- end
229
-
230
-
231
-
232
- it 'captures an existing customer charge' do
233
- pending 'check if the cancel method in reality works, documentation has some discrepancies'
234
- end
235
247
 
236
248
 
237
249
  end
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
 
4
4
  describe Customers do
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
 
4
4
  describe 'Openpay Exceptions' do
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
  describe Fees do
4
4
 
@@ -69,7 +69,7 @@ describe Fees do
69
69
  @charges.create(charge_hash, customer['id'])
70
70
 
71
71
  #create customer fee using json
72
- fee_json =%^{"customer_id":"#{customer['id']}","amount":"12.50","description":"Cobro de Comisión"}^
72
+ fee_json =%^{"customer_id":"#{customer['id']}","amount":"12.50","description":"Cobro de Comision"}^
73
73
  #performs check , it returns json
74
74
  expect(@fees.create(fee_json)).to have_json_path('amount')
75
75
 
@@ -77,6 +77,9 @@ describe Fees do
77
77
 
78
78
  end
79
79
 
80
+
81
+
82
+
80
83
  describe '.all' do
81
84
 
82
85
  it 'get all fees' do
@@ -1,5 +1,5 @@
1
1
 
2
- require '../spec_helper'
2
+ require './test/spec_helper'
3
3
 
4
4
  describe Payouts do
5
5
 
@@ -144,7 +144,7 @@ describe Payouts do
144
144
  expect(@payouts.all.last['transaction_type']) .to match 'payout'
145
145
  end
146
146
 
147
- it 'all customer payout' do
147
+ it 'all customer payouts' do
148
148
  #create new customer
149
149
  customer_hash= FactoryGirl.build(:customer)
150
150
  customer=@customers.create(customer_hash)
@@ -1,4 +1,4 @@
1
- require '../spec_helper'
1
+ require './test/spec_helper'
2
2
 
3
3
  describe Plans do
4
4
 
@@ -166,61 +166,7 @@ describe Plans do
166
166
  end
167
167
 
168
168
 
169
- #
170
- #describe 'all_subscriptions' do
171
- #
172
- #
173
- # it 'returns all subscriptions for a given plan' do
174
- # #creates a plan
175
- # plan_hash= FactoryGirl.build(:plan, trial_days: 10)
176
- # plan=@plans.create(plan_hash)
177
- # expect(@plans.all_subscriptions(plan['id']).size).to be 0
178
- #
179
- #
180
- # #creates subscriptions
181
- #
182
- # subscription_hash= FactoryGirl.build(:subscription)
183
- #
184
- # @subscriptions.create(subscription_hash,plan['id'])
185
- # @subscriptions.create(subscription_hash,plan['id'])
186
- #
187
- # expect(@plans.all_subscriptions(plan['id'])).to be 2
188
- #
189
- # @plans.delete_all(customer['id'])
190
- # expect(@plans.all_subscriptions(plan['id'])).to be 0
191
- #
192
- # end
193
- #
194
- #
195
- #end
196
- #
197
- #describe '.each_subscription' do
198
- #
199
- #
200
- # it 'itereates over all subscriptions for a given plan' do
201
- #
202
- # #creates a plan
203
- # plan_hash= FactoryGirl.build(:plan, trial_days: 10)
204
- # plan=@plans.create(plan_hash)
205
- #
206
- #
207
- # #creates subscriptions
208
- #
209
- # customer_hash= FactoryGirl.build(:subscription)
210
- #
211
- # @subscriptions.create(subscription_hash)
212
- # @subscriptions.create(subscription_hash)
213
- #
214
- #
215
- # it 'iterates over all paln subscription' do
216
- #
217
- # @plans.each_subscription do |subscription|
218
- # pending 'no esta bien algo le falta'
219
- # end
220
- #
221
- # end
222
- # end
223
- #end
169
+
224
170
 
225
171
  end
226
172