Module: NakoPay

Defined in:
lib/nakopay/client.rb,
lib/nakopay/errors.rb,
lib/nakopay/version.rb,
lib/nakopay/webhook.rb,
lib/nakopay/resource.rb,
lib/nakopay/resources.rb

Defined Under Namespace

Modules: Credit, Customer, Event, Invoice, Key, Logs, PaymentLink, Rate, Refund, Sandbox, Subscription, SubscriptionPlan, Webhook, WebhookEndpoint Classes: APIError, AuthenticationError, Client, ConnectionError, Error, IdempotencyError, RateLimitError, Resource, SignatureVerificationError

Constant Summary collapse

VERSION =
"1.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



155
156
157
# File 'lib/nakopay/client.rb', line 155

def api_key
  @api_key
end

.api_versionObject

Returns the value of attribute api_version.



155
156
157
# File 'lib/nakopay/client.rb', line 155

def api_version
  @api_version
end

.base_urlObject

Returns the value of attribute base_url.



155
156
157
# File 'lib/nakopay/client.rb', line 155

def base_url
  @base_url
end

.max_retriesObject

Returns the value of attribute max_retries.



155
156
157
# File 'lib/nakopay/client.rb', line 155

def max_retries
  @max_retries
end

.timeoutObject

Returns the value of attribute timeout.



155
156
157
# File 'lib/nakopay/client.rb', line 155

def timeout
  @timeout
end

Class Method Details

.build_api_error(payload, status_code:) ⇒ Object

Maps API error envelope to specialized subclass.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/nakopay/errors.rb', line 66

def self.build_api_error(payload, status_code:)
  code = payload["code"]
  message = payload["message"]
  common = {
    code: code,
    type: payload["type"],
    param: payload["param"],
    doc_url: payload["doc_url"],
    request_id: payload["request_id"],
    status_code: status_code,
  }

  if status_code == 401 || code == "authentication_error"
    AuthenticationError.new(message: message || "Invalid API key", **common)
  elsif status_code == 429 || code == "rate_limit_error"
    RateLimitError.new(message: message || "Rate limit exceeded", **common)
  elsif code == "idempotency_error"
    IdempotencyError.new(message: message || "Idempotency conflict", **common)
  else
    APIError.new(message: message || "Unknown error", **common)
  end
end

.clientObject

Default singleton client. Resources call into this; tests may swap it.



158
159
160
# File 'lib/nakopay/client.rb', line 158

def client
  @client ||= Client.new
end

.reset_client!Object

Reset the singleton (used in tests).



163
164
165
# File 'lib/nakopay/client.rb', line 163

def reset_client!
  @client = nil
end