mirror of
https://github.com/plausible/analytics.git
synced 2024-12-25 02:24:55 +03:00
f977351ae2
* allow using Stats API and Props for free_10k subscriptions * return v3 plans for legacy trials * do not display grandfathering notice for legacy trials * set a more accurate BT release date * fix bug on dev env Allow the `find/1` function to find sandbox plans * add error handling and tests for change_plan_preview * fix feature warning bug * fix credo warnings * fix tests * set BT release date further into the future * rename function and some vars * bugfix with limit exceeding * fix test
92 lines
2.2 KiB
Elixir
92 lines
2.2 KiB
Elixir
defmodule Plausible.PaddleApi.Mock do
|
|
def get_subscription(_) do
|
|
{:ok,
|
|
%{
|
|
"next_payment" => %{
|
|
"date" => "2019-07-10",
|
|
"amount" => 6
|
|
},
|
|
"last_payment" => %{
|
|
"date" => "2019-06-10",
|
|
"amount" => 6
|
|
}
|
|
}}
|
|
end
|
|
|
|
def update_subscription(_, %{plan_id: new_plan_id}) do
|
|
new_plan_id = String.to_integer(new_plan_id)
|
|
|
|
{:ok,
|
|
%{
|
|
"plan_id" => new_plan_id,
|
|
"next_payment" => %{
|
|
"date" => "2019-07-10",
|
|
"amount" => 6
|
|
}
|
|
}}
|
|
end
|
|
|
|
def update_subscription_preview(_user, _new_plan_id) do
|
|
{:ok,
|
|
%{
|
|
"immediate_payment" => %{
|
|
"amount" => -72.6,
|
|
"currency" => "EUR",
|
|
"date" => "2023-11-05"
|
|
},
|
|
"next_payment" => %{
|
|
"amount" => 47.19,
|
|
"currency" => "EUR",
|
|
"date" => "2023-12-05"
|
|
},
|
|
"plan_id" => 63_852,
|
|
"subscription_id" => 600_279,
|
|
"user_id" => 666_317
|
|
}}
|
|
end
|
|
|
|
def get_invoices(nil), do: {:error, :no_invoices}
|
|
def get_invoices(%{paddle_subscription_id: nil}), do: {:error, :no_invoices}
|
|
|
|
def get_invoices(subscription) do
|
|
case subscription.paddle_subscription_id do
|
|
"invalid_subscription_id" ->
|
|
{:error, :request_failed}
|
|
|
|
_ ->
|
|
{:ok,
|
|
[
|
|
%{
|
|
"amount" => 11.11,
|
|
"currency" => "EUR",
|
|
"payout_date" => "2020-12-24",
|
|
"receipt_url" => "https://some-receipt-url.com"
|
|
},
|
|
%{
|
|
"amount" => 22,
|
|
"currency" => "USD",
|
|
"payout_date" => "2020-11-24",
|
|
"receipt_url" => "https://other-receipt-url.com"
|
|
}
|
|
]}
|
|
end
|
|
end
|
|
|
|
# to give a reasonable testing structure for monthly and yearly plan
|
|
# prices, this function returns prices with the following logic:
|
|
# 10, 100, 20, 200, 30, 300, ...and so on.
|
|
def fetch_prices([_ | _] = product_ids) do
|
|
{prices, _index} =
|
|
Enum.reduce(product_ids, {%{}, 1}, fn p, {acc, i} ->
|
|
price =
|
|
if rem(i, 2) == 1,
|
|
do: ceil(i / 2.0) * 10.0,
|
|
else: ceil(i / 2.0) * 100.0
|
|
|
|
{Map.put(acc, p, Money.from_float!(:EUR, price)), i + 1}
|
|
end)
|
|
|
|
{:ok, prices}
|
|
end
|
|
end
|