@Embox

Почему ошибка Cannot use object of type stdClass as array in?

Получаю 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": "dummy@dummy.com",
"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
}
}

Выполняю код для обработки "event": "order:paid"
Но выдает ошибку
$payload = file_get_contents('php://input');
$event_payload= json_decode($payload); 
$eventType = $event_payload[0]->event;

echo $eventType;
  • Вопрос задан
  • 52 просмотра
Решения вопроса 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
$eventType = $event_payload->event;
У вас нет массива, только объект
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@Ordec
Если все же хотите работать как с массивом
$event_payload= json_decode($payload, true);
Обращаетесь напрямую как
event_payload['event']
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы