auto create shopify discount code and moved to secrets

main
alex 2024-07-24 17:43:48 +02:00
parent fb16516ddb
commit 049084f705
5 changed files with 25 additions and 30 deletions

View File

@ -15,11 +15,6 @@
"type": "text",
"displayName": "E-Mail vom Kunden"
},
{
"parameterName": "voucher_code",
"type": "text",
"displayName": "Gutscheincode für den Kunden (in Shopify erstellen)"
},
{
"parameterName": "voucher_type",
"type": "select",

View File

@ -16,35 +16,26 @@ STATIC_PATH = "../../groupsData/shx-order-voucher-code-activated/"
json_object = json.loads(sys.argv[1])
customer_email = json_object["customer_email"]
voucher_code = json_object["voucher_code"]
voucher_type = json_object["voucher_type"]
if (customer_email is None
or voucher_code is None
or voucher_type is None):
if customer_email is None or voucher_type is None:
print("Missing required parameters")
sys.exit(1)
customer_email = customer_email["value"]
voucher_code = voucher_code["value"]
voucher_type = voucher_type["value"]
def load_email_config(filename):
with open(filename, "r") as f:
config = yaml.safe_load(f)
return config["email"], config["smtp"]
email_config, smtp_config = load_email_config(f"{STATIC_PATH}config.yml")
secrets = utils.get_secrets()["email"]
# extract the email parameters
auth_email = email_config["auth_email"]
from_email_name = email_config["from_email_name"]
from_email = email_config["from_email"]
password = email_config["password"]
auth_email = secrets["auth_email"]
from_email_name = secrets["from_email_name"]
from_email = secrets["from_email"]
password = secrets["password"]
# extract the smtp parameters
smtp_server = smtp_config["server"]
smtp_port = smtp_config["port"]
smtp_server = secrets["smtp_server"]
smtp_port = secrets["smtp_port"]
receiver_email = customer_email
@ -66,16 +57,24 @@ with open(f"{STATIC_PATH}email.html", "r") as file:
if voucher_type == "5 €":
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, uns zu bewerten. Deine Meinung ist uns sehr wichtig und hilft uns, unseren Service stetig zu verbessern."
price = "5"
discount_code = utils.create_shopify_discount_code("order_voucher_5_euro")
else:
message = "Wir möchten uns herzlich bei dir bedanken, dass du dir die Zeit genommen hast, einen Beitrag über uns auf Social Media zu erstellen."
price = "10"
discount_code = utils.create_shopify_discount_code("order_voucher_10_euro")
if discount_code == "":
sys.exit("Discount code is empty")
html = html.replace("{{PRICE}}", price)
html = html.replace("{{MESSAGE}}", message)
html = html.replace("{{VOUCHER_CODE}}", voucher_code)
html = html.replace("{{DISCOUNT_CODE}}", discount_code)
text = text.replace("{{PRICE}}", price)
text = text.replace("{{MESSAGE}}", message)
text = text.replace("{{VOUCHER_CODE}}", voucher_code)
text = text.replace("{{DISCOUNT_CODE}}", discount_code)
# add text and html part to the email
part1 = MIMEText(text, "plain", "utf-8")
@ -91,7 +90,7 @@ try:
server.login(auth_email, password)
server.sendmail(from_email, receiver_email, msg.as_string())
print(f"Email sent to {receiver_email} with voucher code {voucher_code} of type {voucher_type}")
print(f"Email sent to {receiver_email} with voucher code {discount_code} of type {voucher_type}")
except Exception as e:
print(f"Error sending email: {e}")
sys.exit(1)

View File

@ -151,7 +151,7 @@
"
>
Dein Gutscheincode lautet:
<strong>{{VOUCHER_CODE}}</strong>
<strong>{{DISCOUNT_CODE}}</strong>
</p>
<table
class="row actions"
@ -189,7 +189,7 @@
bgcolor="#af9363"
>
<a
href="https://shinnex.de?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher_{{PRICE}}&utm_content=deserved_voucher_{{PRICE}}"
href="https://shinnex.de/discount/{{DISCOUNT_CODE}}?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher_{{PRICE}}&utm_content=deserved_voucher_{{PRICE}}"
class="button__text"
style="
font-size: 16px;

View File

@ -1,9 +1,10 @@
Dein Gutscheincode als Dankeschön
{{MESSAGE}} Du kannst den Gutschein beim Checkout einlösen.
{{MESSAGE}} Als kleines Dankeschön möchten wir dir einen {{PRICE}} € Gutschein überreichen.
Du kannst den Gutschein beim Checkout einlösen.
Dein Gutscheincode lautet: {{VOUCHER_CODE}}
Dein Gutscheincode lautet: {{DISCOUNT_CODE}}
Zu unserem Shop: https://shinnex.de?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher&utm_content=deserved_voucher
Zu unserem Shop: https://shinnex.de?/discount/{{DISCOUNT_CODE}}?utm_source=email&utm_medium=email&utm_campaign=deserved_voucher&utm_content=deserved_voucher
Falls du Fragen hast, antworte auf diese E-Mail oder kontaktiere uns unter info@shinnex.de.