RazorpayEx.Entity (razorpay_ex v0.1.3)

Copy Markdown View Source

Base entity module for all Razorpay resources.

This module provides the foundation for all Razorpay resource structs, similar to how Ruby SDK uses inheritance for entities.

Summary

Functions

Lists entities for a given resource type.

Dynamically creates a struct for a given entity type.

Fetches an entity by ID for a given resource type.

Creates an entity struct from a map.

Converts an entity to a map, filtering out nil values.

Types

t()

@type t() :: %RazorpayEx.Entity{
  created_at: integer() | nil,
  entity: String.t() | nil,
  id: String.t() | nil
}

Functions

all(resource_type, params \\ %{})

@spec all(atom(), map()) :: {:ok, [struct()]} | {:error, RazorpayEx.Error.t()}

Lists entities for a given resource type.

Similar to Ruby SDK's class.all method.

build(entity_name, attributes)

@spec build(String.t(), map()) :: struct()

Dynamically creates a struct for a given entity type.

This mimics Ruby SDK's dynamic class creation based on entity names.

Examples

RazorpayEx.Entity.build("payment", %{"id" => "pay_123", "amount" => 5000})

fetch(id, resource_type)

@spec fetch(String.t(), atom()) :: {:ok, struct()} | {:error, RazorpayEx.Error.t()}

Fetches an entity by ID for a given resource type.

Similar to Ruby SDK's instance.fetch method.

from_map(map)

@spec from_map(map()) :: t()

Creates an entity struct from a map.

Examples

RazorpayEx.Entity.from_map(%{"id" => "pay_123", "entity" => "payment"})

to_map(entity)

@spec to_map(t()) :: map()

Converts an entity to a map, filtering out nil values.