...

/

Coding the Checkout Process

Coding the Checkout Process

Learn how to code the application’s checkout process with Stripe.

InitPayment in Stripe

This lesson walks through the application’s checkout process. Take a look at the <ShoppingCart/> component inside imports/ui/Shoppingcart.jsx. On lines 195–203, we should notice that we’re pushing the user to the /init_payment route. This route renders the <InitPayment/> component.

Open the imports/ui/InitPayment.jsx file. This is the component that’s rendered after clicking the “Checkout” button. The InitPayment component is used to make a Meteor call to the server, which, in turn, makes an API request to Stripe to create a paymentIntent.

The component receives the authenticated and user object props. We want to display two input textboxes for users that are authenticated so that we can collect their names and email addresses. This is done in lines 93–121. The total number of books in the cart is calculated by the sumItems function. Remember that the cart is stored in React context, so we have access to it on our component.

On lines 141–149, there’s a “submit” button that submits the form. Take a look at the onSubmit form function called handlePaymentCheckout. We prevent the default action of a form, which is to submit the ...