openpay 0.9.8

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.idea/.name +1 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/OpenPay.iml +614 -0
  6. data/.idea/dictionaries/ronnie.xml +7 -0
  7. data/.idea/encodings.xml +5 -0
  8. data/.idea/misc.xml +5 -0
  9. data/.idea/modules.xml +9 -0
  10. data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +37 -0
  11. data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +37 -0
  12. data/.idea/runConfigurations/all_specs.xml +41 -0
  13. data/.idea/scopes/scope_settings.xml +5 -0
  14. data/.idea/vcs.xml +7 -0
  15. data/Gemfile +11 -0
  16. data/LICENSE.txt +13 -0
  17. data/OpenPay.gemspec +24 -0
  18. data/README.md +370 -0
  19. data/Rakefile +1 -0
  20. data/lib/OpenPay/Cards.rb +76 -0
  21. data/lib/OpenPay/Charges.rb +79 -0
  22. data/lib/OpenPay/Customers.rb +195 -0
  23. data/lib/OpenPay/Fees.rb +5 -0
  24. data/lib/OpenPay/Payouts.rb +59 -0
  25. data/lib/OpenPay/Plans.rb +28 -0
  26. data/lib/OpenPay/Subscriptions.rb +58 -0
  27. data/lib/OpenPay/Transfers.rb +43 -0
  28. data/lib/OpenPay/bankaccounts.rb +66 -0
  29. data/lib/OpenPay/errors/open_pay_exception.rb +51 -0
  30. data/lib/OpenPay/errors/open_pay_exception_factory.rb +58 -0
  31. data/lib/OpenPay/errors/openpay_connection_exception.rb +3 -0
  32. data/lib/OpenPay/errors/openpay_transaction_exception.rb +5 -0
  33. data/lib/OpenPay/open_pay_resource.rb +242 -0
  34. data/lib/OpenPay/open_pay_resource_factory.rb +10 -0
  35. data/lib/OpenPay/openpay_api.rb +63 -0
  36. data/lib/OpenPay/version.rb +3 -0
  37. data/lib/openpay.rb +34 -0
  38. data/test/Factories.rb +258 -0
  39. data/test/spec/bankaccounts_spec.rb +187 -0
  40. data/test/spec/cards_spec.rb +411 -0
  41. data/test/spec/charges_spec.rb +377 -0
  42. data/test/spec/customers_spec.rb +230 -0
  43. data/test/spec/exceptions_spec.rb +138 -0
  44. data/test/spec/fees_spec.rb +113 -0
  45. data/test/spec/openpayresource_spec.rb +52 -0
  46. data/test/spec/payouts_spec.rb +197 -0
  47. data/test/spec/plans_spec.rb +229 -0
  48. data/test/spec/subscriptions_spec.rb +228 -0
  49. data/test/spec/transfers_spec.rb +221 -0
  50. data/test/spec_helper.rb +16 -0
  51. metadata +135 -0
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,76 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Cards < OpenPayResource
4
+
5
+
6
+ def list(creation,before,after,offset=0,limit=10)
7
+
8
+ end
9
+
10
+
11
+ def get(card='',customer_id=nil)
12
+ if customer_id
13
+ customers=@api_hook.create(:customers)
14
+ customers.get_card(customer_id,card)
15
+ else
16
+ super card
17
+ end
18
+ end
19
+
20
+
21
+ def create(card,customer_id=nil)
22
+ if customer_id
23
+ customers=@api_hook.create(:customers)
24
+ customers.create_card(customer_id,card)
25
+ else
26
+ super card
27
+ end
28
+ end
29
+
30
+
31
+ def delete(card_id,customer_id=nil)
32
+ if customer_id
33
+ customers=@api_hook.create(:customers)
34
+ customers.delete_card(customer_id,card_id)
35
+ else
36
+ super card_id
37
+ end
38
+ end
39
+
40
+
41
+ def delete_all(customer_id=nil)
42
+ if customer_id
43
+ customers=@api_hook.create(:customers)
44
+ customers.delete_all_cards(customer_id)
45
+ else
46
+ each do |card|
47
+ delete(card['id'])
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ def each(customer_id=nil)
54
+ if customer_id
55
+ all(customer_id).each do |card|
56
+ yield card
57
+ end
58
+ else
59
+ all.each do |card|
60
+ yield card
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+ def all(customer_id=nil)
67
+ if customer_id
68
+ customers=@api_hook.create(:customers)
69
+ customers.all_cards(customer_id)
70
+ else
71
+ super ''
72
+ end
73
+ end
74
+
75
+
76
+ end
@@ -0,0 +1,79 @@
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(description, transaction_id+'/capture')
41
+ end
42
+ end
43
+
44
+
45
+
46
+
47
+ def each(customer_id=nil)
48
+ if customer_id
49
+ all(customer_id).each do |card|
50
+ yield card
51
+ end
52
+ else
53
+ all.each do |card|
54
+ yield card
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+
61
+ def get(charge='', customer_id=nil)
62
+ if customer_id
63
+ customers=@api_hook.create(:customers)
64
+ customers.get_charge(customer_id, charge)
65
+ else
66
+ super charge
67
+ end
68
+ end
69
+
70
+ def create(charge, customer_id=nil)
71
+ if customer_id
72
+ customers=@api_hook.create(:customers)
73
+ customers.create_charge(customer_id, charge)
74
+ else
75
+ super charge
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,195 @@
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
+ warn "deleting bank_account: #{account['id']}"
38
+ delete("#{customer}/bankaccounts/#{account['id']}")
39
+ end
40
+ end
41
+
42
+
43
+ #Charges
44
+ # customers.create_charge(customer_id,charge)
45
+ def create_charge(customer_id,charge)
46
+ create(charge,"#{customer_id}/charges")
47
+ end
48
+
49
+ #gets a charge_id for a given customer_id
50
+ def get_charge(customer_id,charge_id)
51
+ get("#{customer_id}/charges/#{charge_id}")
52
+ end
53
+
54
+ #return all charges for the given customer_id
55
+ def all_charges(customer_id)
56
+ get("#{customer_id}/charges/")
57
+ end
58
+
59
+ def cancel_charge(customer_id,charge_id)
60
+ post(charge_id,"#{customer_id}/charges/#{charge_id}/cancel")
61
+ end
62
+
63
+ def refund_charge(customer_id,charge_id,description)
64
+ post(description,"#{customer_id}/charges/#{charge_id}/refund")
65
+ end
66
+
67
+ def capture_charge(customer_id,charge_id)
68
+ post('',"#{customer_id}/charges/#{charge_id}/capture")
69
+ end
70
+
71
+
72
+
73
+ #Payouts
74
+ def create_payout(customer_id,payout)
75
+ post(payout,"#{customer_id}/payouts")
76
+ end
77
+
78
+ def all_payouts(customer_id)
79
+ get("#{customer_id}/payouts")
80
+ end
81
+
82
+ def get_payout(customer_id,payout_id)
83
+ get("#{customer_id}/payouts/#{payout_id}")
84
+ end
85
+
86
+ def each_payout(customer_id)
87
+ all_payouts(customer_id).each do |pay|
88
+ yield pay
89
+ end
90
+ end
91
+
92
+
93
+
94
+
95
+ #Transfers
96
+ def create_transfer(customer_id,transfer)
97
+ post(transfer,"#{customer_id}/transfers")
98
+ end
99
+
100
+ def all_transfers(customer_id)
101
+ get("#{customer_id}/transfers/")
102
+ end
103
+
104
+ def get_transfer(customer_id,transfer_id)
105
+ get("#{customer_id}/transfers/#{transfer_id}")
106
+ end
107
+
108
+ def each_transfer(customer_id)
109
+ all_transfers(customer_id).each do |trans|
110
+ yield trans
111
+ end
112
+ end
113
+
114
+
115
+
116
+
117
+ #Subscriptions
118
+ def create_subscription(subscription, plan_id)
119
+ post(subscription,"#{plan_id}/subscriptions")
120
+ end
121
+
122
+
123
+ def delete_subscription(customer_id,subscription_id)
124
+ delete("#{customer_id}/subscriptions/#{subscription_id}")
125
+ end
126
+
127
+
128
+ def get_subscription(customer_id,subscription_id)
129
+ get("#{customer_id}/subscriptions/#{subscription_id}")
130
+ end
131
+
132
+
133
+ def all_subscriptions(customer_id)
134
+ get("#{customer_id}/subscriptions/")
135
+ end
136
+
137
+ def each_subscription(customer_id)
138
+ all_subscriptions(customer_id).each do |cust|
139
+ yield cust
140
+ end
141
+ end
142
+
143
+
144
+ def delete_all_subscriptions(customer_id)
145
+ if env == :production
146
+ raise OpenPayError ('This method is not supported on PRODUCTION')
147
+ end
148
+ all_subscriptions(customer_id).each do |sub|
149
+ delete_subscription(customer_id,sub['id'])
150
+ end
151
+ end
152
+
153
+
154
+
155
+
156
+ #Card
157
+ def create_card(customer,card)
158
+ create(card,"#{customer}/cards")
159
+ end
160
+
161
+
162
+ def get_card(customer,card_id)
163
+ get("#{customer}/cards/#{card_id}")
164
+ end
165
+
166
+
167
+ def delete_card(customer,card_id)
168
+ delete("#{customer}/cards/#{card_id}")
169
+ end
170
+
171
+
172
+ def delete_all_cards(customer_id)
173
+ if env == :production
174
+ raise OpenPayError ('This method is not supported on PRODUCTION')
175
+ end
176
+ each_card(customer_id) do |card|
177
+ delete_card(customer_id,card['id'])
178
+ end
179
+ end
180
+
181
+
182
+ def each_card(customer)
183
+ get("#{customer}/cards").each do |card|
184
+ yield card
185
+ end
186
+ end
187
+
188
+
189
+ def all_cards(customer)
190
+ get("#{customer}/cards")
191
+ end
192
+
193
+
194
+
195
+ end
@@ -0,0 +1,5 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Fees < OpenPayResource
4
+
5
+ end
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,28 @@
1
+ require 'open_pay_resource'
2
+
3
+ class Plans < OpenPayResource
4
+
5
+
6
+ def update(plan,plan_id)
7
+ put(plan, "#{plan_id}")
8
+ end
9
+
10
+
11
+
12
+ def each_subscription(plan_id)
13
+ get("#{plan_id}/subscriptions")
14
+ end
15
+
16
+
17
+ def all_subscriptions(plan_id)
18
+ get("#{plan_id}/subscriptions")
19
+ end
20
+
21
+
22
+ def each
23
+ end
24
+
25
+
26
+
27
+
28
+ end