im trying to working on this project https://www.youtube.com/watch?v=bu0J-j5qYas so i can charge multiple times with dummy credit-card. But i got exception error message when i try to check out, it say must provide source or customer, below is the javascript i wrote.
Stripe.setPublishableKey(''); // im not showingt this key (censored)
var $form = $('#checkout-form');
$form.submit(function(event) {
$('#charge-error').addClass('hidden');
$form.find('button').prop('disabled', true);
Stripe.card.createToken({
number: $('#card-number').val(),
cvc: $('#card-cvc').val(),
exp_month: $('#card-expiry-month').val(),
exp_year: $('#card-expiry-year').val(),
name: $('#card-name').val()
}, stripeResponseHandler);
return false;
});
function stripeResponseHandler(status, response) {
if (response.error) {
$('#charge-error').removeClass('hidden');
$('#charge-error').text(response.error.message);
$form.find('button').prop('disabled', false);
} else {
var token = response.id;
$form.append($('<input type="hidden" name="stripeToken" />').val(token)); // this will generate the stripeToken
// Submit the form:
$form.get(0).submit();
}
}
and i make this functionc below inside the controller directory just like the guide say
public function postCheckout(Request $request)
{
if (!Session::has('cart')) {
return redirect()->route('shop.shoppingCart');
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
Stripe::setApiKey(''); // not showing this key (censored)
try {
Charge::create(array(
"amount" => $cart->totalPrice * 100,
"currency" => "usd",
"source" => $request->input('stripeToken'), // obtained with first code i wrote above
"description" => "Test Charge"
));
} catch (\Exception $e) {
return redirect()->route('checkout')->with('error', $e->getMessage());
}
Session::forget('cart');
return redirect()->route('product.index')->with('success', 'Successfully purchased products!');
}
}
it keep return the catch that throw exception error message, is this mean it failed to get the stripetoken, how am i suppose to fix this? please help me