Zoonk.Billing.Stripe (Zoonk v0.1.0-dev)

View Source

Stripe API client for Zoonk.

This module provides functions to interact with the Stripe API, including creating, retrieving, and managing Stripe resources.

Summary

Functions

Sends a DELETE request to the Stripe API.

Sends a GET request to the Stripe API.

Sends a POST request to the Stripe API.

Functions

delete(endpoint, params \\ %{}, opts \\ [])

Sends a DELETE request to the Stripe API.

Parameters

  • endpoint: The Stripe API endpoint to send the request to.
  • params: Optional query parameters for the request.
  • opts: Additional options for the request, such as headers.

Examples

iex> Stripe.delete("/subscriptions/sub_1J2Y3Z4A5B6C7D8E9F0G")
{:ok, %{id: "sub_1J2Y3Z4A5B6C7D8E9F0G", status: "canceled"}}

iex> Stripe.delete("/subscriptions/invalid_id")
{:error, "No such subscription: invalid_id"}

get(endpoint, params \\ %{}, opts \\ [])

Sends a GET request to the Stripe API.

Parameters

  • endpoint: The Stripe API endpoint to send the request to.
  • params: Optional query parameters for the request.
  • opts: Additional options for the request, such as headers.

Examples

iex> Stripe.get("/prices")
{:ok, %{data: [%{id: "price_1J2Y3Z4A5B6C7D8E9F0G", product: "prod_1A2B3C4D", unit_amount: 1000}]}}

iex> Stripe.get("/prices", %{lookup_keys: ["starter_monthly"]})
{:ok, %{data: [%{id: "price_1J2Y3Z4A5B6C7D8E9F0G", lookup_key: "starter_monthly", unit_amount: 1000}]}}

post(endpoint, payload, opts \\ [])

Sends a POST request to the Stripe API.

Parameters

  • endpoint: The Stripe API endpoint to send the request to.
  • payload: The payload to include in the request body.
  • opts: Additional options for the request, such as headers and query parameters.

Examples

iex> Stripe.post("/charges", %{amount: 1000, currency: "usd"})
{:ok, %{id: "ch_1J2Y3Z4A5B6C7D8E9F0G", amount: 1000, currency: "usd"}}

iex> Stripe.post("/charges", %{amount: 1000, currency: "usd"})
{:error, "Invalid request"}