openpay 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/lib/OpenPay/Fees.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'open_pay_resource'
2
-
3
- class Fees < OpenPayResource
4
-
5
- end
@@ -1,59 +0,0 @@
1
- require 'open_pay_resource'
2
-
3
-
4
-
5
- class Payouts < OpenPayResource
6
-
7
-
8
-
9
-
10
-
11
- def all(customer_id=nil)
12
- if customer_id
13
- customers=@api_hook.create(:customers)
14
- customers.all_payouts(customer_id)
15
- else
16
- super ''
17
- end
18
- end
19
-
20
- def get(payout='', customer_id=nil)
21
- if customer_id
22
- customers=@api_hook.create(:customers)
23
- customers.get_payout(customer_id, payout)
24
- else
25
- super payout
26
- end
27
- end
28
-
29
-
30
- def each(customer_id=nil)
31
- if customer_id
32
- customers=@api_hook.create(:customers)
33
- customers.each_payout(customer_id) do |cust|
34
- yield cust
35
- end
36
- else
37
- all.each do |cust|
38
- yield cust
39
- end
40
- end
41
-
42
- end
43
-
44
-
45
-
46
-
47
- def create(payout, customer_id=nil)
48
- if customer_id
49
- customers=@api_hook.create(:customers)
50
- customers.create_payout(customer_id, payout)
51
- else
52
- super payout
53
- end
54
- end
55
-
56
-
57
-
58
-
59
- end
data/lib/OpenPay/Plans.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'open_pay_resource'
2
-
3
- class Plans < OpenPayResource
4
-
5
- def update(plan,plan_id)
6
- put(plan, "#{plan_id}")
7
- end
8
-
9
- def each_subscription(plan_id)
10
- get("#{plan_id}/subscriptions")
11
- end
12
-
13
-
14
- def all_subscriptions(plan_id)
15
- get("#{plan_id}/subscriptions")
16
- end
17
-
18
-
19
- def each
20
- end
21
-
22
-
23
- end
@@ -1,58 +0,0 @@
1
- require 'open_pay_resource'
2
-
3
- class Subscriptions < OpenPayResource
4
-
5
-
6
-
7
- def create(subscription,plan_id)
8
- customers=@api_hook.create(:customers)
9
- customers.create_subscription(subscription,plan_id)
10
- end
11
-
12
-
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
-
21
- customers=@api_hook.create(:customers)
22
- customers.get_subscription(customer_id, subscription_id)
23
-
24
- end
25
-
26
-
27
- def all(customer_id)
28
-
29
- customers=@api_hook.create(:customers)
30
- customers.all_subscriptions(customer_id)
31
-
32
- end
33
-
34
-
35
- def each(customer_id)
36
- customers=@api_hook.create(:customers)
37
- customers.each_subscription(customer_id) do |c|
38
- yield c
39
- end
40
- end
41
-
42
-
43
- def delete_all(customer_id)
44
- customers=@api_hook.create(:customers)
45
- customers.delete_all_subscriptions(customer_id)
46
-
47
- end
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
- end
@@ -1,43 +0,0 @@
1
- require 'open_pay_resource'
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)
10
-
11
- end
12
-
13
- def all(customer_id)
14
- customers=@api_hook.create(:customers)
15
- customers.all_transfers(customer_id)
16
- end
17
-
18
-
19
-
20
- def get(transfer,customer_id)
21
-
22
- customers=@api_hook.create(:customers)
23
- customers.get_transfer(customer_id,transfer)
24
-
25
- end
26
-
27
-
28
- def each(customer_id)
29
- customers=@api_hook.create(:customers)
30
- customers.each_transfer(customer_id) do |tran|
31
- yield tran
32
- end
33
-
34
- end
35
-
36
-
37
-
38
-
39
-
40
- end
41
-
42
-
43
-
@@ -1,59 +0,0 @@
1
- require 'open_pay_resource'
2
-
3
-
4
- class Bankaccounts < OpenPayResource
5
-
6
-
7
- def create(bank_account,customer_id)
8
- customers=@api_hook.create(:customers)
9
- customers.create_bank_account(customer_id,bank_account)
10
- end
11
-
12
-
13
- def get(customer_id='',bank_account=nil)
14
- customers=@api_hook.create(:customers)
15
-
16
- if bank_account
17
- customers.get_bank_account(customer_id,bank_account)
18
- else
19
- customers.get_bank_account(customer_id)
20
- end
21
-
22
- end
23
-
24
-
25
- def delete(customer_id,bank_account)
26
- customers=@api_hook.create(:customers)
27
- customers.delete_bank_account(customer_id,bank_account)
28
- end
29
-
30
-
31
- def each(customer_id)
32
- customers=@api_hook.create(:customers)
33
- customers.each_bank_account(customer_id) do |acc|
34
- yield acc
35
- end
36
-
37
- end
38
-
39
-
40
- def all(customer_id)
41
- customers=@api_hook.create(:customers)
42
- customers.all_bank_accounts(customer_id)
43
- end
44
-
45
-
46
- def delete_all(customer_id)
47
-
48
- if env == :production
49
- raise OpenpayException.new('This method is not supported on PRODUCTION',false)
50
- end
51
-
52
- customers=@api_hook.create(:customers)
53
- customers.delete_all_bank_accounts(customer_id)
54
-
55
- end
56
-
57
-
58
-
59
- end
@@ -1,3 +0,0 @@
1
- require 'openpay/errors/openpay_exception'
2
- class OpenpayConnectionException < OpenpayException
3
- end
@@ -1,29 +0,0 @@
1
- class OpenpayException < StandardError
2
-
3
- attr_reader :description
4
- attr_reader :http_code
5
- attr_reader :http_body
6
- attr_reader :json_body
7
- attr_reader :error_code
8
- attr_reader :category
9
-
10
- def initialize(message=nil,json_message=true)
11
- #openpay errors have a json error string
12
- if json_message
13
- json= JSON.parse message
14
- @description = json['description']
15
- @http_code = json['http_code']
16
- @error_code = json['error_code']
17
- @json_body = message
18
- @category = json['category']
19
- #other errors may or not have a json error string, so this case is for them
20
- else
21
- @description = message
22
- @http_code = ''
23
- @http_body = ''
24
- @json_body = ''
25
- @error_code = ''
26
- end
27
- end
28
-
29
- end
@@ -1,60 +0,0 @@
1
- class OpenpayExceptionFactory
2
-
3
-
4
-
5
- def OpenpayExceptionFactory::create(exception)
6
-
7
- LOG.warn("An exception has been raised (original exception class: #{exception.class})")
8
- LOG.warn("An exception has been raised (original exception class: #{exception.message })")
9
-
10
-
11
- case exception
12
-
13
- #resource not found
14
- #malformed jason, invalid data, invalid request
15
- when RestClient::BadRequest , RestClient::ResourceNotFound ,
16
- RestClient::Conflict , RestClient::PaymentRequired ,
17
- RestClient::UnprocessableEntity
18
-
19
- oe=OpenpayTransactionException.new exception.http_body
20
- LOG.warn "-OpenpayTransactionException: #{exception.http_body}"
21
- @errors=true
22
- raise oe
23
-
24
-
25
-
26
- #connection, timeouts, network related errors
27
- when Errno::EADDRINUSE , Errno::ETIMEDOUT ,OpenSSL::SSL::SSLError
28
- #since this execeptions are not based on the rest api exeptions
29
- #we do not have the json message so we just build the exception
30
- #with the original exception message set in e.description and e.message
31
- oe=OpenpayConnectionException.new(exception.message,false)
32
- LOG.warn exception.message
33
- @errors=true
34
- raise oe
35
- #badgateway-connection error, invalid credentials
36
- when RestClient::BadGateway, RestClient::Unauthorized
37
- oe=OpenpayConnectionException.new exception.http_body
38
- LOG.warn exception.http_body
39
- @errors=true
40
- raise oe
41
-
42
- when RestClient::Exception , RestClient::InternalServerError
43
- oe=OpenpayException.new exception.http_body
44
- LOG.warn exception.http_body
45
- @errors=true
46
- raise oe
47
- else
48
- #We won't hide unknown exceptions , those should be raised
49
- LOG.warn exception.message
50
- raise exception
51
- end
52
- end
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
- end
@@ -1,5 +0,0 @@
1
- require 'openpay/errors/openpay_exception'
2
-
3
- class OpenpayTransactionException < OpenpayException
4
-
5
- end
@@ -1,242 +0,0 @@
1
-
2
-
3
- #This class is the abstract base class for other Openpay resources
4
- #This class defines the basic rest verbs making use of the rest-api gem.
5
- #Method aliases are created to provide friendly names.
6
- class OpenPayResource
7
-
8
- attr_accessor :api_hook
9
-
10
- def initialize(merchant_id,private_key,production=false)
11
- @merchant_id=merchant_id
12
- @private_key=private_key
13
- #assigns base url depending the requested env
14
- @base_url=OpenpayApi::base_url(production)
15
- @errors=false
16
- @production=production
17
- @timeout=90
18
- #created resources should have a hook with the base class to keep control of created resources
19
- @api_hook=nil
20
- end
21
-
22
-
23
- #returns the env set
24
- def env
25
- if @production
26
- :production
27
- else
28
- :test
29
- end
30
- end
31
-
32
- #errors on last call
33
- def errors?
34
- @errors
35
- end
36
-
37
-
38
- def list(args='')
39
- @base_url+ "#{@merchant_id}/"+ self.class.name.to_s.downcase+"/"+args
40
- end
41
-
42
- def each
43
- all.each do |line|
44
- yield line
45
- end
46
- end
47
-
48
- def delete_all
49
-
50
- if env == :production
51
- raise OpenpayException.new('delete_all method cannot be used on production',false)
52
- end
53
-
54
- each do |res|
55
- self.delete(res['id'])
56
- end
57
-
58
- end
59
-
60
- def get(args='')
61
-
62
- @errors=false
63
-
64
- LOG.debug("#{self.class.name.downcase}:")
65
- LOG.debug(" GET Resource URL:#{url(args)}")
66
- res=RestClient::Request.new(
67
- :method => :get,
68
- :url => url(args),
69
- :user => @private_key,
70
- :timeout => @timeout,
71
- :headers => {:accept => :json,
72
- :content_type => :json,
73
- :user_agent => 'Openpay/v1 Ruby-API',
74
- }
75
- )
76
- json_out=nil
77
- begin
78
- json_out=res.execute
79
- #exceptions
80
- rescue Exception => e
81
- @errors=true
82
- #will raise the appropriate exception and return
83
- OpenpayExceptionFactory::create(e)
84
- end
85
-
86
- JSON[json_out]
87
-
88
- end
89
-
90
- def delete(args)
91
-
92
- @errors=false
93
-
94
- LOG.debug("#{self.class.name.downcase}:")
95
- LOG.debug(" DELETE URL:#{url(args)}")
96
-
97
- res=''
98
- req=RestClient::Request.new(
99
- :method => :delete,
100
- :url => url(args),
101
- :user => @private_key,
102
- :timeout => @timeout,
103
- :headers => {:accept => :json,
104
- :content_type => :json,
105
- :user_agent => 'Openpay/v1 Ruby-API',
106
- }
107
- )
108
-
109
- begin
110
- res=req.execute
111
- #exceptions
112
- rescue Exception => e
113
- @errors=true
114
- #will raise the appropriate exception and return
115
- OpenpayExceptionFactory::create(e)
116
- end
117
-
118
- #returns a hash
119
- JSON[res] if not res.empty?
120
-
121
- end
122
-
123
- def post(message,args='')
124
-
125
- return_hash=false
126
- @errors=false
127
-
128
- if message.is_a?(Hash)
129
- return_hash=true
130
- json= hash2json message
131
- else
132
- json=message
133
- return_hash=false
134
- end
135
-
136
- LOG.debug("#{self.class.name.downcase}:")
137
- LOG.debug " POST URL:#{url(args)}"
138
- #For security reasons we keep it hide
139
- #LOG.debug " json: #{json}"
140
-
141
- begin
142
-
143
- #request
144
- res= RestClient::Request.new(
145
- :method => :post,
146
- :url => url(args) ,
147
- :user => @private_key,
148
- :timeout => @timeout,
149
- :payload => json,
150
- :headers => {:accept => :json,
151
- :content_type => :json,
152
- :user_agent => 'Openpay/v1 Ruby-API',
153
- :json => json}
154
- ) .execute
155
-
156
- #exceptions
157
- rescue Exception => e
158
- @errors=true
159
- #will raise the appropriate exception and return
160
- OpenpayExceptionFactory::create(e)
161
- end
162
-
163
- #return
164
- if return_hash
165
- JSON.parse res
166
- else
167
- res
168
- end
169
-
170
- end
171
-
172
-
173
-
174
- def put (message,args='')
175
-
176
- return_hash=false
177
-
178
- if message.is_a?(Hash)
179
- return_hash=true
180
- json= hash2json message
181
- else
182
- json=message
183
- return_hash=false
184
- end
185
-
186
-
187
- LOG.info "PUT URL:#{url}"
188
- #LOG.info " json: #{json}"
189
-
190
- begin
191
- res= RestClient::Request.new(
192
- :method => :put,
193
- :url => url(args),
194
- :user => @private_key,
195
- :timeout => @timeout,
196
- :payload => json,
197
- :headers => {:accept => :json,
198
- :content_type => :json,
199
- :user_agent => 'Openpay/v1 Ruby-API',
200
- :json => json}
201
- ) .execute
202
- rescue RestClient::BadRequest => e
203
- warn e.http_body
204
- @errors=true
205
- return JSON.parse e.http_body
206
- end
207
-
208
-
209
- if return_hash
210
- JSON.parse res
211
- else
212
- res
213
- end
214
-
215
- end
216
-
217
-
218
- #aliases for rest verbs
219
- alias_method :all, :get
220
- alias_method :list, :get
221
- alias_method :update, :put
222
- alias_method :create , :post
223
-
224
-
225
- def hash2json(jash)
226
- JSON.generate(jash)
227
- end
228
-
229
- def json2hash(json)
230
- JSON[json]
231
- end
232
-
233
-
234
- private
235
- def url(args='')
236
- @base_url+"#{@merchant_id}/"+ self.class.name.to_s.downcase+ '/'+args
237
- end
238
-
239
-
240
-
241
-
242
- end