Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 11, 2022 04:21 pm GMT

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 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 havent 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 devices screen using setReaderDisplay, you can clear it using clearReaderDisplay(). This will bring the screen back to its original state.

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

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

And heres 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 youd 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 shes not coding, she enjoys spending time outdoors, trying new beers and reading.


Original Link: https://dev.to/stripe/how-to-display-cart-details-on-stripe-terminal-jg1

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To