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,231 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Payouts 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
|
+
@payouts=@openpay.create(:payouts)
|
14
|
+
|
15
|
+
@customers=@openpay.create(:customers)
|
16
|
+
@cards=@openpay.create(:cards)
|
17
|
+
@charges=@openpay.create(:charges)
|
18
|
+
|
19
|
+
@bank_accounts=@openpay.create(:bankaccounts)
|
20
|
+
|
21
|
+
@fees=@openpay.create(:fees)
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has all required methods' do
|
26
|
+
%w(all each create get list delete).each do |meth|
|
27
|
+
expect(@cards).to respond_to(meth)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.create' do
|
32
|
+
|
33
|
+
skip 'creates a merchant payout' do
|
34
|
+
#pending("is a pending example")
|
35
|
+
#create merchant card
|
36
|
+
card_hash = FactoryBot.build(:valid_card)
|
37
|
+
card = @cards.create(card_hash)
|
38
|
+
|
39
|
+
#create charge
|
40
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
41
|
+
charge=@charges.create(charge_hash)
|
42
|
+
|
43
|
+
payout_hash=FactoryBot.build(:payout_card, destination_id: card['id'], amount: 100)
|
44
|
+
|
45
|
+
payout=@payouts.create(payout_hash)
|
46
|
+
expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(100)
|
47
|
+
|
48
|
+
@cards.delete(card['id'])
|
49
|
+
end
|
50
|
+
|
51
|
+
skip 'creates a customer payout using a card' do
|
52
|
+
#We need to charge 1st into the card we are going to use
|
53
|
+
|
54
|
+
#create new customer
|
55
|
+
customer_hash=FactoryBot.build(:customer)
|
56
|
+
customer=@customers.create(customer_hash)
|
57
|
+
|
58
|
+
#create new customer card
|
59
|
+
card_hash=FactoryBot.build(:valid_card)
|
60
|
+
card=@cards.create(card_hash, customer['id'])
|
61
|
+
|
62
|
+
#create charge
|
63
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
64
|
+
charge=@charges.create(charge_hash, customer['id'])
|
65
|
+
|
66
|
+
payout_hash=FactoryBot.build(:payout_card, destination_id: card['id'], amount: 400)
|
67
|
+
|
68
|
+
payout=@payouts.create(payout_hash, customer['id'])
|
69
|
+
expect(@payouts.get(payout['id'], customer['id'])['amount']).to be_within(0.1).of(400)
|
70
|
+
|
71
|
+
#cleanup
|
72
|
+
@cards.delete_all(customer['id'])
|
73
|
+
@bank_accounts.delete_all(customer['id'])
|
74
|
+
|
75
|
+
end
|
76
|
+
skip 'creates a customer payout using a bank account' do
|
77
|
+
|
78
|
+
#create new customer
|
79
|
+
customer_hash=FactoryBot.build(:customer)
|
80
|
+
customer=@customers.create(customer_hash)
|
81
|
+
|
82
|
+
#create new customer card
|
83
|
+
card_hash=FactoryBot.build(:valid_card)
|
84
|
+
card=@cards.create(card_hash, customer['id'])
|
85
|
+
|
86
|
+
#create new customer bank account
|
87
|
+
account_hash=FactoryBot.build(:bank_account)
|
88
|
+
account=@bank_accounts.create(account_hash, customer['id'])
|
89
|
+
|
90
|
+
#create charge
|
91
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
92
|
+
charge=@charges.create(charge_hash, customer['id'])
|
93
|
+
|
94
|
+
payout_hash=FactoryBot.build(:payout_card, destination_id: account['id'], amount: 400)
|
95
|
+
|
96
|
+
payout=@payouts.create(payout_hash, customer['id'])
|
97
|
+
expect(@payouts.get(payout['id'], customer['id'])['amount']).to be_within(0.1).of(400)
|
98
|
+
|
99
|
+
#cleanup
|
100
|
+
@cards.delete_all(customer['id'])
|
101
|
+
@bank_accounts.delete_all(customer['id'])
|
102
|
+
# @customers.delete_all
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '.get' do
|
107
|
+
|
108
|
+
skip 'gets a merchant payout' do
|
109
|
+
#pending("is a pending example")
|
110
|
+
payout_hash= FactoryBot.build(:payout_card, destination_id: 'bxz8ixftukkkjnrnypzb', amount: 10)
|
111
|
+
payout=@payouts.create(payout_hash)
|
112
|
+
expect(@payouts.get(payout['id'])['amount']).to be_within(0.1).of(10)
|
113
|
+
end
|
114
|
+
|
115
|
+
skip 'gets a customer payout' do
|
116
|
+
#create new customer
|
117
|
+
customer_hash= FactoryBot.build(:customer)
|
118
|
+
customer=@customers.create(customer_hash)
|
119
|
+
|
120
|
+
#create new customer card
|
121
|
+
card_hash=FactoryBot.build(:valid_card)
|
122
|
+
card=@cards.create(card_hash, customer['id'])
|
123
|
+
|
124
|
+
#create charge
|
125
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
126
|
+
charge=@charges.create(charge_hash, customer['id'])
|
127
|
+
|
128
|
+
payout_hash= FactoryBot.build(:payout_card, destination_id: card['id'], amount: 40)
|
129
|
+
|
130
|
+
payout=@payouts.create(payout_hash, customer['id'])
|
131
|
+
|
132
|
+
res=@payouts.get(payout['id'], customer['id'])
|
133
|
+
expect(res['amount']).to be_within(0.1).of(40)
|
134
|
+
|
135
|
+
#cleanup
|
136
|
+
@cards.delete_all(customer['id'])
|
137
|
+
@bank_accounts.delete_all(customer['id'])
|
138
|
+
#@customers.delete_all
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '.all' do
|
143
|
+
|
144
|
+
skip 'all merchant payouts' do
|
145
|
+
#pending("is a pending example")
|
146
|
+
expect(@payouts.all.size).to be_a Integer
|
147
|
+
expect(@payouts.all.last['transaction_type']).to match 'payout'
|
148
|
+
end
|
149
|
+
|
150
|
+
skip 'all customer payouts' do
|
151
|
+
#create new customer
|
152
|
+
customer_hash= FactoryBot.build(:customer)
|
153
|
+
customer=@customers.create(customer_hash)
|
154
|
+
|
155
|
+
#create new customer card
|
156
|
+
card_hash=FactoryBot.build(:valid_card)
|
157
|
+
card=@cards.create(card_hash, customer['id'])
|
158
|
+
|
159
|
+
#create charge
|
160
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
161
|
+
charge=@charges.create(charge_hash, customer['id'])
|
162
|
+
|
163
|
+
payout_hash= FactoryBot.build(:payout_card, destination_id: card['id'], amount: 40)
|
164
|
+
|
165
|
+
payout=@payouts.create(payout_hash, customer['id'])
|
166
|
+
|
167
|
+
res=@payouts.get(payout['id'], customer['id'])
|
168
|
+
expect(res['amount']).to be_within(0.1).of(40)
|
169
|
+
|
170
|
+
expect(@payouts.all(customer['id']).last['transaction_type']).to match 'payout'
|
171
|
+
|
172
|
+
#cleanup
|
173
|
+
@cards.delete_all(customer['id'])
|
174
|
+
@bank_accounts.delete_all(customer['id'])
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
describe '.list' do
|
181
|
+
|
182
|
+
skip 'list payouts given the filter' do
|
183
|
+
|
184
|
+
#create new customer
|
185
|
+
customer_hash= FactoryBot.build(:customer)
|
186
|
+
customer=@customers.create(customer_hash)
|
187
|
+
|
188
|
+
#create new customer card
|
189
|
+
card_hash=FactoryBot.build(:valid_card)
|
190
|
+
card=@cards.create(card_hash, customer['id'])
|
191
|
+
|
192
|
+
#create charge
|
193
|
+
charge_hash=FactoryBot.build(:card_charge, source_id: card['id'], order_id: card['id'])
|
194
|
+
charge=@charges.create(charge_hash, customer['id'])
|
195
|
+
|
196
|
+
payout_hash= FactoryBot.build(:payout_card, destination_id: card['id'], amount: 40)
|
197
|
+
|
198
|
+
payout1=@payouts.create(payout_hash, customer['id'])
|
199
|
+
payout2=@payouts.create(payout_hash, customer['id'])
|
200
|
+
|
201
|
+
search_params = OpenpayUtils::SearchParams.new
|
202
|
+
search_params.limit = 1
|
203
|
+
|
204
|
+
expect(@payouts.all(customer['id']).size).to eq 2
|
205
|
+
expect(@payouts.list(search_params, customer['id']).size).to eq 1
|
206
|
+
|
207
|
+
#cleanup
|
208
|
+
@cards.delete_all(customer['id'])
|
209
|
+
@bank_accounts.delete_all(customer['id'])
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
describe '.each' do
|
216
|
+
|
217
|
+
it 'iterates over all merchant payouts' do
|
218
|
+
@payouts.each do |pay|
|
219
|
+
expect(@payouts.get(pay['id'])['transaction_type']).to match 'payout'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
#skipping for review
|
224
|
+
skip 'iterates over a given customer payouts' do
|
225
|
+
a_customer=@customers.all.last
|
226
|
+
@payouts.each(a_customer['id']) do |pay|
|
227
|
+
expect(@payouts.get(pay['id'], a_customer['id'])['transaction_type']).to match 'payout'
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
@@ -0,0 +1,363 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Cards do
|
5
|
+
|
6
|
+
# %w(create delete get list each all fail).each do |meth|
|
7
|
+
# end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@merchant_id = 'm3cji4ughukthjcsglv0'
|
11
|
+
@private_key = 'sk_f934dfe51645483e82106301d985a4f6'
|
12
|
+
@openpay = OpenpayApi.new(@merchant_id, @private_key, "pe")
|
13
|
+
@cards=@openpay.create(:cards)
|
14
|
+
@customers=@openpay.create(:customers)
|
15
|
+
@cards.delete_all
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
#each test should build and clean it's own mess.
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has all required methods' do
|
23
|
+
%w(all each create get list delete).each do |meth|
|
24
|
+
expect(@cards).to respond_to(meth)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.create' do
|
29
|
+
it 'creates merchant card' do
|
30
|
+
#creates merchant card
|
31
|
+
card_hash = FactoryBot.build(:valid_card_peru)
|
32
|
+
cards=@cards.create(card_hash)
|
33
|
+
expect(cards).to be_a(Hash)
|
34
|
+
id=cards['id']
|
35
|
+
name='Vicente Olmos'
|
36
|
+
#perform check
|
37
|
+
card=@cards.get(id)
|
38
|
+
expect(card['holder_name']).to match(name)
|
39
|
+
expect(card['card_number']).to match('1111')
|
40
|
+
#cleanup
|
41
|
+
@cards.delete(card['id'])
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'creates a customer card' do
|
45
|
+
#creates a customer
|
46
|
+
card_hash = FactoryBot.build(:valid_card_peru, holder_name: 'Pepe')
|
47
|
+
customers=@openpay.create(:customers)
|
48
|
+
customer_hash = FactoryBot.build(:customer_pe)
|
49
|
+
customer=customers.create(customer_hash)
|
50
|
+
#creates a customer card
|
51
|
+
cards=@cards.create(card_hash, customer['id'])
|
52
|
+
expect(cards).to be_a(Hash)
|
53
|
+
id=cards['id']
|
54
|
+
#performs check
|
55
|
+
customer_cards=customers.all_cards(customer['id'])
|
56
|
+
expect(customer_cards.size).to be 1
|
57
|
+
expect(cards['holder_name']).to match 'Pepe'
|
58
|
+
stored_card=@cards.get(id, customer['id'])
|
59
|
+
expect(stored_card['holder_name']).to match 'Pepe'
|
60
|
+
expect(stored_card['id']).to match id
|
61
|
+
#cleanup
|
62
|
+
@cards.delete(id, customer['id'])
|
63
|
+
@customers.delete(customer['id'])
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'create an existing merchant card' do
|
67
|
+
#creates merchant card
|
68
|
+
card_hash = FactoryBot.build(:valid_card_peru)
|
69
|
+
card=@cards.create(card_hash)
|
70
|
+
#cleanup
|
71
|
+
@cards.delete(card['id'])
|
72
|
+
|
73
|
+
card=@cards.create(card_hash)
|
74
|
+
#cleanup
|
75
|
+
@cards.delete(card['id'])
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'trying to create an existing customer card' do
|
80
|
+
#creates a customer
|
81
|
+
card_hash = FactoryBot.build(:valid_card_peru, holder_name: 'Pepe')
|
82
|
+
customers=@openpay.create(:customers)
|
83
|
+
customer_hash = FactoryBot.build(:customer_pe)
|
84
|
+
customer=customers.create(customer_hash)
|
85
|
+
#creates a customer card
|
86
|
+
card=@cards.create(card_hash, customer['id'])
|
87
|
+
expect(card).to be_a(Hash)
|
88
|
+
#cleanup
|
89
|
+
@cards.delete(card['id'], customer['id'])
|
90
|
+
@customers.delete(customer['id'])
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'fails when using an expired card' do
|
94
|
+
card_hash = FactoryBot.build(:valid_card_peru, expiration_year: 20)
|
95
|
+
#check
|
96
|
+
expect { @cards.create(card_hash) }.to raise_error(OpenpayTransactionException)
|
97
|
+
#extended check
|
98
|
+
begin
|
99
|
+
@cards.create(card_hash)
|
100
|
+
rescue OpenpayTransactionException => e
|
101
|
+
expect(e.description).to match 'The expiration date has expired'
|
102
|
+
expect(e.error_code).to be 2005
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'fails when using a stolen card' do
|
107
|
+
card_json = FactoryBot.build(:valid_card_peru, card_number: '340000000000009')
|
108
|
+
expect { @cards.create(card_json) }.to raise_error(OpenpayTransactionException)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '.each' do
|
113
|
+
|
114
|
+
it 'iterates over all existing merchant cards' do
|
115
|
+
@cards.each do |card|
|
116
|
+
expect(card['expiration_year']).to match '20'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'iterates over all existing customer cards' do
|
121
|
+
|
122
|
+
#creates a customer
|
123
|
+
card_hash = FactoryBot.build(:valid_card_peru, holder_name: 'Pepe')
|
124
|
+
customers=@openpay.create(:customers)
|
125
|
+
customer_hash = FactoryBot.build(:customer_pe)
|
126
|
+
customer=customers.create(customer_hash)
|
127
|
+
|
128
|
+
#creates a customer card
|
129
|
+
card=@cards.create(card_hash, customer['id'])
|
130
|
+
expect(card).to be_a(Hash)
|
131
|
+
|
132
|
+
@cards.each(customer['id']) do |c|
|
133
|
+
expect(c['expiration_year']).to match '25'
|
134
|
+
end
|
135
|
+
|
136
|
+
#cleanup
|
137
|
+
@cards.delete(card['id'], customer['id'])
|
138
|
+
@customers.delete(customer['id'])
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '.delete' do
|
145
|
+
|
146
|
+
it 'deletes a merchant card' do
|
147
|
+
|
148
|
+
#creates merchant card
|
149
|
+
card_hash = FactoryBot.build(:valid_card_peru)
|
150
|
+
cards=@cards.create(card_hash)
|
151
|
+
expect(cards).to be_a(Hash)
|
152
|
+
|
153
|
+
id=cards['id']
|
154
|
+
name='Vicente Olmos'
|
155
|
+
|
156
|
+
#perform check
|
157
|
+
card=@cards.delete(id)
|
158
|
+
expect { @cards.get(id) }.to raise_exception(OpenpayTransactionException)
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'fails to deletes a non existing card' do
|
163
|
+
expect { @cards.delete('1111111') }.to raise_exception(OpenpayTransactionException)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'deletes a customer card' do
|
167
|
+
|
168
|
+
#create customer
|
169
|
+
customers=@openpay.create(:customers)
|
170
|
+
customer_hash = FactoryBot.build(:customer_pe, name: 'Juan', last_name: 'Paez')
|
171
|
+
customer=customers.create(customer_hash)
|
172
|
+
|
173
|
+
#create customer card
|
174
|
+
card_hash = FactoryBot.build(:valid_card_peru)
|
175
|
+
card=@cards.create(card_hash, customer['id'])
|
176
|
+
|
177
|
+
#delete card
|
178
|
+
@cards.delete(card['id'], customer['id'])
|
179
|
+
|
180
|
+
#perform check
|
181
|
+
expect { @cards.get(card['id'], customer['id']) }.to raise_exception(OpenpayTransactionException)
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'fails to deletes a non existing customer card' do
|
186
|
+
expect { @cards.delete('1111111', '1111') }.to raise_exception(OpenpayTransactionException)
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '.get' do
|
192
|
+
it ' gets an existing merchant card' do
|
193
|
+
#create merchant card
|
194
|
+
bank_name='Banamex'
|
195
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
196
|
+
card=@cards.create(card_hash)
|
197
|
+
id=card['id']
|
198
|
+
#pass just a single parameter for getting merchant cards
|
199
|
+
stored_card = @cards.get(id)
|
200
|
+
bank=stored_card['bank_name']
|
201
|
+
expect(bank).to match bank_name
|
202
|
+
#cleanup
|
203
|
+
@cards.delete(id)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'fails when getting a non existing card' do
|
207
|
+
expect { @cards.get('11111') }.to raise_exception(OpenpayTransactionException)
|
208
|
+
end
|
209
|
+
|
210
|
+
it ' gets an existing customer card' do
|
211
|
+
#create customer
|
212
|
+
customer_hash = FactoryBot.build(:customer_col)
|
213
|
+
customer=@customers.create(customer_hash)
|
214
|
+
#creates card
|
215
|
+
bank_name='Banamex'
|
216
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
217
|
+
card=@cards.create(card_hash, customer['id'])
|
218
|
+
id=card['id']
|
219
|
+
#two parameters for getting customer cards
|
220
|
+
stored_cards = @cards.get(id, customer['id'])
|
221
|
+
bank=stored_cards['bank_name']
|
222
|
+
#perform check
|
223
|
+
expect(bank).to match bank_name
|
224
|
+
#cleanup
|
225
|
+
@cards.delete(id, customer['id'])
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'fails when getting a non existing customer card' do
|
229
|
+
expect { @cards.get('11111', '1111') }.to raise_exception(OpenpayTransactionException)
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
describe '.all' do
|
235
|
+
|
236
|
+
it 'all merchant cards' do
|
237
|
+
#check initial state
|
238
|
+
expect(@cards.all.size).to be 0
|
239
|
+
#create merchant card
|
240
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
241
|
+
card=@cards.create(card_hash)
|
242
|
+
id=card['id']
|
243
|
+
#perform check
|
244
|
+
expect(@cards.all.size).to be 1
|
245
|
+
#cleanup
|
246
|
+
@cards.delete(id)
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'all customer cards' do
|
250
|
+
#create customer
|
251
|
+
customer_hash = FactoryBot.build(:customer_col)
|
252
|
+
customer=@customers.create(customer_hash)
|
253
|
+
#check initial state
|
254
|
+
expect(@cards.all(customer['id']).size).to be 0
|
255
|
+
#create customer card
|
256
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
257
|
+
card=@cards.create(card_hash, customer['id'])
|
258
|
+
id=card['id']
|
259
|
+
#perform check
|
260
|
+
expect(@cards.all(customer['id']).size).to be 1
|
261
|
+
#cleanup
|
262
|
+
@cards.delete(id, customer['id'])
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'cards for a non existing customer' do
|
266
|
+
expect { @cards.all('111111') }.to raise_exception OpenpayTransactionException
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
describe '.list' do
|
272
|
+
it 'list the merchant cards using a filter' do
|
273
|
+
#create merchant card
|
274
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
275
|
+
card1 = @cards.create(card_hash)
|
276
|
+
card_hash = FactoryBot.build(:valid_card2_col)
|
277
|
+
card2 = @cards.create(card_hash)
|
278
|
+
search_params = OpenpayUtils::SearchParams.new
|
279
|
+
search_params.limit = 1
|
280
|
+
expect(@cards.list(search_params).size).to eq 1
|
281
|
+
@cards.delete_all
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'list the customer cards using a filter' do
|
285
|
+
#create customer
|
286
|
+
customer_hash = FactoryBot.build(:customer_col)
|
287
|
+
customer = @customers.create(customer_hash)
|
288
|
+
#creates card
|
289
|
+
bank_name ='Banamex'
|
290
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
291
|
+
card = @cards.create(card_hash, customer['id'])
|
292
|
+
id = card['id']
|
293
|
+
#creates card 2
|
294
|
+
bank_name = 'Bancomer'
|
295
|
+
card_hash = FactoryBot.build(:valid_card2_col)
|
296
|
+
card = @cards.create(card_hash, customer['id'])
|
297
|
+
id = card['id']
|
298
|
+
search_params = OpenpayUtils::SearchParams.new
|
299
|
+
search_params.limit = 1
|
300
|
+
expect(@cards.all(customer['id']).size).to eq 2
|
301
|
+
expect(@cards.list(search_params , customer['id']).size).to eq 1
|
302
|
+
@cards.delete_all(customer['id'])
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'list the merchant cards using a filter creation and amount' do
|
306
|
+
#create merchant card
|
307
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
308
|
+
card1 = @cards.create(card_hash)
|
309
|
+
card_hash = FactoryBot.build(:valid_card2_col)
|
310
|
+
card2 = @cards.create(card_hash)
|
311
|
+
search_params = OpenpayUtils::SearchParams.new
|
312
|
+
search_params.limit = 1
|
313
|
+
creation_date = "2013-11-01"
|
314
|
+
search_params.creation_gte = creation_date
|
315
|
+
expect(@cards.list(search_params).size).to eq 1
|
316
|
+
@cards.delete_all
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
describe '.delete_all' do
|
322
|
+
|
323
|
+
it 'raise an exception when used on Production' do
|
324
|
+
openpayprod=OpenpayApi.new(@merchant_id, @private_key, "pe",false)
|
325
|
+
cust=openpayprod.create(:customers)
|
326
|
+
expect { cust.delete_all }.to raise_error
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'deletes all existing merchant cards' do
|
330
|
+
#create merchant card
|
331
|
+
card_hash = FactoryBot.build(:valid_card_peru)
|
332
|
+
@cards.create(card_hash)
|
333
|
+
#using json just for fun ...and test
|
334
|
+
card2_json = FactoryBot.build(:valid_card2_pe).to_json
|
335
|
+
@cards.create(card2_json)
|
336
|
+
#perform check
|
337
|
+
expect(@cards.all.size).to be 2
|
338
|
+
#cleanup
|
339
|
+
@cards.delete_all
|
340
|
+
#perform check
|
341
|
+
expect(@cards.all.size).to be 0
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'deletes all existing cards for a given customer' do
|
345
|
+
#creates customer
|
346
|
+
customer_hash = FactoryBot.build(:customer_col)
|
347
|
+
customer=@customers.create(customer_hash)
|
348
|
+
#check initial state
|
349
|
+
expect(@cards.all(customer['id']).size).to be 0
|
350
|
+
#create card
|
351
|
+
card_hash = FactoryBot.build(:valid_card_col)
|
352
|
+
card=@cards.create(card_hash, customer['id'])
|
353
|
+
#perform check
|
354
|
+
expect(@cards.all(customer['id']).size).to be 1
|
355
|
+
#cleanup
|
356
|
+
@cards.delete_all(customer['id'])
|
357
|
+
#check
|
358
|
+
expect(@cards.all(customer['id']).size).to be 0
|
359
|
+
end
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|