openpay 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -0
- data/lib/openpay.rb +2 -0
- data/lib/openpay/open_pay_resource.rb +36 -9
- data/lib/openpay/points.rb +10 -0
- data/lib/openpay/tokens.rb +7 -0
- data/lib/openpay/utils/search_params.rb +4 -1
- data/lib/version.rb +1 -1
- data/openpay.gemspec +2 -2
- data/test/Factories.rb +3 -3
- data/test/spec/bankaccounts_spec.rb +24 -0
- data/test/spec/cards_spec.rb +14 -1
- data/test/spec/charges_spec.rb +2 -4
- data/test/spec/customers_spec.rb +2 -1
- data/test/spec/points_spec.rb +26 -0
- data/test/spec/utils/search_params_spec.rb +1 -1
- data/test/spec_helper.rb +2 -2
- metadata +10 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 908d4735c18ecdeb9521040c4fc9b19189539d21fd16709deafd67459725d0d5
|
4
|
+
data.tar.gz: 9c04f62e083ead6ea73e269529c496dfa347c633d8217a8665f4e9618e986402
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1edc635785a82ecdd9e3746943063151a1c204a1f10d120feb4544ff3f47098581a734bc820a926b29356166c52888c2a6333451676d28957c2079430d6ebdad
|
7
|
+
data.tar.gz: 9726aeeb22f7b637728ce9c14bb2ce806335dafb72eb49d46fb513b5b9bb2720eca7a34150de538ec67f5762d7896f1fdc0a9cdb3701e97a28512878ae476e1e
|
data/.travis.yml
CHANGED
data/lib/openpay.rb
CHANGED
@@ -62,11 +62,14 @@ class OpenPayResource
|
|
62
62
|
terminated = false
|
63
63
|
end
|
64
64
|
|
65
|
+
strUrl = url(args, terminated)
|
66
|
+
strUrlAux = delete_ending_slash(strUrl)
|
67
|
+
|
65
68
|
LOG.debug("#{resource_name}:")
|
66
69
|
LOG.debug(" GET Resource URL:#{url(args, terminated)}")
|
67
70
|
res=RestClient::Request.new(
|
68
71
|
:method => :get,
|
69
|
-
:url =>
|
72
|
+
:url => strUrlAux,
|
70
73
|
:user => @private_key,
|
71
74
|
:timeout => @timeout,
|
72
75
|
:ssl_version => :TLSv1_2,
|
@@ -93,13 +96,17 @@ class OpenPayResource
|
|
93
96
|
|
94
97
|
@errors=false
|
95
98
|
|
99
|
+
|
100
|
+
strUrl = url(args)
|
101
|
+
strUrlAux = delete_ending_slash(strUrl)
|
102
|
+
|
96
103
|
LOG.debug("#{self.class.name.downcase}:")
|
97
|
-
LOG.debug(" DELETE URL:#{
|
104
|
+
LOG.debug(" DELETE URL:#{strUrlAux}")
|
98
105
|
|
99
106
|
res=''
|
100
107
|
req=RestClient::Request.new(
|
101
108
|
:method => :delete,
|
102
|
-
:url =>
|
109
|
+
:url => strUrlAux,
|
103
110
|
:user => @private_key,
|
104
111
|
:timeout => @timeout,
|
105
112
|
:ssl_version => :TLSv1_2,
|
@@ -133,16 +140,19 @@ class OpenPayResource
|
|
133
140
|
return_hash=false
|
134
141
|
end
|
135
142
|
|
143
|
+
|
144
|
+
strUrl = url(args)
|
145
|
+
strUrlAux = delete_ending_slash(strUrl)
|
146
|
+
|
136
147
|
# LOG.debug("#{self.class.name.downcase}:")
|
137
|
-
LOG.debug " POST URL:#{
|
148
|
+
LOG.debug " POST URL:#{strUrlAux}"
|
138
149
|
LOG.debug " json: #{json}"
|
139
150
|
|
140
151
|
begin
|
141
|
-
|
142
152
|
#request
|
143
153
|
res= RestClient::Request.new(
|
144
154
|
:method => :post,
|
145
|
-
:url =>
|
155
|
+
:url => strUrlAux,
|
146
156
|
:user => @private_key,
|
147
157
|
:timeout => @timeout,
|
148
158
|
:ssl_version => :TLSv1_2,
|
@@ -181,13 +191,16 @@ class OpenPayResource
|
|
181
191
|
return_hash=false
|
182
192
|
end
|
183
193
|
|
184
|
-
|
194
|
+
strUrl = url(args)
|
195
|
+
strUrlAux = delete_ending_slash(strUrl)
|
196
|
+
|
197
|
+
LOG.info "PUT URL:#{strUrlAux}"
|
185
198
|
#LOG.info " json: #{json}"
|
186
199
|
|
187
|
-
begin
|
200
|
+
begin
|
188
201
|
res= RestClient::Request.new(
|
189
202
|
:method => :put,
|
190
|
-
:url =>
|
203
|
+
:url => strUrlAux,
|
191
204
|
:user => @private_key,
|
192
205
|
:timeout => @timeout,
|
193
206
|
:ssl_version => :TLSv1_2,
|
@@ -227,6 +240,9 @@ class OpenPayResource
|
|
227
240
|
private
|
228
241
|
|
229
242
|
def url(args = '', terminated = true)
|
243
|
+
if args.nil? || args.empty?
|
244
|
+
terminated = false
|
245
|
+
end
|
230
246
|
termination = terminated ? '/' : ''
|
231
247
|
@base_url + "#{@merchant_id}/" + resource_name + termination + args
|
232
248
|
end
|
@@ -235,6 +251,17 @@ class OpenPayResource
|
|
235
251
|
self.class.name.to_s.downcase
|
236
252
|
end
|
237
253
|
|
254
|
+
def delete_ending_slash(url)
|
255
|
+
slash = '/'
|
256
|
+
strUrl = url
|
257
|
+
strUrlAux = url
|
258
|
+
ending = strUrl.to_s[-1,1]
|
259
|
+
if ending == slash
|
260
|
+
strUrlAux = strUrl.to_s[0,strUrl.length - 1]
|
261
|
+
end
|
262
|
+
strUrlAux
|
263
|
+
end
|
264
|
+
|
238
265
|
def is_filter_string?(args)
|
239
266
|
is_filter = false
|
240
267
|
if args =~ /^\?/
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'ostruct'
|
2
|
+
require 'cgi'
|
2
3
|
module OpenpayUtils
|
3
4
|
|
4
5
|
class SearchParams < OpenStruct
|
@@ -8,7 +9,9 @@ module OpenpayUtils
|
|
8
9
|
filter = '?'
|
9
10
|
self.marshal_dump.each do |attribute, value|
|
10
11
|
if attribute =~ /(\w+)_(gte|lte)/
|
11
|
-
|
12
|
+
square_bracket_open_encode = CGI.escape('[')
|
13
|
+
square_bracket_close_encode = CGI.escape(']')
|
14
|
+
attribute = "#{$1}#{square_bracket_open_encode}#{$2}#{square_bracket_close_encode}"
|
12
15
|
end
|
13
16
|
filter << "#{attribute}=#{value}&"
|
14
17
|
end
|
data/lib/version.rb
CHANGED
data/openpay.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Openpay::VERSION
|
10
10
|
spec.authors = ["Openpay","ronnie_bermejo"]
|
11
11
|
spec.email = ["hola@openpay.mx"]
|
12
|
-
spec.description = %q{ruby client for Openpay API services (version 2.0.
|
12
|
+
spec.description = %q{ruby client for Openpay API services (version 2.0.1)}
|
13
13
|
spec.summary = %q{ruby api for openpay resources}
|
14
14
|
spec.homepage = "http://openpay.mx/"
|
15
15
|
spec.license = "Apache-2.0"
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib','lib/openpay','openpay','.']
|
21
21
|
|
22
22
|
spec.add_runtime_dependency 'rest-client' , '~>2.0'
|
23
|
-
spec.add_runtime_dependency 'json', '
|
23
|
+
spec.add_runtime_dependency 'json', '>= 1.8'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
26
|
spec.add_development_dependency 'rake'
|
data/test/Factories.rb
CHANGED
@@ -28,7 +28,7 @@ FactoryBot.define do
|
|
28
28
|
holder_name 'Vicente Olmos'
|
29
29
|
expiration_month '09'
|
30
30
|
card_number '4111111111111111'
|
31
|
-
expiration_year '
|
31
|
+
expiration_year '25'
|
32
32
|
bank_code 'bmx'
|
33
33
|
cvv2 '111'
|
34
34
|
address { {
|
@@ -51,7 +51,7 @@ FactoryBot.define do
|
|
51
51
|
holder_name 'Alma Olmos'
|
52
52
|
expiration_month '09'
|
53
53
|
card_number '4242424242424242'
|
54
|
-
expiration_year '
|
54
|
+
expiration_year '22'
|
55
55
|
bank_code 'bmx'
|
56
56
|
cvv2 '111'
|
57
57
|
address { {
|
@@ -97,7 +97,7 @@ FactoryBot.define do
|
|
97
97
|
holder_name 'Vicente Olmos'
|
98
98
|
expiration_month '09'
|
99
99
|
card_number '4000000000000069'
|
100
|
-
expiration_year '
|
100
|
+
expiration_year '21'
|
101
101
|
bank_code 'bmx'
|
102
102
|
cvv2 '111'
|
103
103
|
address { {
|
@@ -23,6 +23,30 @@ describe Bankaccounts do
|
|
23
23
|
expect(@bank_accounts).to respond_to(meth)
|
24
24
|
end
|
25
25
|
end
|
26
|
+
describe '.list' do
|
27
|
+
|
28
|
+
it 'list the bank accounts using a creation_gte filter' do
|
29
|
+
|
30
|
+
customer_hash= FactoryBot.build(:customer)
|
31
|
+
customer=@customers.create(customer_hash)
|
32
|
+
expect(@bank_accounts.all(customer['id']).size).to be 0
|
33
|
+
|
34
|
+
account_hash=FactoryBot.build(:bank_account)
|
35
|
+
bank=@bank_accounts.create(account_hash, customer['id'])
|
36
|
+
expect(@bank_accounts.all(customer['id']).size).to be 1
|
37
|
+
|
38
|
+
search_params = OpenpayUtils::SearchParams.new
|
39
|
+
search_params.limit = 1
|
40
|
+
search_params.creation_gte = '2000-01-01'
|
41
|
+
|
42
|
+
expect(@bank_accounts.all(customer['id']).size).to eq 1
|
43
|
+
expect(@bank_accounts.list(search_params , customer['id']).size).to eq 1
|
44
|
+
|
45
|
+
@bank_accounts.delete(customer['id'], bank['id'])
|
46
|
+
@customers.delete(customer['id'])
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
26
50
|
=begin
|
27
51
|
describe '.create' do
|
28
52
|
|
data/test/spec/cards_spec.rb
CHANGED
@@ -157,7 +157,7 @@ describe Cards do
|
|
157
157
|
expect(card).to be_a(Hash)
|
158
158
|
|
159
159
|
@cards.each(customer['id']) do |c|
|
160
|
-
expect(c['expiration_year']).to match '
|
160
|
+
expect(c['expiration_year']).to match '25'
|
161
161
|
end
|
162
162
|
|
163
163
|
#cleanup
|
@@ -363,6 +363,19 @@ describe Cards do
|
|
363
363
|
|
364
364
|
end
|
365
365
|
|
366
|
+
it 'list the merchant cards using a filter creation and amount' do
|
367
|
+
#create merchant card
|
368
|
+
card_hash = FactoryBot.build(:valid_card)
|
369
|
+
card1 = @cards.create(card_hash)
|
370
|
+
card_hash = FactoryBot.build(:valid_card2)
|
371
|
+
card2 = @cards.create(card_hash)
|
372
|
+
search_params = OpenpayUtils::SearchParams.new
|
373
|
+
search_params.limit = 1
|
374
|
+
creation_date = "2013-11-01"
|
375
|
+
search_params.creation_gte = creation_date
|
376
|
+
expect(@cards.list(search_params).size).to eq 1
|
377
|
+
@cards.delete_all
|
378
|
+
end
|
366
379
|
end
|
367
380
|
|
368
381
|
|
data/test/spec/charges_spec.rb
CHANGED
@@ -305,23 +305,21 @@ describe Charges do
|
|
305
305
|
#create new customer
|
306
306
|
customer_hash= FactoryBot.build(:customer)
|
307
307
|
customer=@customers.create(customer_hash)
|
308
|
-
|
309
308
|
#create customer card
|
310
309
|
card_hash=FactoryBot.build(:valid_card)
|
311
310
|
card=@cards.create(card_hash,customer['id'])
|
312
|
-
|
313
311
|
#create charge
|
314
312
|
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
315
313
|
charge=@charges.create(charge_hash,customer['id'])
|
316
314
|
charge_hash=FactoryBot.build(:card_charge, source_id:card['id'],order_id: card['id']+"1")
|
317
315
|
charge2=@charges.create(charge_hash,customer['id'])
|
318
|
-
|
319
316
|
#perform check
|
320
317
|
search_params = OpenpayUtils::SearchParams.new
|
321
318
|
search_params.limit = 1
|
319
|
+
search_params.creation_gte = '2000-01-01'
|
320
|
+
search_params.amount_gte = 1
|
322
321
|
expect(@charges.all(customer['id']).size).to eq 2
|
323
322
|
expect(@charges.list(search_params,customer['id']).size).to eq 1
|
324
|
-
|
325
323
|
#clean up
|
326
324
|
@cards.delete(card['id'],customer['id'])
|
327
325
|
@customers.delete(customer['id'])
|
data/test/spec/customers_spec.rb
CHANGED
@@ -156,6 +156,7 @@ describe Customers do
|
|
156
156
|
|
157
157
|
search_params = OpenpayUtils::SearchParams.new
|
158
158
|
search_params.limit=1
|
159
|
+
search_params.creation_gte='2020-01-01'
|
159
160
|
|
160
161
|
#perform check
|
161
162
|
expect(@customers.list(search_params).size).to eq 1
|
@@ -204,7 +205,7 @@ describe Customers do
|
|
204
205
|
#performs check
|
205
206
|
expect(@customers.all.size).to be > 4
|
206
207
|
@customers.delete_all
|
207
|
-
expect(@customers.all.size).to be
|
208
|
+
expect(@customers.all.size).to be < 11
|
208
209
|
end
|
209
210
|
|
210
211
|
it 'raise an exception when used on Production' do
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe 'Points' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
@merchant_id='mhbzmkji20dhu9kq3r2i'
|
8
|
+
@private_key='sk_0070ce5a12d948e0a0c9b5b8b7ff51ae'
|
9
|
+
|
10
|
+
@openpay=OpenpayApi.new(@merchant_id,@private_key)
|
11
|
+
@points=@openpay.create(:points)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:all) do
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.get' do
|
20
|
+
it 'Card Points ' do
|
21
|
+
point=@points.getPointsBalance('ka2fi3h6ikppavewn5ne')
|
22
|
+
puts point.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -28,7 +28,7 @@ describe OpenpayUtils do
|
|
28
28
|
search_params.limit = limit
|
29
29
|
amount = 100
|
30
30
|
search_params.amount_lte = amount
|
31
|
-
expect(search_params.to_s).to eq("?creation
|
31
|
+
expect(search_params.to_s).to eq("?creation%5Bgte%5D=2013-11-01&limit=2&amount%5Blte%5D=100")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/test/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Openpay
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -29,14 +29,14 @@ dependencies:
|
|
29
29
|
name: json
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.8'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.8'
|
42
42
|
- !ruby/object:Gem::Dependency
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
description: ruby client for Openpay API services (version 2.0.
|
84
|
+
description: ruby client for Openpay API services (version 2.0.1)
|
85
85
|
email:
|
86
86
|
- hola@openpay.mx
|
87
87
|
executables: []
|
@@ -96,19 +96,6 @@ files:
|
|
96
96
|
- ".idea/encodings.xml"
|
97
97
|
- ".idea/misc.xml"
|
98
98
|
- ".idea/modules.xml"
|
99
|
-
- ".idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml"
|
100
|
-
- ".idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml"
|
101
|
-
- ".idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml"
|
102
|
-
- ".idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml"
|
103
|
-
- ".idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml"
|
104
|
-
- ".idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml"
|
105
|
-
- ".idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml"
|
106
|
-
- ".idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml"
|
107
|
-
- ".idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml"
|
108
|
-
- ".idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml"
|
109
|
-
- ".idea/runConfigurations/all_specs.xml"
|
110
|
-
- ".idea/runConfigurations/install_open_pay.xml"
|
111
|
-
- ".idea/runConfigurations/scrapbook.xml"
|
112
99
|
- ".idea/scopes/scope_settings.xml"
|
113
100
|
- ".idea/vcs.xml"
|
114
101
|
- ".idea/workspace.xml"
|
@@ -132,7 +119,9 @@ files:
|
|
132
119
|
- lib/openpay/openpay_api.rb
|
133
120
|
- lib/openpay/payouts.rb
|
134
121
|
- lib/openpay/plans.rb
|
122
|
+
- lib/openpay/points.rb
|
135
123
|
- lib/openpay/subscriptions.rb
|
124
|
+
- lib/openpay/tokens.rb
|
136
125
|
- lib/openpay/transfers.rb
|
137
126
|
- lib/openpay/utils/search_params.rb
|
138
127
|
- lib/openpay/webhooks.rb
|
@@ -148,6 +137,7 @@ files:
|
|
148
137
|
- test/spec/openpayresource_spec.rb
|
149
138
|
- test/spec/payouts_spec.rb
|
150
139
|
- test/spec/plans_spec.rb
|
140
|
+
- test/spec/points_spec.rb
|
151
141
|
- test/spec/requesttimeout_spec.rb
|
152
142
|
- test/spec/subscriptions_spec.rb
|
153
143
|
- test/spec/transfers_spec.rb
|
@@ -175,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
165
|
- !ruby/object:Gem::Version
|
176
166
|
version: '0'
|
177
167
|
requirements: []
|
178
|
-
|
179
|
-
rubygems_version: 2.6.14
|
168
|
+
rubygems_version: 3.0.3
|
180
169
|
signing_key:
|
181
170
|
specification_version: 4
|
182
171
|
summary: ruby api for openpay resources
|
@@ -191,6 +180,7 @@ test_files:
|
|
191
180
|
- test/spec/openpayresource_spec.rb
|
192
181
|
- test/spec/payouts_spec.rb
|
193
182
|
- test/spec/plans_spec.rb
|
183
|
+
- test/spec/points_spec.rb
|
194
184
|
- test/spec/requesttimeout_spec.rb
|
195
185
|
- test/spec/subscriptions_spec.rb
|
196
186
|
- test/spec/transfers_spec.rb
|