culqi-ruby-oficial 1.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/lib/CulqiCRUD.rb +344 -0
- data/lib/culqi/card.rb +16 -0
- data/lib/culqi/charge.rb +20 -0
- data/lib/culqi/customer.rb +17 -0
- data/lib/culqi/event.rb +14 -0
- data/lib/culqi/iins.rb +14 -0
- data/lib/culqi/order.rb +17 -0
- data/lib/culqi/plan.rb +16 -0
- data/lib/culqi/refund.rb +15 -0
- data/lib/culqi/subscription.rb +16 -0
- data/lib/culqi/token.rb +15 -0
- data/lib/culqi/transfer.rb +14 -0
- data/lib/culqi/version.rb +3 -0
- data/lib/culqi/yape.rb +13 -0
- data/lib/culqi-ruby.rb +32 -0
- data/lib/operation/confirm_type.rb +19 -0
- data/lib/operation/delete.rb +14 -0
- data/lib/operation/get.rb +14 -0
- data/lib/operation/list.rb +14 -0
- data/lib/operation/post.rb +27 -0
- data/lib/operation/update.rb +17 -0
- data/lib/test_list.rb +37 -0
- data/lib/util/connect.rb +42 -0
- data/lib/util/encrypt-data.rb +49 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ecb2fa769b2c48bff2617ebdbf33ca50d5c27621215d9e6d769e1e2236b60616
|
4
|
+
data.tar.gz: ada3857f363a49eb69eba554eec7c3929d34c111cf73aa802ff85629a16156b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a658abafef77c3a968e20199f346763215566238d7f77b783710efab78d29b60a196cdfd711ed43df4f301de10d73e628fe8711ecadb8f9d6770aafc0f61e7c
|
7
|
+
data.tar.gz: c4abdc144f4c182cfd44af1fb410094c57982088539f76acfe84b060fdc1e26e968f5d0d4b7e56caf52f18e9871a747fc606f83305f358698de343d84cc9602c
|
data/lib/CulqiCRUD.rb
ADDED
@@ -0,0 +1,344 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class CulqiTest < Minitest::Test
|
6
|
+
|
7
|
+
def createTokenEncrypt
|
8
|
+
rsa_key = Culqi.rsa_key
|
9
|
+
rsa_id = Culqi.rsa_id
|
10
|
+
params ={
|
11
|
+
:card_number => '4557880621568322',
|
12
|
+
:cvv => '111',
|
13
|
+
:currency_code => 'PEN',
|
14
|
+
:email => 'test1231@culqi.com',
|
15
|
+
:expiration_month => 11,
|
16
|
+
:expiration_year => 2026
|
17
|
+
}
|
18
|
+
token = Culqi::Token.create(params, rsa_key, rsa_id)
|
19
|
+
puts token
|
20
|
+
return JSON.parse(token)
|
21
|
+
end
|
22
|
+
def createYape
|
23
|
+
params = {
|
24
|
+
:amount => '1000',
|
25
|
+
:fingerprint => '86d3c875769bf62b0471b47853bfda77',
|
26
|
+
:number_phone => '900000001',
|
27
|
+
:otp => '111111'
|
28
|
+
}
|
29
|
+
|
30
|
+
yape = Culqi::Token.create(params)
|
31
|
+
return JSON.parse(yape)
|
32
|
+
|
33
|
+
end
|
34
|
+
def createToken
|
35
|
+
params ={
|
36
|
+
:card_number => '4557880621568322',
|
37
|
+
:cvv => '111',
|
38
|
+
:currency_code => 'PEN',
|
39
|
+
:email => 'test1231@culqi.com',
|
40
|
+
:expiration_month => 11,
|
41
|
+
:expiration_year => 2026
|
42
|
+
}
|
43
|
+
token = Culqi::Token.create(params)
|
44
|
+
puts token
|
45
|
+
return JSON.parse(token)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def createCharge
|
50
|
+
params = {
|
51
|
+
:amount => 1000,
|
52
|
+
:capture => false,
|
53
|
+
:currency_code => 'PEN',
|
54
|
+
:description => 'Venta de prueba',
|
55
|
+
:email => 'test'+SecureRandom.uuid+'@culqi.com',
|
56
|
+
:installments => 0,
|
57
|
+
:metadata => ({
|
58
|
+
:test => 'test123'
|
59
|
+
}),
|
60
|
+
:source_id => createToken['id']
|
61
|
+
}
|
62
|
+
charge = Culqi::Charge.create(params)
|
63
|
+
puts charge
|
64
|
+
return JSON.parse(charge)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def createChargeEncrypt
|
69
|
+
rsa_key = Culqi.rsa_key
|
70
|
+
rsa_id = Culqi.rsa_id
|
71
|
+
params = {
|
72
|
+
:amount => 1000,
|
73
|
+
:capture => false,
|
74
|
+
:currency_code => 'PEN',
|
75
|
+
:description => 'Venta de prueba',
|
76
|
+
:email => 'test'+SecureRandom.uuid+'@culqi.com',
|
77
|
+
:installments => 0,
|
78
|
+
:metadata => ({
|
79
|
+
:test => 'test123'
|
80
|
+
}),
|
81
|
+
:source_id => createToken['id']
|
82
|
+
}
|
83
|
+
charge = Culqi::Charge.create(params, rsa_key, rsa_id)
|
84
|
+
return JSON.parse(charge)
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def createOrder
|
89
|
+
params = {
|
90
|
+
:amount => 1000,
|
91
|
+
:currency_code => 'PEN',
|
92
|
+
:description => 'Venta de prueba',
|
93
|
+
:order_number => 'pedido-9966690044449',
|
94
|
+
:client_details => ({
|
95
|
+
:first_name => 'Richard',
|
96
|
+
:last_name => 'Hendricks',
|
97
|
+
:email => 'richar3d@piedpiper.com',
|
98
|
+
:phone_number => '+51945145280'
|
99
|
+
}),
|
100
|
+
:expiration_date => '1682039645'
|
101
|
+
}
|
102
|
+
order = Culqi::Order.create(params)
|
103
|
+
puts order
|
104
|
+
return JSON.parse(order)
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
def updateOrder
|
109
|
+
id = 'ord_live_q9TujOO4KSf2kRNv'
|
110
|
+
params = {
|
111
|
+
:metadata => ({
|
112
|
+
:dni => '71701978'
|
113
|
+
}),
|
114
|
+
:expiration_date => '1682039645'
|
115
|
+
}
|
116
|
+
order = Culqi::Order.update(id, params)
|
117
|
+
puts order
|
118
|
+
return JSON.parse(order)
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
def createOrderEncrypt
|
123
|
+
rsa_key = Culqi.rsa_key
|
124
|
+
rsa_id = Culqi.rsa_id
|
125
|
+
params = {
|
126
|
+
:amount => 1000,
|
127
|
+
:currency_code => 'PEN',
|
128
|
+
:description => 'Venta de prueba',
|
129
|
+
:order_number => 'pedido-999002',
|
130
|
+
:client_details => ({
|
131
|
+
:first_name => 'Richard',
|
132
|
+
:last_name => 'Hendricks',
|
133
|
+
:email => 'richard@piedpiper.com',
|
134
|
+
:phone_number => '+51945145280'
|
135
|
+
}),
|
136
|
+
:expiration_date => '1682039645'
|
137
|
+
}
|
138
|
+
order = Culqi::Order.create(params, rsa_key, rsa_id)
|
139
|
+
return JSON.parse(order)
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
def createPlan
|
144
|
+
params = {
|
145
|
+
:amount => 1000,
|
146
|
+
:currency_code => 'PEN',
|
147
|
+
:interval => 'dias',
|
148
|
+
:interval_count => 2,
|
149
|
+
:limit => 10,
|
150
|
+
:metadata => ({
|
151
|
+
:alias => 'plan_test'
|
152
|
+
}),
|
153
|
+
:name => 'plan-test-'+SecureRandom.uuid,
|
154
|
+
:trial_days => 50
|
155
|
+
}
|
156
|
+
|
157
|
+
plan = Culqi::Plan.create(params)
|
158
|
+
|
159
|
+
return JSON.parse(plan)
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
def createCustomer
|
164
|
+
params = {
|
165
|
+
:address => 'Avenida Lima 123213',
|
166
|
+
:address_city => 'LIMA',
|
167
|
+
:country_code => 'PE',
|
168
|
+
:email => 'test'+SecureRandom.uuid+'@culqi.com',
|
169
|
+
:first_name => 'William',
|
170
|
+
:last_name => 'Muro',
|
171
|
+
:metadata => ({
|
172
|
+
:other_number => '789953655'
|
173
|
+
}),
|
174
|
+
:phone_number => 998989789
|
175
|
+
}
|
176
|
+
customer = Culqi::Customer.create(params)
|
177
|
+
|
178
|
+
return JSON.parse(customer)
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
def createCard
|
183
|
+
params = {
|
184
|
+
:customer_id => createCustomer['id'],
|
185
|
+
:token_id => createToken['id']
|
186
|
+
}
|
187
|
+
card = Culqi::Card.create(params)
|
188
|
+
|
189
|
+
return JSON.parse(card)
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
def createSubscription
|
195
|
+
params = {
|
196
|
+
:card_id => createCard['id'],
|
197
|
+
:plan_id => createPlan['id']
|
198
|
+
}
|
199
|
+
subscription = Culqi::Subscription.create(params)
|
200
|
+
|
201
|
+
return JSON.parse(subscription)
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
def createRefund
|
206
|
+
params = {
|
207
|
+
:amount => 500,
|
208
|
+
:charge_id => createCharge['id'],
|
209
|
+
:reason => 'solicitud_comprador'
|
210
|
+
}
|
211
|
+
refund = Culqi::Refund.create(params)
|
212
|
+
return JSON.parse(refund)
|
213
|
+
end
|
214
|
+
|
215
|
+
def confirmOrder
|
216
|
+
confirmOrder = Culqi::Order.confirm(
|
217
|
+
:order_id => 'ord_live_7QmBi7Sh1ctxAe5s',
|
218
|
+
:order_types => ([
|
219
|
+
"cuotealo",
|
220
|
+
"cip"
|
221
|
+
])
|
222
|
+
)
|
223
|
+
puts confirmOrder
|
224
|
+
return JSON.parse(confirmOrder)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_create_token_encrypt
|
228
|
+
assert_equal 'token', createTokenEncrypt['object']
|
229
|
+
end
|
230
|
+
def test_create_yape
|
231
|
+
assert_equal 'token', createYape['object']
|
232
|
+
end
|
233
|
+
def test_create_token
|
234
|
+
assert_equal 'token', createToken['object']
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_create_charge
|
238
|
+
assert_equal 'charge', createCharge['object']
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_create_charge_encrypt
|
242
|
+
assert_equal 'charge', createChargeEncrypt['object']
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_create_order
|
246
|
+
assert_equal 'order', createOrder['object']
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_update_order
|
250
|
+
assert_equal 'order', updateOrder['object']
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_create_order_encrypt
|
254
|
+
assert_equal 'order', createOrderEncrypt['object']
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_create_plan
|
258
|
+
assert_equal "plan", createPlan['object']
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_create_customer
|
262
|
+
assert_equal 'customer', createCustomer['object']
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_create_card
|
266
|
+
assert_equal 'card', createCard['object']
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_create_subscription
|
270
|
+
assert_equal 'subscription', createSubscription['object']
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_create_refund
|
274
|
+
assert_equal 'refund', createRefund['object']
|
275
|
+
end
|
276
|
+
|
277
|
+
#CONFIRM ORDER
|
278
|
+
def test_confirm_order
|
279
|
+
assert_equal 'order', confirmOrder['object']
|
280
|
+
end
|
281
|
+
|
282
|
+
# GET RESOURCES
|
283
|
+
|
284
|
+
def test_get_token
|
285
|
+
assert_equal 'token', JSON.parse(Culqi::Token.get(createToken['id']))['object']
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_get_order
|
289
|
+
assert_equal 'order', JSON.parse(Culqi::Token.get(createOrder['id']))['object']
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_get_charge
|
293
|
+
assert_equal 'charge', JSON.parse(Culqi::Charge.get(createCharge['id']))['object']
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_get_plan
|
297
|
+
assert_equal "plan", JSON.parse(Culqi::Plan.get(createPlan['id']))['object']
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_get_customer
|
301
|
+
assert_equal 'customer', JSON.parse(Culqi::Customer.get(createCustomer['id']))['object']
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_get_card
|
305
|
+
assert_equal 'card', JSON.parse(Culqi::Card.get(createCard['id']))['object']
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_get_subscription
|
309
|
+
assert_equal 'subscription', JSON.parse(Culqi::Subscription.get(createSubscription['id']))['object']
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_get_refund
|
313
|
+
assert_equal 'refund', JSON.parse(Culqi::Refund.get(createRefund['id']))['object']
|
314
|
+
end
|
315
|
+
|
316
|
+
# DELETE RESOURCES
|
317
|
+
|
318
|
+
def test_delete_subscription
|
319
|
+
assert_equal true, JSON.parse(Culqi::Subscription.delete(createSubscription['id']))['deleted']
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_delete_plan
|
323
|
+
assert_equal true, JSON.parse(Culqi::Plan.delete(createPlan['id']))['deleted']
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_delete_card
|
327
|
+
assert_equal true, JSON.parse(Culqi::Card.delete(createCard['id']))['deleted']
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_delete_customer
|
331
|
+
assert_equal true, JSON.parse(Culqi::Customer.delete(createCustomer['id']))['deleted']
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_delete_order
|
335
|
+
assert_equal true, JSON.parse(Culqi::Order.delete(createOrder['id']))['deleted']
|
336
|
+
end
|
337
|
+
|
338
|
+
# CAPTURE CHARGE
|
339
|
+
|
340
|
+
def test_capture_charge
|
341
|
+
assert_equal 'charge', JSON.parse(Culqi::Charge.capture(createCharge['id']))['object']
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
data/lib/culqi/card.rb
ADDED
data/lib/culqi/charge.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Culqi
|
2
|
+
|
3
|
+
class Charge
|
4
|
+
|
5
|
+
extend List
|
6
|
+
extend Post
|
7
|
+
extend Get
|
8
|
+
|
9
|
+
URL = '/charges/'
|
10
|
+
|
11
|
+
@url = URL
|
12
|
+
|
13
|
+
def self.capture(id)
|
14
|
+
response, statuscode = Culqi.connect("#{@url}#{id}/capture/", Culqi.secret_key, nil, "post", Culqi::READ_TIMEOUT)
|
15
|
+
return response.read_body, statuscode
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/culqi/event.rb
ADDED
data/lib/culqi/iins.rb
ADDED
data/lib/culqi/order.rb
ADDED
data/lib/culqi/plan.rb
ADDED
data/lib/culqi/refund.rb
ADDED
data/lib/culqi/token.rb
ADDED
data/lib/culqi/yape.rb
ADDED
data/lib/culqi-ruby.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'operation/list'
|
2
|
+
require 'operation/get'
|
3
|
+
require 'operation/post'
|
4
|
+
require 'operation/delete'
|
5
|
+
require 'operation/update'
|
6
|
+
require 'operation/confirm_type'
|
7
|
+
|
8
|
+
require 'culqi/version'
|
9
|
+
require 'culqi/iins'
|
10
|
+
require 'culqi/card'
|
11
|
+
require 'culqi/event'
|
12
|
+
require 'culqi/customer'
|
13
|
+
require 'culqi/token'
|
14
|
+
require 'culqi/charge'
|
15
|
+
require 'culqi/plan'
|
16
|
+
require 'culqi/subscription'
|
17
|
+
require 'culqi/refund'
|
18
|
+
require 'culqi/transfer'
|
19
|
+
require 'culqi/yape'
|
20
|
+
require 'culqi/order'
|
21
|
+
module Culqi
|
22
|
+
|
23
|
+
API_BASE = 'https://api.culqi.com/v2'
|
24
|
+
API_BASE_SECURE = 'https://secure.culqi.com/v2'
|
25
|
+
READ_TIMEOUT = 120
|
26
|
+
LIST_TIMEOUT = 360
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_accessor :public_key, :secret_key, :rsa_id, :rsa_key
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'util/connect'
|
2
|
+
|
3
|
+
module Culqi::ConfirmType
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@url = ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def confirm(params={}, rsa_key='', rsa_id='')
|
10
|
+
key = ''
|
11
|
+
if(rsa_key != '')
|
12
|
+
params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
|
13
|
+
end
|
14
|
+
key = Culqi.public_key
|
15
|
+
response = Culqi.connect(@url+'confirm', key, params, 'post', Culqi::READ_TIMEOUT, false, rsa_id)
|
16
|
+
return response
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'util/connect'
|
2
|
+
require 'util/encrypt-data'
|
3
|
+
module Culqi::Post
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@url = ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(params={}, rsa_key='', rsa_id='')
|
10
|
+
key = ''
|
11
|
+
puts params
|
12
|
+
if @url.include? 'token'
|
13
|
+
if(rsa_key != '')
|
14
|
+
params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
|
15
|
+
end
|
16
|
+
key = Culqi.public_key
|
17
|
+
response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
|
18
|
+
return response, statuscode
|
19
|
+
else
|
20
|
+
key = Culqi.secret_key
|
21
|
+
response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
|
22
|
+
return response, statuscode
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'util/connect'
|
2
|
+
|
3
|
+
module Culqi::Update
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@url = ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def update(id, params={}, rsa_key='', rsa_id='')
|
10
|
+
if(rsa_key != '')
|
11
|
+
params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
|
12
|
+
end
|
13
|
+
response, statusCode = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
|
14
|
+
return response, statusCode
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/test_list.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestList < Minitest::Test
|
4
|
+
|
5
|
+
def test_tokens
|
6
|
+
assert_operator JSON.parse(Culqi::Token.list())['data'].count, :>=, 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_charges
|
10
|
+
assert_operator JSON.parse(Culqi::Charge.list())['data'].count, :>=, 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_plans
|
14
|
+
assert_operator JSON.parse(Culqi::Plan.list())['data'].count, :>=, 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_customers
|
18
|
+
assert_operator JSON.parse(Culqi::Customer.list())['data'].count, :>=, 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_cards
|
22
|
+
assert_operator JSON.parse(Culqi::Card.list())['data'].count, :>=, 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_refunds
|
26
|
+
assert_operator JSON.parse(Culqi::Refund.list())['data'].count, :>=, 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_events
|
30
|
+
assert_operator JSON.parse(Culqi::Event.list())['data'].count, :>=, 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_transfers
|
34
|
+
assert_operator JSON.parse(Culqi::Transfer.list())['data'].count, :>=, 0
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/util/connect.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
require 'culqi-ruby'
|
4
|
+
|
5
|
+
module Culqi
|
6
|
+
def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
|
7
|
+
base_url = secure_url ? Culqi::API_BASE_SECURE : Culqi::API_BASE
|
8
|
+
full_url = "#{base_url}#{url}"
|
9
|
+
|
10
|
+
headers = {
|
11
|
+
"Authorization" => "Bearer #{api_key}",
|
12
|
+
"Content-Type" => "application/json",
|
13
|
+
"x-culqi-rsa-id" => rsa_id
|
14
|
+
}
|
15
|
+
|
16
|
+
puts "Body"
|
17
|
+
puts data.to_json
|
18
|
+
|
19
|
+
response = Excon.new(full_url,
|
20
|
+
headers: headers,
|
21
|
+
read_timeout: time_out,
|
22
|
+
idempotent: true,
|
23
|
+
retry_limit: 6)
|
24
|
+
|
25
|
+
case type.upcase
|
26
|
+
when 'GET'
|
27
|
+
result = response.request(method: :get, query: data)
|
28
|
+
when 'POST'
|
29
|
+
result = response.request(method: :post, body: data.to_json)
|
30
|
+
when 'DELETE'
|
31
|
+
result = response.request(method: :delete)
|
32
|
+
when 'PATCH'
|
33
|
+
result = response.request(method: :patch, body: data.to_json)
|
34
|
+
else
|
35
|
+
raise ArgumentError, "Unsupported request type: #{type}"
|
36
|
+
end
|
37
|
+
|
38
|
+
puts result.body
|
39
|
+
|
40
|
+
return result.body, result.status
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
require 'json'
|
4
|
+
require 'openssl/oaep'
|
5
|
+
|
6
|
+
module Encrypt
|
7
|
+
def self.generate_random_bytes(length)
|
8
|
+
OpenSSL::Random.random_bytes(length)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.encrypt_with_aes_rsa(data, public_key, is_json)
|
12
|
+
key = generate_random_bytes(32) # Generate a 256-bit random key for AES encryption
|
13
|
+
iv = generate_random_bytes(12) # GCM mode requires a 96-bit (12 bytes) random initialization vector
|
14
|
+
auth_data = generate_random_bytes(16)
|
15
|
+
cipher = OpenSSL::Cipher.new('AES-256-GCM')
|
16
|
+
cipher.encrypt
|
17
|
+
cipher.key = key
|
18
|
+
cipher.iv = iv
|
19
|
+
cipher.auth_data = auth_data
|
20
|
+
|
21
|
+
# Since GCM does not require padding, we can directly pass the data to be encrypted
|
22
|
+
cipher_text = cipher.update(data.to_json) + cipher.final
|
23
|
+
|
24
|
+
# Get the auth tag
|
25
|
+
auth_tag = cipher.auth_tag
|
26
|
+
|
27
|
+
# Combine cipher text and auth tag
|
28
|
+
encrypted = cipher_text #+ auth_tag
|
29
|
+
#encrypted = encrypted.slice(0...-16)
|
30
|
+
encrypted_data = Base64.strict_encode64(encrypted)
|
31
|
+
|
32
|
+
####
|
33
|
+
rsa_public_key = OpenSSL::PKey::RSA.new(public_key)
|
34
|
+
encrypted_key = rsa_encrypt(key, rsa_public_key)
|
35
|
+
encrypted_iv = rsa_encrypt(iv, rsa_public_key)
|
36
|
+
|
37
|
+
{ encrypted_data: encrypted_data, encrypted_key: encrypted_key, encrypted_iv: encrypted_iv }
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.rsa_encrypt(data, public_key)
|
41
|
+
# Define the encryption parameters
|
42
|
+
label = ''
|
43
|
+
|
44
|
+
md = OpenSSL::Digest::SHA256
|
45
|
+
cipher_text = public_key.public_encrypt_oaep(data, label, md, md)
|
46
|
+
|
47
|
+
Base64.strict_encode64(cipher_text)
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: culqi-ruby-oficial
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Culqi Team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Nuestra Biblioteca Culqi-Ruby oficial, es compatible con la v2.0 del Culqi API, con el cual tendrás la posibilidad de realizar cobros con tarjetas de débito y crédito, Yape, PagoEfectivo, billeteras móviles y Cuotéalo con solo unos simples pasos de configuración.
|
15
|
+
</br>Nuestra biblioteca te da la posibilidad de capturar el status_code de la solicitud HTTP que se realiza al API de Culqi, así como el response que contiene el cuerpo de la respuesta obtenida.
|
16
|
+
email:
|
17
|
+
- jose.calderon@culqi.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/CulqiCRUD.rb
|
23
|
+
- lib/culqi-ruby.rb
|
24
|
+
- lib/culqi/card.rb
|
25
|
+
- lib/culqi/charge.rb
|
26
|
+
- lib/culqi/customer.rb
|
27
|
+
- lib/culqi/event.rb
|
28
|
+
- lib/culqi/iins.rb
|
29
|
+
- lib/culqi/order.rb
|
30
|
+
- lib/culqi/plan.rb
|
31
|
+
- lib/culqi/refund.rb
|
32
|
+
- lib/culqi/subscription.rb
|
33
|
+
- lib/culqi/token.rb
|
34
|
+
- lib/culqi/transfer.rb
|
35
|
+
- lib/culqi/version.rb
|
36
|
+
- lib/culqi/yape.rb
|
37
|
+
- lib/operation/confirm_type.rb
|
38
|
+
- lib/operation/delete.rb
|
39
|
+
- lib/operation/get.rb
|
40
|
+
- lib/operation/list.rb
|
41
|
+
- lib/operation/post.rb
|
42
|
+
- lib/operation/update.rb
|
43
|
+
- lib/test_list.rb
|
44
|
+
- lib/util/connect.rb
|
45
|
+
- lib/util/encrypt-data.rb
|
46
|
+
homepage: http://rubygems.org/gems/culqi-ruby-oficial
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 3.0.0
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.2.33
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Culqi Ruby
|
69
|
+
test_files: []
|