0

I encounter this problem with stripe and Symfony 4: Must provide source or customer. after to submit my payment request.

I have absolutely no idea how to fix this.

here is my code:

view:

<script                       
 src="https://checkout.stripe.com/checkout.js"
 class="stripe-button"
 data-key="pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"
 data-amount="{{ app.request.request.get('hiddenPrice') * 100 }}"
 data-name="stripe.com"
 data-description="Widget"
 data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
 data-locale="auto"
 data-currency="eur">
</script>

my controller:

\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxx");


        // Get the credit card details submitted by the form

        $token = $request->request->get('stripeToken');


        // Create a charge: this will charge the user's card
        try {
            $charge = \Stripe\Charge::create(array(
                "amount" => 1000, // Amount in cents
                "currency" => "eur",
                "source" => $token,
                "description" => "Paiement Stripe - OpenClassrooms Exemple"
            ));
            $this->addFlash("success","Bravo ça marche !");
            return $this->redirectToRoute("emails");
        } catch(\Stripe\Error\Card $e) {

            $this->addFlash("error","Snif ça marche pas :(");
            return $this->redirectToRoute("payment");
            // The card has been declined
        }

i tried to follow many tutorials but i have failed.

  • Maybe duplicate of https://stackoverflow.com/questions/42500984/stripe-must-provide-source-or-customer – rebru Feb 27 '19 at 18:20
  • 1
    If you're receiving that error it means that the value you're trying to assign to `$token` is empty and thus when Stripe tries to Charge it fails. I'd try to debug by: echo-ing out all post vars, ensure that your front-end
    is posting to the right place.
    – duck Feb 27 '19 at 20:20

0 Answers0