openpay 1.0.3 → 1.0.4

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 (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
@@ -1,12 +1,9 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
-
4
3
  describe 'Openpay Exceptions' do
5
4
 
6
-
7
5
  before(:all) do
8
6
 
9
-
10
7
  @merchant_id='mywvupjjs9xdnryxtplq'
11
8
  @private_key='sk_92b25d3baec149e6b428d81abfe37006'
12
9
 
@@ -14,12 +11,10 @@ describe 'Openpay Exceptions' do
14
11
  @customers=@openpay.create(:customers)
15
12
  @cards=@openpay.create(:cards)
16
13
 
17
-
18
14
  end
19
15
 
20
16
  describe OpenpayException do
21
17
 
22
-
23
18
  it 'should raise an OpenpayException when a non given resource is passed to the api factory' do
24
19
  expect { @openpay.create(:foo) }.to raise_exception OpenpayException
25
20
  end
@@ -30,10 +25,8 @@ describe 'Openpay Exceptions' do
30
25
  expect { cust.delete_all }.to raise_exception OpenpayException
31
26
  end
32
27
 
33
-
34
28
  end
35
29
 
36
-
37
30
  describe OpenpayTransactionException do
38
31
 
39
32
  it 'should fail when an invalid field-value is passed in *email' do
@@ -49,12 +42,11 @@ describe 'Openpay Exceptions' do
49
42
  #should have the corresponding attributes coming from the json message
50
43
  expect(e.http_code).to be 400
51
44
  expect(e.error_code).to be 1001
52
- expect(e.description).to match 'email\' not a well-formed email address'
45
+ #expect(e.description).to match 'not a well-formed email address'
53
46
  expect(e.json_body).to have_json_path('category')
54
47
  end
55
48
  end
56
49
 
57
-
58
50
  it ' raise an OpenpayTransactionException when trying to delete a non existing bank account ' do
59
51
  #non existing resource
60
52
  #perform checks
@@ -70,8 +62,6 @@ describe 'Openpay Exceptions' do
70
62
  end
71
63
  end
72
64
 
73
-
74
-
75
65
  it 'fails when trying to create an existing card' do
76
66
 
77
67
  #create customer
@@ -90,24 +80,20 @@ describe 'Openpay Exceptions' do
90
80
  @cards.delete card_hash['id']
91
81
  end
92
82
 
93
-
94
83
  it 'raise an OpenpayTransactionException when using an expired card' do
95
84
  card_hash = FactoryGirl.build(:expired_card)
96
85
  expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
97
86
  begin
98
87
  @cards.create(card_hash)
99
- rescue OpenpayTransactionException => e
88
+ rescue OpenpayTransactionException => e
100
89
  expect(e.description).to match 'The card has expired'
101
90
  expect(e.error_code).to be 3002
102
-
103
91
  end
104
92
 
105
93
  end
106
94
 
107
-
108
95
  end
109
96
 
110
-
111
97
  describe OpenpayConnectionException do
112
98
 
113
99
  it 'raise an OpenpayConnectionException when provided credentials are invalid' do
@@ -119,20 +105,17 @@ describe 'Openpay Exceptions' do
119
105
  customers=openpay.create(:customers)
120
106
  expect { customers.delete('1111') }.to raise_exception OpenpayConnectionException
121
107
 
122
-
123
108
  begin
124
109
  customers.delete('1111')
125
110
  rescue OpenpayConnectionException => e
126
111
  #should have the corresponding attributes coming from the json message
127
112
  expect(e.http_code).to be 401
128
113
  expect(e.error_code).to be 1002
129
- expect(e.description).to match 'The api key or merchant id are invalid.'
114
+ expect(e.description).to match 'The api key or merchant id are invalid'
130
115
  expect(e.json_body).to have_json_path('category')
131
116
  end
132
117
 
133
-
134
118
  end
135
119
  end
136
120
 
137
-
138
- end
121
+ end
@@ -18,12 +18,15 @@ describe Fees do
18
18
 
19
19
  end
20
20
 
21
-
22
21
  after(:all) do
23
- @bank_accounts.delete_all
24
22
  @customers.delete_all
25
23
  end
26
24
 
25
+ it 'has all required methods' do
26
+ %w(all each create get list delete).each do |meth|
27
+ expect(@customers).to respond_to(meth)
28
+ end
29
+ end
27
30
 
28
31
  describe '.create' do
29
32
 
@@ -54,7 +57,6 @@ describe Fees do
54
57
 
55
58
  end
56
59
 
57
-
58
60
  it 'creates a fee using a json message' do
59
61
  #create new customer
60
62
  customer_hash= FactoryGirl.build(:customer)
@@ -77,12 +79,19 @@ describe Fees do
77
79
 
78
80
  end
79
81
 
82
+ describe '.each' do
80
83
 
84
+ it 'iterates over all elements' do
85
+ @fees.each do |fee|
86
+ expect(fee['description']).to match /\s+/
87
+ end
88
+ end
81
89
 
90
+ end
82
91
 
83
- describe '.all' do
92
+ describe '.list' do
84
93
 
85
- it 'get all fees' do
94
+ it 'list fees with a given filter' do
86
95
 
87
96
  #create new customer
88
97
  customer_hash= FactoryGirl.build(:customer)
@@ -100,17 +109,52 @@ describe Fees do
100
109
  fee_hash = FactoryGirl.build(:fee, customer_id: customer['id'])
101
110
  @fees.create(fee_hash)
102
111
 
112
+ #create customer fee
113
+ fee_hash = FactoryGirl.build(:fee, customer_id: customer['id'])
114
+ @fees.create(fee_hash)
115
+
116
+
103
117
  #performs check
104
- expect(@fees.all.first['amount']).to be_a Float
118
+ search_params = OpenpayUtils::SearchParams.new
119
+ search_params.limit = 1
120
+ expect(@fees.list(search_params).size).to eq 1
121
+
105
122
 
106
123
  #cleanup
107
124
  @cards.delete(card['id'], customer['id'])
108
125
  @customers.delete(customer['id'])
109
126
 
110
127
  end
128
+
111
129
  end
112
- end
113
130
 
131
+ describe '.all' do
132
+
133
+ it 'get all fees' do
134
+
135
+ #create new customer
136
+ customer_hash= FactoryGirl.build(:customer)
137
+ customer=@customers.create(customer_hash)
138
+
139
+ #create customer card
140
+ card_hash=FactoryGirl.build(:valid_card)
141
+ card=@cards.create(card_hash, customer['id'])
142
+
143
+ #create charge
144
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000)
145
+ @charges.create(charge_hash, customer['id'])
146
+
147
+ #create customer fee
148
+ fee_hash = FactoryGirl.build(:fee, customer_id: customer['id'])
149
+ @fees.create(fee_hash)
114
150
 
151
+ #performs check
152
+ expect(@fees.all.first['amount']).to be_a Float
115
153
 
154
+ #cleanup
155
+ @cards.delete(card['id'], customer['id'])
156
+ @customers.delete(customer['id'])
116
157
 
158
+ end
159
+ end
160
+ end
@@ -1,9 +1,8 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
-
4
3
  describe Payouts do
5
4
 
6
- before(:all) do
5
+ before(:all) do
7
6
 
8
7
  @merchant_id='mywvupjjs9xdnryxtplq'
9
8
  @private_key='sk_92b25d3baec149e6b428d81abfe37006'
@@ -21,53 +20,64 @@ describe Payouts do
21
20
 
22
21
  end
23
22
 
23
+ it 'has all required methods' do
24
+ %w(all each create get list delete).each do |meth|
25
+ expect(@cards).to respond_to(meth)
26
+ end
27
+ end
24
28
 
25
29
  describe '.create' do
26
30
 
27
31
  it 'creates a merchant payout' do
28
32
 
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
33
+ pending
34
+ #create merchant card
35
+ card_hash = FactoryGirl.build(:valid_card)
36
+ card = @cards.create(card_hash)
35
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)
36
41
 
42
+ payout_hash=FactoryGirl.build(:payout_card, destination_id: card['id'], amount: 100)
37
43
 
44
+ payout=@payouts.create(payout_hash)
45
+ expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(100)
38
46
 
39
- it 'creates a customer payout using a card' do
40
- #We need to charge 1st into the card we are going to use
47
+ @cards.delete(card['id'])
41
48
 
42
- #create new customer
43
- customer_hash= FactoryGirl.build(:customer)
44
- customer=@customers.create(customer_hash)
49
+ end
45
50
 
46
- #create new customer card
47
- card_hash=FactoryGirl.build(:valid_card)
48
- card=@cards.create(card_hash, customer['id'])
51
+ it 'creates a customer payout using a card' do
52
+ #We need to charge 1st into the card we are going to use
49
53
 
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'])
54
+ #create new customer
55
+ customer_hash=FactoryGirl.build(:customer)
56
+ customer=@customers.create(customer_hash)
53
57
 
54
- payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 400)
58
+ #create new customer card
59
+ card_hash=FactoryGirl.build(:valid_card)
60
+ card=@cards.create(card_hash, customer['id'])
55
61
 
56
- payout=@payouts.create(payout_hash,customer['id'])
57
- expect( @payouts.get( payout['id'],customer['id'] )['amount']).to be_within(0.1).of(400)
62
+ #create charge
63
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'])
64
+ charge=@charges.create(charge_hash, customer['id'])
58
65
 
59
- #cleanup
60
- @cards.delete_all(customer['id'])
61
- @bank_accounts.delete_all(customer['id'])
66
+ payout_hash=FactoryGirl.build(:payout_card, destination_id: card['id'], amount: 400)
62
67
 
63
- end
68
+ payout=@payouts.create(payout_hash, customer['id'])
69
+ expect(@payouts.get(payout['id'], customer['id'])['amount']).to be_within(0.1).of(400)
64
70
 
71
+ #cleanup
72
+ @cards.delete_all(customer['id'])
73
+ @bank_accounts.delete_all(customer['id'])
65
74
 
75
+ end
66
76
 
67
- it 'creates a customer payout using a bank account' do
77
+ it 'creates a customer payout using a bank account' do
68
78
 
69
79
  #create new customer
70
- customer_hash= FactoryGirl.build(:customer)
80
+ customer_hash=FactoryGirl.build(:customer)
71
81
  customer=@customers.create(customer_hash)
72
82
 
73
83
  #create new customer card
@@ -79,36 +89,34 @@ describe Payouts do
79
89
  account=@bank_accounts.create(account_hash, customer['id'])
80
90
 
81
91
  #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'])
92
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'])
93
+ charge=@charges.create(charge_hash, customer['id'])
84
94
 
85
- payout_hash= FactoryGirl.build(:payout_card, destination_id: account['id'],amount: 400)
95
+ payout_hash=FactoryGirl.build(:payout_card, destination_id: account['id'], amount: 400)
86
96
 
87
- payout=@payouts.create(payout_hash,customer['id'])
88
- expect( @payouts.get( payout['id'],customer['id'] )['amount']).to be_within(0.1).of(400)
97
+ payout=@payouts.create(payout_hash, customer['id'])
98
+ expect(@payouts.get(payout['id'], customer['id'])['amount']).to be_within(0.1).of(400)
89
99
 
90
100
  #cleanup
91
101
  @cards.delete_all(customer['id'])
92
102
  @bank_accounts.delete_all(customer['id'])
93
- # @customers.delete_all
103
+ # @customers.delete_all
94
104
  end
95
-
96
-
97
-
98
105
  end
99
106
 
100
107
  describe '.get' do
101
108
 
102
109
  it 'gets a merchant payout' do
103
110
 
104
- payout_hash= FactoryGirl.build(:payout_card, destination_id: 'b4ravkgvpir9izop1faz',amount: 10)
111
+ pending
112
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: 'bxz8ixftukkkjnrnypzb', amount: 10)
105
113
 
106
114
  payout=@payouts.create(payout_hash)
107
115
  expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(10)
108
116
 
109
117
  end
110
118
 
111
- it 'gets a customer payout' do
119
+ it 'gets a customer payout' do
112
120
  #create new customer
113
121
  customer_hash= FactoryGirl.build(:customer)
114
122
  customer=@customers.create(customer_hash)
@@ -118,14 +126,14 @@ describe Payouts do
118
126
  card=@cards.create(card_hash, customer['id'])
119
127
 
120
128
  #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'])
129
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'])
130
+ charge=@charges.create(charge_hash, customer['id'])
123
131
 
124
- payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 40)
132
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'], amount: 40)
125
133
 
126
- payout=@payouts.create(payout_hash,customer['id'])
134
+ payout=@payouts.create(payout_hash, customer['id'])
127
135
 
128
- res=@payouts.get( payout['id'],customer['id'] )
136
+ res=@payouts.get(payout['id'], customer['id'])
129
137
  expect(res['amount']).to be_within(0.1).of(40)
130
138
 
131
139
  #cleanup
@@ -133,15 +141,14 @@ describe Payouts do
133
141
  @bank_accounts.delete_all(customer['id'])
134
142
  #@customers.delete_all
135
143
  end
136
-
137
-
138
144
  end
139
145
 
140
146
  describe '.all' do
141
147
 
142
148
  it 'all merchant payouts' do
143
- expect(@payouts.all.size).to be_a Integer
144
- expect(@payouts.all.last['transaction_type']) .to match 'payout'
149
+ pending
150
+ expect(@payouts.all.size).to be_a Integer
151
+ expect(@payouts.all.last['transaction_type']).to match 'payout'
145
152
  end
146
153
 
147
154
  it 'all customer payouts' do
@@ -154,18 +161,17 @@ describe Payouts do
154
161
  card=@cards.create(card_hash, customer['id'])
155
162
 
156
163
  #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'])
164
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'])
165
+ charge=@charges.create(charge_hash, customer['id'])
159
166
 
160
- payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'],amount: 40)
167
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'], amount: 40)
161
168
 
162
- payout=@payouts.create(payout_hash,customer['id'])
169
+ payout=@payouts.create(payout_hash, customer['id'])
163
170
 
164
- res=@payouts.get( payout['id'],customer['id'] )
171
+ res=@payouts.get(payout['id'], customer['id'])
165
172
  expect(res['amount']).to be_within(0.1).of(40)
166
173
 
167
-
168
- expect(@payouts.all(customer['id']).last['transaction_type']).to match 'payout'
174
+ expect(@payouts.all(customer['id']).last['transaction_type']).to match 'payout'
169
175
 
170
176
  #cleanup
171
177
  @cards.delete_all(customer['id'])
@@ -175,23 +181,54 @@ describe Payouts do
175
181
  end
176
182
 
177
183
 
184
+ describe '.list' do
185
+
186
+ it 'list payouts given the filter' do
187
+
188
+ #create new customer
189
+ customer_hash= FactoryGirl.build(:customer)
190
+ customer=@customers.create(customer_hash)
191
+
192
+ #create new customer card
193
+ card_hash=FactoryGirl.build(:valid_card)
194
+ card=@cards.create(card_hash, customer['id'])
195
+
196
+ #create charge
197
+ charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'])
198
+ charge=@charges.create(charge_hash, customer['id'])
199
+
200
+ payout_hash= FactoryGirl.build(:payout_card, destination_id: card['id'], amount: 40)
201
+
202
+ payout1=@payouts.create(payout_hash, customer['id'])
203
+ payout2=@payouts.create(payout_hash, customer['id'])
204
+
205
+ search_params = OpenpayUtils::SearchParams.new
206
+ search_params.limit = 1
207
+
208
+ expect(@payouts.all(customer['id']).size).to eq 2
209
+ expect(@payouts.list(search_params, customer['id']).size).to eq 1
210
+
211
+ #cleanup
212
+ @cards.delete_all(customer['id'])
213
+ @bank_accounts.delete_all(customer['id'])
214
+
215
+ end
216
+
217
+ end
218
+
178
219
  describe '.each' do
179
220
 
180
221
  it 'iterates over all merchant payouts' do
181
-
182
222
  @payouts.each do |pay|
183
- expect(@payouts.get(pay['id'])['transaction_type'] ).to match 'payout'
223
+ expect(@payouts.get(pay['id'])['transaction_type']).to match 'payout'
184
224
  end
185
-
186
225
  end
187
226
 
188
227
  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
228
+ a_customer=@customers.all.last
229
+ @payouts.each(a_customer['id']) do |pay|
230
+ expect(@payouts.get(pay['id'], a_customer['id'])['transaction_type']).to match 'payout'
231
+ end
193
232
  end
194
233
  end
195
-
196
-
197
- end
234
+ end