0

Please i need help..i am trying to access the values inside data from the the webhook sent to my application.

{
      "event": "charge.completed",
      "data": {
        "id": 285959875,
        "tx_ref": "Links-616626414629",
        "flw_ref": "PeterEkene/FLW270177170",
        "device_fingerprint": "a42937f4a73ce8bb8b8df14e63a2df31",
        "amount": 100,
        "currency": "NGN",
        "charged_amount": 100,
        "app_fee": 1.4,
        "merchant_fee": 0,
        "processor_response": "Approved by Financial Institution",
        "auth_model": "PIN",
        "ip": "197.210.64.96",
        "narration": "CARD Transaction ",
        "status": "successful",
        "payment_type": "card",
        "created_at": "2020-07-06T19:17:04.000Z",
        "account_id": 17321,
        "customer": {
          "id": 215604089,
          "name": "Yemi Desola",
          "phone_number": null,
          "email": "user@gmail.com",
          "created_at": "2020-07-06T19:17:04.000Z"
        },
        "card": {
          "first_6digits": "123456",
          "last_4digits": "7889",
          "issuer": "VERVE FIRST CITY MONUMENT BANK PLC",
          "country": "NG",
          "type": "VERVE",
          "expiry": "02/23"
        }
      }
    }

i have tried to call it like this

 $postdata = file_get_contents("php://input");   

  $referenc = $postdata->data->tx_ref; 

but it didnt work..

but if i call just $postdata, i am able to get the full record..but i need just a single record

shine odigie
  • 156
  • 1
  • 6
  • 3
    Hint: `json_decode()`. – Zhorov Feb 08 '21 at 07:19
  • no..the content is already sent in json format – shine odigie Feb 08 '21 at 07:27
  • Why, what does `$referenc = json_decode($postdata, false); echo $referenc->data->tx_ref;` return? – Zhorov Feb 08 '21 at 07:47
  • _"no..the content is already sent in json format"_ - I think you misunderstand. To be able to use json data in PHP, you need to decode it into a PHP structure, which is what `json_decode()` does. So `$postdata` is just a string, not a PHP object until you decode it. – M. Eriksson Feb 08 '21 at 07:58

0 Answers0