Elixir 条纹长生不老药如何获得;“付款来源”;
我使用此软件包将Stripe整合到phoenix应用程序中:Elixir 条纹长生不老药如何获得;“付款来源”;,elixir,phoenix-framework,stripe.js,stripe-elixir,Elixir,Phoenix Framework,Stripe.js,Stripe Elixir,我使用此软件包将Stripe整合到phoenix应用程序中: 我正在尝试创建一个订阅计划的客户 defmodule StripeTestWeb.PaymentController do use StripeTestWeb, :controller use Stripe.API def index(conn, %{"stripeEmail" => email} = _params) do {:ok, customer_data} = Stripe.Customer.
我正在尝试创建一个订阅计划的客户
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
客户已创建,但请求在尝试创建订阅时返回错误。错误是:
{
"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"
}
}
我不知道API希望我作为“付款来源”发送什么,也不清楚这是在创建客户还是在创建订阅时发送的
我正在使用JavaScript嵌入代码创建付款弹出窗口:
<form action="payment" method="POST">
<input type="hidden" name="_csrf_token" value="<%= Plug.CSRFProtection.get_csrf_token()%>">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_2vzqy4IW9zHAYyKSjDNZkd2l"
data-amount="14900"
data-name="Demo Site"
data-description="Subscription $149"
data-locale="auto">
</script>
</form>
我不熟悉Stripe Elixir,但在Stripe上创建客户时,您可以传递
源代码,因此请尝试通过您的create调用传递该源代码
defmodule StripeTestWeb.PaymentController do
use StripeTestWeb, :controller
use Stripe.API
def index(conn, %{"stripeEmail" => email, "stripeToken" => stripe_token} = _params) do
{:ok, customer_data} = Stripe.Customer.create(%{email: email, source: stripe_token})
Stripe.Subscription.create(%{
customer: customer_data["id"],
items: [%{plan: "plan_D9JehUOiyPGtgp"}]
})
render(conn, "index.html")
end
end
是的,我明白了,我正要回答我自己的问题。