File size: 1,909 Bytes
6778ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
defmodule Plausible.Billing.TestPaddleApiMock do
  @moduledoc false

  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

  def fetch_prices(product_ids, customer_ip) do
    Plausible.Billing.DevPaddleApiMock.fetch_prices(product_ids, customer_ip)
  end
end