简体   繁体   English

Laravel 4和收银员

[英]Laravel 4 and Cashier

I am trying to use Laravel Cashier with Javascript so credit card data is not posed to the server. 我正在尝试将Laravel CashierJavascript结合使用,以便不将信用卡数据提交给服务器。
When I do this, I always get an error that says " This customer has no attached card ". 当我这样做时,我总是得到一个错误,指出“ This customer has no attached card ”。

I have done research and this usually means something is not being posted to Stripe , and I think this might be an issue with my JS. 我已经进行了研究,这通常意味着某些东西没有发布到Stripe ,并且我认为这可能是我的JS的问题。
I'm going to post my code below, and please chime in if you may have an answer! 我将在下面发布我的代码,如果您有答案,请输入提示音!

Thanks ;) 谢谢 ;)

signup.blade.php signup.blade.php

@extends("masters.default")

@section("content")

@if( $errors->any() )
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
        {{ implode("", $errors->all('<p>:message</p>') ) }}
    </div>
@endif

<div id="signupbox" style="margin-top:50px" class="mainbox mainbox col-md-8 col-md-offset-2 col-sm-8 col-sm-offset-2">
    <div class="panel panel-info">
        <div class="panel-heading">
            <div class="panel-title">Sign Up</div>

            <div style="float:right; font-size: 85%; position: relative; top:-10px">
                {{ HTML::link( '/login', 'Login' ) }}
            </div>
        </div>  
        <div class="panel-body" >
            {{ Form::open( [ 'route' => 'signup.store', 'class' => 'form-horizontal', 'role' => 'form', 'id' => 'subscription-form' ] )}}
                <div class="payment-errors"></div>
                <div id="signupalert" style="display:none" class="alert alert-danger">
                    <p>Error:</p>
                    <span></span>
                </div>

                <div class="form-group">
                    {{ Form::label( 'subscription', 'Subscription plan', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-9">
                        {{ Form::select( 'subscription' , [ 'basic' => '(BASIC) 10$ per month', 'gold' => '(GOLD) 40$ per month' ], 'gold', [ 'class' => 'form-control' ])}}
                    </div>
                </div>

                <div class="form-group">
                    {{ Form::label( 'email', 'Email', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-9">
                        {{ Form::email('email', '', [ 'class' => 'form-control', 'placeholder' => 'Email address' ])}}
                    </div>
                </div>

                <div class="form-group">
                    {{ Form::label( 'password', 'Password', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-9">
                        {{ Form::password('password', [ 'class' => 'form-control', 'placeholder' => 'Password' ])}}
                    </div>
                </div>

                <div class="form-group">
                    {{ Form::label( 'password_confirmation', 'Re-type Password', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-9">
                        {{ Form::password('password_confirmation', [ 'class' => 'form-control', 'placeholder' => 'Re-type Password' ])}}
                    </div>
                </div>

                <div class="divider"></div>

                <div class="form-group">
                    {{ Form::label( 'ccn', 'Credit card number', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-9">
                        {{ Form::text('ccn', '', [ 'class' => 'form-control', 'data-stripe' => 'number' ])}}
                    </div>
                </div>

                <div class="form-group">
                    {{ Form::label( 'expiration', 'Expiration date', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-6">
                        {{ Form::selectMonth('month', 'junuary', [ 'class' => 'form-control', 'data-stripe' => 'exp-month' ])}}
                    </div>
                    <div class="col-md-3">
                        {{ Form::selectRange('year', 2014, 2029, 2014, [ 'class' => 'form-control', 'data-stripe' => 'exp-year' ])}}
                    </div>
                </div>

                <div class="form-group">
                    {{ Form::label( 'cvc', 'CVC number', [ 'class' => 'col-md-3 control-label' ])}}
                    <div class="col-md-3">
                        {{ Form::text('cvc', '', [ 'class' => 'form-control', 'data-stripe' => 'cvc' ])}}
                    </div>
                </div>

                <div class="form-group">
                    <!-- Button -->                                        
                    <div class="col-md-offset-3 col-md-9">
                        {{ Form::button('<i class="glyphicon glyphicon-hand-right"></i> &nbsp Sign Up', [ 'type' => 'submit', 'id'  => 'btn-signup', 'class' => 'btn btn-info'] ) }}
                    </div>
                </div>
            {{ Form::close() }}
         </div> <!-- Panel body -->
    </div> <!-- Panel -->
 </div> <!-- Signup box -->

<script type="text/javascript" src="https://js.stripe.com/v2/"></script>

<script>
    Stripe.setPublishableKey('pk_test_HdoLAxfuWl53vjchF01fMphS ');
    jQuery(function($) {
        $('#subscription-form').submit(function(event) {
            var $form = $(this);

            // Disable the submit button to prevent repeated clicks
            $form.find('button').prop('disabled', true);

            Stripe.card.createToken($form, stripeResponseHandler);

            // Prevent the form from submitting with the default action
            return false;
        });
    });

    var stripeResponseHandler = function(status, response) {
        var $form = $('#subscription-form');

        if (response.error) {
            // Show the errors on the form
            $form.find('.payment-errors').text(response.error.message);
            $form.find('button').prop('disabled', false);
        } else {
            // token contains id, last4, and card type
            var token = response.id;
            // Insert the token into the form so it gets submitted to the server
            $form.append($('<input type="hidden" name="stripeToken" />').val(token));
            // and submit
            $form.get(0).submit();
        }
    };
</script>
@stop

SignupController: SignupController:

<?php

class SignupController extends BaseController{

    public function index( ){
        if( Auth::check() )
            return Redirect::to("/");

        return View::make('signup');
    }

    public function store(){
        $user = new User;
        $user->email = Input::get( 'email' );
        $user->password = Hash::make( Input::get( 'password' ) );
        $user->save();
        $user->subscription(Input::get( 'subscription' ))->create( Input::get( 'stripeToken' ) );

        return 'you are now registred';
    }

}

Thanks for any possible help/insight. 感谢您提供任何可能的帮助/见解。

If you're posting form data to a controller you could try this: 如果要将表单数据发布到控制器,则可以尝试以下操作:

{{ Form::open(array('url' => 'subscribe_route', 'class' => 'form-horizontal', 
'method' => 'POST', 'action' => 'SignupController@store')) }}

This method works best for me. 这种方法最适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM