GameServer.Payments (game_server_core v1.0.999)

Copy Markdown

Payment catalog, purchase ledger, and entitlements.

Provider-specific integrations validate or create transactions, but this context remains the source of truth for what a user owns inside the game.

Summary

Functions

Functions

admin_stats()

@spec admin_stats() :: map()

cancel_stripe_subscription_at_period_end(user, entitlement_id)

@spec cancel_stripe_subscription_at_period_end(
  GameServer.Accounts.User.t(),
  integer()
) ::
  {:ok,
   %{
     purchase: GameServer.Payments.Purchase.t(),
     entitlement: GameServer.Payments.Entitlement.t(),
     stripe_subscription: map()
   }}
  | {:error, term()}

count_entitlements(opts \\ [])

@spec count_entitlements(keyword()) :: non_neg_integer()

count_products(opts \\ [])

@spec count_products(keyword()) :: non_neg_integer()

count_provider_events(opts \\ [])

@spec count_provider_events(keyword()) :: non_neg_integer()

count_provider_products(opts \\ [])

@spec count_provider_products(keyword()) :: non_neg_integer()

count_purchases(opts \\ [])

@spec count_purchases(keyword()) :: non_neg_integer()

count_reconciliation_cursors(opts \\ [])

@spec count_reconciliation_cursors(keyword()) :: non_neg_integer()

create_product(attrs)

@spec create_product(map()) ::
  {:ok, GameServer.Payments.Product.t()} | {:error, Ecto.Changeset.t()}

create_provider_product(attrs)

@spec create_provider_product(map()) ::
  {:ok, GameServer.Payments.ProviderProduct.t()} | {:error, Ecto.Changeset.t()}

create_purchase(user_or_id, provider_product, attrs \\ %{})

create_steam_checkout(user, attrs)

@spec create_steam_checkout(GameServer.Accounts.User.t(), map()) ::
  {:ok,
   %{
     purchase: GameServer.Payments.Purchase.t(),
     provider_transaction_id: String.t() | nil,
     steam_url: String.t() | nil
   }}
  | {:error, term()}

create_stripe_checkout(user, attrs)

@spec create_stripe_checkout(GameServer.Accounts.User.t(), map()) ::
  {:ok,
   %{
     purchase: GameServer.Payments.Purchase.t(),
     checkout_url: String.t(),
     provider_session_id: String.t()
   }}
  | {:error, term()}

finalize_steam_purchase(user, attrs)

@spec finalize_steam_purchase(GameServer.Accounts.User.t(), map()) ::
  {:ok, %{purchase: GameServer.Payments.Purchase.t()}} | {:error, term()}

fulfill_purchase(purchase, provider_payload \\ %{})

@spec fulfill_purchase(GameServer.Payments.Purchase.t(), map()) ::
  {:ok, GameServer.Payments.Purchase.t()} | {:error, term()}

get_product(id)

@spec get_product(integer()) :: GameServer.Payments.Product.t() | nil

get_product_by_sku(sku)

@spec get_product_by_sku(String.t()) :: GameServer.Payments.Product.t() | nil

get_provider_product(id)

@spec get_provider_product(integer()) :: GameServer.Payments.ProviderProduct.t() | nil

get_provider_product(provider, external_id)

@spec get_provider_product(String.t(), String.t()) ::
  GameServer.Payments.ProviderProduct.t() | nil

get_purchase(id)

@spec get_purchase(integer()) :: GameServer.Payments.Purchase.t() | nil

get_purchase_by_order_id(order_id)

@spec get_purchase_by_order_id(String.t()) :: GameServer.Payments.Purchase.t() | nil

get_purchase_by_provider_original_transaction(provider, transaction_id)

@spec get_purchase_by_provider_original_transaction(String.t(), String.t()) ::
  GameServer.Payments.Purchase.t() | nil

get_purchase_by_provider_transaction(provider, transaction_id)

@spec get_purchase_by_provider_transaction(String.t(), String.t()) ::
  GameServer.Payments.Purchase.t() | nil

handle_apple_webhook(raw_body)

@spec handle_apple_webhook(binary()) :: {:ok, atom()} | {:error, term()}

handle_google_webhook(raw_body, authorization_header)

@spec handle_google_webhook(binary(), binary() | nil) ::
  {:ok, atom()} | {:error, term()}

handle_stripe_webhook(raw_body, signature)

@spec handle_stripe_webhook(binary(), binary() | nil) ::
  {:ok, atom()} | {:error, term()}

has_entitlement?(user_id, key)

@spec has_entitlement?(integer(), String.t()) :: boolean()

list_admin_entitlements(opts \\ [])

@spec list_admin_entitlements(keyword()) :: [GameServer.Payments.Entitlement.t()]

list_admin_products(opts \\ [])

@spec list_admin_products(keyword()) :: [GameServer.Payments.Product.t()]

list_admin_provider_products(opts \\ [])

@spec list_admin_provider_products(keyword()) :: [
  GameServer.Payments.ProviderProduct.t()
]

list_admin_purchases(opts \\ [])

@spec list_admin_purchases(keyword()) :: [GameServer.Payments.Purchase.t()]

list_catalog(provider \\ nil)

@spec list_catalog(String.t() | nil) :: [GameServer.Payments.ProviderProduct.t()]

list_products(opts \\ [])

@spec list_products(keyword()) :: [GameServer.Payments.Product.t()]

list_provider_events(opts \\ [])

@spec list_provider_events(keyword()) :: [GameServer.Payments.ProviderEvent.t()]

list_reconciliation_cursors(opts \\ [])

@spec list_reconciliation_cursors(keyword()) :: [
  GameServer.Payments.ReconciliationCursor.t()
]

list_user_entitlements(user_id, opts \\ [])

@spec list_user_entitlements(
  integer(),
  keyword()
) :: [GameServer.Payments.Entitlement.t()]

list_user_purchases(user_id, opts \\ [])

@spec list_user_purchases(
  integer(),
  keyword()
) :: [GameServer.Payments.Purchase.t()]

product_entitlement_key(product)

@spec product_entitlement_key(GameServer.Payments.Product.t()) :: String.t()

provider_adapter_statuses()

@spec provider_adapter_statuses() :: [map()]

reconcile_stripe_purchase(id)

@spec reconcile_stripe_purchase(GameServer.Payments.Purchase.t() | integer()) ::
  {:ok,
   %{
     purchase: GameServer.Payments.Purchase.t(),
     result: atom(),
     stripe_session: map()
   }}
  | {:error, term()}

record_provider_event(provider, event_id, event_type, payload, metadata \\ %{})

@spec record_provider_event(String.t(), String.t(), String.t(), map(), map()) ::
  {:ok, GameServer.Payments.ProviderEvent.t(), boolean()}
  | {:error, Ecto.Changeset.t()}

revoke_purchase(purchase, attrs \\ %{})

@spec revoke_purchase(GameServer.Payments.Purchase.t(), map()) ::
  {:ok, GameServer.Payments.Purchase.t()} | {:error, term()}

stripe_config_status()

@spec stripe_config_status() :: map()

update_product(product, attrs)

@spec update_product(GameServer.Payments.Product.t(), map()) ::
  {:ok, GameServer.Payments.Product.t()} | {:error, Ecto.Changeset.t()}

update_provider_product(provider_product, attrs)

@spec update_provider_product(GameServer.Payments.ProviderProduct.t(), map()) ::
  {:ok, GameServer.Payments.ProviderProduct.t()} | {:error, Ecto.Changeset.t()}

validate_store_purchase(user, provider, attrs)

@spec validate_store_purchase(GameServer.Accounts.User.t(), String.t(), map()) ::
  {:ok, %{purchase: GameServer.Payments.Purchase.t(), seen_before: boolean()}}
  | {:error, term()}