| | |
| | from square.client import Client |
| | import os |
| | from dotenv import load_dotenv |
| | import uuid |
| | import datetime |
| |
|
| | load_dotenv() |
| |
|
| |
|
| | now = datetime.datetime.utcnow() |
| | formatted_time = now.isoformat(timespec='microseconds') |
| | |
| | client = Client( |
| | access_token=os.environ['SQUARE_ACCESS_TOKEN'], |
| | environment='sandbox' |
| | ) |
| |
|
| | |
| | food_items = { |
| | "pizza": 10.00, |
| | "burger": 8.00, |
| | "salad": 6.00, |
| | "orange juice": 2.00, |
| | "iced tea": 3.00, |
| | "Ice coffee": 3.00, |
| | "Chicken": 5.00, |
| | "Steak": 10.00, |
| | "Mashed Potatoes": 4.00, |
| | "Soup": 2.00, |
| | "Sandwich": 5.50, |
| | "Pasta": 3.50, |
| | "Coffee": 3.00, |
| | "Cappuccino": 3.00, |
| | "Latte": 3.00, |
| | "Americano": 3.00, |
| | "Hot Chocolate": 3.00, |
| | "Muffin": 4.00, |
| | "Cookie": 2.00, |
| | "Croissant": 3.00, |
| | "Tea": 2.00, |
| | "Apple Juice": 2.00 |
| | } |
| |
|
| | |
| | for name, price in food_items.items(): |
| | idempotency_key = str(uuid.uuid4()) |
| |
|
| | |
| | variation = { |
| | 'type': 'ITEM_VARIATION', |
| | 'id': f'#{str(uuid.uuid4())}', |
| | 'item_variation_data': { |
| | 'item_id': f'#{name}', |
| | 'pricing_type': 'FIXED_PRICING', |
| | 'price_money': { |
| | 'amount': int(price * 100), |
| | 'currency': 'USD' |
| | } |
| | } |
| | } |
| |
|
| | |
| | catalog_object = { |
| | 'idempotency_key': idempotency_key, |
| | 'object': { |
| | 'id': f'#{name}', |
| | 'type': 'ITEM', |
| | 'item_data': { |
| | 'name': name, |
| | 'variations': [variation] |
| | } |
| | } |
| | } |
| | response = client.catalog.upsert_catalog_object(body=catalog_object) |
| | print("\nCATALOGUE STATUS:", response.status_code) |
| | print("\nCATALOGUE RESPONSE:", response.body) |
| | catalog_object_id = response.body['catalog_object']['item_data']['variations'][0]['id'] |
| | created_at = response.body['catalog_object']['created_at'] |
| | |
| | inventory_adjustment = { |
| | 'idempotency_key': idempotency_key, |
| | 'changes': [ |
| | { |
| | 'type': 'PHYSICAL_COUNT', |
| | 'physical_count': { |
| | 'catalog_object_id': catalog_object_id, |
| | 'state': 'IN_STOCK', |
| | 'location_id': 'LFA70NPRQAEV1', |
| | 'quantity': '53', |
| | 'occurred_at': created_at |
| | } |
| | } |
| | ], |
| | 'ignore_unchanged_counts': True |
| | } |
| |
|
| | |
| | try: |
| | response = client.inventory.batch_change_inventory( |
| | inventory_adjustment) |
| | print("\nINVENTORY STATUS:", response.status_code) |
| | print("\nINVENTORY RESPONSE", response.body) |
| | print(f"Added {name} to inventory successfully.") |
| | except: |
| | continue |
| |
|
| |
|