defmodule DaProductApp.SaasKit.Billing do @moduledoc """ Module for handling billing operations through SaaS Kit. """ alias DaProductApp.SaasKit.Client @doc """ Create a new customer """ def create_customer(user_id, params \\ %{}) do body = %{ user_id: user_id } |> Map.merge(params) Client.post("/customers", body) end @doc """ Get customer information """ def get_customer(customer_id) do Client.get("/customers/#{customer_id}") end @doc """ Update customer information """ def update_customer(customer_id, params) do Client.put("/customers/#{customer_id}", params) end @doc """ Get customer's billing history """ def get_billing_history(customer_id, params \\ %{}) do Client.get("/customers/#{customer_id}/billing-history", params) end @doc """ Create a payment method for a customer """ def create_payment_method(customer_id, payment_method_data) do Client.post("/customers/#{customer_id}/payment-methods", payment_method_data) end @doc """ List customer's payment methods """ def list_payment_methods(customer_id) do Client.get("/customers/#{customer_id}/payment-methods") end @doc """ Delete a payment method """ def delete_payment_method(customer_id, payment_method_id) do Client.delete("/customers/#{customer_id}/payment-methods/#{payment_method_id}") end @doc """ Create an invoice """ def create_invoice(customer_id, items) do body = %{ customer_id: customer_id, items: items } Client.post("/invoices", body) end @doc """ Get invoice details """ def get_invoice(invoice_id) do Client.get("/invoices/#{invoice_id}") end @doc """ List invoices for a customer """ def list_customer_invoices(customer_id, params \\ %{}) do Client.get("/invoices", Map.put(params, :customer_id, customer_id)) end @doc """ Process a payment """ def process_payment(payment_data) do Client.post("/payments", payment_data) end @doc """ Get payment details """ def get_payment(payment_id) do Client.get("/payments/#{payment_id}") end @doc """ Refund a payment """ def refund_payment(payment_id, amount \\ nil) do body = if amount, do: %{amount: amount}, else: %{} Client.post("/payments/#{payment_id}/refund", body) end end