openpay 0.9.8 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.rakeTasks +1 -1
- data/.idea/OpenPay.iml +76 -79
- data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +1 -1
- data/.idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml +39 -0
- data/.idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml +39 -0
- data/.idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/all_specs.xml +1 -1
- data/.idea/runConfigurations/install_open_pay.xml +26 -0
- data/.idea/runConfigurations/scrapbook.xml +26 -0
- data/.travis.yml +3 -0
- data/Gemfile +0 -1
- data/README.md +398 -28
- data/Rakefile +12 -1
- data/lib/OpenPay/Charges.rb +1 -3
- data/lib/OpenPay/errors/openpay_connection_exception.rb +1 -1
- data/lib/OpenPay/errors/{open_pay_exception.rb → openpay_exception.rb} +2 -24
- data/lib/OpenPay/errors/{open_pay_exception_factory.rb → openpay_exception_factory.rb} +0 -0
- data/lib/OpenPay/errors/openpay_transaction_exception.rb +1 -1
- data/lib/OpenPay/openpay_api.rb +2 -2
- data/lib/openpay.rb +4 -4
- data/lib/version.rb +6 -0
- data/{OpenPay.gemspec → openpay.gemspec} +5 -3
- data/test/Factories.rb +3 -3
- data/test/spec/bankaccounts_spec.rb +1 -1
- data/test/spec/cards_spec.rb +43 -8
- data/test/spec/charges_spec.rb +29 -17
- data/test/spec/customers_spec.rb +1 -1
- data/test/spec/exceptions_spec.rb +1 -1
- data/test/spec/fees_spec.rb +5 -2
- data/test/spec/payouts_spec.rb +2 -2
- data/test/spec/plans_spec.rb +2 -56
- data/test/spec/subscriptions_spec.rb +1 -1
- data/test/spec/transfers_spec.rb +1 -3
- data/test/spec_helper.rb +1 -1
- metadata +19 -7
- data/lib/OpenPay/version.rb +0 -3
data/Rakefile
CHANGED
data/lib/OpenPay/Charges.rb
CHANGED
@@ -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(
|
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,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
|
-
|
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
|
File without changes
|
data/lib/OpenPay/openpay_api.rb
CHANGED
@@ -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/
|
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::
|
13
|
+
LOG.level=Logger::INFO
|
14
14
|
|
15
15
|
|
16
16
|
class OpenpayApi
|
data/lib/openpay.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#openpay version
|
2
|
-
require '
|
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/
|
30
|
-
require 'openpay/errors/
|
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
|
data/lib/version.rb
ADDED
@@ -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
|
-
|
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.
|
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"
|
data/test/Factories.rb
CHANGED
@@ -165,8 +165,8 @@ FactoryGirl.define do
|
|
165
165
|
|
166
166
|
|
167
167
|
factory :refund_description, class:Hash do
|
168
|
-
|
169
|
-
|
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
|
177
|
+
description 'Cobro de Comision'
|
178
178
|
initialize_with { attributes }
|
179
179
|
|
180
180
|
end
|
data/test/spec/cards_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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 '
|
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
|
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
|
-
|
171
|
-
@cards.
|
203
|
+
card=@cards.delete(id)
|
204
|
+
expect { @cards.get(id) }.to raise_exception(OpenpayTransactionException)
|
205
|
+
|
206
|
+
|
172
207
|
end
|
173
208
|
|
174
209
|
|
data/test/spec/charges_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require '
|
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
|
-
|
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
|
-
|
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
|
data/test/spec/customers_spec.rb
CHANGED
data/test/spec/fees_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
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
|
data/test/spec/payouts_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require '
|
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
|
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)
|
data/test/spec/plans_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
|