0

在我的控制器上

public function postJoin(Request $request){

    $user=Auth::user();

    $plan=$request['plan'];

    $user->subscription($plan)->create($request['token'],['email'=>$users->email]);
    return Redirect::action('subscripton')->with('notice','Ahora estás registrado');
}

所以错误是“在 null 上调用成员函数 create()”,当我执行

dd($user->subscription($plan));

它也说NULL。

问题是订阅功能。有什么帮助吗?

这是我用 Jquery 发送到条带的地方

$(document).ready(function(){

Stripe.setPublishableKey('MYKEY');

$('#subscription-form button').on('click', function(){
    var form                =   $('#subscription-form');
    var submit              =   form.find('button');
    var submitInitialText   =   submit.text();
    submit.attr('disabled','disabled').text('Espere un momento...');

    Stripe.card.createToken(form, function(status, response){
        var token;
        if (response.error) {
            //esta parte no responde si hay error
            form.find('.stripe-errors').text(response.error.message);
            submit.removeAttr('disabled');
            submit.text(submitInitialText);
        }else{

            token=response.id;
            form.append($('<input type="hidden" name="token">').val(token));
            form.submit();
        }
    });
});

});

我的观点

 @extends('layouts.app')

 @section('content')
 <div class="container">
     <div class="row">
        <div class="col-md-8 col-md-offset-2">
             <div class="panel panel-default">
                 <div class="panel-heading">Suscribirse</div>

            <div class="panel-body">    
                          {{Form::open(array('url'=>'subscription/join','id'=>'subscription-form'))}}


                            @include('subscription.partials.card')
                            <button class="btn btn-primary">Suscribirse</button>
                            <!-- {{Form::submit('Suscribirse',['class'=>'btn btn-primary'])}} -->
            {{Form::token()}}
            {{Form::close()}}
            </div>
        </div>
    </div>
</div>

@endsection

这是我的表单视图

   <div class="stripe-errors panel"></div>
                <div class="form-group">
                     {{Form::label('escoge un plan')}}
                     {{Form::select('plan', ['Premium' => 'Grande ($5,000 MXN)', 'Vip' => 'Vip (5,500 MXN)'],null,['placeholder'=>'escoga un plan','class'=>'form-control'])}}
                </div>
                <div class="form-group">
                     {{Form::label('tarjeta de credito')}}
                     {{Form::text('number',null, ['placeholder'=>'0000-0000-0000-0000','class'=>'form-control','data-stripe'=>'number'])}}
                </div>
                <div class="form-group">
                     {{Form::label('Año de expiracion')}}
                     {{Form::text('año',null, ['placeholder'=>'00','class'=>'form-control','data-stripe'=>'exp-year'])}}
            </div>
            <div class="form-group">
                     {{Form::label('mes de expiracion')}}
                     {{Form::text('mes',null, ['placeholder'=>'00','class'=>'form-control','data-stripe'=>'exp-month'])}}
                </div>
                <div class="form-group">
                     {{Form::label('CVC')}}
                     {{Form::text('cvc',null, ['placeholder'=>'000','class'=>'form-control','data-stripe'=>'cvc'])}}
                </div>      
4

2 回答 2

1

始终检查用户是否登录:

if (auth()->check()) {
    // Do something.
}

另一件事是你应该使用这样的关系:

$user->subscription()->create(....);
于 2017-01-02T06:44:01.100 回答
1

我用这条线解决了问题->

$user->newSubscription('main', $plan)->create($creditCardToken, ['email' =>$email,]);

但现在它显示“此客户没有附加付款来源”。

myDasbord 刷新客户,但没有付款。

于 2017-01-03T04:26:41.843 回答