E
E
Embox2021-06-25 00:09:13
PHP
Embox, 2021-06-25 00:09:13

Why Cannot use object of type stdClass as array in error?

I get payload
{
"event": "order:paid",
"data": {
"id": 1141843,
"uniqid": "dummy",
"type": "PRODUCT",
"total": 0,
"total_display": 0,
"exchange_rate": 0,
"crypto_exchange_rate": 0,
"currency": "USD",
"shop_id": 0,
"shop_image_name": null,
"shop_image_storage": null,
"name": null,
"customer_email": "[email protected]",
"paypal_email_delivery": 0,
"product_id": "dummy",
"product_title": "Dummy Product",
"product_type": "SERIALS",
"subscription_id": null,
"subscription_time": null,
"gateway": null,
"paypal_email": null,
"paypal_order_id": null,
"paypal_payer_email": null,
"paypal_fee": 0,
"paypal_subscription_id": null,
"paypal_subscription_link": null,
"lex_order_id ": null,
"lex_payment_method": null,
"paydash_paymentID": null,
"stripe_client_secret": null,
"skrill_email": null,
"skrill_sid": null,
"skrill_link": null,
"perfectmoney_id": null,
"crypto_address": null,
"crypto_amount": 0,
"crypto_received": 0,
"crypto_uri": null,
"crypto_confirmations_needed": 1,
"crypto_scheduled_payout": 0,
"crypto_payout": 0,
"cashapp_qrcode": null,
"cashapp_note": null,
"cashapp_cashtag": null,
"country": null,
"location": ", () ",
"ip": null,
"is_vpn_or_proxy": false,
"user_agent": null,
"quantity": 1,
"coupon_id": null,
"custom_fields": null,
"developer_invoice": false,
"developer_title": null,
"developer_webhook": null,
"developer_return_url": null,
"status": "VOIDED",
"discount": 0,
"fee_percentage": 0,
"day_value": 1,
"day": "Mon",
"month": "Jan",
"year": 2020,
"created_at": 1577836800,
"updated_at": 0,
"updated_by": 0,
"ip_info": null,
"serials": [],
"webhooks": [],
"paypal_dispute": null,
"status_history": [
{
"id": 2166538,
"invoice_id": "dummy",
"status": "VOIDED",
"details": "The invoice has been voided: we have not received a payment within the time limit.",
"created_at": 1605114081
}
],
"crypto_transactions": [],
"gateways_available": [
""
],
"shop_paypal_credit_card": null,
"shop_force_paypal_email_delivery": null
}
}

Execute code to handle "event": "order:paid"
But it gives an error

$payload = file_get_contents('php://input');
$event_payload= json_decode($payload); 
$eventType = $event_payload[0]->event;

echo $eventType;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-06-25
@Embox

$eventType = $event_payload->event;
You don't have an array, only an object

O
Ordec, 2021-06-25
@Ordec

If you still want to work as with an array, you
$event_payload= json_decode($payload, true);
access it directly as
event_payload['event']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question