openpay 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/OpenPay.iml +614 -0
- data/.idea/dictionaries/ronnie.xml +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/runConfigurations/Run_spec__bankaccounts_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/Run_spec__customers_spec___OpenPay.xml +37 -0
- data/.idea/runConfigurations/all_specs.xml +41 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +13 -0
- data/OpenPay.gemspec +24 -0
- data/README.md +370 -0
- data/Rakefile +1 -0
- data/lib/OpenPay/Cards.rb +76 -0
- data/lib/OpenPay/Charges.rb +79 -0
- data/lib/OpenPay/Customers.rb +195 -0
- data/lib/OpenPay/Fees.rb +5 -0
- data/lib/OpenPay/Payouts.rb +59 -0
- data/lib/OpenPay/Plans.rb +28 -0
- data/lib/OpenPay/Subscriptions.rb +58 -0
- data/lib/OpenPay/Transfers.rb +43 -0
- data/lib/OpenPay/bankaccounts.rb +66 -0
- data/lib/OpenPay/errors/open_pay_exception.rb +51 -0
- data/lib/OpenPay/errors/open_pay_exception_factory.rb +58 -0
- data/lib/OpenPay/errors/openpay_connection_exception.rb +3 -0
- data/lib/OpenPay/errors/openpay_transaction_exception.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 +63 -0
- data/lib/OpenPay/version.rb +3 -0
- data/lib/openpay.rb +34 -0
- data/test/Factories.rb +258 -0
- data/test/spec/bankaccounts_spec.rb +187 -0
- data/test/spec/cards_spec.rb +411 -0
- data/test/spec/charges_spec.rb +377 -0
- data/test/spec/customers_spec.rb +230 -0
- data/test/spec/exceptions_spec.rb +138 -0
- data/test/spec/fees_spec.rb +113 -0
- data/test/spec/openpayresource_spec.rb +52 -0
- data/test/spec/payouts_spec.rb +197 -0
- data/test/spec/plans_spec.rb +229 -0
- data/test/spec/subscriptions_spec.rb +228 -0
- data/test/spec/transfers_spec.rb +221 -0
- data/test/spec_helper.rb +16 -0
- metadata +135 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
require '../spec_helper'
|
2
|
+
|
3
|
+
describe Subscriptions 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
|
+
@cards=@openpay.create(:cards)
|
14
|
+
@charges=@openpay.create(:charges)
|
15
|
+
|
16
|
+
@plans=@openpay.create(:plans)
|
17
|
+
|
18
|
+
@subscriptions=@openpay.create(:subscriptions)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
describe '.create' do
|
25
|
+
|
26
|
+
it 'creates a subscription' do
|
27
|
+
|
28
|
+
#creates a customer
|
29
|
+
customer_hash= FactoryGirl.build(:customer)
|
30
|
+
customer=@customers.create(customer_hash)
|
31
|
+
|
32
|
+
#creates a customer card
|
33
|
+
card_hash= FactoryGirl.build(:valid_card)
|
34
|
+
card=@cards.create(card_hash, customer['id'])
|
35
|
+
|
36
|
+
#creates a plan
|
37
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
38
|
+
plan=@plans.create(plan_hash)
|
39
|
+
|
40
|
+
#creates subscription
|
41
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
42
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
43
|
+
|
44
|
+
#performs check
|
45
|
+
saved_subscription=@subscriptions.get(subscription['id'], customer['id'])
|
46
|
+
expect(saved_subscription['plan_id']).to match plan['id']
|
47
|
+
|
48
|
+
#cleanup
|
49
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
describe '.get' do
|
58
|
+
|
59
|
+
it 'gets customer subscriptions' do
|
60
|
+
|
61
|
+
#creates a customer
|
62
|
+
customer_hash= FactoryGirl.build(:customer)
|
63
|
+
customer=@customers.create(customer_hash)
|
64
|
+
|
65
|
+
#creates a customer card
|
66
|
+
card_hash= FactoryGirl.build(:valid_card)
|
67
|
+
card=@cards.create(card_hash, customer['id'])
|
68
|
+
|
69
|
+
#creates a plan
|
70
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
71
|
+
plan=@plans.create(plan_hash)
|
72
|
+
|
73
|
+
#creates subscription
|
74
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
75
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
76
|
+
|
77
|
+
#get customer subscription
|
78
|
+
stored_s=@subscriptions.get(subscription['id'], customer['id'])
|
79
|
+
|
80
|
+
#performs check
|
81
|
+
expect(stored_s['status']).to match 'trial'
|
82
|
+
|
83
|
+
#cleanup
|
84
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe '.all' do
|
92
|
+
|
93
|
+
it 'returns all subscriptions for a given customer' do
|
94
|
+
|
95
|
+
#creates a customer
|
96
|
+
customer_hash= FactoryGirl.build(:customer)
|
97
|
+
customer=@customers.create(customer_hash)
|
98
|
+
|
99
|
+
#creates a customer card
|
100
|
+
card_hash= FactoryGirl.build(:valid_card)
|
101
|
+
card=@cards.create(card_hash, customer['id'])
|
102
|
+
|
103
|
+
#creates a plan
|
104
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
105
|
+
plan=@plans.create(plan_hash)
|
106
|
+
|
107
|
+
#creates subscription
|
108
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
109
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
110
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
111
|
+
|
112
|
+
#performs check
|
113
|
+
expect(@subscriptions.all(customer['id']).size).to be 1
|
114
|
+
|
115
|
+
#cleanup
|
116
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
describe '.each' do
|
125
|
+
|
126
|
+
it 'iterates over all subscriptions for a given customer' do
|
127
|
+
|
128
|
+
#creates a customer
|
129
|
+
customer_hash= FactoryGirl.build(:customer)
|
130
|
+
customer=@customers.create(customer_hash)
|
131
|
+
|
132
|
+
#creates a customer card
|
133
|
+
card_hash= FactoryGirl.build(:valid_card)
|
134
|
+
card=@cards.create(card_hash, customer['id'])
|
135
|
+
|
136
|
+
#creates a plan
|
137
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
138
|
+
plan=@plans.create(plan_hash)
|
139
|
+
|
140
|
+
#creates subscription
|
141
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
142
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
143
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
144
|
+
|
145
|
+
#performs check
|
146
|
+
@subscriptions.each(customer['id']) do |stored_s|
|
147
|
+
#check and clean
|
148
|
+
expect(stored_s['status']).to match 'trial'
|
149
|
+
@subscriptions.delete(stored_s['id'],customer['id'])
|
150
|
+
end
|
151
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
describe '.delete' do
|
159
|
+
|
160
|
+
it 'deletes an existing subscription for a given customer' do
|
161
|
+
|
162
|
+
#creates a customer
|
163
|
+
customer_hash= FactoryGirl.build(:customer)
|
164
|
+
customer=@customers.create(customer_hash)
|
165
|
+
|
166
|
+
#creates a customer card
|
167
|
+
card_hash= FactoryGirl.build(:valid_card)
|
168
|
+
card=@cards.create(card_hash, customer['id'])
|
169
|
+
|
170
|
+
#creates a plan
|
171
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
172
|
+
plan=@plans.create(plan_hash)
|
173
|
+
|
174
|
+
#creates subscription
|
175
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
176
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
177
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
178
|
+
|
179
|
+
#performs check
|
180
|
+
expect(@subscriptions.all(customer['id']).size).to be 1
|
181
|
+
|
182
|
+
#cleanup
|
183
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
describe '.delete_all' do
|
191
|
+
|
192
|
+
it 'deletes all existing subscription for a given customer' do
|
193
|
+
|
194
|
+
#creates a customer
|
195
|
+
customer_hash= FactoryGirl.build(:customer)
|
196
|
+
customer=@customers.create(customer_hash)
|
197
|
+
|
198
|
+
#creates a customer card
|
199
|
+
card_hash= FactoryGirl.build(:valid_card)
|
200
|
+
card=@cards.create(card_hash, customer['id'])
|
201
|
+
|
202
|
+
#creates a plan
|
203
|
+
plan_hash= FactoryGirl.build(:plan, repeat_every: 5, amount: 500)
|
204
|
+
plan=@plans.create(plan_hash)
|
205
|
+
|
206
|
+
#creates subscriptions
|
207
|
+
subscription_hash= FactoryGirl.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
208
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
209
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
210
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
211
|
+
|
212
|
+
#perform check and clean up
|
213
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
214
|
+
@subscriptions.delete_all(customer['id'])
|
215
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require '../spec_helper'
|
2
|
+
|
3
|
+
describe Transfers do
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
|
10
|
+
@merchant_id='mywvupjjs9xdnryxtplq'
|
11
|
+
@private_key='sk_92b25d3baec149e6b428d81abfe37006'
|
12
|
+
|
13
|
+
@openpay=OpenpayApi.new(@merchant_id, @private_key)
|
14
|
+
@customers=@openpay.create(:customers)
|
15
|
+
@cards=@openpay.create(:cards)
|
16
|
+
@charges=@openpay.create(:charges)
|
17
|
+
|
18
|
+
@bank_accounts=@openpay.create(:bankaccounts)
|
19
|
+
@transfers=@openpay.create(:transfers)
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.create' do
|
25
|
+
|
26
|
+
|
27
|
+
it 'transfers money from customer to customer' do
|
28
|
+
|
29
|
+
|
30
|
+
#create new customer
|
31
|
+
customer_hash= FactoryGirl.build(:customer)
|
32
|
+
customer=@customers.create(customer_hash)
|
33
|
+
|
34
|
+
#create new customer card
|
35
|
+
card_hash=FactoryGirl.build(:valid_card)
|
36
|
+
card=@cards.create(card_hash, customer['id'])
|
37
|
+
|
38
|
+
#create charge
|
39
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
40
|
+
charge=@charges.create(charge_hash,customer['id'])
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
#create customer 2
|
45
|
+
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
46
|
+
customer2=@customers.create(customer_hash)
|
47
|
+
|
48
|
+
#create new transfer
|
49
|
+
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
50
|
+
|
51
|
+
|
52
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
53
|
+
t=@transfers.get(transfer['id'],customer['id'])
|
54
|
+
expect(t['amount']).to be_within(0.1).of 12.5
|
55
|
+
expect(t['method']).to match 'customer'
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
#clanup
|
61
|
+
@cards.delete_all(customer['id'])
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
describe 'get' do
|
80
|
+
|
81
|
+
it 'gets a customer transfer' do
|
82
|
+
|
83
|
+
#create new customer
|
84
|
+
customer_hash= FactoryGirl.build(:customer)
|
85
|
+
customer=@customers.create(customer_hash)
|
86
|
+
|
87
|
+
#create new customer card
|
88
|
+
card_hash=FactoryGirl.build(:valid_card)
|
89
|
+
card=@cards.create(card_hash, customer['id'])
|
90
|
+
|
91
|
+
#create charge
|
92
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
93
|
+
charge=@charges.create(charge_hash,customer['id'])
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
#create customer 2
|
98
|
+
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
99
|
+
customer2=@customers.create(customer_hash)
|
100
|
+
|
101
|
+
#create new transfer
|
102
|
+
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
103
|
+
|
104
|
+
|
105
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
106
|
+
t=@transfers.get(transfer['id'],customer['id'])
|
107
|
+
expect(t).to be_a Hash
|
108
|
+
expect(t['amount']).to be_within(0.1).of 12.5
|
109
|
+
expect(t['method']).to match 'customer'
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
#clanup
|
114
|
+
@cards.delete_all(customer['id'])
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
it 'fails to get a non existing transfer' do
|
121
|
+
expect { @transfers.get(11111,11111) }.to raise_exception OpenpayTransactionException
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
describe '.each' do
|
129
|
+
|
130
|
+
|
131
|
+
it 'iterates over a given customer transfers' do
|
132
|
+
|
133
|
+
#create new customer
|
134
|
+
customer_hash= FactoryGirl.build(:customer)
|
135
|
+
customer=@customers.create(customer_hash)
|
136
|
+
|
137
|
+
#create new customer card
|
138
|
+
card_hash=FactoryGirl.build(:valid_card)
|
139
|
+
card=@cards.create(card_hash, customer['id'])
|
140
|
+
|
141
|
+
#create charge
|
142
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
143
|
+
charge=@charges.create(charge_hash,customer['id'])
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
#create customer 2
|
148
|
+
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
149
|
+
customer2=@customers.create(customer_hash)
|
150
|
+
|
151
|
+
#create new transfer
|
152
|
+
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
153
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
154
|
+
|
155
|
+
|
156
|
+
#iterates over transfers
|
157
|
+
@transfers.each(customer2['id']) do |tran|
|
158
|
+
|
159
|
+
expect(tran['amount']).to be_within(0.1).of 12.5
|
160
|
+
expect(tran['method']).to match 'customer'
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
#clanup
|
165
|
+
@cards.delete_all(customer['id'])
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
describe '.all' do
|
182
|
+
|
183
|
+
|
184
|
+
it 'returns all customer transfers' do
|
185
|
+
|
186
|
+
#create new customer
|
187
|
+
customer_hash= FactoryGirl.build(:customer)
|
188
|
+
customer=@customers.create(customer_hash)
|
189
|
+
|
190
|
+
#create new customer card
|
191
|
+
card_hash=FactoryGirl.build(:valid_card)
|
192
|
+
card=@cards.create(card_hash, customer['id'])
|
193
|
+
|
194
|
+
#create charge
|
195
|
+
charge_hash=FactoryGirl.build(:card_charge, source_id:card['id'],order_id: card['id'])
|
196
|
+
charge=@charges.create(charge_hash,customer['id'])
|
197
|
+
|
198
|
+
|
199
|
+
#create customer 2
|
200
|
+
customer_hash= FactoryGirl.build(:customer,name: 'Alejandro')
|
201
|
+
customer2=@customers.create(customer_hash)
|
202
|
+
|
203
|
+
#create new transfer
|
204
|
+
customer_hash= FactoryGirl.build(:transfer,customer_id: customer2['id'])
|
205
|
+
transfer=@transfers.create(customer_hash,customer['id'])
|
206
|
+
|
207
|
+
|
208
|
+
#returns all transfers
|
209
|
+
@transfers.all(customer2['id'])
|
210
|
+
expect(@transfers.all(customer2['id']).size ).to be 1
|
211
|
+
|
212
|
+
#cleanup
|
213
|
+
@cards.delete_all(customer['id'])
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
end
|
data/test/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'openpay'
|
2
|
+
|
3
|
+
|
4
|
+
require 'factory_girl'
|
5
|
+
require '../Factories'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec-expectations'
|
8
|
+
require 'json_spec'
|
9
|
+
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = :expect
|
14
|
+
config.include JsonSpec::Helpers
|
15
|
+
end
|
16
|
+
end
|