openpay 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/.idea/.rakeTasks +1 -1
- data/.idea/OpenPay.iml +63 -28
- data/.idea/workspace.xml +1501 -0
- data/Gemfile +7 -2
- data/README.md +6 -15
- data/Rakefile +10 -7
- data/lib/OpenPay/Cards.rb +1 -2
- data/lib/OpenPay/Customers.rb +0 -1
- data/lib/OpenPay/Plans.rb +0 -5
- data/lib/OpenPay/bankaccounts.rb +0 -7
- data/lib/OpenPay/errors/openpay_exception_factory.rb +2 -0
- data/lib/OpenPay/open_pay_resource.rb +3 -3
- data/lib/OpenPay/openpay_api.rb +3 -6
- data/lib/openpay/bankaccounts.rb +59 -0
- data/lib/openpay/cards.rb +75 -0
- data/lib/openpay/charges.rb +77 -0
- data/lib/openpay/customers.rb +194 -0
- data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
- data/lib/openpay/errors/openpay_exception.rb +29 -0
- data/lib/openpay/errors/openpay_exception_factory.rb +60 -0
- data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
- data/lib/openpay/fees.rb +5 -0
- data/lib/openpay/open_pay_resource.rb +242 -0
- data/lib/openpay/open_pay_resource_factory.rb +10 -0
- data/lib/openpay/openpay_api.rb +60 -0
- data/lib/openpay/payouts.rb +59 -0
- data/lib/openpay/plans.rb +23 -0
- data/lib/openpay/subscriptions.rb +58 -0
- data/lib/openpay/transfers.rb +43 -0
- data/lib/openpay.rb +5 -5
- data/lib/version.rb +2 -2
- data/openpay.gemspec +17 -5
- data/test/spec/bankaccounts_spec.rb +1 -2
- data/test/spec/cards_spec.rb +1 -1
- data/test/spec/charges_spec.rb +1 -2
- data/test/spec/customers_spec.rb +2 -2
- data/test/spec/exceptions_spec.rb +1 -1
- data/test/spec/fees_spec.rb +2 -2
- data/test/spec/openpayresource_spec.rb +1 -1
- data/test/spec/payouts_spec.rb +1 -1
- data/test/spec/plans_spec.rb +1 -1
- data/test/spec/subscriptions_spec.rb +1 -1
- data/test/spec/transfers_spec.rb +1 -1
- data/test/spec_helper.rb +7 -2
- metadata +91 -3
data/Gemfile
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
|
3
4
|
gem 'rspec'
|
4
|
-
gem 'rest-client'
|
5
|
-
gem 'factory_girl'
|
5
|
+
gem 'rest-client', '~>1.6.7'
|
6
|
+
gem 'factory_girl' , '4.2.0'
|
6
7
|
gem 'json_spec'
|
7
8
|
|
8
9
|
|
10
|
+
|
11
|
+
|
12
|
+
|
9
13
|
# Specify your gem's dependencies in Openpay.gemspec
|
10
14
|
gemspec
|
15
|
+
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Openpay-Ruby
|
3
2
|
|
4
3
|
##Description
|
5
4
|
|
@@ -322,14 +321,6 @@ open_pay_resource.delete_all(customer_id=nil)
|
|
322
321
|
|
323
322
|
customer_cards=cards.all(customer_id)
|
324
323
|
|
325
|
-
- all merchant cards
|
326
|
-
|
327
|
-
merchant_cards=cards.all
|
328
|
-
|
329
|
-
- all customer card
|
330
|
-
|
331
|
-
customer_cards=cards.all(customer_id)
|
332
|
-
|
333
324
|
- delete merchant card
|
334
325
|
|
335
326
|
cards.delete(card_id)
|
@@ -338,11 +329,11 @@ open_pay_resource.delete_all(customer_id=nil)
|
|
338
329
|
|
339
330
|
cards.delete(card_id,customer_id)
|
340
331
|
|
341
|
-
-delete all merchant cards
|
332
|
+
- delete all merchant cards
|
342
333
|
|
343
334
|
cards.delete_all
|
344
335
|
|
345
|
-
-delete all customer cards
|
336
|
+
- delete all customer cards
|
346
337
|
|
347
338
|
cards.delete_all(customer_id)
|
348
339
|
|
@@ -662,7 +653,6 @@ rescue OpenpayApiTransactionError => e
|
|
662
653
|
end
|
663
654
|
```
|
664
655
|
|
665
|
-
|
666
656
|
###These exceptions have the following attributes:
|
667
657
|
|
668
658
|
- *category*
|
@@ -686,12 +676,13 @@ In the Openpay dashboard you are able to see every request and its corresponding
|
|
686
676
|
- bank accounts for merchant cannot be created using the api. It should be done through the dashboard.
|
687
677
|
- Is recommended to reset your account using the dashboard when running serious testing (assure clean state)
|
688
678
|
- check openpay_ap.rb for Logger configuration
|
689
|
-
- travis https://travis-ci.org/open-pay/openpay-ruby
|
679
|
+
- travis https://travis-ci.org/open-pay/openpay-ruby , if a test fails it will leave leave some records, it may affect posterior tests.
|
680
|
+
it is recommended to reset the console/account to assure a clean state after a failure occurs.
|
690
681
|
|
691
682
|
## More information
|
692
683
|
For more use cases take a look at the *test/spec* folder
|
693
684
|
|
694
|
-
1. http://docs.openpay.mx/
|
685
|
+
1. http://docs.openpay.mx/
|
695
686
|
|
696
687
|
|
697
688
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
require 'rspec/core/rake_task'
|
1
|
+
require 'rspec'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
+
task :default => [:spec]
|
4
5
|
|
6
|
+
desc 'run specifications'
|
7
|
+
RSpec::Core::RakeTask.new do |t|
|
8
|
+
t.pattern = 'test/spec/*'
|
9
|
+
end
|
5
10
|
|
6
|
-
task :default => [:spec]
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
+
RSpec::Core::RakeTask.new('bankaccounts') do |t|
|
13
|
+
t.pattern = 'test/spec/bankaccounts*'
|
14
|
+
end
|
12
15
|
|
data/lib/OpenPay/Cards.rb
CHANGED
data/lib/OpenPay/Customers.rb
CHANGED
@@ -34,7 +34,6 @@ class Customers < OpenPayResource
|
|
34
34
|
raise OpenpayException.new('This method is not supported on PRODUCTION',false)
|
35
35
|
end
|
36
36
|
each_bank_account(customer) do |account|
|
37
|
-
warn "deleting bank_account: #{account['id']}"
|
38
37
|
delete("#{customer}/bankaccounts/#{account['id']}")
|
39
38
|
end
|
40
39
|
end
|
data/lib/OpenPay/Plans.rb
CHANGED
@@ -2,13 +2,10 @@ require 'open_pay_resource'
|
|
2
2
|
|
3
3
|
class Plans < OpenPayResource
|
4
4
|
|
5
|
-
|
6
5
|
def update(plan,plan_id)
|
7
6
|
put(plan, "#{plan_id}")
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
9
|
def each_subscription(plan_id)
|
13
10
|
get("#{plan_id}/subscriptions")
|
14
11
|
end
|
@@ -23,6 +20,4 @@ class Plans < OpenPayResource
|
|
23
20
|
end
|
24
21
|
|
25
22
|
|
26
|
-
|
27
|
-
|
28
23
|
end
|
data/lib/OpenPay/bankaccounts.rb
CHANGED
@@ -5,6 +5,8 @@ class OpenpayExceptionFactory
|
|
5
5
|
def OpenpayExceptionFactory::create(exception)
|
6
6
|
|
7
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
|
+
|
8
10
|
|
9
11
|
case exception
|
10
12
|
|
@@ -52,7 +52,6 @@ class OpenPayResource
|
|
52
52
|
end
|
53
53
|
|
54
54
|
each do |res|
|
55
|
-
warn "deleting #{res}"
|
56
55
|
self.delete(res['id'])
|
57
56
|
end
|
58
57
|
|
@@ -136,7 +135,8 @@ class OpenPayResource
|
|
136
135
|
|
137
136
|
LOG.debug("#{self.class.name.downcase}:")
|
138
137
|
LOG.debug " POST URL:#{url(args)}"
|
139
|
-
|
138
|
+
#For security reasons we keep it hide
|
139
|
+
#LOG.debug " json: #{json}"
|
140
140
|
|
141
141
|
begin
|
142
142
|
|
@@ -185,7 +185,7 @@ class OpenPayResource
|
|
185
185
|
|
186
186
|
|
187
187
|
LOG.info "PUT URL:#{url}"
|
188
|
-
LOG.info " json: #{json}"
|
188
|
+
#LOG.info " json: #{json}"
|
189
189
|
|
190
190
|
begin
|
191
191
|
res= RestClient::Request.new(
|
data/lib/OpenPay/openpay_api.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
1
1
|
require 'logger'
|
2
|
-
require 'open_pay_resource_factory'
|
3
2
|
require 'base64'
|
4
3
|
require 'rest-client'
|
5
4
|
require 'uri'
|
6
|
-
require 'openpay/errors/openpay_exception'
|
7
5
|
|
6
|
+
require 'openpay/open_pay_resource_factory'
|
7
|
+
require 'errors/openpay_exception'
|
8
8
|
|
9
9
|
LOG= Logger.new(STDOUT)
|
10
|
-
|
11
10
|
#change to Logger::DEBUG if need trace information
|
12
11
|
#due the nature of the information, we recommend to never use a log file when in debug
|
13
|
-
LOG.level=Logger::
|
12
|
+
LOG.level=Logger::ERROR
|
14
13
|
|
15
14
|
|
16
15
|
class OpenpayApi
|
17
16
|
|
18
|
-
|
19
17
|
#API Endpoints
|
20
18
|
API_DEV='https://sandbox-api.openpay.mx/v1/'
|
21
19
|
API_PROD='https://api.openpay.mx'
|
22
20
|
|
23
|
-
|
24
21
|
#by default the testing environment is used
|
25
22
|
def initialize(merchant_id, private_key,production=false)
|
26
23
|
@merchant_id=merchant_id
|
@@ -0,0 +1,59 @@
|
|
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
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'open_pay_resource'
|
2
|
+
|
3
|
+
class Cards < OpenPayResource
|
4
|
+
|
5
|
+
def list(creation,before,after,offset=0,limit=10)
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def get(card='',customer_id=nil)
|
11
|
+
if customer_id
|
12
|
+
customers=@api_hook.create(:customers)
|
13
|
+
customers.get_card(customer_id,card)
|
14
|
+
else
|
15
|
+
super card
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def create(card,customer_id=nil)
|
21
|
+
if customer_id
|
22
|
+
customers=@api_hook.create(:customers)
|
23
|
+
customers.create_card(customer_id,card)
|
24
|
+
else
|
25
|
+
super card
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def delete(card_id,customer_id=nil)
|
31
|
+
if customer_id
|
32
|
+
customers=@api_hook.create(:customers)
|
33
|
+
customers.delete_card(customer_id,card_id)
|
34
|
+
else
|
35
|
+
super card_id
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def delete_all(customer_id=nil)
|
41
|
+
if customer_id
|
42
|
+
customers=@api_hook.create(:customers)
|
43
|
+
customers.delete_all_cards(customer_id)
|
44
|
+
else
|
45
|
+
each do |card|
|
46
|
+
delete(card['id'])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def each(customer_id=nil)
|
53
|
+
if customer_id
|
54
|
+
all(customer_id).each do |card|
|
55
|
+
yield card
|
56
|
+
end
|
57
|
+
else
|
58
|
+
all.each do |card|
|
59
|
+
yield card
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def all(customer_id=nil)
|
66
|
+
if customer_id
|
67
|
+
customers=@api_hook.create(:customers)
|
68
|
+
customers.all_cards(customer_id)
|
69
|
+
else
|
70
|
+
super ''
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'open_pay_resource'
|
2
|
+
|
3
|
+
class Charges < OpenPayResource
|
4
|
+
|
5
|
+
def all(customer_id=nil)
|
6
|
+
if customer_id
|
7
|
+
customers=@api_hook.create(:customers)
|
8
|
+
customers.all_charges(customer_id)
|
9
|
+
else
|
10
|
+
super ''
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def cancel(transaction_id,customer_id=nil)
|
16
|
+
if customer_id
|
17
|
+
customers=@api_hook.create(:customers)
|
18
|
+
customers.cancel_charge(customer_id, transaction_id)
|
19
|
+
else
|
20
|
+
post('', transaction_id+'/cancel')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def refund(transaction_id,description,customer_id=nil)
|
26
|
+
if customer_id
|
27
|
+
customers=@api_hook.create(:customers)
|
28
|
+
customers.refund_charge(customer_id,transaction_id,description)
|
29
|
+
else
|
30
|
+
post(description, transaction_id+'/refund')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def capture(transaction_id,customer_id=nil)
|
36
|
+
if customer_id
|
37
|
+
customers=@api_hook.create(:customers)
|
38
|
+
customers.capture_charge(customer_id,transaction_id )
|
39
|
+
else
|
40
|
+
post( '',transaction_id+'/capture')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def each(customer_id=nil)
|
46
|
+
if customer_id
|
47
|
+
all(customer_id).each do |card|
|
48
|
+
yield card
|
49
|
+
end
|
50
|
+
else
|
51
|
+
all.each do |card|
|
52
|
+
yield card
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def get(charge='', customer_id=nil)
|
60
|
+
if customer_id
|
61
|
+
customers=@api_hook.create(:customers)
|
62
|
+
customers.get_charge(customer_id, charge)
|
63
|
+
else
|
64
|
+
super charge
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create(charge, customer_id=nil)
|
69
|
+
if customer_id
|
70
|
+
customers=@api_hook.create(:customers)
|
71
|
+
customers.create_charge(customer_id, charge)
|
72
|
+
else
|
73
|
+
super charge
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'open_pay_resource'
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
class Customers < OpenPayResource
|
6
|
+
|
7
|
+
|
8
|
+
#Bankaccount
|
9
|
+
def create_bank_account(customer,bank_account)
|
10
|
+
create(bank_account,"#{customer}/bankaccounts")
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_bank_account(customer,bank_id)
|
14
|
+
get("#{customer}/bankaccounts/#{bank_id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def all_bank_accounts(customer)
|
18
|
+
get("#{customer}/bankaccounts/")
|
19
|
+
end
|
20
|
+
|
21
|
+
def each_bank_account(customer)
|
22
|
+
get("#{customer}/bankaccounts/").each do |account|
|
23
|
+
yield account
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def delete_bank_account(customer,bank_id)
|
29
|
+
delete("#{customer}/bankaccounts/#{bank_id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_all_bank_accounts(customer)
|
33
|
+
if env == :production
|
34
|
+
raise OpenpayException.new('This method is not supported on PRODUCTION',false)
|
35
|
+
end
|
36
|
+
each_bank_account(customer) do |account|
|
37
|
+
delete("#{customer}/bankaccounts/#{account['id']}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#Charges
|
43
|
+
# customers.create_charge(customer_id,charge)
|
44
|
+
def create_charge(customer_id,charge)
|
45
|
+
create(charge,"#{customer_id}/charges")
|
46
|
+
end
|
47
|
+
|
48
|
+
#gets a charge_id for a given customer_id
|
49
|
+
def get_charge(customer_id,charge_id)
|
50
|
+
get("#{customer_id}/charges/#{charge_id}")
|
51
|
+
end
|
52
|
+
|
53
|
+
#return all charges for the given customer_id
|
54
|
+
def all_charges(customer_id)
|
55
|
+
get("#{customer_id}/charges/")
|
56
|
+
end
|
57
|
+
|
58
|
+
def cancel_charge(customer_id,charge_id)
|
59
|
+
post(charge_id,"#{customer_id}/charges/#{charge_id}/cancel")
|
60
|
+
end
|
61
|
+
|
62
|
+
def refund_charge(customer_id,charge_id,description)
|
63
|
+
post(description,"#{customer_id}/charges/#{charge_id}/refund")
|
64
|
+
end
|
65
|
+
|
66
|
+
def capture_charge(customer_id,charge_id)
|
67
|
+
post('',"#{customer_id}/charges/#{charge_id}/capture")
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
#Payouts
|
73
|
+
def create_payout(customer_id,payout)
|
74
|
+
post(payout,"#{customer_id}/payouts")
|
75
|
+
end
|
76
|
+
|
77
|
+
def all_payouts(customer_id)
|
78
|
+
get("#{customer_id}/payouts")
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_payout(customer_id,payout_id)
|
82
|
+
get("#{customer_id}/payouts/#{payout_id}")
|
83
|
+
end
|
84
|
+
|
85
|
+
def each_payout(customer_id)
|
86
|
+
all_payouts(customer_id).each do |pay|
|
87
|
+
yield pay
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
#Transfers
|
95
|
+
def create_transfer(customer_id,transfer)
|
96
|
+
post(transfer,"#{customer_id}/transfers")
|
97
|
+
end
|
98
|
+
|
99
|
+
def all_transfers(customer_id)
|
100
|
+
get("#{customer_id}/transfers/")
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_transfer(customer_id,transfer_id)
|
104
|
+
get("#{customer_id}/transfers/#{transfer_id}")
|
105
|
+
end
|
106
|
+
|
107
|
+
def each_transfer(customer_id)
|
108
|
+
all_transfers(customer_id).each do |trans|
|
109
|
+
yield trans
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
#Subscriptions
|
117
|
+
def create_subscription(subscription, plan_id)
|
118
|
+
post(subscription,"#{plan_id}/subscriptions")
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def delete_subscription(customer_id,subscription_id)
|
123
|
+
delete("#{customer_id}/subscriptions/#{subscription_id}")
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def get_subscription(customer_id,subscription_id)
|
128
|
+
get("#{customer_id}/subscriptions/#{subscription_id}")
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def all_subscriptions(customer_id)
|
133
|
+
get("#{customer_id}/subscriptions/")
|
134
|
+
end
|
135
|
+
|
136
|
+
def each_subscription(customer_id)
|
137
|
+
all_subscriptions(customer_id).each do |cust|
|
138
|
+
yield cust
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def delete_all_subscriptions(customer_id)
|
144
|
+
if env == :production
|
145
|
+
raise OpenPayError ('This method is not supported on PRODUCTION')
|
146
|
+
end
|
147
|
+
all_subscriptions(customer_id).each do |sub|
|
148
|
+
delete_subscription(customer_id,sub['id'])
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
#Card
|
156
|
+
def create_card(customer,card)
|
157
|
+
create(card,"#{customer}/cards")
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def get_card(customer,card_id)
|
162
|
+
get("#{customer}/cards/#{card_id}")
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def delete_card(customer,card_id)
|
167
|
+
delete("#{customer}/cards/#{card_id}")
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
def delete_all_cards(customer_id)
|
172
|
+
if env == :production
|
173
|
+
raise OpenPayError ('This method is not supported on PRODUCTION')
|
174
|
+
end
|
175
|
+
each_card(customer_id) do |card|
|
176
|
+
delete_card(customer_id,card['id'])
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def each_card(customer)
|
182
|
+
get("#{customer}/cards").each do |card|
|
183
|
+
yield card
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def all_cards(customer)
|
189
|
+
get("#{customer}/cards")
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|