openpay_copemx 3.0.0

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 (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +1984 -0
  7. data/Rakefile +16 -0
  8. data/lib/openpay/bankaccounts.rb +58 -0
  9. data/lib/openpay/cards.rb +73 -0
  10. data/lib/openpay/charges.rb +101 -0
  11. data/lib/openpay/colombia/cards_co.rb +73 -0
  12. data/lib/openpay/colombia/charges_co.rb +76 -0
  13. data/lib/openpay/colombia/customers_co.rb +166 -0
  14. data/lib/openpay/colombia/plans_co.rb +17 -0
  15. data/lib/openpay/colombia/pse_co.rb +17 -0
  16. data/lib/openpay/colombia/subscriptions_co.rb +50 -0
  17. data/lib/openpay/colombia/tokens_co.rb +5 -0
  18. data/lib/openpay/colombia/webhooks_co.rb +5 -0
  19. data/lib/openpay/customers.rb +200 -0
  20. data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
  21. data/lib/openpay/errors/openpay_exception.rb +29 -0
  22. data/lib/openpay/errors/openpay_exception_factory.rb +56 -0
  23. data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
  24. data/lib/openpay/fees.rb +5 -0
  25. data/lib/openpay/open_pay_resource.rb +295 -0
  26. data/lib/openpay/open_pay_resource_factory.rb +17 -0
  27. data/lib/openpay/openpay_api.rb +72 -0
  28. data/lib/openpay/payouts.rb +55 -0
  29. data/lib/openpay/peru/cards_pe.rb +73 -0
  30. data/lib/openpay/peru/charges_pe.rb +76 -0
  31. data/lib/openpay/peru/checkouts_pe.rb +51 -0
  32. data/lib/openpay/peru/customers_pe.rb +79 -0
  33. data/lib/openpay/peru/tokens_pe.rb +5 -0
  34. data/lib/openpay/peru/webhooks_pe.rb +5 -0
  35. data/lib/openpay/plans.rb +17 -0
  36. data/lib/openpay/points.rb +10 -0
  37. data/lib/openpay/subscriptions.rb +50 -0
  38. data/lib/openpay/tokens.rb +7 -0
  39. data/lib/openpay/transfers.rb +39 -0
  40. data/lib/openpay/utils/country.rb +3 -0
  41. data/lib/openpay/utils/search_params.rb +24 -0
  42. data/lib/openpay/webhooks.rb +9 -0
  43. data/lib/openpay.rb +55 -0
  44. data/lib/version.rb +3 -0
  45. data/openpay.gemspec +30 -0
  46. data/test/Factories.rb +524 -0
  47. data/test/spec/bankaccounts_spec.rb +52 -0
  48. data/test/spec/cards_spec.rb +437 -0
  49. data/test/spec/charges_spec.rb +382 -0
  50. data/test/spec/colombia/cards_col_spec.rb +364 -0
  51. data/test/spec/colombia/charges_col_spec.rb +258 -0
  52. data/test/spec/colombia/customers_co_spec.rb +151 -0
  53. data/test/spec/colombia/plans_col_spec.rb +133 -0
  54. data/test/spec/colombia/pse_col_spec.rb +49 -0
  55. data/test/spec/colombia/subscriptions_col_spec.rb +230 -0
  56. data/test/spec/colombia/tokens_col_spec.rb +38 -0
  57. data/test/spec/customers_spec.rb +172 -0
  58. data/test/spec/exceptions_spec.rb +105 -0
  59. data/test/spec/fees_spec.rb +166 -0
  60. data/test/spec/openpayresource_spec.rb +54 -0
  61. data/test/spec/payouts_spec.rb +231 -0
  62. data/test/spec/peru/cards_pe_spec.rb +363 -0
  63. data/test/spec/peru/charges_pe_spec.rb +218 -0
  64. data/test/spec/peru/checkouts_pe_spec.rb +71 -0
  65. data/test/spec/peru/customers_pe_spec.rb +151 -0
  66. data/test/spec/peru/tokens_pe_spec.rb +38 -0
  67. data/test/spec/peru/webhook_pe_spec.rb +50 -0
  68. data/test/spec/plans_spec.rb +158 -0
  69. data/test/spec/points_spec.rb +26 -0
  70. data/test/spec/requesttimeout_spec.rb +22 -0
  71. data/test/spec/subscriptions_spec.rb +294 -0
  72. data/test/spec/transfers_spec.rb +219 -0
  73. data/test/spec/utils/search_params_spec.rb +36 -0
  74. data/test/spec_helper.rb +24 -0
  75. metadata +219 -0
@@ -0,0 +1,218 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe ChargesPe do
4
+
5
+ before(:all) do
6
+ @merchant_id = 'm3cji4ughukthjcsglv0'
7
+ @private_key = 'sk_f934dfe51645483e82106301d985a4f6'
8
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
9
+ @customers = @openpay.create(:customers)
10
+ #LOG.level=Logger::DEBUG
11
+ @charges = @openpay.create(:charges)
12
+ @cards = @openpay.create(:cards)
13
+
14
+ end
15
+
16
+ it 'has all required methods' do
17
+ %w(all each create get list delete).each do |meth|
18
+ expect(@charges).to respond_to(meth)
19
+ end
20
+ end
21
+
22
+ describe '.create' do
23
+
24
+ it 'create charge to customer' do
25
+ #create new customer
26
+ card_hash = FactoryBot.build(:valid_card_peru, holder_name: 'Pepe')
27
+ customers = @openpay.create(:customers)
28
+ customer_hash = FactoryBot.build(:customer_pe)
29
+ customer = customers.create(customer_hash)
30
+ #creates a customer card
31
+ card = @cards.create(card_hash, customer['id'])
32
+ charge_hash = FactoryBot.build(:charge_pe, source_id: card['id'], amount: 101)
33
+ charge = @charges.create(charge_hash, customer['id'])
34
+ expect(charge['amount']).to be_within(0.1).of(101)
35
+ end
36
+
37
+ it 'create charge to merchant' do
38
+ card_hash = FactoryBot.build(:valid_card_peru)
39
+ card = @cards.create(card_hash)
40
+ #create charge attached to prev created card
41
+ charge_hash = FactoryBot.build(:charge_merchant_pe, source_id: card['id'], amount: 101)
42
+ charge = @charges.create(charge_hash)
43
+ #perform check
44
+ stored_charge = @charges.get(charge['id'])
45
+ expect(stored_charge['amount']).to be_within(0.1).of(101)
46
+ #clean up
47
+ @cards.delete(card['id'])
48
+ end
49
+
50
+ it 'create redirect charge to customer' do
51
+ #create new customer
52
+ customers = @openpay.create(:customers)
53
+ customer_hash = FactoryBot.build(:customer_pe)
54
+ customer = customers.create(customer_hash)
55
+ #creates a customer card
56
+ charge_hash = FactoryBot.build(:charge_redirect_customer_peru, amount: 101)
57
+ charge = @charges.create(charge_hash, customer['id'])
58
+ expect(charge['amount']).to be_within(0.1).of(101)
59
+ end
60
+
61
+ it 'create redirect charge to merchant' do
62
+ charge_hash = FactoryBot.build(:charge_redirect_peru, amount: 101, method: 'card')
63
+ charge = @charges.create(charge_hash)
64
+ #perform check
65
+ redircet_charge = @charges.get(charge['id'])
66
+ paymen_method = redircet_charge['payment_method']
67
+ expect(paymen_method['type']).to eq('redirect')
68
+ expect(redircet_charge['amount']).to be_within(0.1).of(101)
69
+ end
70
+
71
+ it 'create store charge to customer' do
72
+ customer_hash = FactoryBot.build(:customer_pe)
73
+ customer = @customers.create(customer_hash)
74
+ charge_hash = FactoryBot.build(:charge_store_peru_customer, amount: 101, method: 'store')
75
+ charge = @charges.create(charge_hash, customer['id'])
76
+ paymen_method = charge['payment_method']
77
+ expect(paymen_method['type']).to eq('store')
78
+ expect(charge['customer_id']).to eq(customer['id'])
79
+ end
80
+
81
+ it 'create store charge to merchant' do
82
+ charge_hash = FactoryBot.build(:charge_store_peru_merchant, amount: 101, method: 'store')
83
+ charge = @charges.create(charge_hash)
84
+ #perform check
85
+ store_charge = @charges.get(charge['id'])
86
+ paymen_method = store_charge['payment_method']
87
+ expect(paymen_method['type']).to eq('store')
88
+ expect(store_charge['amount']).to be_within(0.1).of(101)
89
+ end
90
+
91
+ end
92
+
93
+ describe '.get' do
94
+ it 'gets a merchant charge' do
95
+ charge_hash = FactoryBot.build(:charge_redirect_peru, amount: 101, method: 'card')
96
+ charge = @charges.create(charge_hash)
97
+ #perform check
98
+ redircet_charge = @charges.get(charge['id'])
99
+ expect(redircet_charge['amount']).to be_within(0.1).of(101)
100
+ #clean up
101
+ end
102
+
103
+ it 'gets a customer charge' do
104
+ card_hash = FactoryBot.build(:valid_card_peru, holder_name: 'Pepe')
105
+ customers = @openpay.create(:customers)
106
+ customer_hash = FactoryBot.build(:customer_pe)
107
+ customer = customers.create(customer_hash)
108
+ #creates a customer card
109
+ card = @cards.create(card_hash, customer['id'])
110
+ charge_hash = FactoryBot.build(:charge_pe, source_id: card['id'], amount: 101)
111
+ charge = @charges.create(charge_hash, customer['id'])
112
+
113
+ #perform check
114
+ stored_charge = @charges.get(charge['id'], customer['id'])
115
+ expect(stored_charge['amount']).to be_within(0.5).of(101)
116
+ #clean up
117
+ @cards.delete(card['id'], customer['id'])
118
+ # no se puede borrar usuario por transacciones asociadas
119
+ # # @customers.delete(customer['id'])
120
+
121
+ end
122
+
123
+ end
124
+
125
+ describe '.all' do
126
+
127
+ it 'all merchant charges' do
128
+ #TODO test can be improved, but since charges cannot be deleted it make this difficult
129
+ expect(@charges.all.size).to be_a Integer
130
+ end
131
+
132
+ it 'all customer charges' do
133
+ #create new customer
134
+ customer_hash = FactoryBot.build(:customer_pe)
135
+ customer = @customers.create(customer_hash)
136
+ expect(@charges.all(customer['id']).size).to be 0
137
+ @customers.delete(customer['id'])
138
+
139
+ end
140
+
141
+ end
142
+
143
+ describe '.refund' do
144
+ #Refunds apply only for card charges
145
+ it 'refunds an existing merchant charge' do
146
+
147
+ end
148
+
149
+ it 'refunds an existing customer charge' do
150
+
151
+ end
152
+
153
+ end
154
+
155
+ describe '.list' do
156
+
157
+ it 'list customer charges' do
158
+ #create new customer
159
+ customer_hash = FactoryBot.build(:customer_pe)
160
+ customer = @customers.create(customer_hash)
161
+ #create customer card
162
+ card_hash = FactoryBot.build(:valid_card_peru)
163
+ card = @cards.create(card_hash, customer['id'])
164
+ #create charge
165
+ charge_hash = FactoryBot.build(:charge_pe, source_id: card['id'], order_id: card['id'])
166
+ charge = @charges.create(charge_hash, customer['id'])
167
+ charge_hash = FactoryBot.build(:charge_pe, source_id: card['id'], order_id: card['id'] + "1")
168
+ charge2 = @charges.create(charge_hash, customer['id'])
169
+ #perform check
170
+ search_params = OpenpayUtils::SearchParams.new
171
+ search_params.limit = 1
172
+ search_params.creation_gte = '2000-01-01'
173
+ search_params.amount_gte = 1
174
+ expect(@charges.all(customer['id']).size).to eq 2
175
+ expect(@charges.list(search_params, customer['id']).size).to eq 1
176
+ #clean up
177
+ @cards.delete(card['id'], customer['id'])
178
+
179
+ # No se puede borrar usuario por transacciones asociadas
180
+ # @customers.delete(customer['id'])
181
+
182
+ end
183
+
184
+ end
185
+
186
+ describe '.each' do
187
+ it 'iterates over merchant charges' do
188
+ @charges.each do |charge|
189
+ #perform check.
190
+ expect(charge['amount']).to be_a Float
191
+ end
192
+ end
193
+ it 'iterate over customer charges' do
194
+ #create new customer
195
+ customer_hash = FactoryBot.build(:customer_pe)
196
+ customer = @customers.create(customer_hash)
197
+ #create customer card
198
+ card_hash = FactoryBot.build(:valid_card_peru)
199
+ card = @cards.create(card_hash, customer['id'])
200
+ #create charge
201
+ charge_hash = FactoryBot.build(:charge_pe, source_id: card['id'], order_id: card['id'], amount: 4)
202
+ @charges.create(charge_hash, customer['id'])
203
+ charge2_hash = FactoryBot.build(:charge_pe, source_id: card['id'], order_id: card['id' + "2"], amount: 4)
204
+ @charges.create(charge2_hash, customer['id'])
205
+ @charges.each(customer['id']) do |charge|
206
+ expect(charge['operation_type']).to match 'in'
207
+ expect(charge['amount']).to be_within(0.1).of(4)
208
+ end
209
+
210
+ #cleanup
211
+ @cards.delete(card['id'], customer['id'])
212
+ # No se puede borrar usuario por transacciones asociadas
213
+ # @customers.delete(customer['id'])
214
+ end
215
+
216
+ end
217
+
218
+ end
@@ -0,0 +1,71 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe CheckoutsPe do
4
+
5
+ before(:all) do
6
+ @merchant_id = 'm3cji4ughukthjcsglv0'
7
+ @private_key = 'sk_f934dfe51645483e82106301d985a4f6'
8
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
9
+ @customers = @openpay.create(:customers)
10
+ #LOG.level=Logger::DEBUG
11
+ @charges = @openpay.create(:charges)
12
+ @cards = @openpay.create(:cards)
13
+ @checkouts = @openpay.create(:checkouts)
14
+
15
+ end
16
+
17
+ it 'has all required methods' do
18
+ %w(all each create get list delete).each do |meth|
19
+ expect(@checkouts).to respond_to(meth)
20
+ end
21
+ end
22
+
23
+ describe '.create' do
24
+ it 'create checkout to customer' do
25
+ customer_hash = FactoryBot.build(:customer_pe)
26
+ customer = @customers.create(customer_hash)
27
+ checkout_hash = FactoryBot.build(:checkou_peru, order_id: customer['id'])
28
+ checkout = @checkouts.create(checkout_hash, customer['id'])
29
+ expect(checkout['id']).not_to be(nil)
30
+ end
31
+
32
+ it 'create charge to merchant' do
33
+ customer_hash = FactoryBot.build(:customer_pe)
34
+ customer = @customers.create(customer_hash)
35
+ checkout_hash = FactoryBot.build(:checkou_peru_merchant, order_id: customer['id'])
36
+ checkout = @checkouts.create(checkout_hash)
37
+ expect(checkout['id']).not_to be(nil)
38
+ end
39
+
40
+ end
41
+
42
+ describe '.get' do
43
+ it 'get a checkout merchant with id' do
44
+ customer_hash = FactoryBot.build(:customer_pe)
45
+ customer = @customers.create(customer_hash)
46
+ checkout_hash = FactoryBot.build(:checkou_peru, order_id: customer['id'])
47
+ checkout = @checkouts.create(checkout_hash, customer['id'])
48
+ checkout_res = @checkouts.get(checkout['id'])
49
+ expect(checkout_res['id']).to match checkout['id']
50
+ end
51
+
52
+ it 'get a checkout with order id' do
53
+ # customer_hash = FactoryBot.build(:customer_pe)
54
+ # customer = @customers.create(customer_hash)
55
+ # checkout_hash = FactoryBot.build(:checkou_peru, order_id: customer['id'])
56
+ # checkout = @checkouts.create(checkout_hash, customer['id'])
57
+ checkout_res = @checkouts.get_by_order_id('aqqgegs57695gysyedkh')
58
+ expect(checkout_res['id']).to match checkout['id']
59
+ end
60
+
61
+ end
62
+
63
+ describe '.all' do
64
+
65
+ it 'all merchant checkouts' do
66
+ checkouts_size = @checkouts.all.size
67
+ expect(checkouts_size).to be_between(10, 100)
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,151 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Customers do
4
+
5
+ before(:all) do
6
+ @merchant_id = 'm3cji4ughukthjcsglv0'
7
+ @private_key = 'sk_f934dfe51645483e82106301d985a4f6'
8
+ #LOG.level=Logger::DEBUG
9
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
10
+ @customers = @openpay.create(:customers)
11
+ end
12
+
13
+ after(:all) do
14
+ # @customers.delete_all
15
+ end
16
+
17
+ it 'has all required methods' do
18
+ %w(all each create get list delete).each do |meth|
19
+ expect(@customers).to respond_to(meth)
20
+ end
21
+ end
22
+
23
+ describe '.create' do
24
+ it 'creates a customer' do
25
+ #creates a new customer
26
+ name = 'Juan'
27
+ last_name = 'Peru'
28
+ #json as input
29
+ customer_json = FactoryBot.build(:customer_pe, name: name, last_name: last_name).to_json
30
+ customer = @customers.create(customer_json)
31
+ #perform check
32
+ #json as output
33
+ expect(customer).to have_json_path('name')
34
+ #build hash out json string
35
+ customer_hash = JSON.parse customer
36
+ id = customer_hash['id']
37
+ #perform check
38
+ saved_customer = @customers.get(id)
39
+ expect(saved_customer['name']).to match(name)
40
+ expect(saved_customer['last_name']).to match(last_name)
41
+ #cleanup
42
+ @customers.delete(id)
43
+ end
44
+
45
+ it 'fails when passing invalid information' do
46
+ #check no errors
47
+ expect(@customers.errors?).to eq false
48
+ #invalid email
49
+ email = 'foo'
50
+ customer_hash = FactoryBot.build(:customer_pe, email: email)
51
+ #perform check
52
+ expect { @customers.create(customer_hash) }.to raise_exception OpenpayTransactionException
53
+ begin
54
+ @customers.create(customer_hash)
55
+ rescue OpenpayTransactionException => e
56
+ expect(e.http_code).to be 400
57
+ expect(e.description).to match /'foo' is not a valid email address/
58
+ end
59
+ expect(@customers.errors?).to eq true
60
+ end
61
+
62
+ end
63
+
64
+ describe '.delete' do
65
+ it 'deletes an existing customer' do
66
+ #creates customer
67
+ customer_hash = FactoryBot.build(:customer_pe, name: :delete_me)
68
+ customer = @customers.create(customer_hash)
69
+ id = customer['id']
70
+ #delete customer
71
+ @customers.delete(id)
72
+ #perform check
73
+ expect { @customers.get(id) }.to raise_exception OpenpayTransactionException
74
+ end
75
+ end
76
+
77
+ describe '.get' do
78
+ it 'get a customer' do
79
+ #create customer
80
+ name = 'get_test'
81
+ customer_hash = FactoryBot.build(:customer_pe, name: name)
82
+ customer = @customers.create(customer_hash)
83
+ id = customer['id']
84
+ #perform check
85
+ expect(@customers.get(id)['name']).to match name
86
+ #cleanup
87
+ @customers.delete(id)
88
+ end
89
+
90
+ end
91
+
92
+ describe '.each' do
93
+ it 'list all customers' do
94
+ @customers.each do |cust|
95
+ expect(cust['id']).to match /.+/
96
+ end
97
+ end
98
+ end
99
+
100
+ describe '.update' do
101
+ it 'updates an existing customer' do
102
+ # creates customer
103
+ name = 'customer_update_test'
104
+ customer_hash = FactoryBot.build(:customer_pe, name: name)
105
+ customer = @customers.create(customer_hash)
106
+ id = customer['id']
107
+ #update customer
108
+ name = 'new_name'
109
+ customer_hash = FactoryBot.build(:customer_pe, name: name)
110
+ @customers.update(customer_hash, id)
111
+ #perform check
112
+ expect(@customers.get(id)['name']).to match name
113
+ #cleanup
114
+ @customers.delete(id)
115
+ end
116
+ end
117
+
118
+ describe '.list' do
119
+ it 'list customers given the filter' do
120
+ # creates customer
121
+ name = 'customer_update_test'
122
+ customer_hash = FactoryBot.build(:customer_pe, name: name)
123
+ customer = @customers.create(customer_hash)
124
+ id = customer['id']
125
+ search_params = OpenpayUtils::SearchParams.new
126
+ search_params.limit = 1
127
+ search_params.creation_gte = '2021-10-01'
128
+ #perform check
129
+ expect(@customers.list(search_params).size).to eq 1
130
+ #cleanup
131
+ @customers.delete(id)
132
+ end
133
+ end
134
+
135
+ describe '.all' do
136
+ it 'all the customers' do
137
+ #initial state check
138
+ initial_num = @customers.all.size
139
+ # creates customer
140
+ name = 'customer_update_test'
141
+ customer_hash = FactoryBot.build(:customer_pe, name: name)
142
+ customer = @customers.create(customer_hash)
143
+ #performs check
144
+ expect(@customers.all.size).to eq initial_num
145
+ #cleanup
146
+ @customers.delete(customer['id'])
147
+ end
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,38 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Subscriptions do
4
+
5
+ before(:all) do
6
+ @merchant_id = 'm3cji4ughukthjcsglv0'
7
+ @private_key = 'sk_f934dfe51645483e82106301d985a4f6'
8
+ #LOG.level=Logger::DEBUG
9
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
10
+ @tokens = @openpay.create(:tokens)
11
+ end
12
+
13
+ it 'has all required methods' do
14
+ %w(all each create get list delete).each do |meth|
15
+ expect(@tokens).to respond_to(meth)
16
+ end
17
+ end
18
+
19
+ describe '.create' do
20
+ it 'creates a token' do
21
+ token_hash = FactoryBot.build(:token_peru)
22
+ token = @tokens.create(token_hash)
23
+ LOG.info token
24
+ expect(token['id']).not_to be(nil)
25
+ end
26
+ end
27
+
28
+ describe '.get' do
29
+ it 'get token' do
30
+ token_hash = FactoryBot.build(:token_peru)
31
+ token = @tokens.create(token_hash)
32
+ LOG.info token
33
+ token_result = @tokens.get(token['id'])
34
+ LOG.info token_result
35
+ expect(token['id']).to eq(token_result['id'])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Webhooks do
4
+
5
+ before(:all) do
6
+ @merchant_id = 'm3cji4ughukthjcsglv0'
7
+ @private_key = 'sk_f934dfe51645483e82106301d985a4f6'
8
+ #LOG.level=Logger::DEBUG
9
+ @openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
10
+ @webhooks = @openpay.create(:webhooks)
11
+ end
12
+
13
+ it 'has all required methods' do
14
+ %w(all each create get list delete).each do |meth|
15
+ expect(@webhooks).to respond_to(meth)
16
+ end
17
+ end
18
+
19
+ describe '.create' do
20
+ it 'creates a webhooks' do
21
+ webhook_hash = FactoryBot.build(:webhook_peru)
22
+ webhook = @webhooks.create(webhook_hash)
23
+ LOG.info webhook
24
+ expect(webhook['id']).not_to be(nil)
25
+ @webhooks.delete(webhook['id'])
26
+ end
27
+ end
28
+
29
+ describe '.get' do
30
+ it 'get token' do
31
+ webhook_hash = FactoryBot.build(:webhook_peru)
32
+ webhook = @webhooks.create(webhook_hash)
33
+ LOG.info webhook
34
+ webhook_result = @webhooks.get(webhook['id'])
35
+ LOG.info webhook_result
36
+ expect(webhook_result['id']).to eq(webhook['id'])
37
+ @webhooks.delete(webhook['id'])
38
+ end
39
+ end
40
+
41
+ describe '.all' do
42
+ it 'creates a webhooks' do
43
+ webhook_hash = FactoryBot.build(:webhook_peru)
44
+ webhook = @webhooks.create(webhook_hash)
45
+ LOG.info webhook
46
+ expect(@webhooks.all.size).to eq 1
47
+ @webhooks.delete(webhook['id'])
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,158 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Plans do
4
+
5
+ before(:all) do
6
+
7
+ @merchant_id='mywvupjjs9xdnryxtplq'
8
+ @private_key='sk_92b25d3baec149e6b428d81abfe37006'
9
+
10
+ #LOG.level=Logger::DEBUG
11
+
12
+ @openpay=OpenpayApi.new(@merchant_id, @private_key,"mx")
13
+ @customers=@openpay.create(:customers)
14
+ @plans=@openpay.create(:plans)
15
+ @subscriptions=@openpay.create(:subscriptions)
16
+
17
+ end
18
+
19
+
20
+ =begin
21
+
22
+ after(:all) do
23
+ @plans.delete_all
24
+ end
25
+
26
+ =end
27
+
28
+ it 'has all required methods' do
29
+ %w(all each create get list delete).each do |meth|
30
+ expect(@plans).to respond_to(meth)
31
+ end
32
+ end
33
+
34
+ describe '.create' do
35
+
36
+ it 'creates a merchant plan' do
37
+
38
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5)
39
+ plan=@plans.create(plan_hash)
40
+
41
+ #validates
42
+ expect(@plans.get(plan['id'])['repeat_every']).to be 5
43
+
44
+ #clean
45
+ @plans.delete(plan['id'])
46
+
47
+ end
48
+
49
+ end
50
+
51
+ describe 'get' do
52
+
53
+ it 'gets a merchant plan' do
54
+
55
+ #creates a plan
56
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
57
+ plan=@plans.create(plan_hash)
58
+
59
+ #validates
60
+ expect(@plans.get(plan['id'])['repeat_every']).to be 5
61
+ expect(@plans.get(plan['id'])['amount']).to be_within(0.1).of(500)
62
+
63
+ #clean
64
+ @plans.delete(plan['id'])
65
+
66
+ end
67
+
68
+ it 'fails to get a non existing customer plan' do
69
+ #validates
70
+ expect { @plans.get('111111') }.to raise_exception OpenpayTransactionException
71
+ begin
72
+ @plans.get('111111')
73
+ rescue OpenpayTransactionException => e
74
+ expect(e.description).to match 'The requested resource doesn\'t exist'
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+ describe '.all' do
82
+ it 'returns all customer plans' do
83
+ expect(@plans.all.size).to be_a Integer
84
+ end
85
+ end
86
+
87
+ describe '.list' do
88
+ it 'list all plans given the filter' do
89
+ #creates a plan
90
+ plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
91
+ plan=@plans.create(plan_hash)
92
+
93
+ search_params = OpenpayUtils::SearchParams.new
94
+ search_params.limit = 1
95
+ expect(@plans.list(search_params).size).to eq 1
96
+
97
+ #clean
98
+ @plans.delete(plan['id'])
99
+ end
100
+
101
+ end
102
+
103
+ describe '.update' do
104
+
105
+ it 'updates an existing customer plan' do
106
+ #creates a plan
107
+ plan_hash= FactoryBot.build(:plan, trial_days: 10)
108
+ plan=@plans.create(plan_hash)
109
+
110
+ expect(plan['trial_days']).to be 10
111
+ plan_hash= FactoryBot.build(:plan, trial_days: 100)
112
+ plan=@plans.update(plan_hash, plan['id'])
113
+ expect(plan['trial_days']).to be 100
114
+
115
+ #cleanup
116
+ @plans.delete(plan['id'])
117
+ end
118
+
119
+ it 'fails to update an non existing customer plan' do
120
+
121
+ plan_hash= FactoryBot.build(:plan, trial_days: 100)
122
+
123
+ #validates
124
+ expect { @plans.update(plan_hash, '111111') }.to raise_exception RestClient::ResourceNotFound
125
+ begin
126
+ @plans.update(plan_hash, '111111')
127
+ rescue RestClient::ResourceNotFound => e
128
+ expect(e.http_body).to be_a String
129
+ expect(e.message).to include("404")
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
136
+ skip '.each' do
137
+
138
+ it 'iterates over all customer plans' do
139
+
140
+ #creates a plan
141
+ plan_hash= FactoryBot.build(:plan, trial_days: 30)
142
+ plan=@plans.create(plan_hash)
143
+ plan1=@plans.create(plan_hash)
144
+ plan2=@plans.create(plan_hash)
145
+
146
+ expect(@plans.all.size).to be_a Integer
147
+ @plans.each do |plan|
148
+ expect(plan['name']).to match 'TODO INCLUIDO'
149
+ @plans.delete(plan['id'])
150
+ end
151
+
152
+ expect(@plans.all.size).to be_a Integer
153
+
154
+ end
155
+
156
+ end
157
+
158
+ end