【问题标题】:Stripe PHP subscription error - customer has no attached payment sourceStripe PHP 订阅错误 - 客户没有附加付款来源
【发布时间】:2018-11-07 11:49:14
【问题描述】:

我在前端使用 Stripe Checkout 并收集用户的卡片详细信息,然后在后端使用 Stripe 的 PHP 库为用户订阅预定义的 Stripe 计划。我收到错误

(1/1) InvalidRequest This customer has no attached payment source

并检查 Stripe 仪表板显示用户(Stripe 客户)没有任何关联的卡详细信息,即使我按照文档等将令牌传递给订阅调用。

前端代码(Laravel 模板):

<form action="{{url('subscribe')}}" method="POST" id="stripeform1" class="nodisplay">
{!! csrf_field() !!}
<input type="hidden" name="plan" value="individual">
    <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="my_stripe_test_key"
        data-image="https://myapp.co/public/images/stripeicon.png"
        data-name="MyApp"
        data-zip-code="true"
        data-locale="auto"
        data-email="testemail@test.com"
        data-description="Subscription for Individual Plan"
        data-currency="gbp"
        data-amount="999"
        data-label="Subscribe!">
    </script>
</form>

和后端代码:

\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));

// Create customer that we can then create a subscription or one-off charges for:
$customer = \Stripe\Customer::create(['email' => $request->input['stripeEmail'], 'source'  => $request->input['stripeToken']]);

// Attach user (as Stripe customer) to existing subscription plan defined in Stripe:
if($request->input('plan') == 'individual') $planID = env('STRIPE_INDIVIDUAL_PLAN_ID');
else if($request->input('plan') == 'business') $planID = env('STRIPE_BUSINESS_PLAN_ID');
$subscription = \Stripe\Subscription::create(['customer' => $customer->id, 'items' => [['plan' => $planID]]]);

不知道我哪里出错了。感谢您的任何建议。

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    你必须使用下面的代码来成功订阅,同时创建订阅

    $subscription = \Stripe\Subscription::create(['customer' =&gt; $customer-&gt;id,"trial_end" =&gt; null, 'items' =&gt; [['plan' =&gt; $planID]]]);

    您的请求中有跳过 trial_end 参数。

    【讨论】:

      【解决方案2】:

      $request-&gt;input['stripeToken'] 很可能是空的。我会记录那个服务器端并确认它里面有东西。

      【讨论】:

      • 谢谢,但事实并非如此,因为它被用于创建 Stripe 客户,而且一切正常。
      • 客户没有卡的唯一方法是stripeToken 为空,因此必须是的情况。
      猜你喜欢
      • 2017-03-13
      • 2018-12-13
      • 2019-01-26
      • 2016-05-22
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多