RazorpayEx.Customer (razorpay_ex v0.1.3)

Copy Markdown View Source

Customer resource for Razorpay API.

This module provides functions for working with customers:

  • Create, fetch, update, and list customers
  • Manage customer details and tokens

See: https://razorpay.com/docs/api/customers/

Summary

Functions

Lists all customers with optional filters.

Creates a new customer.

Fetches a customer by ID.

Updates a customer.

Types

t()

@type t() :: %RazorpayEx.Customer{
  contact: String.t() | nil,
  created_at: integer() | nil,
  email: String.t() | nil,
  entity: String.t() | nil,
  gstin: String.t() | nil,
  id: String.t() | nil,
  name: String.t() | nil,
  notes: map() | nil
}

Functions

all(params \\ %{})

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

Lists all customers with optional filters.

Parameters

  • params: Query parameters (count, skip, etc.)

Examples

# List first 10 customers
{:ok, customers} = RazorpayEx.Customer.all(%{count: 10})

create(params)

@spec create(map()) :: {:ok, t()} | {:error, RazorpayEx.Error.t()}

Creates a new customer.

Parameters

  • params: Customer parameters (name, email, contact, etc.)

Required Parameters

  • name: Customer name
  • email: Customer email
  • contact: Customer contact number

Optional Parameters

  • gstin: Customer GSTIN
  • notes: Additional notes

Examples

{:ok, customer} = RazorpayEx.Customer.create(%{
  name: "John Doe",
  email: "john@example.com",
  contact: "+919999999999",
  notes: %{
    customer_since: "2023"
  }
})

fetch(id)

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

Fetches a customer by ID.

Parameters

  • id: Customer ID

Examples

{:ok, customer} = RazorpayEx.Customer.fetch("cust_9A33XWu170gUtm")

update(id, params)

@spec update(String.t(), map()) :: {:ok, t()} | {:error, RazorpayEx.Error.t()}

Updates a customer.

Parameters

  • id: Customer ID
  • params: Update parameters (name, email, contact, notes, etc.)

Examples

{:ok, customer} = Razorpay.Customer.update("cust_9A33XWu170gUtm", %{
  name: "John Updated",
  email: "updated@example.com",
  notes: %{updated_at: "2024-01-01"}
})