ruby-culqi 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: e8c5217b4754416c6bb2c10ad446367c13b8e9ee86df0821f092673dcefa6bf1
4
+ data.tar.gz: f1cf22a2099dc9bcdbfd084ca33064a5855e849e1b7731d24e467bedbf6eb775
5
+ SHA512:
6
+ metadata.gz: 733ad68cc11af57dd4faed69ee3e7fb86f8c392efdb37c20c8f33a1d7032b745f47950b959eb3b3675dcf439769e986417de47f25223a1e1d45ce3178db502a0
7
+ data.tar.gz: cdee344c339e4bdf79846d24ee67ea48cb0cc6067c4988ca1cf95a1b7d5e1131c5caf0a1da21955c212d735fa416c1451ed07a68dca81c64b76b9ed55b53dfa4
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,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 = Culqi.connect("#{@url}#{id}/capture/", Culqi.secret_key, nil, "post", Culqi::READ_TIMEOUT)
15
+ return response.read_body
16
+ end
17
+
18
+ end
19
+
20
+ 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,17 @@
1
+ module Culqi
2
+
3
+ class Order
4
+
5
+ extend List
6
+ extend Post
7
+ extend Get
8
+ extend ConfirmType
9
+ extend Update
10
+
11
+ URL = '/orders/'
12
+
13
+ @url = URL
14
+
15
+ end
16
+
17
+ 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,15 @@
1
+ module Culqi
2
+
3
+ class Token
4
+
5
+ extend List
6
+ extend Post
7
+ extend Get
8
+
9
+ URL = '/tokens/'
10
+
11
+ @url = URL
12
+
13
+ end
14
+
15
+ 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,34 @@
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
+ API_BASE = 'https://qa-api.culqi.xyz/v2'
26
+ API_BASE_SECURE = 'https://qa-secure.culqi.xyz/v2'
27
+ READ_TIMEOUT = 120
28
+ LIST_TIMEOUT = 360
29
+
30
+ class << self
31
+ attr_accessor :public_key, :secret_key, :rsa_id, :rsa_key
32
+ end
33
+
34
+ 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,14 @@
1
+ require 'util/connect'
2
+
3
+ module Culqi::Delete
4
+
5
+ def initialize
6
+ @url = ''
7
+ end
8
+
9
+ def delete(id)
10
+ response = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, nil, 'delete', Culqi::READ_TIMEOUT)
11
+ return response.read_body
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'util/connect'
2
+
3
+ module Culqi::Get
4
+
5
+ def initialize
6
+ @url = ''
7
+ end
8
+
9
+ def get(id)
10
+ response = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, nil, 'get', Culqi::READ_TIMEOUT)
11
+ return response
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'util/connect'
2
+
3
+ module Culqi::List
4
+
5
+ def initialize
6
+ @url = ''
7
+ end
8
+
9
+ def list(params={})
10
+ response = Culqi.connect(@url, Culqi.secret_key, params, 'get', Culqi::LIST_TIMEOUT)
11
+ return response.read_body
12
+ end
13
+
14
+ 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 = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
18
+ return response
19
+ else
20
+ key = Culqi.secret_key
21
+ response = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
22
+ return response
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 = Culqi.connect("#{@url}#{id}/", Culqi.secret_key, params, 'patch', Culqi::READ_TIMEOUT, rsa_id)
14
+ return response
15
+ end
16
+
17
+ end
@@ -0,0 +1,72 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+ require 'culqi-ruby'
6
+ require 'open3'
7
+
8
+
9
+ module Culqi
10
+
11
+ def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
12
+
13
+ if secure_url == true
14
+ url = URI("#{Culqi::API_BASE_SECURE}#{url}")
15
+ else
16
+ url = URI("#{Culqi::API_BASE}#{url}")
17
+ end
18
+
19
+ http = Net::HTTP.new(url.host, url.port)
20
+ http.read_timeout = time_out
21
+ http.use_ssl = true
22
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
+
24
+ request = ''
25
+ if type.upcase == 'POST'
26
+
27
+ url = url.to_s
28
+ auth_header = "Authorization: Bearer #{api_key}"
29
+ content_type_header = "Content-Type: application/json"
30
+ rsa_id_header = "x-culqi-rsa-id: #{rsa_id}"
31
+ cache_control_header = "cache-control: no-cache"
32
+ data = data.to_json
33
+
34
+ stdout, stderr, status = Open3.capture3(
35
+ "curl",
36
+ "-X", "POST",
37
+ url,
38
+ "-H", auth_header,
39
+ "-H", content_type_header,
40
+ "-H", rsa_id_header,
41
+ "-H", cache_control_header,
42
+ "-d", data
43
+ )
44
+
45
+ end
46
+
47
+ if type.upcase == 'GET'
48
+ if !data.nil?
49
+ url.query = URI.encode_www_form(data)
50
+ command = "curl '#{url}' -G -d '#{URI.encode_www_form(data)}'"
51
+ else
52
+ command = "curl '#{url}'"
53
+ end
54
+
55
+ stdout, stderr, status = Open3.capture3("#{command} -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'cache-control: no-cache'")
56
+
57
+ end
58
+
59
+ if type.upcase == 'DELETE'
60
+ command = "curl -X DELETE '#{url}' -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'cache-control: no-cache'"
61
+ stdout, stderr, status = Open3.capture3(command)
62
+ end
63
+
64
+ if type.upcase == 'PATCH'
65
+ command = "curl -X PATCH '#{url}' -H 'Authorization: Bearer #{api_key}' -H 'Content-Type: application/json' -H 'x-culqi-rsa-id: #{rsa_id}' -H 'cache-control: no-cache' -d '#{data.to_json}'"
66
+ stdout, stderr, status = Open3.capture3(command)
67
+ end
68
+
69
+ return stdout
70
+
71
+ end
72
+ end
@@ -0,0 +1,46 @@
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(16) # Generate a 128-bit random initialization vector for AES encryption
14
+
15
+ cipher = OpenSSL::Cipher.new('AES-256-CBC')
16
+ cipher.encrypt
17
+ cipher.key = key
18
+ cipher.iv = iv
19
+
20
+ encrypted = if is_json
21
+ cipher.update(data.to_json) + cipher.final
22
+ else
23
+ cipher.update(data) + cipher.final
24
+ end
25
+
26
+ encrypted_data = Base64.strict_encode64(encrypted)
27
+
28
+ ####
29
+ rsa_public_key = OpenSSL::PKey::RSA.new(public_key)
30
+ encrypted_key = rsa_encrypt(key, rsa_public_key)
31
+ encrypted_iv = rsa_encrypt(iv, rsa_public_key)
32
+
33
+ { encrypted_data: encrypted_data, encrypted_key: encrypted_key, encrypted_iv: encrypted_iv }
34
+ end
35
+
36
+ def self.rsa_encrypt(data, public_key)
37
+ # Define the encryption parameters
38
+ label = ''
39
+
40
+ md = OpenSSL::Digest::SHA256
41
+ cipher_text = public_key.public_encrypt_oaep(data, label, md, md)
42
+
43
+ return Base64.strict_encode64(cipher_text)
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-culqi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Diaz Diaz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2223-07-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Biblioteca de Culqi en Ruby API v2
14
+ email:
15
+ - jordandiaz2016@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/culqi-ruby.rb
21
+ - lib/culqi/card.rb
22
+ - lib/culqi/charge.rb
23
+ - lib/culqi/customer.rb
24
+ - lib/culqi/event.rb
25
+ - lib/culqi/iins.rb
26
+ - lib/culqi/order.rb
27
+ - lib/culqi/plan.rb
28
+ - lib/culqi/refund.rb
29
+ - lib/culqi/subscription.rb
30
+ - lib/culqi/token.rb
31
+ - lib/culqi/transfer.rb
32
+ - lib/culqi/version.rb
33
+ - lib/culqi/yape.rb
34
+ - lib/operation/confirm_type.rb
35
+ - lib/operation/delete.rb
36
+ - lib/operation/get.rb
37
+ - lib/operation/list.rb
38
+ - lib/operation/post.rb
39
+ - lib/operation/update.rb
40
+ - lib/util/connect.rb
41
+ - lib/util/encrypt-data.rb
42
+ homepage: http://rubygems.org/gems/culqi
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.3
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Culqi Ruby
65
+ test_files: []