devtech-culqi-ruby 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1346bcb588645112bbe6080b3ebde93145a8e8c3a0b2873db89bd4e41f6bae73
4
+ data.tar.gz: c709059c9a760f8cbb914bfabcce72accf1a37192d43516f4daa6278ab33fe17
5
+ SHA512:
6
+ metadata.gz: 0f284d15d5db55c33291dc6db8f75d91b53d950afd4ccf40f6da9d957922e093d439329c130c99c8f1ec80e9a21bd5a9d63a413dc15ccba3f21232831e6e680f
7
+ data.tar.gz: 53a020ded450c0db3a9deeb1d70cb8486e4115396b0a2dd26b8d416fcf21926dc4c6d43ec3132c80ef9ea43df0c0dafd59ec1c997739bf7a8dfe2da16ba07c56
data/lib/culqi/card.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Culqi
2
+
3
+ class Card
4
+
5
+ extend List
6
+ extend Post
7
+ extend Delete
8
+ extend Get
9
+
10
+ URL = '/cards/'
11
+
12
+ @url = URL
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
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
+ Rails.logger.info "Culqi::Charge.capture: #{response}"
16
+ Rails.logger.info "Culqi::Charge.capture: #{statuscode}"
17
+ return response, statuscode
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,17 @@
1
+ module Culqi
2
+
3
+ class Customer
4
+
5
+ extend List
6
+ extend Post
7
+ extend Delete
8
+ extend Get
9
+ extend Update
10
+
11
+ URL = '/customers/'
12
+
13
+ @url = URL
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,14 @@
1
+ module Culqi
2
+
3
+ class Event
4
+
5
+ extend List
6
+ extend Get
7
+
8
+ URL = '/events/'
9
+
10
+ @url = URL
11
+
12
+ end
13
+
14
+ end
data/lib/culqi/iins.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Culqi
2
+
3
+ class Iins
4
+
5
+ extend List
6
+ extend Get
7
+
8
+ URL = '/iins/'
9
+
10
+ @url = URL
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,18 @@
1
+ module Culqi
2
+
3
+ class Order
4
+
5
+ extend List
6
+ extend Post
7
+ extend Get
8
+ extend Delete
9
+ extend ConfirmType
10
+ extend Update
11
+
12
+ URL = '/orders/'
13
+
14
+ @url = URL
15
+
16
+ end
17
+
18
+ end
data/lib/culqi/plan.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Culqi
2
+
3
+ class Plan
4
+
5
+ extend List
6
+ extend Post
7
+ extend Get
8
+ extend Delete
9
+
10
+ URL = '/plans/'
11
+
12
+ @url = URL
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+ module Culqi
2
+
3
+ class Refund
4
+
5
+ extend List
6
+ extend Post
7
+ extend Get
8
+
9
+ URL = '/refunds/'
10
+
11
+ @url = URL
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ module Culqi
2
+
3
+ class Subscription
4
+
5
+ extend List
6
+ extend Post
7
+ extend Delete
8
+ extend Get
9
+
10
+ URL = '/subscriptions/'
11
+
12
+ @url = URL
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'util/validation/token'
2
+ require 'util/validation/error'
3
+
4
+
5
+ module Culqi
6
+
7
+ class Token
8
+
9
+ extend List
10
+ extend Post
11
+ extend Get
12
+
13
+ URL = '/tokens/'
14
+
15
+ @url = URL
16
+
17
+ def self.createYape(params={}, rsa_key='', rsa_id='')
18
+ begin
19
+ key = ''
20
+ puts params
21
+ if @url.include? 'token'
22
+ TokenValidation.create_token_yape_validation(params)
23
+ if(rsa_key != '')
24
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
25
+ end
26
+ key = Culqi.public_key
27
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
28
+ return response, statuscode
29
+ end
30
+ rescue CustomException => e
31
+ return e.message
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,14 @@
1
+ module Culqi
2
+
3
+ class Transfer
4
+
5
+ extend List
6
+ extend Get
7
+
8
+ URL = '/transfers/'
9
+
10
+ @url = URL
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module Culqi
2
+ VERSION = "1.0.0"
3
+ end
data/lib/culqi/yape.rb ADDED
@@ -0,0 +1,13 @@
1
+ module Culqi
2
+
3
+ class Yape
4
+
5
+ extend Post
6
+
7
+ URL = '/tokens/yape/'
8
+
9
+ @url = URL
10
+
11
+ end
12
+
13
+ end
data/lib/culqi-ruby.rb ADDED
@@ -0,0 +1,38 @@
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
+ X_CULQI_ENV_TEST = "test"
28
+ X_CULQI_ENV_LIVE = "live"
29
+ X_API_VERSION = "2"
30
+ X_CULQI_CLIENT = "culqi-ruby"
31
+ X_CULQI_CLIENT_VERSION = "0.1.0"
32
+
33
+
34
+ class << self
35
+ attr_accessor :public_key, :secret_key, :rsa_id, :rsa_key
36
+ end
37
+
38
+ end
@@ -0,0 +1,24 @@
1
+ require 'util/connect'
2
+ require 'util/validation/helper'
3
+
4
+ module Culqi::ConfirmType
5
+
6
+ def initialize
7
+ @url = ''
8
+ end
9
+
10
+ def confirm(params={}, rsa_key='', rsa_id='')
11
+ error = HelperValidation.validate_string_start(params[:order_id], "ord")
12
+ if error
13
+ return error
14
+ end
15
+ key = ''
16
+ if(rsa_key != '')
17
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
18
+ end
19
+ key = Culqi.public_key
20
+ response = Culqi.connect(@url+'confirm', key, params, 'post', Culqi::READ_TIMEOUT, false, rsa_id)
21
+ return response
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'util/connect'
2
+ require 'util/validation/helper'
3
+
4
+ module Culqi::Delete
5
+
6
+ def initialize
7
+ @url = ''
8
+ end
9
+
10
+ def delete(id)
11
+ error = verifyClassValidationGet(@url, id)
12
+ if error
13
+ return error
14
+ end
15
+
16
+ response = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, nil, 'delete', Culqi::READ_TIMEOUT)
17
+ return response
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ require 'util/connect'
2
+ require 'util/validation/helper'
3
+
4
+ module Culqi::Get
5
+
6
+ def initialize
7
+ @url = ''
8
+ end
9
+
10
+ def get(id)
11
+ error = verifyClassValidationGet(@url, id)
12
+ if error
13
+ return error
14
+ end
15
+ response = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, nil, 'get', Culqi::READ_TIMEOUT)
16
+ return response
17
+ end
18
+
19
+ def verifyClassValidationGet(url='', id)
20
+ begin
21
+ if @url.include? 'token'
22
+ HelperValidation.validate_string_start(id, "tkn")
23
+ end
24
+
25
+ if @url.include? 'charge'
26
+ HelperValidation.validate_string_start(id, "chr")
27
+ end
28
+
29
+ if @url.include? 'card'
30
+ HelperValidation.validate_string_start(id, "crd")
31
+ end
32
+
33
+ if @url.include? 'customer'
34
+ HelperValidation.validate_string_start(id, "cus")
35
+ end
36
+
37
+ if @url.include? 'refund'
38
+ HelperValidation.validate_string_start(id, "ref")
39
+ end
40
+
41
+ if @url.include? 'plan'
42
+ HelperValidation.validate_string_start(id, "pln")
43
+ end
44
+
45
+ if @url.include? 'subscription'
46
+ HelperValidation.validate_string_start(id, "sxn")
47
+ end
48
+
49
+ if @url.include? 'order'
50
+ HelperValidation.validate_string_start(id, "ord")
51
+ end
52
+ rescue CustomException => e
53
+ return e.message
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,64 @@
1
+ require 'util/connect'
2
+ require 'util/validation/token'
3
+ require 'util/validation/charge'
4
+ require 'util/validation/customer'
5
+ require 'util/validation/refund'
6
+ require 'util/validation/plan'
7
+ require 'util/validation/card'
8
+ require 'util/validation/subscription'
9
+ require 'util/validation/order'
10
+
11
+ module Culqi::List
12
+
13
+ def initialize
14
+ @url = ''
15
+ end
16
+
17
+ def list(params={})
18
+ error = verifyClassValidationList(@url, params)
19
+ if error
20
+ return error
21
+ end
22
+ response = Culqi.connect(@url, Culqi.secret_key, params, 'get', Culqi::LIST_TIMEOUT)
23
+ return response
24
+ end
25
+
26
+ def verifyClassValidationList(url='', params)
27
+ begin
28
+ if @url.include? 'token'
29
+ TokenValidation.list(params)
30
+ end
31
+
32
+ if @url.include? 'charge'
33
+ ChargeValidation.list(params)
34
+ end
35
+
36
+ if @url.include? 'card'
37
+ CardValidation.list(params)
38
+ end
39
+
40
+ if @url.include? 'customer'
41
+ CustomerValidation.list(params)
42
+ end
43
+
44
+ if @url.include? 'refund'
45
+ RefundValidation.list(params)
46
+ end
47
+
48
+ if @url.include? 'plan'
49
+ PlanValidation.list(params)
50
+ end
51
+
52
+ if @url.include? 'subscription'
53
+ SubscriptionValidation.list(params)
54
+ end
55
+
56
+ if @url.include? 'order'
57
+ OrderValidation.list(params)
58
+ end
59
+ rescue CustomException => e
60
+ return e.message
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,79 @@
1
+ require 'util/connect'
2
+ require 'util/encrypt-data'
3
+ require 'util/validation/token'
4
+ require 'util/validation/charge'
5
+ require 'util/validation/customer'
6
+ require 'util/validation/refund'
7
+ require 'util/validation/plan'
8
+ require 'util/validation/card'
9
+ require 'util/validation/subscription'
10
+ require 'util/validation/order'
11
+
12
+ module Culqi::Post
13
+
14
+ def initialize
15
+ @url = ''
16
+ end
17
+
18
+ def create(params={}, rsa_key='', rsa_id='')
19
+ key = ''
20
+ puts params
21
+ error = verifyClassValidation(@url, params)
22
+ if error
23
+ return error
24
+ end
25
+
26
+ if @url.include? 'token'
27
+ if(rsa_key != '')
28
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
29
+ end
30
+ key = Culqi.public_key
31
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
32
+ return response, statuscode
33
+ else
34
+ key = Culqi.secret_key
35
+ response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
36
+ return response, statuscode
37
+ end
38
+
39
+ end
40
+
41
+ def verifyClassValidation(url='', params)
42
+ begin
43
+ if @url.include? 'token'
44
+ TokenValidation.create(params)
45
+ end
46
+
47
+ if @url.include? 'charge'
48
+ ChargeValidation.create(params)
49
+ end
50
+
51
+ if @url.include? 'card'
52
+ CardValidation.create(params)
53
+ end
54
+
55
+ if @url.include? 'customer'
56
+ CustomerValidation.create(params)
57
+ end
58
+
59
+ if @url.include? 'refund'
60
+ RefundValidation.create(params)
61
+ end
62
+
63
+ if @url.include? 'plan'
64
+ PlanValidation.create(params)
65
+ end
66
+
67
+ if @url.include? 'subscription'
68
+ SubscriptionValidation.create(params)
69
+ end
70
+
71
+ if @url.include? 'order'
72
+ OrderValidation.create(params)
73
+ end
74
+ rescue CustomException => e
75
+ return e.message
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,22 @@
1
+ require 'util/connect'
2
+ require 'util/validation/helper'
3
+
4
+ module Culqi::Update
5
+
6
+ def initialize
7
+ @url = ''
8
+ end
9
+
10
+ def update(id, params={}, rsa_key='', rsa_id='')
11
+ error = verifyClassValidationGet(@url, id)
12
+ if error
13
+ return error
14
+ end
15
+ if(rsa_key != '')
16
+ params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
17
+ end
18
+ response, statusCode = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
19
+ return response, statusCode
20
+ end
21
+
22
+ end
@@ -0,0 +1,54 @@
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
+ print full_url
11
+
12
+ if(api_key.include? 'test')
13
+ env = Culqi::X_CULQI_ENV_TEST
14
+ else
15
+ env = Culqi::X_CULQI_ENV_LIVE
16
+ end
17
+
18
+ headers = {
19
+ "Authorization" => "Bearer #{api_key}",
20
+ "Content-Type" => "application/json",
21
+ "x-culqi-env" => env,
22
+ "x-api-version" => Culqi::X_API_VERSION,
23
+ "x-culqi-client" => Culqi::X_CULQI_CLIENT,
24
+ "x-culqi-client-version" => Culqi::X_CULQI_CLIENT,
25
+ "x-culqi-rsa-id" => rsa_id
26
+ }
27
+
28
+ puts "Body"
29
+ puts data.to_json
30
+
31
+ response = Excon.new(full_url,
32
+ headers: headers,
33
+ read_timeout: time_out,
34
+ idempotent: true,
35
+ retry_limit: 6)
36
+
37
+ case type.upcase
38
+ when 'GET'
39
+ result = response.request(method: :get, query: data)
40
+ when 'POST'
41
+ result = response.request(method: :post, body: data.to_json)
42
+ when 'DELETE'
43
+ result = response.request(method: :delete)
44
+ when 'PATCH'
45
+ result = response.request(method: :patch, body: data.to_json)
46
+ else
47
+ raise ArgumentError, "Unsupported request type: #{type}"
48
+ end
49
+
50
+ puts result.body
51
+
52
+ return result.body, result.status
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ # country_codes.rb
2
+ module CountryCodes
3
+ def self.get_country_codes
4
+ ['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ',
5
+ 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS',
6
+ 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
7
+ 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE',
8
+ 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF',
9
+ 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM',
10
+ 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM',
11
+ 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC',
12
+ 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK',
13
+ 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA',
14
+ 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG',
15
+ 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW',
16
+ 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS',
17
+ 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO',
18
+ 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI',
19
+ 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']
20
+ end
21
+ end
22
+
@@ -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
@@ -0,0 +1,36 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class CardValidation
8
+ def self.create(data)
9
+ HelperValidation.validate_string_start(data[:customer_id], "cus")
10
+ HelperValidation.validate_string_start(data[:token_id], "tkn")
11
+ end
12
+
13
+ def self.list(data)
14
+ # Validate card_brand
15
+ if data.key?('card_brand')
16
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
17
+ Helpers.validate_value(data[:card_brand], allowed_brand_values)
18
+ end
19
+
20
+ # Validate card_type
21
+ if data.key?('card_type')
22
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
23
+ Helpers.validate_value(data[:card_type], allowed_card_type_values)
24
+ end
25
+
26
+ # Validate date filter
27
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
28
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
29
+ end
30
+
31
+ # Validate country_code
32
+ if data.key?('country_code')
33
+ Helpers.validate_value(data[:country_code], get_country_codes)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,129 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class ChargeValidation
8
+ def self.create(data)
9
+ # Validate email
10
+ raise 'Invalid email.' unless HelperValidation.is_valid_email(data[:email])
11
+
12
+ # Validate amount
13
+ amount = data[:amount]
14
+
15
+ if amount.is_a?(String)
16
+ begin
17
+ amount = Integer(amount)
18
+ print amount
19
+ rescue ArgumentError
20
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
21
+ end
22
+ end
23
+
24
+ unless amount.is_a?(Integer)
25
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
26
+ end
27
+
28
+ HelperValidation.validate_currency_code(data[:currency_code])
29
+ source_id = data[:source_id]
30
+
31
+ if source_id.start_with?("tkn")
32
+ HelperValidation.validate_string_start(source_id, "tkn")
33
+ elsif source_id.start_with?("ype")
34
+ HelperValidation.validate_string_start(source_id, "ype")
35
+ elsif source_id.start_with?("crd")
36
+ HelperValidation.validate_string_start(source_id, "crd")
37
+ else
38
+ raise CustomException.new("Incorrect format. The format must start with tkn, ype, or crd")
39
+ end
40
+ end
41
+
42
+ def self.list(data)
43
+ # Validate email
44
+ if data.key?('email')
45
+ unless Helpers.is_valid_email(data[:email])
46
+ raise CustomException.new('Invalid email.')
47
+ end
48
+ end
49
+
50
+ # Validate amount
51
+ if data.key?('amount')
52
+ amount = data[:amount]
53
+
54
+ if amount.is_a?(String)
55
+ begin
56
+ amount = Integer(amount)
57
+ rescue ArgumentError
58
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
59
+ end
60
+ end
61
+
62
+ unless amount.is_a?(Integer)
63
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
64
+ end
65
+ end
66
+
67
+ # Validate min_amount
68
+ if data.key?('min_amount')
69
+ unless data[:min_amount].is_a?(Integer)
70
+ raise CustomException.new('Invalid min amount.')
71
+ end
72
+ end
73
+
74
+ # Validate max_amount
75
+ if data.key?('max_amount')
76
+ unless data[:max_amount].is_a?(Integer)
77
+ raise CustomException.new('Invalid max amount.')
78
+ end
79
+ end
80
+
81
+ # Validate installments
82
+ if data.key?('installments')
83
+ unless data[:installments].is_a?(Integer)
84
+ raise CustomException.new('Invalid installments.')
85
+ end
86
+ end
87
+
88
+ # Validate min_installments
89
+ if data.key?('min_installments')
90
+ unless data[:min_installments].is_a?(Integer)
91
+ raise CustomException.new('Invalid min installments.')
92
+ end
93
+ end
94
+
95
+ # Validate max_installments
96
+ if data.key?('max_installments')
97
+ unless data[:max_installments].is_a?(Integer)
98
+ raise CustomException.new('Invalid max installments.')
99
+ end
100
+ end
101
+
102
+ # Validate currency_code
103
+ if data.key?('currency_code')
104
+ Helpers.validate_currency_code(data[:currency_code])
105
+ end
106
+
107
+ # Validate card_brand
108
+ if data.key?('card_brand')
109
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
110
+ Helpers.validate_value(data[:card_brand], allowed_brand_values)
111
+ end
112
+
113
+ # Validate card_type
114
+ if data.key?('card_type')
115
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
116
+ Helpers.validate_value(data[:card_type], allowed_card_type_values)
117
+ end
118
+
119
+ # Validate date filter
120
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
121
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
122
+ end
123
+
124
+ # Validate country_code
125
+ if data.key?('country_code')
126
+ Helpers.validate_value(data[:country_code], get_country_codes)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,39 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/country-codes'
5
+ require 'util/validation/helper'
6
+ require 'util/validation/error'
7
+
8
+ class CustomerValidation
9
+ def self.create(data)
10
+ # Validate address, firstname, and lastname
11
+ raise CustomException.new('first name is empty.') if data[:first_name].nil? || data[:first_name].empty?
12
+ raise CustomException.new('last name is empty.') if data[:last_name].nil? || data[:last_name].empty?
13
+ raise CustomException.new('address is empty.') if data[:address].nil? || data[:address].empty?
14
+ raise CustomException.new('address_city is empty.') if data[:address_city].nil? || data[:address_city].empty?
15
+
16
+ unless data[:phone_number].is_a?(String)
17
+ raise CustomException.new("Invalid 'phone_number'. It should be a string.")
18
+ end
19
+
20
+ # Validate country code
21
+ HelperValidation.validate_value(data[:country_code], CountryCodes.get_country_codes)
22
+
23
+ # Validate email
24
+ raise 'Invalid email.' unless HelperValidation.is_valid_email(data[:email])
25
+ end
26
+
27
+ def self.list(data)
28
+ # Validate email
29
+ if data.key?('email')
30
+ unless Helpers.is_valid_email(data[:email])
31
+ raise CustomException.new('Invalid email.')
32
+ end
33
+ end
34
+ # Validate country_code
35
+ if data.key?('country_code')
36
+ Helpers.validate_value(data[:country_code], get_country_codes)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ class CustomException < StandardError
4
+ def initialize(merchant_message)
5
+ @error_data = {
6
+ "object" => "error",
7
+ "type" => "param_error",
8
+ "merchant_message" => merchant_message,
9
+ "user_message" => merchant_message
10
+ }
11
+ super("CustomException: #{@error_data}")
12
+ end
13
+
14
+ def to_s
15
+ JSON.generate(@error_data)
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/error'
5
+
6
+ class HelperValidation
7
+
8
+ def self.is_valid_card_number(number)
9
+ !number.match(/^\d{13,19}$/).nil?
10
+ end
11
+
12
+ def self.is_valid_email(email)
13
+ !email.match(/^\S+@\S+\.\S+$/).nil?
14
+ end
15
+
16
+ def self.validate_currency_code(currency_code)
17
+ raise CustomException.new('Currency code is empty.') if currency_code.nil? || currency_code.empty?
18
+
19
+ raise CustomException.new('Currency code must be a string.') unless currency_code.is_a?(String)
20
+
21
+ allowed_values = ['PEN', 'USD']
22
+ raise CustomException.new('Currency code must be either "PEN" or "USD".') unless allowed_values.include?(currency_code)
23
+ end
24
+
25
+ def self.validate_string_start(string, start)
26
+ unless string.start_with?("#{start}_test_") || string.start_with?("#{start}_live_")
27
+ raise CustomException.new("Incorrect format. The format must start with #{start}_test_ or #{start}_live_")
28
+ end
29
+ end
30
+
31
+ def self.validate_value(value, allowed_values)
32
+ raise CustomException.new("Invalid value. It must be #{JSON.generate(allowed_values)}.") unless allowed_values.include?(value)
33
+ end
34
+
35
+ def self.is_future_date(expiration_date)
36
+ exp_date = Time.at(expiration_date)
37
+ exp_date > Time.now
38
+ end
39
+
40
+ end
@@ -0,0 +1,76 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class OrderValidation
8
+ def self.create(data)
9
+ # Validate amount
10
+ amount = data[:amount]
11
+
12
+ if amount.is_a?(String)
13
+ begin
14
+ amount = Integer(amount)
15
+ rescue ArgumentError
16
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
17
+ end
18
+ end
19
+
20
+ unless amount.is_a?(Integer)
21
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
22
+ end
23
+
24
+ # Validate currency
25
+ HelperValidation.validate_currency_code(data[:currency_code])
26
+
27
+ # Validate firstname, lastname, and phone
28
+ client_details = data[:client_details] || {}
29
+ raise CustomException.new('first name is empty.') if client_details[:first_name].nil? || client_details[:first_name].empty?
30
+ raise CustomException.new('last name is empty.') if client_details[:last_name].nil? || client_details[:last_name].empty?
31
+ raise CustomException.new('phone_number is empty.') if client_details[:phone_number].nil? || client_details[:phone_number].empty?
32
+
33
+ # Validate email
34
+ raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(client_details[:email])
35
+
36
+ # Validate expiration date
37
+ raise CustomException.new('expiration_date must be a future date.') unless HelperValidation.is_future_date(data[:expiration_date])
38
+ end
39
+
40
+ def self.list(data)
41
+ # Validate amount
42
+ if data.key?('amount')
43
+ amount = data[:amount]
44
+
45
+ if amount.is_a?(String)
46
+ begin
47
+ amount = Integer(amount)
48
+ rescue ArgumentError
49
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
50
+ end
51
+ end
52
+
53
+ unless amount.is_a?(Integer)
54
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
55
+ end
56
+ end
57
+
58
+ # Validate min_amount
59
+ if data.key?('min_amount')
60
+ unless data[:min_amount].is_a?(Integer)
61
+ raise CustomException.new('Invalid min amount.')
62
+ end
63
+ end
64
+
65
+ # Validate max_amount
66
+ if data.key?('max_amount')
67
+ unless data[:max_amount].is_a?(Integer)
68
+ raise CustomException.new('Invalid max amount.')
69
+ end
70
+ end
71
+
72
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
73
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,69 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class PlanValidation
8
+ def self.create(data)
9
+ # Validate amount
10
+ amount = data[:amount]
11
+
12
+ if amount.is_a?(String)
13
+ begin
14
+ amount = Integer(amount)
15
+ print amount
16
+ rescue ArgumentError
17
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
18
+ end
19
+ end
20
+
21
+ unless amount.is_a?(Integer)
22
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
23
+ end
24
+
25
+ # Validate interval
26
+ allowed_values = ['dias', 'semanas', 'meses', 'años']
27
+ HelperValidation.validate_value(data[:interval], allowed_values)
28
+
29
+ # Validate currency
30
+ HelperValidation.validate_currency_code(data[:currency_code])
31
+ end
32
+
33
+ def self.list(data)
34
+ # Validate amount
35
+ if data.key?('amount')
36
+ amount = data[:amount]
37
+
38
+ if amount.is_a?(String)
39
+ begin
40
+ amount = Integer(amount)
41
+ rescue ArgumentError
42
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
43
+ end
44
+ end
45
+
46
+ unless amount.is_a?(Integer)
47
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
48
+ end
49
+ end
50
+
51
+ # Validate min_amount
52
+ if data.key?('min_amount')
53
+ unless data[:min_amount].is_a?(Integer)
54
+ raise CustomException.new('Invalid min amount.')
55
+ end
56
+ end
57
+
58
+ # Validate max_amount
59
+ if data.key?('max_amount')
60
+ unless data[:max_amount].is_a?(Integer)
61
+ raise CustomException.new('Invalid max amount.')
62
+ end
63
+ end
64
+
65
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
66
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class RefundValidation
8
+ def self.create(data)
9
+ # Validate charge format
10
+ HelperValidation.validate_string_start(data[:charge_id], "chr")
11
+
12
+ # Validate reason
13
+ allowed_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
14
+ HelperValidation.validate_value(data[:reason], allowed_values)
15
+
16
+ # Validate amount
17
+ amount = data[:amount]
18
+
19
+ if amount.is_a?(String)
20
+ begin
21
+ amount = Integer(amount)
22
+ print amount
23
+ rescue ArgumentError
24
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
25
+ end
26
+ end
27
+
28
+ unless amount.is_a?(Integer)
29
+ raise CustomException.new("Invalid 'amount'. It should be an integer or a string representing an integer.")
30
+ end
31
+ end
32
+
33
+ def self.list(data)
34
+ # Validate card_brand
35
+ if data.key?('reason')
36
+ allowed_brand_values = ['duplicado', 'fraudulento', 'solicitud_comprador']
37
+ Helpers.validate_value(data[:reason], allowed_brand_values)
38
+ end
39
+
40
+ # Validate date filter
41
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
42
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/validation/helper'
5
+ require 'util/validation/error'
6
+
7
+ class SubscriptionValidation
8
+ def self.create(data)
9
+ HelperValidation.validate_string_start(data[:card_id], "crd")
10
+ HelperValidation.validate_string_start(data[:plan_id], "pln")
11
+ end
12
+
13
+ def self.list(data)
14
+ # Validate card_brand
15
+ if data.key?('plan_id')
16
+ HelperValidation.validate_string_start(data[:plan_id], "pln")
17
+ end
18
+
19
+ # Validate date filter
20
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
21
+ Helpers.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,65 @@
1
+ require 'date'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'util/country-codes'
5
+ require 'util/validation/helper'
6
+ require 'util/validation/error'
7
+
8
+ class TokenValidation
9
+ def self.create(data)
10
+ # Validate card number
11
+ raise CustomException.new('Invalid card number.') unless HelperValidation.is_valid_card_number(data[:card_number])
12
+
13
+ # Validate CVV
14
+ raise CustomException.new('Invalid CVV.') unless data[:cvv]&.match?(/^\d{3,4}$/)
15
+
16
+ # Validate email
17
+ raise CustomException.new('Invalid email.') unless HelperValidation.is_valid_email(data[:email])
18
+
19
+ # Validate expiration month
20
+ raise 'Invalid expiration month.' unless data[:expiration_month].to_s.match?(/^(0?[1-9]|1[012])$/)
21
+
22
+ # Validate expiration year
23
+ current_year = Date.today.year
24
+ if !data[:expiration_year].to_s.match?(/^\d{4}$/) || data[:expiration_year].to_s.to_i < current_year
25
+ raise 'Invalid expiration year.'
26
+ end
27
+
28
+ # Check if the card is expired
29
+ exp_date = Date.strptime("#{data[:expiration_year]}-#{data[:expiration_month]}", '%Y-%m')
30
+ raise 'Card has expired.' if exp_date < Date.today
31
+ end
32
+
33
+ def self.create_token_yape_validation(data)
34
+ # Validate amount
35
+ unless data[:amount].is_a?(Numeric) && data[:amount].to_i == data[:amount]
36
+ raise CustomException.new('Invalid amount.')
37
+ end
38
+ end
39
+
40
+ def self.list(data)
41
+ if data.key?('device_type')
42
+ allowed_device_values = ['desktop', 'mobile', 'tablet']
43
+ HelperValidation.validate_value(data[:device_type], allowed_device_values)
44
+ end
45
+
46
+ if data.key?('card_brand')
47
+ allowed_brand_values = ['Visa', 'Mastercard', 'Amex', 'Diners']
48
+ HelperValidation.validate_value(data[:card_brand], allowed_brand_values)
49
+ end
50
+
51
+ if data.key?('card_type')
52
+ allowed_card_type_values = ['credito', 'debito', 'internacional']
53
+ HelperValidation.validate_value(data[:card_type], allowed_card_type_values)
54
+ end
55
+
56
+ if data.key?('country_code')
57
+ HelperValidation.validate_value(data[:country_code], get_country_codes)
58
+ end
59
+
60
+ if data.key?('creation_date_from') && data.key?('creation_date_to')
61
+ HelperValidation.validate_date_filter(data[:creation_date_from], data[:creation_date_to])
62
+ end
63
+ end
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devtech-culqi-ruby
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
+ Biblioteca Culqi-Ruby, 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/culqi-ruby.rb
23
+ - lib/culqi/card.rb
24
+ - lib/culqi/charge.rb
25
+ - lib/culqi/customer.rb
26
+ - lib/culqi/event.rb
27
+ - lib/culqi/iins.rb
28
+ - lib/culqi/order.rb
29
+ - lib/culqi/plan.rb
30
+ - lib/culqi/refund.rb
31
+ - lib/culqi/subscription.rb
32
+ - lib/culqi/token.rb
33
+ - lib/culqi/transfer.rb
34
+ - lib/culqi/version.rb
35
+ - lib/culqi/yape.rb
36
+ - lib/operation/confirm_type.rb
37
+ - lib/operation/delete.rb
38
+ - lib/operation/get.rb
39
+ - lib/operation/list.rb
40
+ - lib/operation/post.rb
41
+ - lib/operation/update.rb
42
+ - lib/util/connect.rb
43
+ - lib/util/country-codes.rb
44
+ - lib/util/encrypt-data.rb
45
+ - lib/util/validation/card.rb
46
+ - lib/util/validation/charge.rb
47
+ - lib/util/validation/customer.rb
48
+ - lib/util/validation/error.rb
49
+ - lib/util/validation/helper.rb
50
+ - lib/util/validation/order.rb
51
+ - lib/util/validation/plan.rb
52
+ - lib/util/validation/refund.rb
53
+ - lib/util/validation/subscription.rb
54
+ - lib/util/validation/token.rb
55
+ homepage: http://rubygems.org/gems/devtech-culqi-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Culqi Ruby
78
+ test_files: []