Client.Xendit (Voile v0.1.26)

Copy Markdown View Source

Client for interacting with Xendit Payment Gateway API. Primarily uses the Payment Link API for fine payments.

Documentation: https://developers.xendit.co/api-reference/

Summary

Functions

Creates a payment link for a fine.

Retrieves a payment link by ID.

Gets payment link by external_id.

Parses a webhook payload and returns the event data.

Validates a Xendit webhook callback signature.

Functions

create_payment_link(opts \\ [])

Creates a payment link for a fine.

Options

  • :external_id - Unique ID for the payment (defaults to "fine{fine_id}{timestamp}")
  • :amount - Amount in IDR (required)
  • :description - Payment description
  • :customer - Map with customer details (:given_names, :email, :mobile_number)
  • :success_redirect_url - URL to redirect after successful payment
  • :failure_redirect_url - URL to redirect after failed payment
  • :items - List of line items (optional)

Examples

iex> Client.Xendit.create_payment_link(
  amount: 50000,
  description: "Library Fine Payment",
  customer: %{
    given_names: "John Doe",
    email: "john@example.com"
  }
)
{:ok, %{
  "id" => "pl-xxx",
  "external_id" => "fine_123_1234567890",
  "invoice_url" => "https://checkout.xendit.co/web/pl-xxx",
  "amount" => 50000,
  "status" => "PENDING"
}}

get_payment_link(payment_link_id)

Retrieves a payment link by ID.

Examples

iex> Client.Xendit.get_payment_link("pl-xxx")
{:ok, %{
  "id" => "pl-xxx",
  "status" => "PENDING",
  "amount" => 50000
}}

parse_webhook_payload(payload)

Parses a webhook payload and returns the event data.

Examples

iex> Client.Xendit.parse_webhook_payload(%{
  "id" => "pl-xxx",
  "external_id" => "fine_123_1234567890",
  "status" => "PAID",
  "paid_amount" => 50000
})
{:ok, %{
  payment_link_id: "pl-xxx",
  external_id: "fine_123_1234567890",
  status: "PAID",
  paid_amount: 50000
}}

validate_webhook_signature(webhook_token, request_body)

Validates a Xendit webhook callback signature.

Examples

iex> Client.Xendit.validate_webhook_signature(webhook_token, request_body)
true