Untitled

 avatar
unknown
plain_text
a month ago
2.3 kB
4
Indexable
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import datetime
import random
import string

class StockXReceipt:
    def __init__(self, platform, item_name, item_price, customer_email, order_number=None, tax_rate=0.08, shipping_fee=10.00):
        self.platform = platform
        self.item_name = item_name
        self.item_price = item_price
        self.tax_rate = tax_rate
        self.shipping_fee = shipping_fee
        self.order_number = order_number or self.generate_order_number()
        self.transaction_id = self.generate_transaction_id()
        self.customer_email = customer_email
        self.date = datetime.datetime.now()

    def generate_order_number(self):
        return ''.join(random.choices(string.ascii_uppercase + string.digits, k=12))

    def generate_transaction_id(self):
        return ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))

    def calculate_tax(self):
        return self.item_price * self.tax_rate

    def calculate_total(self):
        tax = self.calculate_tax()
        total = self.item_price + tax + self.shipping_fee
        return total

    def generate_receipt(self):
        tax = self.calculate_tax()
        total = self.calculate_total()

        receipt = f"""
        {'='*40}
                        {self.platform} Receipt
        {'='*40}
        
        Order Number: {self.order_number}
        Transaction ID: {self.transaction_id}

        Item: {self.item_name}
        Price: ${self.item_price:.2f}

        Tax Rate: {self.tax_rate*100}%  →  Tax: ${tax:.2f}
        Shipping Fee: ${self.shipping_fee:.2f}

        ----------------------------------------
        Total: ${total:.2f}
        
        {'='*40}
        Date: {self.date.strftime('%Y-%m-%d %H:%M:%S')}
        {'='*40}

        Thank you for shopping with {self.platform}!
        """
        return receipt

    def send_email(self, sender_email, sender_password, smtp_server, smtp_port):
        # Generate the email content (receipt)
        email_content = self.generate_receipt()

        # Set up the email
        msg = MIMEMultipart()
        msg['From'] = sender_email
        msg['To'] = self.customer_email
        msg['Subject'] = f"{self.platform} Rec
Leave a Comment