RazorpayEx.Refund (razorpay_ex v0.1.3)

Copy Markdown View Source

Refund resource for Razorpay API.

This module provides functions for working with refunds:

  • Create, fetch, and list refunds
  • Process refunds for payments

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

Summary

Functions

Lists all refunds with optional filters.

Creates a refund for a payment.

Fetches a refund by ID.

Fetches multiple refunds for a payment.

Types

t()

@type t() :: %RazorpayEx.Refund{
  acquirer_data: map() | nil,
  amount: integer() | nil,
  batch_id: String.t() | nil,
  created_at: integer() | nil,
  currency: String.t() | nil,
  entity: String.t() | nil,
  id: String.t() | nil,
  notes: map() | nil,
  payment_id: String.t() | nil,
  receipt: String.t() | nil,
  speed_processed: String.t() | nil,
  speed_requested: String.t() | nil,
  status: String.t() | nil
}

Functions

all(params \\ %{})

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

Lists all refunds with optional filters.

Parameters

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

Examples

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

# List refunds for a specific payment
{:ok, refunds} = RazorpayEx.Refund.all(%{payment_id: "pay_29QQoUBi66xm2f"})

create(payment_id, params)

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

Creates a refund for a payment.

Parameters

  • payment_id: Payment ID
  • params: Refund parameters (amount, notes, etc.)

Required Parameters

  • amount: Amount to refund (in paise)

Optional Parameters

  • notes: Additional notes
  • receipt: Your refund receipt ID
  • speed: Refund speed ("normal", "optimum")

Examples

# Full refund
{:ok, refund} = RazorpayEx.Refund.create("pay_29QQoUBi66xm2f", %{
  amount: 50000
})

# Partial refund with notes
{:ok, refund} = RazorpayEx.Refund.create("pay_29QQoUBi66xm2f", %{
  amount: 25000,
  notes: %{reason: "Defective product"},
  speed: "optimum"
})

fetch(id)

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

Fetches a refund by ID.

Parameters

  • id: Refund ID

Examples

{:ok, refund} = RazorpayEx.Refund.fetch("rfnd_9A33XWu170gUtm")

for_payment(payment_id, params \\ %{})

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

Fetches multiple refunds for a payment.

Parameters

  • payment_id: Payment ID
  • params: Query parameters

Examples

{:ok, refunds} = RazorpayEx.Refund.for_payment("pay_29QQoUBi66xm2f")