I have a code in php that listen to stripe which sends to the my server a json format information. I would like to retrieve the email from the json and assign it to a variable $email. I don't understand what is wrong with my php code.
PHP code: {
"id": "evt_7nxAKynL74HXUu",
"object": "event",
"api_version": "2012-11-07",
"created": 1454008591,
"data": {
"object": {
"id": "ch_7nxA7QWn3069zJ",
"object": "charge",
"amount": 15000,
"amount_refunded": 0,
"application_fee": null,
"balance_transaction": "txn_7nxAqCOclHRnAv",
"captured": true,
"card": {
"id": "card_7nxAJFJ52PhS8G",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_7nxAxI4lGICtyv",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 11,
"exp_year": 2022,
"fingerprint": "lEO6YJCu2ASyQbvB",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": "futjakot@gmail.com",
"tokenization_method": null,
"type": "Visa"
},
"created": 1454008591,
"currency": "gbp",
"customer": "cus_7nxAxI4lGICtyv",
"description": null,
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
"invoice": null,
"livemode": false,
"metadata": {},
"order": null,
"paid": true,
"receipt_email": "futjakot@gmail.com",
"receipt_number": null,
"refunded": false,
"refunds": [],
"shipping": null,
"source": {
"id": "card_7nxAJFJ52PhS8G",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_7nxAxI4lGICtyv",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 11,
"exp_year": 2022,
"fingerprint": "lEO6YJCu2ASyQbvB",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": "futjakot@gmail.com",
"tokenization_method": null,
"type": "Visa"
},
"statement_descriptor": null,
"status": "paid",
"statement_description": null,
"fee": 455,
"fee_details": [
{
"amount": 455,
"amount_refunded": 0,
"application": null,
"currency": "gbp",
"description": "Stripe processing fees",
"type": "stripe_fee"
}
]
}
},
"livemode": false,
"pending_webhooks": 1,
"request": "req_7nxAFmUej9UkFy",
"type": "charge.succeeded"
}
Json code:
{ "id": "evt_7nxAKynL74HXUu", "object": "event", "api_version": "2012-11-07", "created": 1454008591, "data": { "object": { "id": "ch_7nxA7QWn3069zJ", "object": "charge", "amount": 15000, "amount_refunded": 0, "application_fee": null, "balance_transaction": "txn_7nxAqCOclHRnAv", "captured": true, "card": { "id": "card_7nxAJFJ52PhS8G", "object": "card", "address_city": null, "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip": null, "address_zip_check": null, "brand": "Visa", "country": "US", "customer": "cus_7nxAxI4lGICtyv", "cvc_check": "pass", "dynamic_last4": null, "exp_month": 11, "exp_year": 2022, "fingerprint": "lEO6YJCu2ASyQbvB", "funding": "credit", "last4": "4242", "metadata": {}, "name": "futjakot@gmail.com", "tokenization_method": null, "type": "Visa" }, "created": 1454008591, "currency": "gbp", "customer": "cus_7nxAxI4lGICtyv", "description": null, "destination": null, "dispute": null, "failure_code": null, "failure_message": null, "fraud_details": {}, "invoice": null, "livemode": false, "metadata": {}, "order": null, "paid": true, "receipt_email": "futjakot@gmail.com", "receipt_number": null, "refunded": false, "refunds": [], "shipping": null, "source": { "id": "card_7nxAJFJ52PhS8G", "object": "card", "address_city": null, "address_country": null, "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip": null, "address_zip_check": null, "brand": "Visa", "country": "US", "customer": "cus_7nxAxI4lGICtyv", "cvc_check": "pass", "dynamic_last4": null, "exp_month": 11, "exp_year": 2022, "fingerprint": "lEO6YJCu2ASyQbvB", "funding": "credit", "last4": "4242", "metadata": {}, "name": "futjakot@gmail.com", "tokenization_method": null, "type": "Visa" }, "statement_descriptor": null, "status": "paid", "statement_description": null, "fee": 455, "fee_details": [ { "amount": 455, "amount_refunded": 0, "application": null, "currency": "gbp", "description": "Stripe processing fees", "type": "stripe_fee" } ] } }, "livemode": false, "pending_webhooks": 1, "request": "req_7nxAFmUej9UkFy", "type": "charge.succeeded" }
Actually, you have 3 emails in that JSON.
$event_json = json_decode($input);
$email1 = $event_json->data->object->card->name;
$email2 = $event_json->data->object->receipt_email;
$email3 = $event_json->data->object->source->name;
You could have figured it out by yourself by doing a series of var_dump
statements on $event_json
.
如您所见,名称位于对象命名数据中的对象命名对象的对象卡中,因此电子邮件的检索应为:
$email = $event_json->data->object->card->name;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.