0

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

Matthias Wiehl
  • 1,799
  • 16
  • 22
  • What's in $request? Are you sure the token is there? If not, what else is in there? You need to dump the data to be able to debug this. For example `var_dump($request);` at the beginning of the function. – koopajah Dec 11 '16 at 15:31

2 Answers2

0

hi i think i figured out the problem, i rest the the api keys and also i check your spaces between the quotation marks in the public and secret keys, Stripe.setPublishableKey('pk_anjndjxnh8hih9u220822'); and Stripe::setApiKey('sk_dkneijhf9u9ue9ujednf9hefnie'); // not showing this key (censored)

0

try this Stripe: Must provide source or customer it is work for me!

just adding script with jquery-3.1.1.min.js like <script type="text/javascript" src="/javascripts/jquery-3.1.1.min.js"></script> before calling your checkout js file.