In the last blog post we saw how to add a product to a shopping cart. This was done by pressing a button in Node-RED which was admittedly not that exciting. Therefore I will now show you some triggers which add something to a shopping cart and also to do the checkout.
Lets trigger the triggers
We’ve already seen the inject node as a trigger and Node-RED has more. At some Hybris Labs prototypes we are using the following nodes:
With MQTT you have an MQTT broker (server) where one or more clients can connect, send a message to a topic and subscribe to this or other topics. This allows, for example, an IoT device to send a temperature value for a specific topic (e.q. /labs/desk7/temperature) and for another device to subscribe to this topic and get notified when that new message arrives. Our Hybris Labs Moto prototype detects when someone is standing in front of a Moto device and sends a presence notification to an MQTT broker. An MQTT node could subscribe to this topic, a change node creates a product id for the product by ID node, which then adds a product to the shopping cart.
Node-RED has a twitter node where you can connect your Twitter ID, select where to search (e.g. all public tweets, follower, specific user or direct message) and what to search for. This allows you to add a product to a shopping cart when someone tweets about your product. In this case you can also use the change node to create the correct product id.
One of our demos uses a big blue button to do a checkout. The button has an Arduino inside which is connected via USB to a laptop where Node-RED is running. The Arduino nodes for Node-RED are also installed like the YaaS nodes. For further information on how to install it, take a look at Interacting with Arduino.
So, every time the button is pressed the node triggers an event. From a ‘mechanical’ point of view, a button is made out of some metal and there will be lots of connections made the moment the metal points comes into contact. The magic is to get only one connection – called debouncing – and you can do it with the delay node:
When you now press the button the first event gets through and the others are blocked for a second. This is fine, as a maximum of one checkout per second should be adequate :)
Talking about checkout – let’s play with the checkout node.
If you’ve setup a new YaaS project, you also have to do some configuration in the YaaS Builder for the Commerce Settings:
- Payment Settings: setup a stripe.com account
- Shipping Settings: define a zone and shipment method
I also recommend to do a checkout on the shop and fill out the customer name (next to the email address) and add a shipping address.
Now we can drag & drop the checkout node in our flow and configure it. We already have Customer and YaaS Credentials. For the Stripe Credentials you have to use the “Test Publishable Key” from your stripe account. You can find test credit card numbers and more information on the stripe documentation page.
After connecting the output of the delay node with the checkout node and the output with a debug node, you should see an order id, when the big blue button is pressed.
In my next blog post I’ll go into PubSub and who we can listen to an order event.
- API description for checkout
- Hybris Expert Forum: Activate Stripe Connect