Case Study - For Vending Machine Operators
Simplifying Vending Machine Payments with SolanaPay
For vending machine operators looking to modernize their payment systems, integrating Snacks on Solana is a game-changer. Contact us today to upgrade your machines and join the future of fast, secure, and convenient payments with SolanaPay.
Backend Server Setup
Requirements
- A server with Python 3.x installed.
- Internet connectivity.
- The following Python libraries: Flask, Solana, QRCode, Requests.
Installation Steps
-
Install Python Libraries:
pip install flask solana qrcode[pil] requests
-
Create the Server Script: Save the following script as
server.py
:from flask import Flask, request, jsonify from solana.rpc.api import Client from solana_pay import create_payment_url import qrcode import os app = Flask(__name__) client = Client("https://api.mainnet-beta.solana.com") @app.route('/generate_payment', methods=['POST']) def generate_payment(): data = request.json item_price = data['item_price'] recipient_wallet = data['recipient_wallet'] memo = os.urandom(16).hex() payment_request = { "recipient": recipient_wallet, "amount": item_price, "label": "Necta Vending", "message": "Purchase at Necta Vending", "memo": memo } payment_url = create_payment_url(payment_request) qr = qrcode.QRCode(version=1, box_size=10, border=5) qr.add_data(payment_url) qr.make(fit=True) img = qr.make_image(fill='black', back_color='white') qr_code_path = f'qr_codes/{memo}.png' img.save(qr_code_path) return jsonify({"payment_url": payment_url, "qr_code_path": qr_code_path, "memo": memo}) @app.route('/verify_payment', methods=['POST']) def verify_payment_status(): data = request.json memo = data['memo'] result = client.get_signatures_for_address('YOUR_SOLANA_WALLET_ADDRESS', limit=10) for signature_info in result['result']: transaction = client.get_confirmed_transaction(signature_info['signature']) for instruction in transaction['result']['transaction']['message']['instructions']: if 'data' in instruction and memo in instruction['data']: return jsonify({"status": "verified"}) return jsonify({"status": "not_verified"}), 404 if __name__ == '__main__': os.makedirs('qr_codes', exist_ok=True) app.run(host='0.0.0.0', port=5000)
Running the Server
- Start the Server:
python server.py
- Verify Server Running: Ensure the server is running by accessing
http://your-server-ip:5000
from a browser or using a tool likecurl
.
Vending Machine Client Setup
Requirements
- A vending machine with Python 3.x installed.
- Internet connectivity.
- The Requests library for Python.
Installation Steps
-
Install Python Libraries:
pip install requests
-
Create the Client Script: Save the following script as
vending_machine.py
:import requests import time SERVER_URL = "http://your-server-ip:5000" def get_payment_url(item_price): url = f"{SERVER_URL}/generate_payment" payload = { "item_price": item_price, "recipient_wallet": "YOUR_SOLANA_WALLET_ADDRESS" } try: response = requests.post(url, json=payload) response.raise_for_status() data = response.json() print(f"Payment URL: {data['payment_url']}") print(f"QR Code saved at: {data['qr_code_path']}") return data['memo'] except requests.RequestException as e: print(f"Error generating payment URL: {e}") return None def verify_payment(memo): url = f"{SERVER_URL}/verify_payment" payload = {"memo": memo} try: response = requests.post(url, json=payload) response.raise_for_status() result = response.json() if result['status'] == "verified": print("Payment verified") return True else: print("Payment not found or not confirmed") return False except requests.RequestException as e: print(f"Error verifying payment: {e}") return False def main(): items = { "A1": 0.5, "A2": 0.75, "A3": 1.0, "B1": 1.25, "B2": 1.5, "B3": 2.0 } while True: print("Available items:") for slot, price in items.items(): print(f"Slot: {slot}, Price: {price} SOL") selected_slot = input("Select an item slot (e.g., A1): ").strip().upper() if selected_slot not in items: print("Invalid slot selected. Try again.") continue item_price = items[selected_slot] print(f"Selected item price: {item_price} SOL") memo = get_payment_url(item_price) if not memo: continue print("Scan the QR code with your Solana wallet to make the payment.") payment_verified = False for _ in range(12): time.sleep(5) if verify_payment(memo): payment_verified = True break if payment_verified: print(f"Dispensing item from slot {selected_slot}...") time.sleep(3) print("Item dispensed.") else: print("Payment verification failed.") time.sleep(5) if __name__ == '__main__': main()
Running the Client Script
- Start the Client Script:
python vending_machine.py
Using the Vending Machine
Selecting an Item
- Item Selection:
- On the vending machine interface, the user is presented with a list of available items and their corresponding slots.
- The user selects an item by entering the slot number (e.g., A1).
Making a Payment
- Payment URL Generation:
- Upon item selection, the client script requests a payment URL and QR code from the backend server.
- The user scans the QR code with their Solana wallet to initiate the payment.
Verifying Payment and Dispensing
- Payment Verification:
- The system continuously polls the backend server to verify the transaction status using the memo identifier.
- Once the payment is verified, the vending machine dispenses the selected item.
- If the payment is not verified within a minute, the transaction is marked as failed.
Maintenance and Troubleshooting
Regular Maintenance
- Check System Updates: Regularly check for updates to the backend server and client script to ensure compatibility and security.
- Monitor Performance: Use monitoring tools to track system performance and identify potential issues.
Troubleshooting Common Issues
- Payment Verification Fails:
- Ensure the backend server is running and accessible.
- Check the Solana blockchain for the transaction status.
- QR Code Not Displayed:
- Verify the connection between the vending machine and the backend server.
- Check for errors in the client script.
Advanced Configuration
Webhooks
- Real-Time Updates:
- Implement webhooks for real-time payment status updates to avoid polling.
Inventory Management
- Automated Tracking:
- Integrate inventory management to track and restock items automatically.
Security Best Practices
- Use HTTPS: Encrypt communication between the vending machine and the backend server.
- Input Validation: Ensure all inputs are validated to prevent injection attacks and other security vulnerabilities.
- Authentication: Implement authentication mechanisms to restrict access to the backend server and sensitive functionalities.
Supported Vending Machine Models
- Necta KREA Touch
- Necta KORO Prime
- Necta KARISMA
- Necta Krea Prime
- Necta Solista
- Necta Opera
- Necta Concerto
- Necta Canto
- Necta Festival
- Necta Samba
- Necta Melodia
- Necta Diesis
- Necta Sfera
- Necta Astro
- Necta Snakky Max
- Necta Tango
- Necta Vivace
- Necta Orchestra
- Necta Zenith
- Necta Jazz
Other Supported Models
- Saeco Cristallo 600
- Saeco Iperautomatica
- Saeco Atlante 500
- Saeco Diamante
- Saeco Rubino 200
- Saeco Phedra
- Saeco Idea Restyle
- Crane Merchant Media
- Crane BevMax 4
- Crane BevMax Media
- Jofemar Vision
- Jofemar Goya
- Jofemar Coffeemar Bluetec
- Jofemar Artic
- Jofemar Nereo
- Azkoyen Palma
- Azkoyen Zen
- Azkoyen Heleo
- Azkoyen Mistral
- Azkoyen Zensia
By embracing thesw innovative scripts, vending machine Owners can significantly enhance their service, providing a modern, crypto-friendly payment option that meets the needs of today's tech-savvy consumers.