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 send as "payment source" nor am I clear if this is supposed to be sent when creating the customer or when creating the subscription.
I am using the JavaScript embedded code to create the payment pop up:
<form action="payment" method="POST">
<input type="hidden" name="_csrf_token" value="<%= Plug.CSRFProtection.get_csrf_token()%>">
https://checkout.stripe.com/checkout.js
</form>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment