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
@@ -11,36 +11,53 @@ class Charges < OpenPayResource
11
11
  end
12
12
  end
13
13
 
14
-
15
- def cancel(transaction_id,customer_id=nil)
14
+ def cancel(transaction_id, customer_id=nil)
16
15
  if customer_id
17
16
  customers=@api_hook.create(:customers)
18
17
  customers.cancel_charge(customer_id, transaction_id)
19
18
  else
20
- post('', transaction_id+'/cancel')
21
- end
19
+ post('', transaction_id+'/cancel')
20
+ end
22
21
  end
23
22
 
24
-
25
- def refund(transaction_id,description,customer_id=nil)
23
+ def refund(transaction_id, description, customer_id=nil)
26
24
  if customer_id
27
25
  customers=@api_hook.create(:customers)
28
- customers.refund_charge(customer_id,transaction_id,description)
26
+ customers.refund_charge(customer_id, transaction_id, description)
29
27
  else
30
28
  post(description, transaction_id+'/refund')
31
29
  end
32
30
  end
33
31
 
34
-
35
- def capture(transaction_id,customer_id=nil)
32
+ def capture(transaction_id, customer_id=nil)
36
33
  if customer_id
37
34
  customers=@api_hook.create(:customers)
38
- customers.capture_charge(customer_id,transaction_id )
35
+ customers.capture_charge(customer_id, transaction_id)
39
36
  else
40
- post( '',transaction_id+'/capture')
37
+ post('', transaction_id+'/capture')
41
38
  end
42
39
  end
43
40
 
41
+ def confirm_capture(options)
42
+
43
+ customer_id = options.fetch(:customer_id) { '' }
44
+ transaction_id = options.fetch(:transaction_id)
45
+ amount = options.fetch(:amount)
46
+
47
+ if amount.nil? or transaction_id.nil?
48
+ raise OpenpayException.new
49
+ end
50
+
51
+ amount_hash = { amount: amount }
52
+
53
+ unless customer_id.empty?
54
+ customers=@api_hook.create(:customers)
55
+ customers.confirm_customer_capture(customer_id, transaction_id, amount_hash)
56
+ else
57
+ post(amount_hash, transaction_id+'/capture')
58
+ end
59
+
60
+ end
44
61
 
45
62
  def each(customer_id=nil)
46
63
  if customer_id
@@ -54,8 +71,6 @@ class Charges < OpenPayResource
54
71
  end
55
72
  end
56
73
 
57
-
58
-
59
74
  def get(charge='', customer_id=nil)
60
75
  if customer_id
61
76
  customers=@api_hook.create(:customers)
@@ -74,4 +89,13 @@ class Charges < OpenPayResource
74
89
  end
75
90
  end
76
91
 
77
- end
92
+ def list(search_params, customer_id=nil)
93
+ if customer_id
94
+ customers=@api_hook.create(:customers)
95
+ customers.list_charges(customer_id, search_params)
96
+ else
97
+ super search_params
98
+ end
99
+ end
100
+
101
+ end
@@ -1,16 +1,13 @@
1
1
  require 'open_pay_resource'
2
2
 
3
-
4
-
5
3
  class Customers < OpenPayResource
6
4
 
7
-
8
5
  #Bankaccount
9
- def create_bank_account(customer,bank_account)
10
- create(bank_account,"#{customer}/bankaccounts")
6
+ def create_bank_account(customer, bank_account)
7
+ create(bank_account, "#{customer}/bankaccounts")
11
8
  end
12
9
 
13
- def get_bank_account(customer,bank_id)
10
+ def get_bank_account(customer, bank_id)
14
11
  get("#{customer}/bankaccounts/#{bank_id}")
15
12
  end
16
13
 
@@ -18,89 +15,102 @@ class Customers < OpenPayResource
18
15
  get("#{customer}/bankaccounts/")
19
16
  end
20
17
 
18
+ def list_bankaccounts(customer, search_params)
19
+ get("#{customer}/bankaccounts#{search_params.to_s}")
20
+ end
21
+
21
22
  def each_bank_account(customer)
22
23
  get("#{customer}/bankaccounts/").each do |account|
23
- yield account
24
+ yield account
24
25
  end
25
26
  end
26
27
 
27
-
28
- def delete_bank_account(customer,bank_id)
28
+ def delete_bank_account(customer, bank_id)
29
29
  delete("#{customer}/bankaccounts/#{bank_id}")
30
30
  end
31
31
 
32
32
  def delete_all_bank_accounts(customer)
33
33
  if env == :production
34
- raise OpenpayException.new('This method is not supported on PRODUCTION',false)
34
+ raise OpenpayException.new('This method is not supported on PRODUCTION', false)
35
35
  end
36
36
  each_bank_account(customer) do |account|
37
37
  delete("#{customer}/bankaccounts/#{account['id']}")
38
38
  end
39
39
  end
40
40
 
41
-
42
- #Charges
41
+ #Charges
43
42
  # customers.create_charge(customer_id,charge)
44
- def create_charge(customer_id,charge)
45
- create(charge,"#{customer_id}/charges")
43
+ def create_charge(customer_id, charge)
44
+ create(charge, "#{customer_id}/charges")
46
45
  end
47
46
 
48
47
  #gets a charge_id for a given customer_id
49
- def get_charge(customer_id,charge_id)
48
+ def get_charge(customer_id, charge_id)
50
49
  get("#{customer_id}/charges/#{charge_id}")
51
50
  end
52
51
 
52
+ def list_charges(customer, search_params)
53
+ get("#{customer}/charges#{search_params.to_s}")
54
+ end
55
+
53
56
  #return all charges for the given customer_id
54
57
  def all_charges(customer_id)
55
58
  get("#{customer_id}/charges/")
56
59
  end
57
60
 
58
- def cancel_charge(customer_id,charge_id)
59
- post(charge_id,"#{customer_id}/charges/#{charge_id}/cancel")
61
+ def cancel_charge(customer_id, charge_id)
62
+ post(charge_id, "#{customer_id}/charges/#{charge_id}/cancel")
60
63
  end
61
64
 
62
- def refund_charge(customer_id,charge_id,description)
63
- post(description,"#{customer_id}/charges/#{charge_id}/refund")
65
+ def refund_charge(customer_id, charge_id, description)
66
+ post(description, "#{customer_id}/charges/#{charge_id}/refund")
64
67
  end
65
68
 
66
- def capture_charge(customer_id,charge_id)
67
- post('',"#{customer_id}/charges/#{charge_id}/capture")
69
+ def capture_charge(customer_id, charge_id)
70
+ post('', "#{customer_id}/charges/#{charge_id}/capture")
68
71
  end
69
72
 
70
-
73
+ def confirm_customer_capture(customer_id, charge_id, amount)
74
+ post(amount, "#{customer_id}/charges/#{charge_id}/capture")
75
+ end
71
76
 
72
77
  #Payouts
73
- def create_payout(customer_id,payout)
74
- post(payout,"#{customer_id}/payouts")
78
+ def create_payout(customer_id, payout)
79
+ post(payout, "#{customer_id}/payouts")
75
80
  end
76
81
 
77
82
  def all_payouts(customer_id)
78
- get("#{customer_id}/payouts")
83
+ get("#{customer_id}/payouts")
79
84
  end
80
85
 
81
- def get_payout(customer_id,payout_id)
86
+ def get_payout(customer_id, payout_id)
82
87
  get("#{customer_id}/payouts/#{payout_id}")
83
88
  end
84
89
 
85
90
  def each_payout(customer_id)
86
- all_payouts(customer_id).each do |pay|
87
- yield pay
88
- end
91
+ all_payouts(customer_id).each do |pay|
92
+ yield pay
93
+ end
89
94
  end
90
95
 
91
-
92
-
96
+ def list_payouts(customer, search_params)
97
+ get("#{customer}/payouts#{search_params.to_s}")
98
+ end
93
99
 
94
100
  #Transfers
95
- def create_transfer(customer_id,transfer)
96
- post(transfer,"#{customer_id}/transfers")
101
+ def create_transfer(customer_id, transfer)
102
+ post(transfer, "#{customer_id}/transfers")
97
103
  end
98
104
 
99
105
  def all_transfers(customer_id)
100
106
  get("#{customer_id}/transfers/")
101
107
  end
102
108
 
103
- def get_transfer(customer_id,transfer_id)
109
+ def list_transfers(customer, search_params)
110
+ get("#{customer}/transfers#{search_params.to_s}")
111
+ end
112
+
113
+ def get_transfer(customer_id, transfer_id)
104
114
  get("#{customer_id}/transfers/#{transfer_id}")
105
115
  end
106
116
 
@@ -110,85 +120,81 @@ class Customers < OpenPayResource
110
120
  end
111
121
  end
112
122
 
113
-
114
-
115
-
116
123
  #Subscriptions
117
- def create_subscription(subscription, plan_id)
118
- post(subscription,"#{plan_id}/subscriptions")
124
+ def create_subscription(subscription, customer_id)
125
+ #revisar la url
126
+ post(subscription, "#{customer_id}/subscriptions")
119
127
  end
120
128
 
121
-
122
- def delete_subscription(customer_id,subscription_id)
129
+ def delete_subscription(customer_id, subscription_id)
123
130
  delete("#{customer_id}/subscriptions/#{subscription_id}")
124
131
  end
125
132
 
126
-
127
- def get_subscription(customer_id,subscription_id)
133
+ def get_subscription(customer_id, subscription_id)
128
134
  get("#{customer_id}/subscriptions/#{subscription_id}")
129
135
  end
130
136
 
131
-
132
137
  def all_subscriptions(customer_id)
133
138
  get("#{customer_id}/subscriptions/")
134
139
  end
135
140
 
141
+ def list_subscriptions(customer, search_params)
142
+ get("#{customer}/subscriptions#{search_params.to_s}")
143
+ end
144
+
136
145
  def each_subscription(customer_id)
137
146
  all_subscriptions(customer_id).each do |cust|
138
- yield cust
147
+ yield cust
139
148
  end
140
149
  end
141
150
 
151
+ def update_subscription(subscription, customer, params)
152
+ put(params, "#{customer}/subscriptions/#{subscription}")
153
+ end
142
154
 
143
155
  def delete_all_subscriptions(customer_id)
144
156
  if env == :production
145
- raise OpenPayError ('This method is not supported on PRODUCTION')
157
+ raise OpenpayException.new('This method is not supported on PRODUCTION', false)
146
158
  end
147
159
  all_subscriptions(customer_id).each do |sub|
148
- delete_subscription(customer_id,sub['id'])
160
+ delete_subscription(customer_id, sub['id'])
149
161
  end
150
162
  end
151
163
 
152
-
153
-
154
-
155
164
  #Card
156
- def create_card(customer,card)
157
- create(card,"#{customer}/cards")
165
+ def create_card(customer, card)
166
+ create(card, "#{customer}/cards")
158
167
  end
159
168
 
160
-
161
- def get_card(customer,card_id)
169
+ def get_card(customer, card_id)
162
170
  get("#{customer}/cards/#{card_id}")
163
171
  end
164
172
 
165
-
166
- def delete_card(customer,card_id)
167
- delete("#{customer}/cards/#{card_id}")
173
+ def delete_card(customer, card_id)
174
+ delete("#{customer}/cards/#{card_id}")
168
175
  end
169
176
 
170
-
171
177
  def delete_all_cards(customer_id)
172
178
  if env == :production
173
- raise OpenPayError ('This method is not supported on PRODUCTION')
179
+ raise OpenpayException.new('This method is not supported on PRODUCTION', false)
174
180
  end
175
181
  each_card(customer_id) do |card|
176
- delete_card(customer_id,card['id'])
182
+ delete_card(customer_id, card['id'])
177
183
  end
178
184
  end
179
185
 
180
-
181
186
  def each_card(customer)
182
- get("#{customer}/cards").each do |card|
183
- yield card
184
- end
187
+ get("#{customer}/cards").each do |card|
188
+ yield card
189
+ end
185
190
  end
186
191
 
192
+ def list_cards(customer, search_params)
193
+ get("#{customer}/cards#{search_params.to_s}")
194
+ end
187
195
 
188
196
  def all_cards(customer)
189
197
  get("#{customer}/cards")
190
198
  end
191
199
 
192
-
193
-
194
- end
200
+ end
@@ -1,49 +1,43 @@
1
1
  class OpenpayExceptionFactory
2
2
 
3
-
4
-
5
- def OpenpayExceptionFactory::create(exception)
3
+ def OpenpayExceptionFactory::create(exception)
6
4
 
7
5
  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
6
 
11
7
  case exception
12
8
 
13
9
  #resource not found
14
10
  #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
-
11
+ when RestClient::BadRequest, RestClient::ResourceNotFound,
12
+ RestClient::Conflict, RestClient::PaymentRequired,
13
+ RestClient::UnprocessableEntity
24
14
 
15
+ oe=OpenpayTransactionException.new exception.http_body
16
+ LOG.warn "-OpenpayTransactionException: #{exception.http_body}"
17
+ @errors=true
18
+ raise oe
25
19
 
26
20
  #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
21
+ when Errno::EADDRINUSE, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError
22
+ #since this exceptions are not based on the rest api exceptions
29
23
  #we do not have the json message so we just build the exception
30
24
  #with the original exception message set in e.description and e.message
31
25
  oe=OpenpayConnectionException.new(exception.message,false)
32
26
  LOG.warn exception.message
33
27
  @errors=true
34
- raise oe
28
+ raise oe
35
29
  #badgateway-connection error, invalid credentials
36
30
  when RestClient::BadGateway, RestClient::Unauthorized
37
31
  oe=OpenpayConnectionException.new exception.http_body
38
32
  LOG.warn exception.http_body
39
33
  @errors=true
40
- raise oe
34
+ raise oe
41
35
 
42
36
  when RestClient::Exception , RestClient::InternalServerError
43
37
  oe=OpenpayException.new exception.http_body
44
38
  LOG.warn exception.http_body
45
39
  @errors=true
46
- raise oe
40
+ raise oe
47
41
  else
48
42
  #We won't hide unknown exceptions , those should be raised
49
43
  LOG.warn exception.message
@@ -51,10 +45,4 @@ class OpenpayExceptionFactory
51
45
  end
52
46
  end
53
47
 
54
-
55
-
56
-
57
-
58
-
59
-
60
- end
48
+ end
data/lib/openpay/fees.rb CHANGED
@@ -2,4 +2,4 @@ require 'open_pay_resource'
2
2
 
3
3
  class Fees < OpenPayResource
4
4
 
5
- end
5
+ end
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  #This class is the abstract base class for other Openpay resources
4
2
  #This class defines the basic rest verbs making use of the rest-api gem.
5
3
  #Method aliases are created to provide friendly names.
@@ -7,21 +5,20 @@ class OpenPayResource
7
5
 
8
6
  attr_accessor :api_hook
9
7
 
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
8
+ def initialize(merchant_id, private_key, production=false)
9
+ @merchant_id=merchant_id
10
+ @private_key=private_key
11
+ #assigns base url depending the requested env
12
+ @base_url=OpenpayApi::base_url(production)
13
+ @errors=false
16
14
  @production=production
17
15
  @timeout=90
18
- #created resources should have a hook with the base class to keep control of created resources
16
+ #created resources should have a hook with the base class to keep control of created resources
19
17
  @api_hook=nil
20
18
  end
21
19
 
22
-
23
20
  #returns the env set
24
- def env
21
+ def env
25
22
  if @production
26
23
  :production
27
24
  else
@@ -31,12 +28,11 @@ class OpenPayResource
31
28
 
32
29
  #errors on last call
33
30
  def errors?
34
- @errors
31
+ @errors
35
32
  end
36
33
 
37
-
38
- def list(args='')
39
- @base_url+ "#{@merchant_id}/"+ self.class.name.to_s.downcase+"/"+args
34
+ def list(search_params)
35
+ get(search_params.to_s)
40
36
  end
41
37
 
42
38
  def each
@@ -48,7 +44,7 @@ class OpenPayResource
48
44
  def delete_all
49
45
 
50
46
  if env == :production
51
- raise OpenpayException.new('delete_all method cannot be used on production',false)
47
+ raise OpenpayException.new('delete_all method cannot be used on production', false)
52
48
  end
53
49
 
54
50
  each do |res|
@@ -59,13 +55,18 @@ class OpenPayResource
59
55
 
60
56
  def get(args='')
61
57
 
62
- @errors=false
58
+ @errors = false
59
+ terminated = true
63
60
 
64
- LOG.debug("#{self.class.name.downcase}:")
65
- LOG.debug(" GET Resource URL:#{url(args)}")
61
+ if is_filter_string?(args)
62
+ terminated = false
63
+ end
64
+
65
+ LOG.debug("#{resource_name}:")
66
+ LOG.debug(" GET Resource URL:#{url(args, terminated)}")
66
67
  res=RestClient::Request.new(
67
68
  :method => :get,
68
- :url => url(args),
69
+ :url => url(args, terminated),
69
70
  :user => @private_key,
70
71
  :timeout => @timeout,
71
72
  :headers => {:accept => :json,
@@ -76,7 +77,7 @@ class OpenPayResource
76
77
  json_out=nil
77
78
  begin
78
79
  json_out=res.execute
79
- #exceptions
80
+ #exceptions
80
81
  rescue Exception => e
81
82
  @errors=true
82
83
  #will raise the appropriate exception and return
@@ -87,42 +88,39 @@ class OpenPayResource
87
88
 
88
89
  end
89
90
 
90
- def delete(args)
91
+ def delete(args)
91
92
 
92
- @errors=false
93
+ @errors=false
93
94
 
94
- LOG.debug("#{self.class.name.downcase}:")
95
- LOG.debug(" DELETE URL:#{url(args)}")
95
+ LOG.debug("#{self.class.name.downcase}:")
96
+ LOG.debug(" DELETE URL:#{url(args)}")
96
97
 
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
- )
98
+ res=''
99
+ req=RestClient::Request.new(
100
+ :method => :delete,
101
+ :url => url(args),
102
+ :user => @private_key,
103
+ :timeout => @timeout,
104
+ :headers => {:accept => :json,
105
+ :content_type => :json,
106
+ :user_agent => 'Openpay/v1 Ruby-API',
107
+ }
108
+ )
108
109
 
109
- begin
110
+ begin
110
111
  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
-
112
+ #exceptions
113
+ rescue Exception => e
114
+ @errors=true
115
+ #will raise the appropriate exception and return
116
+ OpenpayExceptionFactory::create(e)
117
+ end
118
118
  #returns a hash
119
- JSON[res] if not res.empty?
120
-
121
- end
119
+ JSON[res] if not res.empty?
120
+ end
122
121
 
123
- def post(message,args='')
122
+ def post(message, args='')
124
123
 
125
- return_hash=false
126
124
  @errors=false
127
125
 
128
126
  if message.is_a?(Hash)
@@ -133,17 +131,16 @@ class OpenPayResource
133
131
  return_hash=false
134
132
  end
135
133
 
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}"
134
+ # LOG.debug("#{self.class.name.downcase}:")
135
+ LOG.debug " POST URL:#{url(args)}"
136
+ LOG.debug " json: #{json}"
140
137
 
141
138
  begin
142
139
 
143
- #request
144
- res= RestClient::Request.new(
140
+ #request
141
+ res= RestClient::Request.new(
145
142
  :method => :post,
146
- :url => url(args) ,
143
+ :url => url(args),
147
144
  :user => @private_key,
148
145
  :timeout => @timeout,
149
146
  :payload => json,
@@ -151,9 +148,9 @@ class OpenPayResource
151
148
  :content_type => :json,
152
149
  :user_agent => 'Openpay/v1 Ruby-API',
153
150
  :json => json}
154
- ) .execute
151
+ ).execute
155
152
 
156
- #exceptions
153
+ #exceptions
157
154
  rescue Exception => e
158
155
  @errors=true
159
156
  #will raise the appropriate exception and return
@@ -169,9 +166,7 @@ class OpenPayResource
169
166
 
170
167
  end
171
168
 
172
-
173
-
174
- def put (message,args='')
169
+ def put(message, args='')
175
170
 
176
171
  return_hash=false
177
172
 
@@ -183,7 +178,6 @@ class OpenPayResource
183
178
  return_hash=false
184
179
  end
185
180
 
186
-
187
181
  LOG.info "PUT URL:#{url}"
188
182
  #LOG.info " json: #{json}"
189
183
 
@@ -198,29 +192,25 @@ class OpenPayResource
198
192
  :content_type => :json,
199
193
  :user_agent => 'Openpay/v1 Ruby-API',
200
194
  :json => json}
201
- ) .execute
202
- rescue RestClient::BadRequest => e
195
+ ).execute
196
+ rescue RestClient::BadRequest => e
203
197
  warn e.http_body
204
198
  @errors=true
205
- return JSON.parse e.http_body
199
+ return JSON.parse e.http_body
206
200
  end
207
201
 
208
-
209
202
  if return_hash
210
- JSON.parse res
203
+ JSON.parse res
211
204
  else
212
- res
205
+ res
213
206
  end
214
207
 
215
208
  end
216
209
 
217
-
218
210
  #aliases for rest verbs
219
211
  alias_method :all, :get
220
- alias_method :list, :get
221
212
  alias_method :update, :put
222
- alias_method :create , :post
223
-
213
+ alias_method :create, :post
224
214
 
225
215
  def hash2json(jash)
226
216
  JSON.generate(jash)
@@ -230,13 +220,23 @@ class OpenPayResource
230
220
  JSON[json]
231
221
  end
232
222
 
223
+ private
233
224
 
234
- private
235
- def url(args='')
236
- @base_url+"#{@merchant_id}/"+ self.class.name.to_s.downcase+ '/'+args
225
+ def url(args = '', terminated = true)
226
+ termination = terminated ? '/' : ''
227
+ @base_url + "#{@merchant_id}/" + resource_name + termination + args
237
228
  end
238
229
 
230
+ def resource_name
231
+ self.class.name.to_s.downcase
232
+ end
239
233
 
234
+ def is_filter_string?(args)
235
+ is_filter = false
236
+ if args =~ /^\?/
237
+ is_filter = true
238
+ end
239
+ is_filter
240
+ end
240
241
 
241
-
242
- end
242
+ end