openpay 1.0.7 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 69310039f78e74baefd2e96785c830f19f2902f3
4
- data.tar.gz: e71006cf6228aafdd92a95bf7f86bb28763c1e75
2
+ SHA256:
3
+ metadata.gz: 908d4735c18ecdeb9521040c4fc9b19189539d21fd16709deafd67459725d0d5
4
+ data.tar.gz: 9c04f62e083ead6ea73e269529c496dfa347c633d8217a8665f4e9618e986402
5
5
  SHA512:
6
- metadata.gz: 3a917c8bdf259cf8580cf3538925948cddbd7e0f6550b833a2e24d6fde96680b29bb1ac4ccc04561b654d76f8f4ebbef19745cd898697d5806ea5be243aa50a9
7
- data.tar.gz: 6d433a86393555430d727393fb8581d96041cb3e8fd65db2891a38edc3e2bae44734a89c107ef2b5f87d41e5025ed129b1ccdb1acd65122a1fcaac91b95b3163
6
+ metadata.gz: 1edc635785a82ecdd9e3746943063151a1c204a1f10d120feb4544ff3f47098581a734bc820a926b29356166c52888c2a6333451676d28957c2079430d6ebdad
7
+ data.tar.gz: 9726aeeb22f7b637728ce9c14bb2ce806335dafb72eb49d46fb513b5b9bb2720eca7a34150de538ec67f5762d7896f1fdc0a9cdb3701e97a28512878ae476e1e
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ .project
data/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.4.2
4
+ before_install:
5
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
6
+ - gem install bundler -v '< 2'
data/Gemfile CHANGED
@@ -2,8 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rspec'
4
4
  gem 'rspec-expectations'
5
- gem 'rest-client', '~>1.6.7'
6
- gem 'factory_girl' , '4.2.0'
5
+ gem 'factory_bot', '4.8.2'
6
+ gem 'rest-client', '~> 2.0', '>= 2.0.2'
7
7
 
8
8
  # Specify your gem's dependencies in Openpay.gemspec
9
9
  gemspec
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- <img src="http://www.openpay.mx/img/logo.png">
1
+ ![Openpay Ruby](http://www.openpay.mx/img/github/ruby.jpg)
2
2
 
3
- # Openpay-Ruby [![Build Status](https://travis-ci.org/open-pay/openpay-ruby.png?branch=master)](https://travis-ci.org/open-pay/openpay-ruby)
3
+ [![Build Status](https://travis-ci.org/open-pay/openpay-ruby.png?branch=master)](https://travis-ci.org/open-pay/openpay-ruby)
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/openpay.svg)](http://badge.fury.io/rb/openpay)
6
6
 
7
- ##Description
7
+ ## Description
8
8
 
9
- ruby client for *Openpay api* services (version 1.0.7)
9
+ ruby client for *Openpay api* services (version 2.0)
10
10
 
11
11
  This is a ruby client implementing the payment services for *Openpay* at openpay.mx
12
12
 
@@ -31,9 +31,9 @@ Or install it from the command line:
31
31
 
32
32
  $ gem install openpay
33
33
 
34
- ###Requirements
34
+ ### Requirements
35
35
 
36
- * ruby 1.9 or higher
36
+ * ruby 2.4 or higher
37
37
 
38
38
  ## Usage
39
39
 
@@ -135,15 +135,15 @@ Methods without inputs will return a ruby hash.
135
135
  ```ruby
136
136
  it 'creates a fee using a json message' do
137
137
  #create new customer
138
- customer_hash= FactoryGirl.build(:customer)
138
+ customer_hash= FactoryBot.build(:customer)
139
139
  customer=@customers.create(customer_hash)
140
140
 
141
141
  #create customer card , using factory girl to build the hash for us
142
- card_hash=FactoryGirl.build(:valid_card)
142
+ card_hash=FactoryBot.build(:valid_card)
143
143
  card=@cards.create(card_hash, customer['id'])
144
144
 
145
145
  #create charge
146
- charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000)
146
+ charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000)
147
147
  charge=@charges.create(charge_hash, customer['id'])
148
148
 
149
149
  #create customer fee , using json as input, we get json as ouput
@@ -175,14 +175,14 @@ pp card_hash =>
175
175
  :city=>"Queretaro"}}
176
176
  ```
177
177
 
178
- Next, how we construct the preceding hash using **FactoryGirl**.
179
- **FactoryGirl** was used in our test suite to facilitate hash construction.
178
+ Next, how we construct the preceding hash using **FactoryBot**.
179
+ **FactoryBot** was used in our test suite to facilitate hash construction.
180
180
  It may help you as well at your final implementation if you decide to use hashes.
181
181
  (more examples at *test/Factories.rb*)
182
182
 
183
183
  ```ruby
184
184
 
185
- FactoryGirl.define do
185
+ FactoryBot.define do
186
186
  factory :valid_card, class:Hash do
187
187
  bank_name 'visa'
188
188
  holder_name 'Vicente Olmos'
@@ -204,7 +204,7 @@ FactoryGirl.define do
204
204
  end
205
205
  ```
206
206
 
207
- ###Methods design
207
+ ### Methods design
208
208
 
209
209
  This ruby API standardize the method names across all different resources using the **create**,**get**,**update** and **delete** verbs.
210
210
 
@@ -213,14 +213,14 @@ For full method documentation take a look at:
213
213
 
214
214
  The test suite at *test/spec* is a good source of reference.
215
215
 
216
- #####create
216
+ ##### create
217
217
 
218
218
  Creates the given resource
219
219
  ```ruby
220
220
  open_pay_resource.create(representation,customer_id=nil)
221
221
  ```
222
222
 
223
- #####get
223
+ ##### get
224
224
 
225
225
  Gets an instance of a given resource
226
226
 
@@ -228,7 +228,7 @@ The test suite at *test/spec* is a good source of reference.
228
228
  open_pay_resource.get(object_id,customer_id=nil)
229
229
  ```
230
230
 
231
- #####update
231
+ ##### update
232
232
 
233
233
  Updates an instance of a given resource
234
234
 
@@ -236,7 +236,7 @@ open_pay_resource.get(object_id,customer_id=nil)
236
236
  open_pay_resource.update(representation,customer_id=nil)
237
237
  ```
238
238
 
239
- #####delete
239
+ ##### delete
240
240
 
241
241
  Deletes an instance of the given resource
242
242
 
@@ -250,13 +250,13 @@ open_pay_resource.delete(object_id,customer_id=nil)
250
250
  open_pay_resource.all(customer_id=nil)
251
251
  ```
252
252
 
253
- #####each
253
+ ##### each
254
254
  Returns a block for each instance resource
255
255
  ```ruby
256
256
  open_pay_resource.each(customer_id=nil)
257
257
  ```
258
258
 
259
- #####delete_all(available only under the development environment)
259
+ ##### delete_all(available only under the development environment)
260
260
 
261
261
  Deletes all instances of the given resource
262
262
 
@@ -266,7 +266,7 @@ open_pay_resource.delete_all(customer_id=nil)
266
266
  ```
267
267
 
268
268
 
269
- ###API Methods
269
+ ### API Methods
270
270
 
271
271
 
272
272
  #### bank_accounts
@@ -722,7 +722,7 @@ This API generates 3 different Exception classes.
722
722
 
723
723
  ```ruby
724
724
  email='foo'
725
- customer_hash = FactoryGirl.build(:customer, email: email)
725
+ customer_hash = FactoryBot.build(:customer, email: email)
726
726
  begin
727
727
  customers.create(customer_hash)
728
728
  rescue OpenpayTransactionException => e
@@ -745,7 +745,7 @@ rescue OpenpayApiTransactionError => e
745
745
  end
746
746
  ```
747
747
 
748
- ###These exceptions have the following attributes:
748
+ ### These exceptions have the following attributes:
749
749
 
750
750
  - *category*
751
751
  - *description*
@@ -758,17 +758,17 @@ For more information about categories, descriptions and codes take a look at:
758
758
  - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
759
759
 
760
760
 
761
- ##Debug
761
+ ## Debug
762
762
 
763
763
  In the Openpay dashboard you are able to see every request and its corresponding request/response.
764
764
  - https://sandbox-dashboard.openpay.mx
765
765
 
766
- ##Developer Notes
766
+ ## Developer Notes
767
767
 
768
768
  - bank accounts for merchant cannot be created using the api. It should be done through the dashboard.
769
769
  - Is recommended to reset your account using the dashboard when running serious testing (assure clean state)
770
770
  - check openpay_api.rb for Logger configuration
771
- - travis https://travis-ci.org/open-pay/openpay-ruby , if a test fails it will leave leave some records, it may affect posterior tests.
771
+ - travis https://travis-ci.org/open-pay/openpay-ruby , if a test fails it will leave some records, it may affect posterior tests.
772
772
  it is recommended to reset the console/account to assure a clean state after a failure occurs.
773
773
 
774
774
  ## More information
data/Rakefile CHANGED
@@ -4,8 +4,9 @@
4
4
  task :default => [:spec]
5
5
 
6
6
  desc 'run specifications'
7
+
7
8
  RSpec::Core::RakeTask.new do |t|
8
- t.pattern = 'test/spec/*'
9
+ t.pattern = Dir.glob('test/spec/**/*_spec.rb')
9
10
  end
10
11
 
11
12
 
data/lib/openpay.rb CHANGED
@@ -14,6 +14,8 @@ module Openpay
14
14
  require 'openpay/open_pay_resource'
15
15
 
16
16
  #resource classes
17
+ require 'openpay/points'
18
+ require 'openpay/tokens'
17
19
  require 'openpay/bankaccounts'
18
20
  require 'openpay/cards'
19
21
  require 'openpay/charges'
@@ -24,6 +26,7 @@ module Openpay
24
26
  require 'openpay/subscriptions'
25
27
  require 'openpay/transfers'
26
28
  require 'openpay/charges'
29
+ require 'openpay/webhooks'
27
30
 
28
31
  #misc
29
32
  require 'openpay/utils/search_params'
@@ -62,13 +62,17 @@ 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 => url(args, terminated),
72
+ :url => strUrlAux,
70
73
  :user => @private_key,
71
74
  :timeout => @timeout,
75
+ :ssl_version => :TLSv1_2,
72
76
  :headers => {:accept => :json,
73
77
  :content_type => :json,
74
78
  :user_agent => 'Openpay/v1 Ruby-API',
@@ -92,15 +96,20 @@ class OpenPayResource
92
96
 
93
97
  @errors=false
94
98
 
99
+
100
+ strUrl = url(args)
101
+ strUrlAux = delete_ending_slash(strUrl)
102
+
95
103
  LOG.debug("#{self.class.name.downcase}:")
96
- LOG.debug(" DELETE URL:#{url(args)}")
104
+ LOG.debug(" DELETE URL:#{strUrlAux}")
97
105
 
98
106
  res=''
99
107
  req=RestClient::Request.new(
100
108
  :method => :delete,
101
- :url => url(args),
109
+ :url => strUrlAux,
102
110
  :user => @private_key,
103
111
  :timeout => @timeout,
112
+ :ssl_version => :TLSv1_2,
104
113
  :headers => {:accept => :json,
105
114
  :content_type => :json,
106
115
  :user_agent => 'Openpay/v1 Ruby-API',
@@ -131,18 +140,22 @@ class OpenPayResource
131
140
  return_hash=false
132
141
  end
133
142
 
143
+
144
+ strUrl = url(args)
145
+ strUrlAux = delete_ending_slash(strUrl)
146
+
134
147
  # LOG.debug("#{self.class.name.downcase}:")
135
- LOG.debug " POST URL:#{url(args)}"
148
+ LOG.debug " POST URL:#{strUrlAux}"
136
149
  LOG.debug " json: #{json}"
137
150
 
138
151
  begin
139
-
140
152
  #request
141
153
  res= RestClient::Request.new(
142
154
  :method => :post,
143
- :url => url(args),
155
+ :url => strUrlAux,
144
156
  :user => @private_key,
145
157
  :timeout => @timeout,
158
+ :ssl_version => :TLSv1_2,
146
159
  :payload => json,
147
160
  :headers => {:accept => :json,
148
161
  :content_type => :json,
@@ -178,15 +191,19 @@ class OpenPayResource
178
191
  return_hash=false
179
192
  end
180
193
 
181
- LOG.info "PUT URL:#{url}"
194
+ strUrl = url(args)
195
+ strUrlAux = delete_ending_slash(strUrl)
196
+
197
+ LOG.info "PUT URL:#{strUrlAux}"
182
198
  #LOG.info " json: #{json}"
183
199
 
184
- begin
200
+ begin
185
201
  res= RestClient::Request.new(
186
202
  :method => :put,
187
- :url => url(args),
203
+ :url => strUrlAux,
188
204
  :user => @private_key,
189
205
  :timeout => @timeout,
206
+ :ssl_version => :TLSv1_2,
190
207
  :payload => json,
191
208
  :headers => {:accept => :json,
192
209
  :content_type => :json,
@@ -223,6 +240,9 @@ class OpenPayResource
223
240
  private
224
241
 
225
242
  def url(args = '', terminated = true)
243
+ if args.nil? || args.empty?
244
+ terminated = false
245
+ end
226
246
  termination = terminated ? '/' : ''
227
247
  @base_url + "#{@merchant_id}/" + resource_name + termination + args
228
248
  end
@@ -231,6 +251,17 @@ class OpenPayResource
231
251
  self.class.name.to_s.downcase
232
252
  end
233
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
+
234
265
  def is_filter_string?(args)
235
266
  is_filter = false
236
267
  if args =~ /^\?/
@@ -0,0 +1,10 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Points < OpenPayResource
4
+
5
+ def getPointsBalance(token_id)
6
+ tokens=@api_hook.create(:tokens)
7
+ tokens.getPoints(token_id)
8
+ end
9
+
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Tokens < OpenPayResource
4
+ def getPoints(token_id)
5
+ get("#{token_id}/points")
6
+ end
7
+ end
@@ -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
- attribute = "#{$1}[#{$2}]"
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
@@ -0,0 +1,9 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Webhooks < OpenPayResource
4
+
5
+ def verify(webhook_id, code)
6
+ post('', "#{webhook_id}/verify/#{code}")
7
+ end
8
+
9
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Openpay
2
- VERSION = '1.0.7'
2
+ VERSION = '2.0.1'
3
3
  end
data/openpay.gemspec CHANGED
@@ -7,20 +7,20 @@ require 'version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "openpay"
9
9
  spec.version = Openpay::VERSION
10
- spec.authors = ["ronnie_bermejo"]
11
- spec.email = ["ronnie.bermejo.mx@gmail.com"]
12
- spec.description = %q{ruby client for Openpay API services (version 1.0.5)}
10
+ spec.authors = ["Openpay","ronnie_bermejo"]
11
+ spec.email = ["hola@openpay.mx"]
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
- spec.license = "Apache"
15
+ spec.license = "Apache-2.0"
16
16
 
17
17
  spec.files = `git ls-files`.split($/)
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec)/})
20
20
  spec.require_paths = ['lib','lib/openpay','openpay','.']
21
21
 
22
- spec.add_runtime_dependency 'rest-client' , '~>1.6.7'
23
- spec.add_runtime_dependency 'json'
22
+ spec.add_runtime_dependency 'rest-client' , '~>2.0'
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
@@ -1,12 +1,12 @@
1
- require 'factory_girl'
1
+ require 'factory_bot'
2
2
 
3
3
 
4
- FactoryGirl.define do
4
+ FactoryBot.define do
5
5
 
6
6
  factory :customer, class: Hash do
7
- name 'Ronnie'
8
- last_name 'Bermejo'
9
- email 'ronnie.bermejo.mx@gmail.com'
7
+ name 'Guadalupe'
8
+ last_name 'Reyes'
9
+ email 'lupereyes@lemail.com'
10
10
  phone_number '0180012345'
11
11
  address { {
12
12
  postal_code: '76190',
@@ -28,7 +28,7 @@ FactoryGirl.define do
28
28
  holder_name 'Vicente Olmos'
29
29
  expiration_month '09'
30
30
  card_number '4111111111111111'
31
- expiration_year '14'
31
+ expiration_year '25'
32
32
  bank_code 'bmx'
33
33
  cvv2 '111'
34
34
  address { {
@@ -45,13 +45,13 @@ FactoryGirl.define do
45
45
 
46
46
  end
47
47
 
48
- factory :valid_card2, class: Hash do
48
+ factory :valid_card2, class: Hash do
49
49
 
50
50
  bank_name 'visa'
51
51
  holder_name 'Alma Olmos'
52
52
  expiration_month '09'
53
53
  card_number '4242424242424242'
54
- expiration_year '14'
54
+ expiration_year '22'
55
55
  bank_code 'bmx'
56
56
  cvv2 '111'
57
57
  address { {
@@ -68,13 +68,13 @@ FactoryGirl.define do
68
68
 
69
69
  end
70
70
 
71
- factory :only_deposit, class: Hash do
71
+ factory :only_deposit, class: Hash do
72
72
 
73
73
  bank_name 'visa'
74
74
  holder_name 'Alma Olmos'
75
75
  expiration_month '09'
76
76
  card_number '4444444444444448'
77
- expiration_year '14'
77
+ expiration_year '20'
78
78
  bank_code 'bmx'
79
79
  cvv2 '111'
80
80
  address { {
@@ -97,7 +97,7 @@ FactoryGirl.define do
97
97
  holder_name 'Vicente Olmos'
98
98
  expiration_month '09'
99
99
  card_number '4000000000000069'
100
- expiration_year '14'
100
+ expiration_year '21'
101
101
  bank_code 'bmx'
102
102
  cvv2 '111'
103
103
  address { {
@@ -114,6 +114,7 @@ FactoryGirl.define do
114
114
 
115
115
  end
116
116
 
117
+
117
118
  factory :bank_account, class: Hash do
118
119
 
119
120
  holder_name 'Juan Perez'
@@ -129,19 +130,20 @@ FactoryGirl.define do
129
130
  amount "1000"
130
131
  description "Cargo inicial a tarjeta"
131
132
  source_id "string"
132
- method "card"
133
+ add_attribute :method, "card"
133
134
  order_id 'required'
134
135
 
135
136
  initialize_with { attributes }
136
137
 
137
138
  end
139
+
138
140
 
139
141
  factory :bank_charge, class: Hash do
140
142
 
141
143
  amount "10000"
142
144
  description "Cargo con banco"
143
145
  order_id 'required'
144
- method "bank_account"
146
+ add_attribute :method, "bank_account"
145
147
 
146
148
  initialize_with { attributes }
147
149
 
@@ -162,7 +164,7 @@ FactoryGirl.define do
162
164
 
163
165
  factory :payout_card, class: Hash do
164
166
 
165
- method 'card'
167
+ add_attribute :method, 'card'
166
168
  destination_id '4444444444444448'
167
169
  amount '2'
168
170
  description 'Retiro de saldo semanal'
@@ -173,7 +175,7 @@ FactoryGirl.define do
173
175
 
174
176
  factory :payout_bank_account, class: Hash do
175
177
 
176
- method 'bank_account'
178
+ add_attribute :method, 'bank_account'
177
179
  amount '1000'
178
180
  destination_id 'required'
179
181
  description 'Retiro de saldo semanal'
@@ -187,7 +189,7 @@ FactoryGirl.define do
187
189
  amount '150.00'
188
190
  status_after_retry 'cancelled'
189
191
  retry_times 2
190
- name 'Curso de ingles'
192
+ add_attribute :name ,'TODO INCLUIDO'
191
193
  repeat_unit 'week'
192
194
  trial_days 30
193
195
  repeat_every 1
@@ -208,5 +210,17 @@ FactoryGirl.define do
208
210
  plan_id 'required'
209
211
  initialize_with { attributes }
210
212
  end
213
+
214
+ factory :webhook1, class: Hash do
215
+ url 'https://requestb.in/15r2d5n1'
216
+ event_types ['charge.succeeded','charge.created','charge.cancelled','charge.failed']
217
+ initialize_with { attributes }
218
+ end
219
+
220
+ factory :webhook2, class: Hash do
221
+ url 'https://requestb.in/s3pj3ds3'
222
+ event_types ['charge.succeeded','charge.created','charge.cancelled','charge.failed']
223
+ initialize_with { attributes }
224
+ end
211
225
 
212
226
  end