Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BillingPortal.Session #604

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/stripe/billing_portal/session.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Stripe.BillingPortal.Session do
@moduledoc """
Work with Stripe Billing (aka Self-serve) Portal Session objects.

You can:

- Create a session

Stripe API reference: https://stripe.com/docs/api/self_service_portal
"""

use Stripe.Entity
import Stripe.Request

@type t :: %__MODULE__{
:id => Stripe.id(),
:object => String.t(),
:created => Stripe.timestamp(),
:customer => Stripe.id() | Stripe.Customer.t(),
:livemode => boolean(),
:return_url => String.t(),
:url => String.t()
}

@type create_params :: %{
:customer => String.t(),
optional(:return_url) => String.t()
}

defstruct [
:id,
:object,
:created,
:customer,
:livemode,
:return_url,
:url
]

@plural_endpoint "billing_portal/sessions"

@spec create(create_params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
def create(params, opts \\ []) do
new_request(opts)
moomerman marked this conversation as resolved.
Show resolved Hide resolved
|> put_endpoint(@plural_endpoint)
|> put_params(params)
|> put_method(:post)
|> make_request()
end
end
1 change: 1 addition & 0 deletions lib/stripe/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Stripe.Converter do
balance
balance_transaction
bank_account
billing_portal.session
card
charge
checkout.session
Expand Down
1 change: 1 addition & 0 deletions lib/stripe/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ defmodule Stripe.Util do
def atomize_key(k), do: k

@spec object_name_to_module(String.t()) :: module
def object_name_to_module("billing_portal.session"), do: Stripe.BillingPortal.Session
def object_name_to_module("checkout.session"), do: Stripe.Session
def object_name_to_module("file"), do: Stripe.FileUpload
def object_name_to_module("issuing.authorization"), do: Stripe.Issuing.Authorization
Expand Down
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ defmodule Stripe.Mixfile do
Stripe.SubscriptionSchedule,
Stripe.TaxRate
],
"Billing Portal": [
Stripe.BillingPortal.Session
],
Connect: [
Stripe.Account,
Stripe.ApplicationFee,
Expand Down
13 changes: 13 additions & 0 deletions test/stripe/billing_portal/session_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Stripe.BillingPortal.SessionTest do
use Stripe.StripeCase, async: true

test "is creatable" do
params = %{
customer: "cus_123",
return_url: "https://stripe.com"
}

assert {:ok, %Stripe.BillingPortal.Session{}} = Stripe.BillingPortal.Session.create(params)
assert_stripe_requested(:post, "/v1/billing_portal/sessions")
end
end