Stripe: Must provide source or customer
Maybe I was also referring to same video lectures as you and I encountered the same problem. I just made changes in the /checkout
route(post request) in index.js file. Replace source: req.body.stripeToken
with source: "tok_mastercard"
and it worked for me, but I'm not sure about the reason behind this.
So I emailed the Stripe support team for help on this issue a few days ago and finally got the solution.
The error was actually in the front-end side. I did not reference jquery under the checkout form. I was able to fix the whole thing by simply adding
<script type="text/javascript" src="/javascripts/jquery-3.1.1.min.js"></script>
before calling the checkout.js file. My checkout form works now.
Huge props to Stripe for going above and beyond with their support!
A payment flow with Stripe is divided in two steps:
Client-side, in your frontend code, you collect and tokenize the customer's payment information using Checkout or Elements, then send the resulting token to your backend server.
Server-side, in your backend code, you use the token in an API request, e.g. to create a charge or a customer.
The code you shared is for the first step. However, the error message you mentioned:
Must provide source or customer.
occurs in the second step. This error is returned by Stripe's API when you send a charge creation request without a source
or customer
parameter.
You need to check your server-side code to figure out what the problem is exactly. You can also check the logs of all requests sent by your integration in your dashboard: https://dashboard.stripe.com/test/logs?method=not_get.