【发布时间】:2014-07-09 11:46:32
【问题描述】:
我希望为我的用户提供在使用 Stripe 注册时输入抄送的选项。我收到错误:
ErrorException
Undefined index: stripeToken
任何帮助将不胜感激。先感谢您。
控制器:
public function getStripe()
{
// get the contractor
$arrPageData['contractor'] = Contractor::find($this->userID);
// show the cc form and pass the contractor
return View::make('contractors.stripe', $arrPageData);
}
public function postStripe()
{
//posting logic goes here.
Stripe::setApiKey("sk_test_xxxx");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = Input::get('email');
// Create a Stripe Record
$stripe = new Stripe;
$stripe->card = $token;
$stripe->email = $email;
$stripe->save();
}
承包商型号:
function stripes() {
return $this->hasOne('Stripe');
}
条纹模型:
public function contractor() {
return $this->belongsTo('Contractor', 'contractor_id');
}
我的视图文件格式为:
//**This is edited to work now**
<script type="text/javascript">
// This identifies your website in the createToken call below
Stripe.setPublishableKey('pk_test_xxxx');
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-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 re-submit
$form.get(0).submit();
}
};
jQuery(function($) {
$('#payment-form').submit(function(e) {
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;
});
});
</script>
<form action="" method="POST" id="payment-form">
<span class="payment-errors"></span>
<div class="form-row">
<input type="text" size="20" placeholder="Card Number" data-stripe="number"/>
</div>
<div class="form-row">
<input type="text" size="4" placeholder="CVC" data-stripe="cvc"/>
</div>
<div class="form-row">
<input type="text" size="2" placeholder="Expiration Month (MM)" data-stripe="exp-month"/>
<span> / </span>
<input type="text" size="4" placeholder="Expiration Year (YYYY)" data-stripe="exp-year"/>
<input type="hidden" name="email" value="{{$contractor->email}}" />
</div>
<input type="submit" class="btn btn-primary"/>
</form>
我一定是少了一步。我虽然表单提交是由 js 文件处理的,但我需要做的就是在我的数据库中记录令牌。
【问题讨论】:
标签: php laravel laravel-4 stripe-payments