openpay 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +1 -0
  3. data/.idea/.rakeTasks +2 -2
  4. data/.idea/OpenPay.iml +30 -20
  5. data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +1 -0
  6. data/.idea/runConfigurations/Run_spec__cards_spec___OpenPay.xml +1 -0
  7. data/.idea/runConfigurations/Run_spec__charges_spec___OpenPay.xml +1 -0
  8. data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +1 -0
  9. data/.idea/runConfigurations/Run_spec__exceptions_spec___OpenPay.xml +1 -0
  10. data/.idea/runConfigurations/Run_spec__fees_spec___OpenPay.xml +1 -0
  11. data/.idea/runConfigurations/Run_spec__payouts_spec___OpenPay.xml +1 -0
  12. data/.idea/runConfigurations/Run_spec__plans_spec___OpenPay.xml +1 -0
  13. data/.idea/runConfigurations/Run_spec__subscriptions_spec___OpenPay.xml +1 -0
  14. data/.idea/runConfigurations/Run_spec__transfers_spec___OpenPay.xml +1 -0
  15. data/.idea/runConfigurations/all_specs.xml +1 -0
  16. data/.idea/workspace.xml +484 -268
  17. data/Gemfile +0 -6
  18. data/README.md +111 -29
  19. data/lib/openpay.rb +7 -3
  20. data/lib/openpay/bankaccounts.rb +10 -11
  21. data/lib/openpay/cards.rb +12 -14
  22. data/lib/openpay/charges.rb +38 -14
  23. data/lib/openpay/customers.rb +73 -67
  24. data/lib/openpay/errors/openpay_exception_factory.rb +14 -26
  25. data/lib/openpay/fees.rb +1 -1
  26. data/lib/openpay/open_pay_resource.rb +77 -77
  27. data/lib/openpay/open_pay_resource_factory.rb +1 -1
  28. data/lib/openpay/openpay_api.rb +6 -16
  29. data/lib/openpay/payouts.rb +13 -17
  30. data/lib/openpay/plans.rb +1 -7
  31. data/lib/openpay/subscriptions.rb +21 -29
  32. data/lib/openpay/transfers.rb +14 -18
  33. data/lib/openpay/utils/search_params.rb +20 -0
  34. data/lib/version.rb +1 -2
  35. data/openpay.gemspec +0 -8
  36. data/test/Factories.rb +80 -126
  37. data/test/spec/bankaccounts_spec.rb +55 -61
  38. data/test/spec/cards_spec.rb +56 -76
  39. data/test/spec/charges_spec.rb +89 -84
  40. data/test/spec/customers_spec.rb +37 -47
  41. data/test/spec/exceptions_spec.rb +4 -21
  42. data/test/spec/fees_spec.rb +51 -7
  43. data/test/spec/payouts_spec.rb +102 -65
  44. data/test/spec/plans_spec.rb +27 -50
  45. data/test/spec/subscriptions_spec.rb +87 -24
  46. data/test/spec/transfers_spec.rb +42 -44
  47. data/test/spec/utils/search_params_spec.rb +36 -0
  48. data/test/spec_helper.rb +1 -5
  49. metadata +15 -55
  50. data/lib/OpenPay/Cards.rb +0 -75
  51. data/lib/OpenPay/Charges.rb +0 -77
  52. data/lib/OpenPay/Customers.rb +0 -194
  53. data/lib/OpenPay/Fees.rb +0 -5
  54. data/lib/OpenPay/Payouts.rb +0 -59
  55. data/lib/OpenPay/Plans.rb +0 -23
  56. data/lib/OpenPay/Subscriptions.rb +0 -58
  57. data/lib/OpenPay/Transfers.rb +0 -43
  58. data/lib/OpenPay/bankaccounts.rb +0 -59
  59. data/lib/OpenPay/errors/openpay_connection_exception.rb +0 -3
  60. data/lib/OpenPay/errors/openpay_exception.rb +0 -29
  61. data/lib/OpenPay/errors/openpay_exception_factory.rb +0 -60
  62. data/lib/OpenPay/errors/openpay_transaction_exception.rb +0 -5
  63. data/lib/OpenPay/open_pay_resource.rb +0 -242
  64. data/lib/OpenPay/open_pay_resource_factory.rb +0 -10
  65. data/lib/OpenPay/openpay_api.rb +0 -58
@@ -3,7 +3,7 @@ class OpenPayResourceFactory
3
3
  begin
4
4
  Object.const_get(resource.capitalize).new(merchant_id,private_key,production)
5
5
  rescue NameError
6
- raise OpenpayException.new("Invalid resource name:#{resource}",false)
6
+ raise OpenpayException.new("Invalid resource name:#{resource}",false)
7
7
  end
8
8
  end
9
9
  end
@@ -9,31 +9,26 @@ require 'errors/openpay_exception'
9
9
  LOG= Logger.new(STDOUT)
10
10
  #change to Logger::DEBUG if need trace information
11
11
  #due the nature of the information, we recommend to never use a log file when in debug
12
- LOG.level=Logger::ERROR
12
+ LOG.level=Logger::FATAL
13
13
 
14
14
  class OpenpayApi
15
15
  #API Endpoints
16
16
  API_DEV='https://sandbox-api.openpay.mx/v1/'
17
17
  API_PROD='https://api.openpay.mx/v1/'
18
18
 
19
- #by default the testing environment is used
20
- def initialize(merchant_id, private_key,production=false)
19
+ #by default testing environment is used
20
+ def initialize(merchant_id, private_key, production=false)
21
21
  @merchant_id=merchant_id
22
22
  @private_key=private_key
23
23
  @production=production
24
24
  end
25
25
 
26
-
27
- # @return [nil]
28
26
  def create(resource)
29
- klass=OpenPayResourceFactory::create(resource, @merchant_id,@private_key,@production)
30
- #attach api hook to be able to refere to same API instance from created resources
31
- #TODO we may move it to the initialize method
27
+ klass=OpenPayResourceFactory::create(resource, @merchant_id, @private_key, @production)
32
28
  klass.api_hook=self
33
29
  klass
34
30
  end
35
31
 
36
-
37
32
  def OpenpayApi::base_url(production)
38
33
  if production
39
34
  API_PROD
@@ -42,8 +37,7 @@ class OpenpayApi
42
37
  end
43
38
  end
44
39
 
45
-
46
- def env
40
+ def env
47
41
  if @production
48
42
  :production
49
43
  else
@@ -51,8 +45,4 @@ class OpenpayApi
51
45
  end
52
46
  end
53
47
 
54
-
55
-
56
-
57
-
58
- end
48
+ end
@@ -1,19 +1,13 @@
1
1
  require 'open_pay_resource'
2
2
 
3
-
4
-
5
3
  class Payouts < OpenPayResource
6
4
 
7
-
8
-
9
-
10
-
11
5
  def all(customer_id=nil)
12
6
  if customer_id
13
7
  customers=@api_hook.create(:customers)
14
8
  customers.all_payouts(customer_id)
15
9
  else
16
- super ''
10
+ super ''
17
11
  end
18
12
  end
19
13
 
@@ -26,24 +20,19 @@ class Payouts < OpenPayResource
26
20
  end
27
21
  end
28
22
 
29
-
30
23
  def each(customer_id=nil)
31
24
  if customer_id
32
25
  customers=@api_hook.create(:customers)
33
26
  customers.each_payout(customer_id) do |cust|
34
- yield cust
27
+ yield cust
35
28
  end
36
29
  else
37
30
  all.each do |cust|
38
31
  yield cust
39
- end
40
- end
41
-
32
+ end
33
+ end
42
34
  end
43
35
 
44
-
45
-
46
-
47
36
  def create(payout, customer_id=nil)
48
37
  if customer_id
49
38
  customers=@api_hook.create(:customers)
@@ -53,7 +42,14 @@ class Payouts < OpenPayResource
53
42
  end
54
43
  end
55
44
 
45
+ def list(search_params, customer_id=nil)
46
+ if customer_id
47
+ customers=@api_hook.create(:customers)
48
+ customers.list_payouts(customer_id, search_params)
49
+ else
50
+ super search_params
51
+ end
52
+ end
56
53
 
57
54
 
58
-
59
- end
55
+ end
data/lib/openpay/plans.rb CHANGED
@@ -10,14 +10,8 @@ class Plans < OpenPayResource
10
10
  get("#{plan_id}/subscriptions")
11
11
  end
12
12
 
13
-
14
13
  def all_subscriptions(plan_id)
15
14
  get("#{plan_id}/subscriptions")
16
15
  end
17
16
 
18
-
19
- def each
20
- end
21
-
22
-
23
- end
17
+ end
@@ -1,37 +1,27 @@
1
1
  require 'open_pay_resource'
2
2
 
3
- class Subscriptions < OpenPayResource
3
+ class Subscriptions < OpenPayResource
4
4
 
5
-
6
-
7
- def create(subscription,plan_id)
5
+ def create(subscription, customer_id)
8
6
  customers=@api_hook.create(:customers)
9
- customers.create_subscription(subscription,plan_id)
7
+ customers.create_subscription(subscription, customer_id)
10
8
  end
11
9
 
10
+ def delete(subscription_id, customer_id)
11
+ customers=@api_hook.create(:customers)
12
+ customers.delete_subscription(customer_id, subscription_id)
13
+ end
12
14
 
13
- def delete(subscription_id,customer_id)
14
- customers=@api_hook.create(:customers)
15
- customers.delete_subscription(customer_id, subscription_id)
16
- end
17
-
18
-
19
- def get(subscription_id,customer_id)
20
-
15
+ def get(subscription_id, customer_id)
21
16
  customers=@api_hook.create(:customers)
22
17
  customers.get_subscription(customer_id, subscription_id)
23
-
24
18
  end
25
19
 
26
-
27
20
  def all(customer_id)
28
-
29
21
  customers=@api_hook.create(:customers)
30
22
  customers.all_subscriptions(customer_id)
31
-
32
23
  end
33
24
 
34
-
35
25
  def each(customer_id)
36
26
  customers=@api_hook.create(:customers)
37
27
  customers.each_subscription(customer_id) do |c|
@@ -39,20 +29,22 @@ end
39
29
  end
40
30
  end
41
31
 
32
+ def list(search_params,customer_id=nil)
33
+ if customer_id
34
+ customers=@api_hook.create(:customers)
35
+ customers.list_subscriptions(customer_id,search_params)
36
+ else
37
+ super search_params
38
+ end
39
+ end
40
+
41
+ def update(subscription_id,customer_id,params)
42
+ customers=@api_hook.create(:customers)
43
+ customers.update_subscription(subscription_id,customer_id,params)
44
+ end
42
45
 
43
46
  def delete_all(customer_id)
44
47
  customers=@api_hook.create(:customers)
45
48
  customers.delete_all_subscriptions(customer_id)
46
-
47
49
  end
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
50
  end
@@ -1,13 +1,10 @@
1
1
  require 'open_pay_resource'
2
2
 
3
- class Transfers < OpenPayResource
4
-
5
-
6
- def create(transfer,customer_id)
7
-
8
- customers=@api_hook.create(:customers)
9
- customers.create_transfer(customer_id,transfer)
3
+ class Transfers < OpenPayResource
10
4
 
5
+ def create(transfer, customer_id)
6
+ customers=@api_hook.create(:customers)
7
+ customers.create_transfer(customer_id, transfer)
11
8
  end
12
9
 
13
10
  def all(customer_id)
@@ -15,27 +12,26 @@ class Transfers < OpenPayResource
15
12
  customers.all_transfers(customer_id)
16
13
  end
17
14
 
18
-
19
-
20
- def get(transfer,customer_id)
21
-
15
+ def get(transfer, customer_id)
22
16
  customers=@api_hook.create(:customers)
23
- customers.get_transfer(customer_id,transfer)
24
-
17
+ customers.get_transfer(customer_id, transfer)
25
18
  end
26
19
 
27
-
28
20
  def each(customer_id)
29
21
  customers=@api_hook.create(:customers)
30
22
  customers.each_transfer(customer_id) do |tran|
31
23
  yield tran
32
24
  end
33
-
34
25
  end
35
26
 
36
-
37
-
38
-
27
+ def list(search_params, customer_id=nil)
28
+ if customer_id
29
+ customers=@api_hook.create(:customers)
30
+ customers.list_transfers(customer_id, search_params)
31
+ else
32
+ super search_params
33
+ end
34
+ end
39
35
 
40
36
  end
41
37
 
@@ -0,0 +1,20 @@
1
+ module OpenpayUtils
2
+
3
+ class SearchParams < OpenStruct
4
+
5
+ #"?creation[gte]=2013-11-01&limit=2&amount[lte]=100"
6
+ def to_str
7
+ filter = '?'
8
+ self.marshal_dump.each do |attribute, value|
9
+ if attribute =~ /(\w+)_(gte|lte)/
10
+ attribute = "#{$1}[#{$2}]"
11
+ end
12
+ filter << "#{attribute}=#{value}&"
13
+ end
14
+ filter.sub(/\&$/, '')
15
+ end
16
+
17
+ alias :to_s :to_str
18
+
19
+ end
20
+ end
data/lib/version.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Openpay
2
-
3
2
  # Dec 31 2014, 6:00 PM Qro Local time.
4
3
  # 97 test cases passed / 220.232 secs
5
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
6
5
  end
data/openpay.gemspec CHANGED
@@ -4,7 +4,6 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  require 'version'
6
6
 
7
-
8
7
  Gem::Specification.new do |spec|
9
8
  spec.name = "openpay"
10
9
  spec.version = Openpay::VERSION
@@ -23,16 +22,9 @@ Gem::Specification.new do |spec|
23
22
  spec.add_runtime_dependency 'rest-client' , '~>1.6.7'
24
23
  spec.add_runtime_dependency 'json'
25
24
 
26
-
27
-
28
25
  spec.add_development_dependency 'bundler', '~> 1.3'
29
26
  spec.add_development_dependency 'rake'
30
27
  spec.add_development_dependency 'json_spec'
31
- spec.add_development_dependency 'rspec'
32
- spec.add_development_dependency 'factory_girl' , '4.2.0'
33
28
  spec.post_install_message = 'Thanks for installing openpay. Enjoy !'
34
29
 
35
-
36
-
37
-
38
30
  end
data/test/Factories.rb CHANGED
@@ -3,12 +3,12 @@ require 'factory_girl'
3
3
 
4
4
  FactoryGirl.define do
5
5
 
6
- factory :customer, class:Hash do
6
+ factory :customer, class: Hash do
7
7
  name 'Ronnie'
8
8
  last_name 'Bermejo'
9
9
  email 'ronnie.bermejo.mx@gmail.com'
10
10
  phone_number '0180012345'
11
- address {{
11
+ address { {
12
12
  postal_code: '76190',
13
13
  state: 'QRO',
14
14
  line1: 'LINE1',
@@ -16,48 +16,45 @@ FactoryGirl.define do
16
16
  line3: 'LINE3',
17
17
  country_code: 'MX',
18
18
  city: 'Queretaro',
19
- }}
19
+ } }
20
20
 
21
21
  initialize_with { attributes }
22
22
 
23
23
  end
24
24
 
25
+ factory :valid_card, class: Hash do
25
26
 
26
-
27
- factory :valid_card, class:Hash do
28
-
29
- bank_name 'visa'
30
- holder_name 'Vicente Olmos'
31
- expiration_month '09'
32
- card_number '4111111111111111'
33
- expiration_year '14'
34
- bank_code 'bmx'
35
- cvv2 '111'
36
- address {{
37
- postal_code: '76190',
38
- state: 'QRO',
39
- line1: 'LINE1',
40
- line2: 'LINE2',
41
- line3: 'LINE3',
42
- country_code: 'MX',
43
- city: 'Queretaro',
44
- }}
27
+ bank_name 'visa'
28
+ holder_name 'Vicente Olmos'
29
+ expiration_month '09'
30
+ card_number '4111111111111111'
31
+ expiration_year '14'
32
+ bank_code 'bmx'
33
+ cvv2 '111'
34
+ address { {
35
+ postal_code: '76190',
36
+ state: 'QRO',
37
+ line1: 'LINE1',
38
+ line2: 'LINE2',
39
+ line3: 'LINE3',
40
+ country_code: 'MX',
41
+ city: 'Queretaro',
42
+ } }
45
43
 
46
44
  initialize_with { attributes }
47
45
 
48
46
  end
49
47
 
48
+ factory :valid_card2, class: Hash do
50
49
 
51
- factory :valid_card2, class:Hash do
52
-
53
- bank_name 'visa'
50
+ bank_name 'visa'
54
51
  holder_name 'Alma Olmos'
55
52
  expiration_month '09'
56
53
  card_number '4242424242424242'
57
54
  expiration_year '14'
58
55
  bank_code 'bmx'
59
- cvv2 '111'
60
- address {{
56
+ cvv2 '111'
57
+ address { {
61
58
  postal_code: '76190',
62
59
  state: 'QRO',
63
60
  line1: 'LINE1',
@@ -65,24 +62,22 @@ FactoryGirl.define do
65
62
  line3: 'LINE3',
66
63
  country_code: 'MX',
67
64
  city: 'Queretaro',
68
- }}
65
+ } }
69
66
 
70
67
  initialize_with { attributes }
71
68
 
72
69
  end
73
70
 
71
+ factory :only_deposit, class: Hash do
74
72
 
75
-
76
- factory :only_deposit, class:Hash do
77
-
78
- bank_name 'visa'
73
+ bank_name 'visa'
79
74
  holder_name 'Alma Olmos'
80
75
  expiration_month '09'
81
76
  card_number '4444444444444448'
82
77
  expiration_year '14'
83
78
  bank_code 'bmx'
84
- cvv2 '111'
85
- address {{
79
+ cvv2 '111'
80
+ address { {
86
81
  postal_code: '76190',
87
82
  state: 'QRO',
88
83
  line1: 'LINE1',
@@ -90,23 +85,22 @@ FactoryGirl.define do
90
85
  line3: 'LINE3',
91
86
  country_code: 'MX',
92
87
  city: 'Queretaro',
93
- }}
88
+ } }
94
89
 
95
90
  initialize_with { attributes }
96
91
 
97
92
  end
98
93
 
94
+ factory :expired_card, class: Hash do
99
95
 
100
- factory :expired_card, class:Hash do
101
-
102
- bank_name 'visa'
96
+ bank_name 'visa'
103
97
  holder_name 'Vicente Olmos'
104
98
  expiration_month '09'
105
99
  card_number '4000000000000069'
106
100
  expiration_year '14'
107
101
  bank_code 'bmx'
108
- cvv2 '111'
109
- address {{
102
+ cvv2 '111'
103
+ address { {
110
104
  postal_code: '76190',
111
105
  state: 'QRO',
112
106
  line1: 'LINE1',
@@ -114,145 +108,105 @@ FactoryGirl.define do
114
108
  line3: 'LINE3',
115
109
  country_code: 'MX',
116
110
  city: 'Queretaro',
117
- }}
111
+ } }
118
112
 
119
113
  initialize_with { attributes }
120
114
 
121
115
  end
122
116
 
117
+ factory :bank_account, class: Hash do
123
118
 
119
+ holder_name 'Juan Perez'
120
+ self.alias 'Cuenta principal'
121
+ clabe '032180000118359719'
124
122
 
125
- factory :bank_account, class:Hash do
126
-
127
- holder_name 'Juan Perez'
128
- self.alias 'Cuenta principal'
129
- clabe '032180000118359719'
130
-
131
- initialize_with { attributes }
123
+ initialize_with { attributes }
132
124
 
133
125
  end
134
126
 
127
+ factory :card_charge, class: Hash do
135
128
 
129
+ amount "1000"
130
+ description "Cargo inicial a tarjeta"
131
+ source_id "string"
132
+ method "card"
133
+ order_id 'required'
136
134
 
137
- factory :card_charge, class:Hash do
138
-
139
-
140
- amount "1000"
141
- description "Cargo inicial a tarjeta"
142
- source_id "string"
143
- method "card"
144
- order_id 'required'
145
-
146
- initialize_with { attributes }
147
-
135
+ initialize_with { attributes }
148
136
 
149
137
  end
150
138
 
151
- factory :bank_charge, class:Hash do
139
+ factory :bank_charge, class: Hash do
152
140
 
153
- amount "10000"
141
+ amount "10000"
154
142
  description "Cargo con banco"
155
- source_id "string"
156
143
  order_id 'required'
157
- method "bank_account"
158
-
144
+ method "bank_account"
159
145
 
160
146
  initialize_with { attributes }
161
147
 
162
-
163
148
  end
164
149
 
165
-
166
-
167
- factory :refund_description, class:Hash do
150
+ factory :refund_description, class: Hash do
168
151
  description 'A peticion del cliente'
169
152
  initialize_with { attributes }
170
153
 
171
154
  end
172
155
 
173
-
174
- factory :fee, class:Hash do
175
- customer_id 'dvocf97jd20es3tw5laz'
176
- amount '12.50'
177
- description 'Cobro de Comision'
178
- initialize_with { attributes }
179
-
156
+ factory :fee, class: Hash do
157
+ customer_id 'dvocf97jd20es3tw5laz'
158
+ amount '12.50'
159
+ description 'Cobro de Comision'
160
+ initialize_with { attributes }
180
161
  end
181
162
 
163
+ factory :payout_card, class: Hash do
182
164
 
165
+ method 'card'
166
+ destination_id '4444444444444448'
167
+ amount '2'
168
+ description 'Retiro de saldo semanal'
183
169
 
184
- factory :payout_card, class:Hash do
185
-
186
- method 'card'
187
- destination_id '4444444444444448'
188
- amount '2'
189
- description 'Retiro de saldo semanal'
190
-
191
- initialize_with { attributes }
192
-
170
+ initialize_with { attributes }
193
171
 
194
172
  end
195
173
 
174
+ factory :payout_bank_account, class: Hash do
196
175
 
197
- factory :payout_bank_account, class:Hash do
198
-
199
- method 'bank_account'
176
+ method 'bank_account'
200
177
  amount '1000'
201
178
  destination_id 'required'
202
179
  description 'Retiro de saldo semanal'
203
180
 
204
181
  initialize_with { attributes }
205
182
 
206
-
207
183
  end
208
184
 
185
+ factory :plan, class: Hash do
209
186
 
210
-
211
-
212
- factory :plan, class:Hash do
213
-
214
- amount '150.00'
215
- status_after_retry 'cancelled'
216
- retry_times 2
217
- name 'Curso de ingles'
218
- repeat_unit 'week'
219
- trial_days 30
220
- repeat_every 1
221
- initialize_with { attributes }
222
-
187
+ amount '150.00'
188
+ status_after_retry 'cancelled'
189
+ retry_times 2
190
+ name 'Curso de ingles'
191
+ repeat_unit 'week'
192
+ trial_days 30
193
+ repeat_every 1
194
+ initialize_with { attributes }
223
195
 
224
196
  end
225
197
 
226
-
227
-
228
- factory :transfer, class:Hash do
229
-
230
- customer_id 'required'
231
- amount 12.50
232
- description 'Transferencia entre cuentas'
233
- initialize_with { attributes }
234
-
235
-
198
+ factory :transfer, class: Hash do
199
+ customer_id 'required'
200
+ amount 12.50
201
+ description 'Transferencia entre cuentas'
202
+ initialize_with { attributes }
236
203
  end
237
204
 
238
-
239
- factory :subscription, class:Hash do
240
-
241
- trial_days 30
205
+ factory :subscription, class: Hash do
206
+ trial_days 30
242
207
  card_id 'required'
243
208
  plan_id 'required'
244
209
  initialize_with { attributes }
245
-
246
-
247
-
248
-
249
-
250
-
251
210
  end
252
211
 
253
-
254
-
255
-
256
-
257
-
258
212
  end