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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +6 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +13 -0
- data/README.md +1984 -0
- data/Rakefile +16 -0
- data/lib/openpay/bankaccounts.rb +58 -0
- data/lib/openpay/cards.rb +73 -0
- data/lib/openpay/charges.rb +101 -0
- data/lib/openpay/colombia/cards_co.rb +73 -0
- data/lib/openpay/colombia/charges_co.rb +76 -0
- data/lib/openpay/colombia/customers_co.rb +166 -0
- data/lib/openpay/colombia/plans_co.rb +17 -0
- data/lib/openpay/colombia/pse_co.rb +17 -0
- data/lib/openpay/colombia/subscriptions_co.rb +50 -0
- data/lib/openpay/colombia/tokens_co.rb +5 -0
- data/lib/openpay/colombia/webhooks_co.rb +5 -0
- data/lib/openpay/customers.rb +200 -0
- data/lib/openpay/errors/openpay_connection_exception.rb +3 -0
- data/lib/openpay/errors/openpay_exception.rb +29 -0
- data/lib/openpay/errors/openpay_exception_factory.rb +56 -0
- data/lib/openpay/errors/openpay_transaction_exception.rb +5 -0
- data/lib/openpay/fees.rb +5 -0
- data/lib/openpay/open_pay_resource.rb +295 -0
- data/lib/openpay/open_pay_resource_factory.rb +17 -0
- data/lib/openpay/openpay_api.rb +72 -0
- data/lib/openpay/payouts.rb +55 -0
- data/lib/openpay/peru/cards_pe.rb +73 -0
- data/lib/openpay/peru/charges_pe.rb +76 -0
- data/lib/openpay/peru/checkouts_pe.rb +51 -0
- data/lib/openpay/peru/customers_pe.rb +79 -0
- data/lib/openpay/peru/tokens_pe.rb +5 -0
- data/lib/openpay/peru/webhooks_pe.rb +5 -0
- data/lib/openpay/plans.rb +17 -0
- data/lib/openpay/points.rb +10 -0
- data/lib/openpay/subscriptions.rb +50 -0
- data/lib/openpay/tokens.rb +7 -0
- data/lib/openpay/transfers.rb +39 -0
- data/lib/openpay/utils/country.rb +3 -0
- data/lib/openpay/utils/search_params.rb +24 -0
- data/lib/openpay/webhooks.rb +9 -0
- data/lib/openpay.rb +55 -0
- data/lib/version.rb +3 -0
- data/openpay.gemspec +30 -0
- data/test/Factories.rb +524 -0
- data/test/spec/bankaccounts_spec.rb +52 -0
- data/test/spec/cards_spec.rb +437 -0
- data/test/spec/charges_spec.rb +382 -0
- data/test/spec/colombia/cards_col_spec.rb +364 -0
- data/test/spec/colombia/charges_col_spec.rb +258 -0
- data/test/spec/colombia/customers_co_spec.rb +151 -0
- data/test/spec/colombia/plans_col_spec.rb +133 -0
- data/test/spec/colombia/pse_col_spec.rb +49 -0
- data/test/spec/colombia/subscriptions_col_spec.rb +230 -0
- data/test/spec/colombia/tokens_col_spec.rb +38 -0
- data/test/spec/customers_spec.rb +172 -0
- data/test/spec/exceptions_spec.rb +105 -0
- data/test/spec/fees_spec.rb +166 -0
- data/test/spec/openpayresource_spec.rb +54 -0
- data/test/spec/payouts_spec.rb +231 -0
- data/test/spec/peru/cards_pe_spec.rb +363 -0
- data/test/spec/peru/charges_pe_spec.rb +218 -0
- data/test/spec/peru/checkouts_pe_spec.rb +71 -0
- data/test/spec/peru/customers_pe_spec.rb +151 -0
- data/test/spec/peru/tokens_pe_spec.rb +38 -0
- data/test/spec/peru/webhook_pe_spec.rb +50 -0
- data/test/spec/plans_spec.rb +158 -0
- data/test/spec/points_spec.rb +26 -0
- data/test/spec/requesttimeout_spec.rb +22 -0
- data/test/spec/subscriptions_spec.rb +294 -0
- data/test/spec/transfers_spec.rb +219 -0
- data/test/spec/utils/search_params_spec.rb +36 -0
- data/test/spec_helper.rb +24 -0
- metadata +219 -0
@@ -0,0 +1,151 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Customers do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@merchant_id = 'mwf7x79goz7afkdbuyqd'
|
7
|
+
@private_key = 'sk_94a89308b4d7469cbda762c4b392152a'
|
8
|
+
#LOG.level=Logger::DEBUG
|
9
|
+
@openpay = OpenpayApi.new(@merchant_id, @private_key, "co")
|
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 = 'Perez'
|
28
|
+
#json as input
|
29
|
+
customer_json = FactoryBot.build(:customer_col, 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_col, 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_col, 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_col, 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_col, 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_col, 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_col, 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 = '2020-01-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_col, name: name)
|
142
|
+
customer = @customers.create(customer_hash)
|
143
|
+
#performs check
|
144
|
+
expect(@customers.all.size).to eq initial_num + 1
|
145
|
+
#cleanup
|
146
|
+
@customers.delete(customer['id'])
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Plans do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
@merchant_id='mwf7x79goz7afkdbuyqd'
|
8
|
+
@private_key='sk_94a89308b4d7469cbda762c4b392152a'
|
9
|
+
|
10
|
+
#LOG.level=Logger::DEBUG
|
11
|
+
|
12
|
+
@openpay=OpenpayApi.new(@merchant_id, @private_key,"co")
|
13
|
+
@customers=@openpay.create(:customers)
|
14
|
+
@plans=@openpay.create(:plans)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
=begin
|
20
|
+
|
21
|
+
after(:all) do
|
22
|
+
@plans.delete_all
|
23
|
+
end
|
24
|
+
|
25
|
+
=end
|
26
|
+
|
27
|
+
it 'has all required methods' do
|
28
|
+
%w(all each create get list delete).each do |meth|
|
29
|
+
expect(@plans).to respond_to(meth)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.create' do
|
34
|
+
it 'creates a merchant plan' do
|
35
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5)
|
36
|
+
plan=@plans.create(plan_hash)
|
37
|
+
#validates
|
38
|
+
expect(@plans.get(plan['id'])['repeat_every']).to be 5
|
39
|
+
#clean
|
40
|
+
@plans.delete(plan['id'])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'get' do
|
45
|
+
it 'gets a merchant plan' do
|
46
|
+
#creates a plan
|
47
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
48
|
+
plan=@plans.create(plan_hash)
|
49
|
+
#validates
|
50
|
+
expect(@plans.get(plan['id'])['repeat_every']).to be 5
|
51
|
+
expect(@plans.get(plan['id'])['amount']).to be_within(0.1).of(500)
|
52
|
+
#clean
|
53
|
+
@plans.delete(plan['id'])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'fails to get a non existing customer plan' do
|
57
|
+
#validates
|
58
|
+
expect { @plans.get('111111') }.to raise_exception OpenpayTransactionException
|
59
|
+
begin
|
60
|
+
@plans.get('111111')
|
61
|
+
rescue OpenpayTransactionException => e
|
62
|
+
expect(e.description).to match 'The requested resource doesn\'t exist'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.all' do
|
69
|
+
it 'returns all customer plans' do
|
70
|
+
expect(@plans.all.size).to be_a Integer
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '.list' do
|
75
|
+
it 'list all plans given the filter' do
|
76
|
+
#creates a plan
|
77
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
78
|
+
plan=@plans.create(plan_hash)
|
79
|
+
search_params = OpenpayUtils::SearchParams.new
|
80
|
+
search_params.limit = 1
|
81
|
+
expect(@plans.list(search_params).size).to eq 1
|
82
|
+
#clean
|
83
|
+
@plans.delete(plan['id'])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.update' do
|
88
|
+
it 'updates an existing customer plan' do
|
89
|
+
#creates a plan
|
90
|
+
plan_hash= FactoryBot.build(:plan, trial_days: 10)
|
91
|
+
plan=@plans.create(plan_hash)
|
92
|
+
expect(plan['trial_days']).to be 10
|
93
|
+
plan_hash= FactoryBot.build(:plan, trial_days: 100)
|
94
|
+
plan=@plans.update(plan_hash, plan['id'])
|
95
|
+
expect(plan['trial_days']).to be 100
|
96
|
+
#cleanup
|
97
|
+
@plans.delete(plan['id'])
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'fails to update an non existing customer plan' do
|
101
|
+
plan_hash= FactoryBot.build(:plan, trial_days: 100)
|
102
|
+
#validates
|
103
|
+
expect { @plans.update(plan_hash, '111111') }.to raise_exception RestClient::ResourceNotFound
|
104
|
+
begin
|
105
|
+
@plans.update(plan_hash, '111111')
|
106
|
+
rescue RestClient::ResourceNotFound => e
|
107
|
+
expect(e.http_body).to be_a String
|
108
|
+
expect(e.message).to include("404")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
skip '.each' do
|
115
|
+
|
116
|
+
it 'iterates over all customer plans' do
|
117
|
+
#creates a plan
|
118
|
+
plan_hash= FactoryBot.build(:plan, trial_days: 30)
|
119
|
+
plan=@plans.create(plan_hash)
|
120
|
+
plan1=@plans.create(plan_hash)
|
121
|
+
plan2=@plans.create(plan_hash)
|
122
|
+
expect(@plans.all.size).to be_a Integer
|
123
|
+
@plans.each do |plan|
|
124
|
+
expect(plan['name']).to match 'TODO INCLUIDO'
|
125
|
+
@plans.delete(plan['id'])
|
126
|
+
end
|
127
|
+
expect(@plans.all.size).to be_a Integer
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Charges do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@merchant_id = 'mwf7x79goz7afkdbuyqd'
|
7
|
+
@private_key = 'sk_94a89308b4d7469cbda762c4b392152a'
|
8
|
+
@openpay = OpenpayApi.new(@merchant_id, @private_key, "co")
|
9
|
+
@customers = @openpay.create(:customers)
|
10
|
+
#LOG.level=Logger::DEBUG
|
11
|
+
@pse = @openpay.create(:pse)
|
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(@pse).to respond_to(meth)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.create' do
|
23
|
+
|
24
|
+
it 'create charge SPE with existing client ' do
|
25
|
+
#create card
|
26
|
+
customer_hash = FactoryBot.build(:customer_col)
|
27
|
+
customer = @customers.create(customer_hash)
|
28
|
+
pse_hash = FactoryBot.build(:charge_pse_col, amount: 101)
|
29
|
+
pse = @pse.create(pse_hash, customer['id'])
|
30
|
+
#perform check
|
31
|
+
method = pse['method']
|
32
|
+
payment_method = pse['payment_method']
|
33
|
+
expect(method).to eq('bank_account')
|
34
|
+
expect(payment_method['type']).to eq('redirect')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'create charge SPE with new client ' do
|
38
|
+
charge_hash = FactoryBot.build(:charge_pse_new_client_col, amount: 101)
|
39
|
+
pse = @pse.create(charge_hash)
|
40
|
+
#perform check
|
41
|
+
method = pse['method']
|
42
|
+
payment_method = pse['payment_method']
|
43
|
+
expect(method).to eq('bank_account')
|
44
|
+
expect(payment_method['type']).to eq('redirect')
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Subscriptions do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
@merchant_id='mwf7x79goz7afkdbuyqd'
|
8
|
+
@private_key='sk_94a89308b4d7469cbda762c4b392152a'
|
9
|
+
|
10
|
+
#LOG.level=Logger::DEBUG
|
11
|
+
|
12
|
+
@openpay=OpenpayApi.new(@merchant_id, @private_key,"co")
|
13
|
+
@customers=@openpay.create(:customers)
|
14
|
+
@cards=@openpay.create(:cards)
|
15
|
+
@charges=@openpay.create(:charges)
|
16
|
+
|
17
|
+
@plans=@openpay.create(:plans)
|
18
|
+
|
19
|
+
@subscriptions=@openpay.create(:subscriptions)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has all required methods' do
|
24
|
+
%w(all each create get list delete).each do |meth|
|
25
|
+
expect(@subscriptions).to respond_to(meth)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.create' do
|
30
|
+
it 'creates a subscription' do
|
31
|
+
#creates a customer
|
32
|
+
customer_hash=FactoryBot.build(:customer_col)
|
33
|
+
customer=@customers.create(customer_hash)
|
34
|
+
#creates a customer card
|
35
|
+
card_hash=FactoryBot.build(:valid_card_col)
|
36
|
+
card=@cards.create(card_hash, customer['id'])
|
37
|
+
#creates a plan
|
38
|
+
plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
39
|
+
plan=@plans.create(plan_hash)
|
40
|
+
#creates subscription
|
41
|
+
subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
42
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
43
|
+
#performs check
|
44
|
+
saved_subscription=@subscriptions.get(subscription['id'], customer['id'])
|
45
|
+
expect(saved_subscription['plan_id']).to eq(plan['id'])
|
46
|
+
#cleanup
|
47
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '.get' do
|
53
|
+
it 'gets customer subscriptions' do
|
54
|
+
#creates a customer
|
55
|
+
customer_hash=FactoryBot.build(:customer_col)
|
56
|
+
customer=@customers.create(customer_hash)
|
57
|
+
#creates a customer card
|
58
|
+
card_hash=FactoryBot.build(:valid_card_col)
|
59
|
+
card=@cards.create(card_hash, customer['id'])
|
60
|
+
#creates a plan
|
61
|
+
plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
62
|
+
plan=@plans.create(plan_hash)
|
63
|
+
#creates subscription
|
64
|
+
subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
65
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
66
|
+
#get customer subscription
|
67
|
+
stored_s=@subscriptions.get(subscription['id'], customer['id'])
|
68
|
+
#performs check
|
69
|
+
expect(stored_s['status']).to match 'trial'
|
70
|
+
#cleanup
|
71
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.update' do
|
77
|
+
it 'updates customer subscription' do
|
78
|
+
time = Time.now + (60*60*24*2)
|
79
|
+
time = time.strftime("%Y-%m-%d")
|
80
|
+
#creates a customer
|
81
|
+
customer_hash=FactoryBot.build(:customer_col)
|
82
|
+
customer=@customers.create(customer_hash)
|
83
|
+
#creates a customer card
|
84
|
+
card_hash=FactoryBot.build(:valid_card_col)
|
85
|
+
card=@cards.create(card_hash, customer['id'])
|
86
|
+
#creates a plan
|
87
|
+
plan_hash=FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
88
|
+
plan=@plans.create(plan_hash)
|
89
|
+
#creates subscription
|
90
|
+
subscription_hash=FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
91
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
92
|
+
#get customer subscription
|
93
|
+
stored_s=@subscriptions.get(subscription['id'], customer['id'])
|
94
|
+
#performs check
|
95
|
+
expect(stored_s['status']).to match 'trial'
|
96
|
+
subscription_update_hash={ trial_end_date: time }
|
97
|
+
sleep(20)
|
98
|
+
stored_s=@subscriptions.update(subscription['id'], customer['id'], subscription_update_hash)
|
99
|
+
expect(stored_s['trial_end_date']).to eq time
|
100
|
+
#cleanup
|
101
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '.all' do
|
107
|
+
it 'returns all subscriptions for a given customer' do
|
108
|
+
#creates a customer
|
109
|
+
customer_hash= FactoryBot.build(:customer_col)
|
110
|
+
customer=@customers.create(customer_hash)
|
111
|
+
#creates a customer card
|
112
|
+
card_hash= FactoryBot.build(:valid_card_col)
|
113
|
+
card=@cards.create(card_hash, customer['id'])
|
114
|
+
#creates a plan
|
115
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
116
|
+
plan=@plans.create(plan_hash)
|
117
|
+
#creates subscription
|
118
|
+
subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
119
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
120
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
121
|
+
#performs check
|
122
|
+
expect(@subscriptions.all(customer['id']).size).to be 1
|
123
|
+
#cleanup
|
124
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '.list' do
|
130
|
+
it 'list subscriptions based on given filter' do
|
131
|
+
#creates a customer
|
132
|
+
customer_hash= FactoryBot.build(:customer_col)
|
133
|
+
customer=@customers.create(customer_hash)
|
134
|
+
#creates a customer card
|
135
|
+
card_hash= FactoryBot.build(:valid_card_col)
|
136
|
+
card=@cards.create(card_hash, customer['id'])
|
137
|
+
#creates a plan
|
138
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
139
|
+
plan=@plans.create(plan_hash)
|
140
|
+
#creates subscription
|
141
|
+
subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
142
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
143
|
+
subscription1=@subscriptions.create(subscription_hash, customer['id'])
|
144
|
+
subscription2=@subscriptions.create(subscription_hash, customer['id'])
|
145
|
+
#performs check
|
146
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
147
|
+
search_params = OpenpayUtils::SearchParams.new
|
148
|
+
search_params.limit = 1
|
149
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
150
|
+
expect(@subscriptions.list(search_params, customer['id']).size).to be 1
|
151
|
+
#cleanup
|
152
|
+
@subscriptions.delete(subscription1['id'], customer['id'])
|
153
|
+
@subscriptions.delete(subscription2['id'], customer['id'])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '.each' do
|
158
|
+
it 'iterates over all subscriptions for a given customer' do
|
159
|
+
#creates a customer
|
160
|
+
customer_hash= FactoryBot.build(:customer_col)
|
161
|
+
customer=@customers.create(customer_hash)
|
162
|
+
#creates a customer card
|
163
|
+
card_hash= FactoryBot.build(:valid_card_col)
|
164
|
+
card=@cards.create(card_hash, customer['id'])
|
165
|
+
#creates a plan
|
166
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
167
|
+
plan=@plans.create(plan_hash)
|
168
|
+
#creates subscription
|
169
|
+
subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
170
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
171
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
172
|
+
#performs check
|
173
|
+
@subscriptions.each(customer['id']) do |stored_s|
|
174
|
+
#check and clean
|
175
|
+
expect(stored_s['status']).to match 'trial'
|
176
|
+
@subscriptions.delete(stored_s['id'],customer['id'])
|
177
|
+
end
|
178
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '.delete' do
|
184
|
+
it 'deletes an existing subscription for a given customer' do
|
185
|
+
#creates a customer
|
186
|
+
customer_hash= FactoryBot.build(:customer_col)
|
187
|
+
customer=@customers.create(customer_hash)
|
188
|
+
#creates a customer card
|
189
|
+
card_hash= FactoryBot.build(:valid_card_col)
|
190
|
+
card=@cards.create(card_hash, customer['id'])
|
191
|
+
#creates a plan
|
192
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
193
|
+
plan=@plans.create(plan_hash)
|
194
|
+
#creates subscription
|
195
|
+
subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
196
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
197
|
+
subscription=@subscriptions.create(subscription_hash, customer['id'])
|
198
|
+
#performs check
|
199
|
+
expect(@subscriptions.all(customer['id']).size).to be 1
|
200
|
+
#cleanup
|
201
|
+
@subscriptions.delete(subscription['id'], customer['id'])
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '.delete_all' do
|
207
|
+
it 'deletes all existing subscription for a given customer' do
|
208
|
+
#creates a customer
|
209
|
+
customer_hash= FactoryBot.build(:customer_col)
|
210
|
+
customer=@customers.create(customer_hash)
|
211
|
+
#creates a customer card
|
212
|
+
card_hash= FactoryBot.build(:valid_card_col)
|
213
|
+
card=@cards.create(card_hash, customer['id'])
|
214
|
+
#creates a plan
|
215
|
+
plan_hash= FactoryBot.build(:plan, repeat_every: 5, amount: 500)
|
216
|
+
plan=@plans.create(plan_hash)
|
217
|
+
#creates subscriptions
|
218
|
+
subscription_hash= FactoryBot.build(:subscription, plan_id: plan['id'], card_id: card['id'])
|
219
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
220
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
221
|
+
@subscriptions.create(subscription_hash, customer['id'])
|
222
|
+
#perform check and clean up
|
223
|
+
expect(@subscriptions.all(customer['id']).size).to be 2
|
224
|
+
@subscriptions.delete_all(customer['id'])
|
225
|
+
expect(@subscriptions.all(customer['id']).size).to be 0
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Subscriptions do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@merchant_id = 'mwf7x79goz7afkdbuyqd'
|
7
|
+
@private_key = 'sk_94a89308b4d7469cbda762c4b392152a'
|
8
|
+
#LOG.level=Logger::DEBUG
|
9
|
+
@openpay = OpenpayApi.new(@merchant_id, @private_key, "co")
|
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_col)
|
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_col)
|
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
|