Module: Culqi

Defined in:
lib/culqi-ruby.rb,
lib/culqi/card.rb,
lib/culqi/iins.rb,
lib/culqi/plan.rb,
lib/culqi/yape.rb,
lib/culqi/event.rb,
lib/culqi/order.rb,
lib/culqi/token.rb,
lib/culqi/charge.rb,
lib/culqi/refund.rb,
lib/util/connect.rb,
lib/culqi/version.rb,
lib/culqi/customer.rb,
lib/culqi/transfer.rb,
lib/culqi/subscription.rb

Defined Under Namespace

Modules: ConfirmType, Delete, Get, List, Post, Update Classes: Card, Charge, Customer, Event, Iins, Order, Plan, Refund, Subscription, Token, Transfer, Yape

Constant Summary collapse

API_BASE =
'https://api.culqi.com/v2'
API_BASE_SECURE =
'https://secure.culqi.com/v2'
READ_TIMEOUT =
120
LIST_TIMEOUT =
360
X_CULQI_ENV_TEST =
"test"
X_CULQI_ENV_LIVE =
"live"
X_API_VERSION =
"2"
X_CULQI_CLIENT =
"culqi-ruby"
X_CULQI_CLIENT_VERSION =
"0.1.0"
VERSION =
"1.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.public_keyObject

Returns the value of attribute public_key.



35
36
37
# File 'lib/culqi-ruby.rb', line 35

def public_key
  @public_key
end

.rsa_idObject

Returns the value of attribute rsa_id.



35
36
37
# File 'lib/culqi-ruby.rb', line 35

def rsa_id
  @rsa_id
end

.rsa_keyObject

Returns the value of attribute rsa_key.



35
36
37
# File 'lib/culqi-ruby.rb', line 35

def rsa_key
  @rsa_key
end

.secret_keyObject

Returns the value of attribute secret_key.



35
36
37
# File 'lib/culqi-ruby.rb', line 35

def secret_key
  @secret_key
end

Class Method Details

.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id = '') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/util/connect.rb', line 6

def self.connect(url, api_key, data, type, time_out, secure_url = false, rsa_id='')
  base_url = secure_url ? Culqi::API_BASE_SECURE : Culqi::API_BASE
  full_url = "#{base_url}#{url}"

  if(api_key.include? 'test')
    env = Culqi::X_CULQI_ENV_TEST
  else
    env = Culqi::X_CULQI_ENV_LIVE
  end
  
  headers = {
    "Authorization" => "Bearer #{api_key}",
    "Content-Type" => "application/json",
    "x-culqi-env" => env,
    "x-api-version" => Culqi::X_API_VERSION,
    "x-culqi-client" => Culqi::X_CULQI_CLIENT,
    "x-culqi-client-version" => Culqi::X_CULQI_CLIENT,
    "x-culqi-rsa-id" => rsa_id
  }

  response = Excon.new(full_url,
                       headers: headers,
                       read_timeout: time_out,
                       idempotent: true,
                       retry_limit: 6)

  case type.upcase
  when 'GET'
    result = response.request(method: :get, query: data)
  when 'POST'
    result = response.request(method: :post, body: data.to_json)
  when 'DELETE'
    result = response.request(method: :delete)
  when 'PATCH'
    result = response.request(method: :patch, body: data.to_json)
  else
    raise ArgumentError, "Unsupported request type: #{type}"
  end

  return result.body, result.status
end