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
@@ -0,0 +1,52 @@
1
+ require 'rspec'
2
+
3
+
4
+ describe 'OpenPayResource' do
5
+
6
+
7
+
8
+
9
+ before(:all) do
10
+
11
+ @merchant_id='mywvupjjs9xdnryxtplq'
12
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
13
+
14
+ @openpay=OpenpayApi.new(@merchant_id,@private_key)
15
+ @cards=@openpay.create(:cards)
16
+
17
+ end
18
+
19
+
20
+ describe '.hash2json' do
21
+
22
+
23
+ it 'converts a ruby hash into a json string' do
24
+ card_hash = FactoryGirl.build(:valid_card, holder_name: 'Juan')
25
+ json=@cards.hash2json(card_hash)
26
+ expect(json).to have_json_path('holder_name')
27
+ expect(json).to have_json_path('expiration_year')
28
+ expect(json).to have_json_path('bank_code')
29
+
30
+ end
31
+
32
+
33
+ end
34
+
35
+
36
+ describe '.json2hash' do
37
+
38
+
39
+ it 'converts json into a ruby hash' do
40
+ card_hash = FactoryGirl.build(:valid_card, holder_name: 'Pepe')
41
+ json=@cards.hash2json(card_hash)
42
+ jash=@cards.json2hash(json)
43
+ expect(jash).to be_a Hash
44
+ expect(jash['holder_name']).to match 'Pepe'
45
+
46
+
47
+ end
48
+
49
+ end
50
+
51
+
52
+ end
@@ -0,0 +1,197 @@
1
+
2
+ require '../spec_helper'
3
+
4
+ describe Payouts do
5
+
6
+ before(:all) do
7
+
8
+ @merchant_id='mywvupjjs9xdnryxtplq'
9
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
10
+
11
+ @openpay=OpenpayApi.new(@merchant_id, @private_key)
12
+ @payouts=@openpay.create(:payouts)
13
+
14
+ @customers=@openpay.create(:customers)
15
+ @cards=@openpay.create(:cards)
16
+ @charges=@openpay.create(:charges)
17
+
18
+ @bank_accounts=@openpay.create(:bankaccounts)
19
+
20
+ @fees=@openpay.create(:fees)
21
+
22
+ end
23
+
24
+
25
+ describe '.create' do
26
+
27
+ it 'creates a merchant payout' do
28
+
29
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: 'b4ravkgvpir9izop1faz',amount: 100)
30
+
31
+ payout=@payouts.create(payout_hash)
32
+ expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(100)
33
+
34
+ end
35
+
36
+
37
+
38
+
39
+ it 'creates a customer payout using a card' do
40
+ #We need to charge 1st into the card we are going to use
41
+
42
+ #create new customer
43
+ customer_hash= FactoryGirl.build(:customer)
44
+ customer=@customers.create(customer_hash)
45
+
46
+ #create new customer card
47
+ card_hash=FactoryGirl.build(:valid_card)
48
+ card=@cards.create(card_hash, customer['id'])
49
+
50
+ #create charge
51
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
52
+ charge=@charges.create(charge_hash,customer['id'])
53
+
54
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 400)
55
+
56
+ payout=@payouts.create(payout_hash,customer['id'])
57
+ expect( @payouts.get( payout['id'],customer['id'] )['amount']).to be_within(0.1).of(400)
58
+
59
+ #cleanup
60
+ @cards.delete_all(customer['id'])
61
+ @bank_accounts.delete_all(customer['id'])
62
+
63
+ end
64
+
65
+
66
+
67
+ it 'creates a customer payout using a bank account' do
68
+
69
+ #create new customer
70
+ customer_hash= FactoryGirl.build(:customer)
71
+ customer=@customers.create(customer_hash)
72
+
73
+ #create new customer card
74
+ card_hash=FactoryGirl.build(:valid_card)
75
+ card=@cards.create(card_hash, customer['id'])
76
+
77
+ #create new customer bank account
78
+ account_hash=FactoryGirl.build(:bank_account)
79
+ account=@bank_accounts.create(account_hash, customer['id'])
80
+
81
+ #create charge
82
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
83
+ charge=@charges.create(charge_hash,customer['id'])
84
+
85
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: account['id'],amount: 400)
86
+
87
+ payout=@payouts.create(payout_hash,customer['id'])
88
+ expect( @payouts.get( payout['id'],customer['id'] )['amount']).to be_within(0.1).of(400)
89
+
90
+ #cleanup
91
+ @cards.delete_all(customer['id'])
92
+ @bank_accounts.delete_all(customer['id'])
93
+ # @customers.delete_all
94
+ end
95
+
96
+
97
+
98
+ end
99
+
100
+ describe '.get' do
101
+
102
+ it 'gets a merchant payout' do
103
+
104
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: 'b4ravkgvpir9izop1faz',amount: 10)
105
+
106
+ payout=@payouts.create(payout_hash)
107
+ expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(10)
108
+
109
+ end
110
+
111
+ it 'gets a customer payout' do
112
+ #create new customer
113
+ customer_hash= FactoryGirl.build(:customer)
114
+ customer=@customers.create(customer_hash)
115
+
116
+ #create new customer card
117
+ card_hash=FactoryGirl.build(:valid_card)
118
+ card=@cards.create(card_hash, customer['id'])
119
+
120
+ #create charge
121
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
122
+ charge=@charges.create(charge_hash,customer['id'])
123
+
124
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 40)
125
+
126
+ payout=@payouts.create(payout_hash,customer['id'])
127
+
128
+ res=@payouts.get( payout['id'],customer['id'] )
129
+ expect(res['amount']).to be_within(0.1).of(40)
130
+
131
+ #cleanup
132
+ @cards.delete_all(customer['id'])
133
+ @bank_accounts.delete_all(customer['id'])
134
+ #@customers.delete_all
135
+ end
136
+
137
+
138
+ end
139
+
140
+ describe '.all' do
141
+
142
+ it 'all merchant payouts' do
143
+ expect(@payouts.all.size).to be_a Integer
144
+ expect(@payouts.all.last['transaction_type']) .to match 'payout'
145
+ end
146
+
147
+ it 'all customer payout' do
148
+ #create new customer
149
+ customer_hash= FactoryGirl.build(:customer)
150
+ customer=@customers.create(customer_hash)
151
+
152
+ #create new customer card
153
+ card_hash=FactoryGirl.build(:valid_card)
154
+ card=@cards.create(card_hash, customer['id'])
155
+
156
+ #create charge
157
+ charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
158
+ charge=@charges.create(charge_hash,customer['id'])
159
+
160
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 40)
161
+
162
+ payout=@payouts.create(payout_hash,customer['id'])
163
+
164
+ res=@payouts.get( payout['id'],customer['id'] )
165
+ expect(res['amount']).to be_within(0.1).of(40)
166
+
167
+
168
+ expect(@payouts.all(customer['id']).last['transaction_type']).to match 'payout'
169
+
170
+ #cleanup
171
+ @cards.delete_all(customer['id'])
172
+ @bank_accounts.delete_all(customer['id'])
173
+ end
174
+
175
+ end
176
+
177
+
178
+ describe '.each' do
179
+
180
+ it 'iterates over all merchant payouts' do
181
+
182
+ @payouts.each do |pay|
183
+ expect(@payouts.get(pay['id'])['transaction_type'] ).to match 'payout'
184
+ end
185
+
186
+ end
187
+
188
+ it 'iterates over a given customer payouts' do
189
+ a_customer=@customers.all.last
190
+ @payouts.each(a_customer['id']) do |pay|
191
+ expect(@payouts.get(pay['id'],a_customer['id'])['transaction_type'] ).to match 'payout'
192
+ end
193
+ end
194
+ end
195
+
196
+
197
+ end
@@ -0,0 +1,229 @@
1
+ require '../spec_helper'
2
+
3
+ describe Plans do
4
+
5
+
6
+ before(:all) do
7
+
8
+ @merchant_id='mywvupjjs9xdnryxtplq'
9
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
10
+
11
+ @openpay=OpenpayApi.new(@merchant_id, @private_key)
12
+ @customers=@openpay.create(:customers)
13
+ @plans=@openpay.create(:plans)
14
+ @subscriptions=@openpay.create(:subscriptions)
15
+
16
+
17
+ end
18
+
19
+
20
+ after(:all) do
21
+ @plans.delete_all
22
+ end
23
+
24
+
25
+ describe '.create' do
26
+
27
+
28
+ it 'creates a merchant plan' do
29
+
30
+ plan_hash= FactoryGirl.build(:plan, repeat_every: 5)
31
+ plan=@plans.create(plan_hash)
32
+
33
+
34
+ #validates
35
+ expect(@plans.get(plan['id'])['repeat_every']).to be 5
36
+
37
+ #clean
38
+ @plans.delete(plan['id'])
39
+
40
+
41
+ end
42
+
43
+
44
+ end
45
+
46
+
47
+ describe 'get' do
48
+
49
+ it 'gets a merchant plan' do
50
+
51
+
52
+ #creates a plan
53
+ plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
54
+ plan=@plans.create(plan_hash)
55
+
56
+
57
+ #validates
58
+ expect(@plans.get(plan['id'])['repeat_every']).to be 5
59
+ expect(@plans.get(plan['id'])['amount']).to be_within(0.1).of(500)
60
+
61
+
62
+ #clean
63
+ @plans.delete(plan['id'])
64
+
65
+ end
66
+
67
+ end
68
+
69
+
70
+ it 'fails to get a non existing customer plan' do
71
+
72
+
73
+ #validates
74
+ expect { @plans.get('111111') }.to raise_exception OpenpayTransactionException
75
+ begin
76
+ @plans.get('111111')
77
+ rescue OpenpayTransactionException => e
78
+
79
+ expect(e.description).to match 'The requested resource doesn\'t exist.'
80
+
81
+ end
82
+
83
+ end
84
+
85
+
86
+ describe '.all' do
87
+
88
+ it 'returns all customer plans' do
89
+
90
+ expect(@plans.all.size).to be_a Integer
91
+
92
+ end
93
+
94
+ end
95
+
96
+
97
+ describe '.update' do
98
+
99
+
100
+ it 'updates an existing customer plan' do
101
+
102
+ #creates a plan
103
+ plan_hash= FactoryGirl.build(:plan, trial_days: 10)
104
+ plan=@plans.create(plan_hash)
105
+
106
+ expect(plan['trial_days']).to be 10
107
+
108
+
109
+ plan_hash= FactoryGirl.build(:plan, trial_days: 100)
110
+
111
+ plan=@plans.update(plan_hash, plan['id'])
112
+
113
+ expect(plan['trial_days']).to be 100
114
+
115
+ #cleanup
116
+ @plans.delete(plan['id'])
117
+
118
+ end
119
+
120
+
121
+ it 'fails to update an non existing customer plan' do
122
+
123
+ plan_hash= FactoryGirl.build(:plan, trial_days: 100)
124
+
125
+ #validates
126
+ expect { @plans.update(plan_hash, '111111') }.to raise_exception RestClient::ResourceNotFound
127
+ begin
128
+ @plans.update(plan_hash, '111111')
129
+ rescue RestClient::ResourceNotFound => e
130
+
131
+ expect(e.http_body).to be_a String
132
+ expect(e.message).to match '404 Resource Not Found'
133
+
134
+ end
135
+
136
+ end
137
+
138
+
139
+ end
140
+
141
+
142
+ describe '.each' do
143
+
144
+ it 'iterates over all customer plans' do
145
+
146
+ #creates a plan
147
+ plan_hash= FactoryGirl.build(:plan, trial_days: 10)
148
+ plan=@plans.create(plan_hash)
149
+ plan1=@plans.create(plan_hash)
150
+ plan2=@plans.create(plan_hash)
151
+
152
+
153
+ expect(@plans.all.size).to be_a Integer
154
+ @plans.each do |plan|
155
+
156
+ expect(plan['name']).to match 'Curso de ingles'
157
+ @plans.delete(plan['id'])
158
+ end
159
+
160
+ expect(@plans.all.size).to be_a Integer
161
+
162
+
163
+ end
164
+
165
+
166
+ end
167
+
168
+
169
+ #
170
+ #describe 'all_subscriptions' do
171
+ #
172
+ #
173
+ # it 'returns all subscriptions for a given plan' do
174
+ # #creates a plan
175
+ # plan_hash= FactoryGirl.build(:plan, trial_days: 10)
176
+ # plan=@plans.create(plan_hash)
177
+ # expect(@plans.all_subscriptions(plan['id']).size).to be 0
178
+ #
179
+ #
180
+ # #creates subscriptions
181
+ #
182
+ # subscription_hash= FactoryGirl.build(:subscription)
183
+ #
184
+ # @subscriptions.create(subscription_hash,plan['id'])
185
+ # @subscriptions.create(subscription_hash,plan['id'])
186
+ #
187
+ # expect(@plans.all_subscriptions(plan['id'])).to be 2
188
+ #
189
+ # @plans.delete_all(customer['id'])
190
+ # expect(@plans.all_subscriptions(plan['id'])).to be 0
191
+ #
192
+ # end
193
+ #
194
+ #
195
+ #end
196
+ #
197
+ #describe '.each_subscription' do
198
+ #
199
+ #
200
+ # it 'itereates over all subscriptions for a given plan' do
201
+ #
202
+ # #creates a plan
203
+ # plan_hash= FactoryGirl.build(:plan, trial_days: 10)
204
+ # plan=@plans.create(plan_hash)
205
+ #
206
+ #
207
+ # #creates subscriptions
208
+ #
209
+ # customer_hash= FactoryGirl.build(:subscription)
210
+ #
211
+ # @subscriptions.create(subscription_hash)
212
+ # @subscriptions.create(subscription_hash)
213
+ #
214
+ #
215
+ # it 'iterates over all paln subscription' do
216
+ #
217
+ # @plans.each_subscription do |subscription|
218
+ # pending 'no esta bien algo le falta'
219
+ # end
220
+ #
221
+ # end
222
+ # end
223
+ #end
224
+
225
+ end
226
+
227
+
228
+
229
+