-
Notifications
You must be signed in to change notification settings - Fork 35
/
send-tax-receipts-for-donations.json
34 lines (34 loc) · 9.13 KB
/
send-tax-receipts-for-donations.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
"docs": "Use this task to email donation receipts to donors as PDF attachments, with an option to cc the shop email. It runs on new, paid orders, or optionally on order creation. The task will sum the donation amount from all line items that have any of the configured donation product tags or titles.\n\nThis task can also receive individual orders sent directly via [admin action links](https://learn.mechanic.dev/core/shopify/admin-action-links#link-usage).\n\n**Notes:**\n\n- The task comes with a sample donation tag, email subject, email body, donation receipt filename, and donation receipt HTML template. The HTML template is used by the PDF file generator, so care must be taken to provide valid HTML if this field is customized.\n- The *[TAX_ID]* and *[DONATION_AMOUNT]* variables need to be present in the HTML template in order for those values to be included in the PDF donation receipt.\n- Orders with no donation products will be ignored by this task.",
"halt_action_run_sequence_on_error": false,
"name": "Send tax receipts for donations",
"online_store_javascript": null,
"options": {
"tax_id__required": null,
"run_on_order_creation_instead_of_paid__boolean": null,
"identify_donation_products_with_any_of_these_tags__array_required": [
"donation"
],
"identify_donation_products_with_any_of_these_titles__array": null,
"send_cc_to_shop_email__boolean": false,
"email_subject__required": "Receipt {{ order.name }} for donation to {{ shop.name }}",
"email_body__multiline_required": "Thank you for your recent donation!\n\nAttached you will find your official donation receipt.",
"donation_receipt_filename__required": "{{ shop.name | handleize }}-donation-receipt-{{ order.name }}.pdf",
"donation_reciept_html_template__code_multiline_required": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <style>\n .container {\n width: 960px;\n margin: 0 auto;\n font-size: 16px;\n }\n .header {\n display: flex;\n flex-direction: row;\n border-top: 1px solid #000; \n border-bottom: 1px dashed #000; \n font-size: 18px;\n }\n .main {\n margin-top: 10px;\n display: flex;\n flex-direction: row;\n font-size: 16px;\n }\n .left {\n width: 50%;\n }\n .right {\n width: 50%;\n }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <div class=\"header\">\n <p class=\"left\">\n {{ shop.name }}<br/>\n {{ shop.address1 }}<br/>{% if shop.address2 != blank -%}{{ shop.address2 }}<br/>{%- endif %}\n {{ shop.city }}, {{ shop.province }} {{ shop.zip }}<br/>\n {{ order.billing_address.country }}\n </p>\n <p class=\"right\">\n OFFICIAL DONATION RECEIPT<br/>\n TAX ID #[TAX_ID]<br/>\n </p>\n </div>\n <div class=\"main\">\n <p class=\"left\">\n <strong>Donor:</strong><br/>\n {{ order.billing_address.first_name }} {{ billing_address.last_name }}<br/>\n {{ order.billing_address.address1 }}<br/>{% if order.billing_address.address2 != blank -%}{{ order.billing_address.address2 }}<br/>{%- endif %}\n {{ order.billing_address.city }}, {{ order.billing_address.province }} {{ order.billing_address.zip }}<br/>\n {{ order.billing_address.country }}\n </p>\n <p class=\"right\">\n <strong>Donation Details:</strong><br/>\n Order Number: {{ order.name }}<br/>\n Donation Received: {{ order.created_at | date: \"%F\" }}<br/>\n Amount: [DONATION_AMOUNT]<br/>\n Date Issued: {{ \"now\" | date: \"%F\" }}<br/>\n Place Issued: {{ shop.province }}, {{ shop.country_name }}<br/>\n <br/>\n Donations are tax deductible to the extent permitted by law.<br/>\n <br/>\n Thank you\n </p>\n </div>\n </div>\n</body>\n</html>"
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"preview_event_definitions": [],
"script": "{% assign tax_id = options.tax_id__required %}\n{% comment %}{{ options.run_on_order_creation_instead_of_paid__boolean }}{% endcomment %}\n{% assign donation_product_tags = options.identify_donation_products_with_any_of_these_tags__array %}\n{% assign donation_product_titles = options.identify_donation_products_with_any_of_these_titles__array %}\n{% assign send_cc_to_shop_email = options.send_cc_to_shop_email__boolean %}\n{% assign email_subject = options.email_subject__required %}\n{% assign email_body = options.email_body__multiline_required %}\n{% assign donation_receipt_filename = options.donation_receipt_filename__required %}\n{% assign donation_reciept_html_template = options.donation_reciept_html_template__code_multiline_required %}\n\n{% if donation_product_tags == blank and donation_product_titles == blank %}\n {% error \"Enter at least one product tag or title to filter on.\" %}\n{% endif %}\n\n{% if event.topic == \"shopify/orders/paid\"\n or event.topic == \"shopify/orders/create\"\n or event.topic == \"mechanic/user/order\"\n%}\n {% if order.email == blank %}\n {% log \"This order does not have an email associated with it.\" %}\n {% break %}\n {% endif %}\n\n {% comment %}\n -- get the order data to see if there are any donation products on this order, by product tag or title\n {% endcomment %}\n\n {% capture query %}\n query {\n order(id: {{ order.admin_graphql_api_id | json }}) {\n id\n presentmentCurrencyCode\n lineItems(first: 100) {\n nodes {\n product {\n tags\n title\n }\n originalTotalSet {\n presentmentMoney {\n amount\n }\n }\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = query | shopify %}\n\n {% if event.preview %}\n {% capture result_json %}\n {\n \"data\": {\n \"order\": {\n \"presentmentCurrencyCode\": \"USD\",\n \"lineItems\": {\n \"nodes\": [\n {\n \"product\": {\n \"tags\": {{ donation_product_tags.first | json }},\n \"title\": {{ donation_product_titles.first | json }}\n },\n \"originalTotalSet\": {\n \"presentmentMoney\": {\n \"amount\": \"100.0\"\n }\n }\n }\n ]\n }\n }\n }\n }\n {% endcapture %}\n\n {% assign result = result_json | parse_json %}\n {% endif %}\n\n {% comment %}\n -- for any donation products, add the non-discounted total for that line item to the runnning donation amount\n {% endcomment %}\n\n {% assign donation_amount = 0 %}\n\n {% for line_item in result.data.order.lineItems.nodes %}\n {% assign is_donation_product = nil %}\n\n {% for donation_product_tag in donation_product_tags %}\n {% if line_item.product.tags contains donation_product_tag %}\n {% assign is_donation_product = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n\n {% for donation_product_title in donation_product_titles %}\n {% if line_item.product.title == donation_product_title %}\n {% assign is_donation_product = true %}\n {% break %}\n {% endif %}\n {% endfor %}\n\n {% if is_donation_product %}\n {% assign donation_amount = donation_amount | plus: line_item.originalTotalSet.presentmentMoney.amount %}\n {% endif %}\n {% endfor %}\n\n {% unless donation_amount > 0 %}\n {% log \"This order has no donation products on it; skipping\" %}\n {% break %}\n {% endunless %}\n\n {% assign donation_with_currency = donation_amount | currency: result.data.order.presentmentCurrencyCode %}\n\n {% comment %}\n -- replace variables in the HTML template for the configured tax ID and the calculated donation amount\n {% endcomment %}\n\n {% assign donation_html\n = donation_reciept_html_template\n | replace: \"[TAX_ID]\", tax_id\n | replace: \"[DONATION_AMOUNT]\", donation_with_currency\n %}\n\n {% comment %}\n -- generate tax receipt as a PDF and attach to email to donor; optionally cc the shop email address\n {% endcomment %}\n\n {% action \"email\" %}\n {\n \"to\": {{ order.email | json }},\n \"subject\": {{ email_subject | json }},\n \"body\": {{ email_body | newline_to_br | json }},\n {% if send_cc_to_shop_email %}\"cc\": {{ shop.customer_email | json }},{% endif %}\n \"reply_to\": {{ shop.customer_email | json }},\n \"from_display_name\": {{ shop.name | json }},\n \"attachments\": {\n {{ donation_receipt_filename | remove: \"#\" | json }}: {\n \"pdf\": {\n \"html\": {{ donation_html | json }},\n \"__force_pdfcrowd\": true\n }\n }\n }\n }\n {% endaction %}\n{% endif %}\n",
"subscriptions": [
"shopify/orders/paid",
"mechanic/user/order"
],
"subscriptions_template": "{% if options.run_on_order_creation_instead_of_paid__boolean %}\n shopify/orders/create\n{% else %}\n shopify/orders/paid\n{% endif %}\nmechanic/user/order",
"tags": [
"Orders",
"PDF",
"Receipts",
"Tax"
]
}