Posts

Showing posts with the label elixir

Stripe-Elixir How to get “payment source”

Stripe-Elixir How to get “payment source” I am trying to create a customer that subscribes to a plan. defmodule StripeTestWeb.PaymentController do use StripeTestWeb, :controller use Stripe.API def index(conn, %{"stripeEmail" => email} = _params) do {:ok, customer_data} = Stripe.Customer.create(%{email: email}) Stripe.Subscription.create(%{ customer: customer_data["id"], items: [%{plan: "plan_D9JehUOiyPGtgp"}] }) render(conn, "index.html") end end The customer is created but the request returns an error when trying to create the subscription. The error is: { "error": { "code": "resource_missing", "doc_url": "https://stripe.com/docs/error-codes/resource-missing", "message": "This customer has no attached payment source", "type": "invalid_request_error" } } I don't know what the API expects me to se...