RazorpayEx.Config (razorpay_ex v0.1.3)

Copy Markdown View Source

Configuration management for RazorpayEx client.

This module handles configuration loading from application environment, environment variables, and provides convenience functions for setup.

Configuration Sources

Configuration is loaded in this order:

  1. Explicit configuration via RazorpayEx.Config.set/1
  2. Application environment (config :razorpay_ex ...)
  3. Environment variables
  4. Default values

Examples

# Configure via application config
config :razorpay_ex
  key_id: "rzp_test_key_id",
  key_secret: "test_secret"

# Configure programmatically
RazorpayEx.Config.set(%{
  key_id: "rzp_test_key_id",
  key_secret: "test_secret"
})

# Setup OAuth
RazorpayEx.Config.setup_oauth("oauth_token_123")

# Setup Basic Auth
RazorpayEx.Config.setup_basic_auth("key_id", "key_secret")

Summary

Functions

Returns the OAuth access token.

Returns the API base URL.

Returns the auth base URL.

Returns the authentication type.

Returns custom headers.

Returns whether logging is enabled.

Returns the current configuration.

Returns the RazorpayEx key ID.

Returns the RazorpayEx key secret.

Sets configuration from a map.

Configures basic authentication.

Configures OAuth authentication.

Returns the request timeout.

Types

t()

@type t() :: %RazorpayEx.Config{
  access_token: String.t() | nil,
  api_base_url: String.t(),
  auth_base_url: String.t(),
  auth_type: :basic | :oauth,
  custom_headers: map(),
  enable_logging: boolean(),
  key_id: String.t() | nil,
  key_secret: String.t() | nil,
  timeout: integer()
}

Functions

access_token()

@spec access_token() :: String.t() | nil

Returns the OAuth access token.

api_base_url()

@spec api_base_url() :: String.t()

Returns the API base URL.

auth_base_url()

@spec auth_base_url() :: String.t()

Returns the auth base URL.

auth_type()

@spec auth_type() :: :basic | :oauth

Returns the authentication type.

custom_headers()

@spec custom_headers() :: map()

Returns custom headers.

enable_logging()

@spec enable_logging() :: boolean()

Returns whether logging is enabled.

get()

@spec get() :: t()

Returns the current configuration.

key_id()

@spec key_id() :: String.t()

Returns the RazorpayEx key ID.

key_secret()

@spec key_secret() :: String.t()

Returns the RazorpayEx key secret.

set(config)

@spec set(map()) :: :ok

Sets configuration from a map.

Examples

RazorpayEx.Config.set(%{
  key_id: "rzp_test_key_id",
  key_secret: "test_secret",
  timeout: 60000
})

setup_basic_auth(key_id, key_secret, opts \\ [])

@spec setup_basic_auth(String.t(), String.t(), keyword()) :: :ok

Configures basic authentication.

Parameters

  • key_id: RazorpayEx key ID
  • key_secret: RazorpayEx key secret
  • opts: Additional options

Examples

RazorpayEx.Config.setup_basic_auth("rzp_test_key_id", "test_secret")

RazorpayEx.Config.setup_basic_auth("key_id", "secret", timeout: 60000)

setup_oauth(access_token, opts \\ [])

@spec setup_oauth(
  String.t(),
  keyword()
) :: :ok

Configures OAuth authentication.

Parameters

  • access_token: OAuth access token
  • opts: Additional options (custom_headers, timeout, etc.)

Examples

RazorpayEx.Config.setup_oauth("oauth_token_123")

RazorpayEx.Config.setup_oauth("oauth_token_123", timeout: 60000)

timeout()

@spec timeout() :: integer()

Returns the request timeout.