How to display cart details on Stripe Terminal

Recently, my colleague Charles Watkins wrote a 4-part intro series to Stripe Terminal, our in-person payment solution. Charles’ articles will teach you how to set up and register a Terminal device and build an app to accept or cancel payments. Let’s ta…


This content originally appeared on DEV Community and was authored by Charlie Gerard

Recently, my colleague Charles Watkins wrote a 4-part intro series to Stripe Terminal, our in-person payment solution. Charles' articles will teach you how to set up and register a Terminal device and build an app to accept or cancel payments. Let's take it a step further and look into an additional feature: displaying the cart items on the Terminal device so your customers can verify what they are purchasing and make any changes if needed.

Listing items

If you haven’t built an application for Terminal yet, check out the previous series or the integration builder in our docs.

You should have a terminal variable created with StripeTerminal.create() on the client side that you can call the setReaderDisplay method on. This method takes a DisplayInfo object as input, like shown below:

terminal.setReaderDisplay({
   type: "cart",
   cart: {
     line_items: [
       {
         description: "Soy Cappuccino",
         amount: 550,
         quantity: 1,
       },
       {
         description: "Avocado on toast",
         amount: 1150,
         quantity: 1,
       },
     ],
     tax: 100,
     total: 1700,
     currency: "usd",
   },
});

In the line_items array, you can add details about the products, including a description, amount and quantity.
You can also specify the currency, tax amount and total amount.

Below is an example of what the cart display looks like on the BBPOS WisePOS E reader:

Terminal reader showing 2 items and the total price

Clearing the display

After updating the device’s screen using setReaderDisplay, you can clear it using clearReaderDisplay(). This will bring the screen back to its original state.

For example, here’s what the code would look like to clear the display by clicking on a button:

document.getElementById("clear-button").onclick = () => {
 terminal.clearReaderDisplay();
};

And here’s what would happen on the Terminal device:

GIF showing a demo UI on an iPad, next to the Terminal reader. I am clicking on buttons to show the cart details on the terminal and then clear the screen.

Now, you should be able to display cart items on the Terminal device, update them and clear the screen!

If you’d like to learn more, feel free to check out the Terminal API reference or the "Get paid IRL" blog post series.

📣 Follow @StripeDev and our team on Twitter
📺 Subscribe to our Youtube channel
💬 Join the official Discord server
📧 Sign up for the Dev Digest

About the author

Charlie's profile picture

Charlie Gerard is a Developer Advocate at Stripe, a creative technologist and Google Developer Expert. She loves researching and experimenting with technologies. When she’s not coding, she enjoys spending time outdoors, trying new beers and reading.


This content originally appeared on DEV Community and was authored by Charlie Gerard


Print Share Comment Cite Upload Translate Updates
APA

Charlie Gerard | Sciencx (2022-07-11T16:21:45+00:00) How to display cart details on Stripe Terminal. Retrieved from https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/

MLA
" » How to display cart details on Stripe Terminal." Charlie Gerard | Sciencx - Monday July 11, 2022, https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/
HARVARD
Charlie Gerard | Sciencx Monday July 11, 2022 » How to display cart details on Stripe Terminal., viewed ,<https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/>
VANCOUVER
Charlie Gerard | Sciencx - » How to display cart details on Stripe Terminal. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/
CHICAGO
" » How to display cart details on Stripe Terminal." Charlie Gerard | Sciencx - Accessed . https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/
IEEE
" » How to display cart details on Stripe Terminal." Charlie Gerard | Sciencx [Online]. Available: https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/. [Accessed: ]
rf:citation
» How to display cart details on Stripe Terminal | Charlie Gerard | Sciencx | https://www.scien.cx/2022/07/11/how-to-display-cart-details-on-stripe-terminal/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.