Here’s a full version of the guide you can copy and paste directly into your README.md. This document is structured and formatted for easy inclusion in your repository.
This guide explains how to set up a Raspberry Pi to interface with a payment gateway and trigger the dispensing process upon successful payment notifications (e.g., via QR code).
- Raspberry Pi (e.g., Raspberry Pi 3/4).
- MicroSD card (16GB or larger).
- Power supply for the Raspberry Pi.
- Monitor, keyboard, and mouse (for initial setup).
- PLC (Programmable Logic Controller) to control the dispensing system.
- Required cables/connectors for communication between Raspberry Pi and PLC.
- Raspberry Pi OS installed on the microSD card.
- Node.js and npm.
- Stripe account for payment processing (or equivalent payment gateway).
- Stripe CLI for testing (or equivalent testing tools).
- Download the Raspberry Pi Imager from raspberrypi.com.
- Flash the Raspberry Pi OS onto the microSD card.
- Insert the microSD card into the Raspberry Pi and boot it up.
- Open the Raspberry Pi Configuration tool:
sudo raspi-config
- Perform the following configurations:
- Enable SSH for remote access.
- Configure Wi-Fi or Ethernet settings.
- Set the hostname (e.g.,
payment-vending-pi). - Enable interfaces like GPIO, SPI, or Serial if needed for PLC communication.
Run the following commands to ensure the system is updated:
sudo apt update && sudo apt upgrade -yInstall Node.js and npm:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejsInstall Git for version control and repository management:
sudo apt install -y gitNavigate to the home directory and clone the repository:
git clone https://github.com/iZND/Payment-for-Vending-Machine.git
cd Payment-for-Vending-MachineInstall the required Node.js packages:
npm install- Create a
.envfile in the project directory:nano .env
- Add the following configurations (replace placeholders with actual keys):
STRIPE_SECRET_KEY=your_stripe_secret_key STRIPE_WEBHOOK_SECRET=your_webhook_secret PLC_PROTOCOL=modbus # Example: Replace with your PLC protocol
- Start the webhook handler server:
node Webhook_handler-Script1.js
- Use the Stripe CLI to forward test events to the server:
stripe listen --forward-to localhost:4242/webhook
- Identify the protocol supported by your PLC (e.g., Modbus RTU, Modbus TCP, GPIO, or Ethernet).
- Connect the Raspberry Pi to the PLC using the appropriate interface (e.g., GPIO pins, serial connection, or Ethernet cable).
- If using Modbus, install the
modbus-seriallibrary:npm install modbus-serial
- Edit the
sendSignalToPLCfunction in the code to send signals to the PLC:const ModbusRTU = require('modbus-serial'); const client = new ModbusRTU(); function sendSignalToPLC(value) { client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 }) .then(() => client.writeRegister(1, value)) .then(() => console.log('Signal sent to PLC')) .catch(console.error) .finally(() => client.close()); }
- Create a systemd service to run the webhook handler at startup:
sudo nano /etc/systemd/system/payment-vending.service
- Add the following content:
[Unit] Description=Payment Vending Webhook Service After=network.target [Service] ExecStart=/usr/bin/node /home/pi/Payment-for-Vending-Machine/Webhook_handler-Script1.js Restart=always User=pi Group=pi Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production WorkingDirectory=/home/pi/Payment-for-Vending-Machine [Install] WantedBy=multi-user.target
- Enable and start the service:
sudo systemctl enable payment-vending sudo systemctl start payment-vending
Check the status of the service:
sudo systemctl status payment-vendingUse the Stripe CLI to simulate a successful payment:
stripe trigger checkout.session.completedConfirm that the Raspberry Pi sends a signal to the PLC and the dispensing mechanism is triggered.
-
Webhook Server Not Running:
- Check the status of the systemd service:
sudo systemctl status payment-vending
- Restart the service if necessary:
sudo systemctl restart payment-vending
- Check the status of the systemd service:
-
PLC Communication Issues:
- Verify the physical connection between the Raspberry Pi and the PLC.
- Check the protocol configuration in the
sendSignalToPLCfunction.
-
Stripe Webhook Signature Error:
- Ensure the
STRIPE_WEBHOOK_SECRETin the.envfile matches your Stripe settings.
- Ensure the
Feel free to contribute to this project by submitting issues or pull requests. Follow the standard GitHub workflow for contributions.
This project is licensed under the MIT License. See the LICENSE file for more information.
This guide ensures a smooth setup process for the Raspberry Pi and payment gateway integration. Let me know if you'd like to refine or customize it further!
This project implements a webhook handler using Node.js to process Stripe payment events. It listens for Stripe webhook events, validates them, and processes successful payment events to send signals to a PLC (Programmable Logic Controller).
- Listens for Stripe webhook events on a specified endpoint.
- Validates incoming webhook events using Stripe's signature.
- Processes
checkout.session.completedevents to handle successful payments. - Sends a signal to a PLC with the payment amount.
- Node.js: Ensure you have Node.js installed. You can download it from Node.js official website.
- Stripe Account: You need a Stripe account to obtain your API keys and webhook secret.
- Clone or download this repository.
- Navigate to the project directory:
- Install the required dependencies:
- Replace the placeholders in the script with your actual Stripe keys:
your_stripe_secret_key: Your Stripe secret key.your_webhook_secret: Your Stripe webhook secret.
- Start the server:
- The server will start listening on port
4242.
- Use the Stripe CLI to forward events to your local server:
- The server will start listening on port
4242.
- Use the Stripe CLI to forward events to your local server:
- Trigger a test event using the Stripe CLI:
- The script listens for POST requests on the
/webhookendpoint. - It validates the incoming request using the
stripe-signatureheader and the webhook secret. - If the event type is
checkout.session.completed, it extracts the payment amount and sends a signal to the PLC using thesendSignalToPLCfunction.
- Dependencies:
express: For creating the server and handling HTTP requests.body-parser: For parsing raw JSON payloads.stripe: For validating and processing Stripe webhook events.
- Key Functions:
sendSignalToPLC(tokens): Sends a signal to the PLC with the payment amount.
- Ensure your firewall or antivirus software does not block port
4242. - This script assumes the payment amount is in cents and converts it to dollars before sending it to the PLC.
This project is licensed under the MIT License.