0
을 Javascript
과 함께 사용하려고하는데 신용 카드 데이터가 서버에 제공되지 않습니다.
이렇게하면 항상 "This customer has no attached card
"이라는 오류가 발생합니다.Laravel 4 and Cashier
나는 연구를했으며 보통 이것은 무언가가 Stripe
에 게시되지 않는다는 것을 의미하며 이것이 내 JS의 문제 일 수 있다고 생각합니다.
아래 코드를 게시하고 답변을 얻을 수 있다면 차임하세요.
감사)
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">×</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>   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 : 가능한 모든 도움/통찰력을위한
<?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';
}
}
감사합니다. 당신이 컨트롤러에 양식 데이터를 게시하는 경우
컨트롤러에 입력 값을 전달하는 자바 스크립트 게시물 유형이 표시되지 않습니다. 컨트롤러에 값을 보내지 않아도 제출 및 일부 DOm 조작 만 볼 수 있습니다. –
Levente Nagy - 그것은 내가 생각한 양식에 숨겨진 입력 필드를 추가하여 컨트롤러에 데이터를 게시하고 있습니다. 내가 틀렸다면 나를 바로 잡아주세요. – Craytor