forked from lightward/mechanic-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-paypal-transactions-as-shopify-orders.json
27 lines (27 loc) · 8.88 KB
/
import-paypal-transactions-as-shopify-orders.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
{
"docs": "Use this task when you want to record your external PayPal transactions as Shopify orders. Are you using PayPal subscriptions? Or receiving direct payments you'd like to record in Shopify? Use this task, or file a task request to have it modified for more purpose-specific uses. :) Again, this isn't for PayPal as a Shopify payment provider – it's for any time you might be using PayPal *outside* of your Shopify store.\n\n**To get set up, follow our tutorial: [Connecting PayPal to Mechanic](https://learn.mechanic.dev/faq/how-do-i-connect-paypal-to-shopify-with-mechanic).**\r\n\r\nThen, configure to taste. :) Mechanic will use the PayPal order memo as the sole line item in the orders that are created, falling back to your \"Default memo\" setting.\r\n\r\nOut of the box, this task will only create orders for transactions in which payment successfully went through. To modify this task to perform extra functionality (like auto-tagging based on subscription events, for example), file a task request from your Mechanic home screen.",
"halt_action_run_sequence_on_error": false,
"name": "Import PayPal transactions as Shopify orders",
"online_store_javascript": null,
"options": {
"only_import_these_transaction_types__array": null,
"only_import_completed_transactions__boolean": true,
"send_receipt__boolean": null,
"default_memo": "Your PayPal payment",
"order_requires_shipping__boolean": null,
"mark_as_fulfilled__boolean": null,
"send_fulfillment_receipt__boolean": null
},
"order_status_javascript": null,
"perform_action_runs_in_sequence": false,
"script": "{% comment %}\n Hello, developer friend! :) Here's the PayPal IPN variable reference:\n\n https://developer.paypal.com/api/nvp-soap/ipn/IPNandPDTVariables/\n\n ... and here's their IPN payload simulator:\n\n https://developer.paypal.com/api/nvp-soap/ipn/IPNSimulator/\n\n Their default payment_date value doesn't even meet *their* standard, so change it to\n something like \"22:03:27 Sep 28, 2018 PDT\" if you need to test that value. <3\n{% endcomment %}\n\n{% if event.preview %}\n {% capture event_data_json %}\n {\n \"mc_gross\": \"-132.29\",\n \"invoice\": \"CF [email protected]_[12345]_12345\",\n \"settle_amount\": \"92.59\",\n \"protection_eligibility\": \"Eligible\",\n \"item_number1\": \"\",\n \"payer_id\": \"ABCDEFABCDEF\",\n \"address_street\": \"1234 Street Lane\",\n \"payment_date\": \"00:00:00 Jan 01, 2000 UTC\",\n \"payment_status\": \"Completed\",\n \"charset\": \"windows-1252\",\n \"address_zip\": \"12345\",\n \"mc_shipping\": \"0.00\",\n \"mc_handling\": \"0.00\",\n \"first_name\": \"Customer\",\n \"mc_fee\": \"-6.78\",\n \"address_country_code\": \"US\",\n \"exchange_rate\": \"0.737685\",\n \"address_name\": \"Customer Name\",\n \"notify_version\": \"3.9\",\n \"reason_code\": null,\n \"settle_currency\": \"GBP\",\n \"custom\": \"\",\n \"business\": \"[email protected]\",\n \"address_country\": \"\",\n \"mc_handling1\": \"0.00\",\n \"address_city\": \"Billingsly\",\n \"verify_sign\": \"B8xyEug85joDO4J7jO5XTilRUzIiAZ.xQozW-0M7PB9q4Z117AtHGEtx\",\n \"payer_email\": \"[email protected]\",\n \"mc_shipping1\": \"0.00\",\n \"tax1\": \"0.00\",\n \"parent_txn_id\": \"ABC123ABC123ABC123ABC123\",\n \"txn_id\": \"123ABC123ABC123ABC123ABC\",\n \"payment_type\": {{ options.only_import_these_transaction_types__array.first | default: \"invoice_payment\" | json }},\n \"last_name\": \"Customer\",\n \"address_state\": \"ST\",\n \"item_name1\": \"Item name\",\n \"receiver_email\": \"[email protected]\",\n \"payment_fee\": \"-6.78\",\n \"shipping_discount\": \"0.00\",\n \"quantity1\": \"1\",\n \"insurance_amount\": \"0.00\",\n \"receiver_id\": \"ABCDEFABCDEF\",\n \"pending_reason\": null,\n \"discount\": \"0.00\",\n \"mc_gross_1\": \"132.29\",\n \"mc_currency\": \"USD\",\n \"residence_country\": \"US\",\n \"shipping_method\": \"\",\n \"transaction_subject\": \"\",\n \"payment_gross\": \"-132.29\",\n \"ipn_track_id\": \"abcdef123456\"\n }\n {% endcapture %}\n\n {% assign event = hash %}\n {% assign event[\"data\"] = event_data_json | parse_json %}\n{% endif %}\n\n{% assign import_order = true %}\n\n{% if options.only_import_completed_transactions__boolean and event.data.payment_status != \"Completed\" %}\n {% log message: \"This transaction's payment status is not Completed; skipping\", payment_status: event.data.payment_status %}\n {% assign import_order = false %}\n{% endif %}\n\n{% comment %}Some notifications have a txn_type, some have a payment_type.{% endcomment %}\n{% assign transaction_type = event.data.txn_type | default: event.data.payment_type %}\n\n{% if options.only_import_these_transaction_types__array != blank %}\n {% unless options.only_import_these_transaction_types__array contains transaction_type %}\n {% log message: \"This transaction's type was not on the list; skipping\", transaction_type: transaction_type %}\n {% assign import_order = false %}\n {% endunless %}\n{% endif %}\n\n{% if import_order %}\n {% comment %}\n PayPal's date format is non-standard: `HH:MM:SS Mmm DD, YYYY PDT`, per their docs.\n We reformat it here, to ensure that Liquid can parse it for Shopify-ready formatting.\n {% endcomment %}\n {% assign date_parts = event.data.payment_date | replace: \",\", \"\" | split: \" \" %}\n {% capture sane_payment_date %}{{ date_parts[3] }} {{ date_parts[1] }} {{ date_parts[2] }} {{ date_parts[0] }} {{ date_parts[4] }}{% endcapture %}\n\n {% action \"shopify\" %}\n [\n \"create\",\n \"order\",\n {\n \"email\": {{ event.data.payer_email | json }},\n \"send_receipt\": {{ options.send_receipt__boolean | json }},\n \"processed_at\": {{ sane_payment_date | date: \"%Y-%m-%dT%H:%M:%S.%L%z\" | json }},\n \"financial_status\": \"paid\",\n \"currency\": {{ event.data.mc_currency | json }},\n \"line_items\": [\n {\n \"title\": {{ event.data.memo | default: options.default_memo | default: \"(no memo given)\" | json }},\n \"price\": {{ event.data.mc_gross | divided_by: 1.0 | json }},\n \"requires_shipping\": {{ options.order_requires_shipping__boolean | json }},\n \"quantity\": 1,\n \"taxable\": false\n }\n ],\n \"fulfillment_status\": {% if options.mark_as_fulfilled__boolean %}\"fulfilled\"{% else %}null{% endif %},\n \"send_fulfillment_receipt\": {{ options.send_fulfillment_receipt__boolean | json }},\n \"transactions\": [\n {\n \"kind\": \"sale\",\n \"status\": \"success\",\n \"amount\": {{ event.data.mc_gross | divided_by: 1.0 | json }}\n }\n ],\n \"customer\": {\n \"id\": {{ shop.customers[event.data.payer_email].id | json }}\n },\n \"billing_address\": {\n \"first_name\": {{ event.data.first_name | json }},\n \"last_name\": {{ event.data.last_name | json }},\n \"address1\": {{ event.data.address_street | json }},\n \"city\": {{ event.data.address_city | json }},\n \"province\": {{ event.data.address_state | json }},\n \"country\": {{ event.data.address_country | json }},\n \"zip\": {{ event.data.address_zip | json }}\n },\n {% if options.order_requires_shipping__boolean %}\n \"shipping_address\": {\n \"first_name\": {{ event.data.first_name | json }},\n \"last_name\": {{ event.data.last_name | json }},\n \"address1\": {{ event.data.address_street | json }},\n \"city\": {{ event.data.address_city | json }},\n \"province\": {{ event.data.address_state | json }},\n \"country\": {{ event.data.address_country | json }},\n \"zip\": {{ event.data.address_zip | json }}\n },\n {% endif %}\n \"note_attributes\": [\n {\n \"name\": \"PayPal protection eligibility\",\n \"value\": {{ event.data.protection_eligibility | json }}\n },\n {\n \"name\": \"PayPal payer ID\",\n \"value\": {{ event.data.payer_id | json }}\n },\n {\n \"name\": \"PayPal transaction ID\",\n \"value\": {{ event.data.txn_id | json }}\n },\n {\n \"name\": \"PayPal receiver ID\",\n \"value\": {{ event.data.receiver_id | json }}\n },\n {\n \"name\": \"PayPal transaction type\",\n \"value\": {{ event.data.txn_type | json }}\n }\n ]\n }\n ]\n {% endaction %}\n{% endif %}",
"subscriptions": [
"user/paypal/ipn"
],
"subscriptions_template": "user/paypal/ipn",
"tags": [
"External API",
"Import",
"Orders"
]
}