View Source Stripe.Connect.OAuth behaviour (stripity_stripe v3.1.1)

Work with Stripe Connect.

You can:

  • generate the URL for starting the OAuth workflow
  • authorize a new connected account with a token
  • deauthorize an existing connected account

Stripe API reference: https://stripe.com/docs/connect/reference

Link to this section Summary

Functions

Generate the URL to start a Stripe workflow.

De-authorizes the connected account.

Execute the OAuth callback to Stripe using the code supplied in the request parameter of the oauth redirect at the end of the onboarding workflow.

Link to this section Callbacks

@callback authorize_url(map()) :: String.t()
@callback deauthorize_url(url :: String.t()) :: {:ok, map()}
@callback token(code :: String.t()) :: {:ok, map()}

Link to this section Functions

Link to this function

authorize_url(param_options \\ %{}, account_type \\ :standard)

View Source
@spec authorize_url(map(), :standard | :express) :: String.t()

Generate the URL to start a Stripe workflow.

parameter-map-keys

Parameter Map Keys

The parameter map keys are derived from the valid request parameter for the Stripe Connect authorize endpoint. A parameter only needs to be provided if you wish to override the default.

  • :always_prompt
  • :client_id
  • :redirect_uri
  • :response_type
  • :scope
  • :state
  • :stripe_landing
  • :stripe_user

For ease of use, any parameters you provide will be merged into the following default map with sensible defaults. This also allows you to call the function with no parameters and it will fall back to this map:

%{
  client_id: client_id, # :connect_client_id from configuration
  response_type: "code",
  scope: "read_write"
}

example

Example

connect_opts = %{
  state: "2686e7a93156ff5af76a83262ac653",
  stripe_user: %{
    "email" => "local@business.example.net",
    "url" => "http://local.example.net",
    "country" => "US",
    "phone_number" => "5555555678",
    "business_name" => "Jeanine & Jerome's Jellies",
    "businessy_type" => "llc",
    "first_name" => "Jeanine",
    "last_name" => "Smith",
    "dob_day" => 29,
    "dob_month" => 1,
    "dob_year" => 1983,
    "street_address" => "123 Main St.",
    "product_category" => "food_and_restuarants"
  }
}
url = Stripe.Connect.OAuth.authorize_url(connect_opts)
Link to this function

deauthorize(stripe_user_id)

View Source
@spec deauthorize(String.t()) ::
  {:ok, map()}
  | {:error,
     %Stripe.Error{
       code: term(),
       extra: term(),
       message: term(),
       request_id: term(),
       source: term(),
       user_message: term()
     }}

De-authorizes the connected account.

Requires the customer to re-establish the link using the onboarding workflow.

example

Example

iex(1)> {:ok, result} = Stripe.Connect.OAuth.deauthorize(stripe_user_id)
@spec token(String.t(), Stripe.options()) ::
  {:ok, map()}
  | {:error,
     %Stripe.Error{
       code: term(),
       extra: term(),
       message: term(),
       request_id: term(),
       source: term(),
       user_message: term()
     }}

Execute the OAuth callback to Stripe using the code supplied in the request parameter of the oauth redirect at the end of the onboarding workflow.

example

Example

iex(1)> {:ok, resp} = Stripe.Connect.OAuth.token(code)
...(1)> IO.inspect resp
%Stripe.Connect.OAuth.TokenResponse{
    access_token: "ACCESS_TOKEN",
    livemode: false,
    refresh_token: "REFRESH_TOKEN",
    scope: "read_write",
    stripe_publishable_key: "PUBLISHABLE_KEY",
    stripe_user_id: "USER_ID",
    token_type: "bearer"
}