Avatar of Valerie Criswell
Valerie Criswell asked on

Need to Receive Webhook in Coldfusion

To be clear upfront, I'm not a professional - just trying to get a task done and I have minimal expertise. What I thought would be easy is apparently not so. I've dealt with APIs and XML but it's always been me initiating. This is apparently different.

Goal:

Receive HTTP POST Webhook data from my Wordpress/Woocommerce website.

==============================================

If you're receiving an http post and it contains the variable/value status:completed

CFIF CODE HERE

Loop through line_items in this transaction

CFIF CODE HERE

Do this if the item is a download

CFIF CODE HERE

Do some database inserts. I've got all this code written and ready to go.

==============================================

1.  The webhook is working and being received perfectly by RequestBin.
2.  HTTP in JSon is being sent.
3.  I'm not even sure the request is being heard by my CF Template.
4.  When I try to write the received data into a session variable so I can at least see it, nothing is there?!?!
Need to know... Is my code being triggered? If not, how can I make it be so. AND Once I'm able to assess that I'm receiving data, how can I curse down into it and grab the bits of info (is the result an array or structure and what's the syntax to drill down)?? Specifically, I only need...

status

line_items.sku

TIA for HELP.

==============================================

First line of code in my CF template to receive HTTP POST from Webhook
<cfset HTTPRequestData = deserializeJSON(ToString(getHTTPRequestData().content))>

Open in new window


==============================================

Example from RequestBin of data being sent:

{
    "id": 259609,
    "parent_id": 0,
    "number": "CW-104-270219",
    "order_key": "xxxxxxxxxxxx",
    "created_via": "checkout",
    "version": "3.5.5",
    "status": "completed",
    "currency": "USD",
    "date_created": "2019-02-27T15:11:58",
    "date_created_gmt": "2019-02-27T20:11:58",
    "date_modified": "2019-02-27T15:11:59",
    "date_modified_gmt": "2019-02-27T20:11:59",
    "discount_total": "0.00",
    "discount_tax": "0.00",
    "shipping_total": "0.00",
    "shipping_tax": "0.00",
    "cart_tax": "0.00",
    "total": "9.68",
    "total_tax": "0.00",
    "prices_include_tax": false,
    "customer_id": 2,
    "customer_ip_address": "xxxxxxxxxxxx",
    "customer_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
    "customer_note": "",
    "billing": {
        "first_name": "xxxxxxxxxx",
        "last_name": "xxxxxxxxxxxxx",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": "",
        "email": "xxxxxxxxxx",
        "phone": ""
    },
    "shipping": {
        "first_name": "",
        "last_name": "",
        "company": "",
        "address_1": "",
        "address_2": "",
        "city": "",
        "state": "",
        "postcode": "",
        "country": ""
    },
    "payment_method": "authorize_net_aim",
    "payment_method_title": "Credit Card",
    "transaction_id": "xxxxxxxxxxxxx",
    "date_paid": "2019-02-27T15:11:59",
    "date_paid_gmt": "2019-02-27T20:11:59",
    "date_completed": "2019-02-27T15:11:59",
    "date_completed_gmt": "2019-02-27T20:11:59",
    "cart_hash": "xxxxxxxxxxxxx",
    "meta_data": [
        {
            "id": 8785641,
            "key": "_wcson_order_number",
            "value": "CWD-259609-022719-108"
        },
        {
            "id": 8785642,
            "key": "_order_number",
            "value": "104"
        },
        {
            "id": 8785643,
            "key": "_order_number_formatted",
            "value": "CW-104-270219"
        },
        {
            "id": 8785644,
            "key": "_order_number_meta",
            "value": {
                "prefix": "CW-",
                "suffix": "-{DD}{MM}{YY}",
                "length": "2"
            }
        },
        {
            "id": 8785645,
            "key": "_wc_authorize_net_aim_retry_count",
            "value": "0"
        },
        {
            "id": 8785646,
            "key": "_wc_authorize_net_aim_trans_id",
            "value": "xxxxxxxx"
        },
        {
            "id": 8785647,
            "key": "_wc_authorize_net_aim_trans_date",
            "value": "2019-02-27 15:11:59"
        },
        {
            "id": 8785648,
            "key": "_wc_authorize_net_aim_environment",
            "value": "production"
        },
        {
            "id": 8785649,
            "key": "_wc_authorize_net_aim_account_four",
            "value": "xxxxxxxx"
        },
        {
            "id": 8785650,
            "key": "_wc_authorize_net_aim_authorization_amount",
            "value": "xxxxxxx"
        },
        {
            "id": 8785651,
            "key": "_wc_authorize_net_aim_authorization_code",
            "value": "xxxxxxx"
        },
        {
            "id": 8785652,
            "key": "_wc_authorize_net_aim_charge_captured",
            "value": "yes"
        },
        {
            "id": 8785653,
            "key": "_wc_authorize_net_aim_card_expiry_date",
            "value": "21-08"
        },
        {
            "id": 8785654,
            "key": "_wc_authorize_net_aim_card_type",
            "value": "mastercard"
        },
        {
            "id": 8785659,
            "key": "_pip_invoice_number",
            "value": "CW-104-270219"
        },
        {
            "id": 8785660,
            "key": "_wc_pip_invoice_email_count",
            "value": "1"
        },
        {
            "id": 8785661,
            "key": "_wc_pip_packing_list_email_count",
            "value": "1"
        }
    ],
    "line_items": [
        {
            "id": 17,
            "name": "I Give Myself Away -   MP3 Download - 30 Day Access",
            "product_id": 192127,
            "variation_id": 192128,
            "quantity": 1,
            "tax_class": "",
            "subtotal": "9.68",
            "subtotal_tax": "0.00",
            "total": "9.68",
            "total_tax": "0.00",
            "taxes": [],
            "meta_data": [
                {
                    "id": 182,
                    "key": "pa_format",
                    "value": "download-30-day"
                }
            ],
            "sku": "131599-DL30DAY",
            "price": 9.68
        }
    ],
    "tax_lines": [],
    "shipping_lines": [],
    "fee_lines": [],
    "coupon_lines": [],
    "refunds": []
}

Open in new window

ColdFusion Language* webhooksJSON

Avatar of undefined
Last Comment
Valerie Criswell

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Valerie Criswell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61