如何阅读条带webhook响应

时间:2014-05-14 12:56:11

标签: javascript jquery json coldfusion stripe-payments

我创建了coldfusion文件以捕获STRIPE webhook响应。

<cfsavecontent variable="headerdump">
    <cfdump var="#toString(getHttpRequestData().content, 'utf-8')#" expand="yes" format="text">
</cfsavecontent>

当我打印headerdump时,得到以下回复。我想提取输出文本的节点值。

<pre>{
  "id": "evt_1041EO45YXiN2y2zPhZbNrgh",
  "created": 1399872268,
  "livemode": false,
  "type": "invoice.payment_succeeded",
  "data": {
    "object": {
      "date": 1399872268,
      "id": "in_1041EO45YXiN2y2zQF1xhLyl",
      "period_start": 1399872268,
      "period_end": 1399872268,
      "lines": {
        "object": "list",
        "total_count": 1,
        "has_more": false,
        "url": "/v1/invoices/in_1041EO45YXiN2y2zQF1xhLyl/lines",
        "data": [
          {
            "id": "sub_41EOmzNFelCyAL",
            "object": "line_item",
            "type": "subscription",
            "livemode": false,
            "amount": 0,
            "currency": "usd",
            "proration": false,
            "period": {
              "start": 1399872268,
              "end": 1399958668
            },
            "quantity": 1,
            "plan": {
              "interval": "month",
              "name": "test one day",
              "created": 1399536505,
              "amount": 500,
              "currency": "usd",
              "id": "test_001",
              "object": "plan",
              "livemode": false,
              "interval_count": 1,
              "trial_period_days": 1,
              "metadata": {
              },
              "statement_description": "half day trial"
            },
            "description": null,
            "metadata": null
          }
        ]
      },
      "subtotal": 0,
      "total": 0,
      "customer": "cus_41EOvhzjYGx7ci",
      "object": "invoice",
      "attempted": true,
      "closed": true,
      "paid": true,
      "livemode": false,
      "attempt_count": 0,
      "amount_due": 0,
      "currency": "usd",
      "starting_balance": 0,
      "ending_balance": null,
      "next_payment_attempt": null,
      "charge": null,
      "discount": null,
      "application_fee": null,
      "subscription": "sub_41EOmzNFelCyAL",
      "metadata": {
      },
      "description": null
    }
  },
  "object": "event",
  "pending_webhooks": 1,
  "request": "iar_41EO1vDF1gpnPn"
}</pre> 

请建议如何在coldfusion或javascript中阅读此内容。

由于

1 个答案:

答案 0 :(得分:2)

我这样做:

<cfscript>
  variables.requestdata = getHTTPRequestData();
  variables.sStripeData = toString(variables.requestdata.content);
  variables.stStripeData  = deserializeJSON(variables.sStripeData);
</cfscript>