Cannot access offset of type string on string in CodeIgniter

20 Views Asked by At

I have this issue whereby I'm trying to confirm the transaction of users via a webhook, I don't know how to resolve this issue, below is my code

$data = @file_get_contents("php://input");
$event = json_decode($data, true);

$result = array_change_key_case($event, CASE_LOWER);

$e = '';
$dataarray = [];

foreach ($event as $key => $value) {
    $dataarray[$key] = $value;
    $e = addslashes($value['id'][0]);
}

and i keep get this

An uncaught Exception was encountered
Type: TypeError

Message: Cannot access offset of type string on string

Filename: /home2/usefastp/public_html/app.usefastpay.ng/application/controllers/PaystackWebhook.php

Line Number: 25

Json

{
    "event": "charge.success",
    "data": {
        "id": 3589405365,
        "domain": "live",
        "status": "success",
        "reference": "000013240229232839000039349865",
        "amount": 10000,
        "message": null,
        "gateway_response": "Approved",
        "paid_at": "2024-02-29T22:29:49.000Z",
        "created_at": "2024-02-29T22:29:49.000Z",
        "channel": "dedicated_nuban",
        "currency": "NGN",
        "ip_address": null,
        "metadata": {
            "receiver_account_number": "9311879633",
            "receiver_bank": "Wema Bank",
            "custom_fields": [
                {
                    "display_name": "Receiver Account",
                    "variable_name": "receiver_account_number",
                    "value": "9311879633"
                },
                {
                    "display_name": "Receiver Bank",
                    "variable_name": "receiver_bank",
                    "value": "Wema Bank"
                }
            ]
        },
        "fees_breakdown": {
            "amount": "100",
            "formula": null,
            "type": "paystack"
        },
        "log": null,
        "fees": 100,
        "fees_split": null,
        "authorization": {
            "authorization_code": "AUTH_pxt202a52t",
            "bin": "024XXX",
            "last4": "X758",
            "exp_month": "01",
            "exp_year": "2024",
            "channel": "dedicated_nuban",
            "card_type": "transfer",
            "bank": "Guaranty Trust Bank",
            "country_code": "NG",
            "brand": "Managed Account",
            "reusable": false,
            "signature": null,
            "account_name": null,
            "sender_country": "NG",
            "sender_bank": "Guaranty Trust Bank",
            "sender_bank_account_number": "XXXXXX9758",
            "sender_name": "NOSAKHARE   ATEKHA  ENDURANCE",
            "narration": "0241459758/9311879633/ICEBERGSYNERG/N",
            "receiver_bank_account_number": "9311879633",
            "receiver_bank": "Wema Bank"
        },
        "customer": {
            "id": 160371778,
            "first_name": "Nosakhare",
            "last_name": "Nosakhare",
            "email": "[email protected]",
            "customer_code": "CUS_kt7u83b7vi2ispc",
            "phone": "0908343",
            "metadata": {},
            "risk_action": "default",
            "international_format_phone": null
        },
        "plan": {},
        "subaccount": {},
        "split": {},
        "order_id": null,
        "paidAt": "2024-02-29T22:29:49.000Z",
        "requested_amount": 10000,
        "pos_transaction_data": null,
        "source": null
    }
}

this is the code that is been passed to the webhook to be verified, and i'm trying to access receiver_bank_account_number from authorization inside data object

0

There are 0 best solutions below