Stripe webhook: able to retrieve data from "source" but nothing else - php

Just as the title says, I am able to get the data from the "source" (I guess that would be the $token) but nothing else.
<?php
require_once('stripe/init.php');
\Stripe\Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxxx");
$input = #file_get_contents("php://input");
$event_json = json_decode($input);
$name = $event_json->data->object->name;
$cvc_check = $event_json->data->object->cvc_check;
?>
=
I can get the $name (which is the email address) and the $cvc_check, but if I do the same for, let's say, status, there's nothing there:
=
$status = $event_json->data->object->status;
=
Can somebody tell / guide me in the right direction? Why can't I get anything outside of the "source"?
{
"object": {
"id": "ch_1EIdL8IcP22cq9aQpA",
"object": "charge",
"amount": 500,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1EIdL8IcP22cq9",
"source": {
"id": "card_1EIdL3IcP22cq",
"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_EmBix3cJ",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 2,
"exp_year": 2022,
"fingerprint": "zrzwvqXQTWp",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": "someemailaddress#yahoo.com",
"tokenization_method": null
},
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
}
=
Stripe test response:
=
object(stdClass)#1 (9) {
["created"]=>
int(1326853478)
["livemode"]=>
bool(false)
["id"]=>
string(31) "charge.succeeded_00000000000000"
["type"]=>
string(16) "charge.succeeded"
["object"]=>
string(5) "event"
["request"]=>
NULL
["pending_webhooks"]=>
int(1)
["api_version"]=>
string(10) "2018-10-31"
["data"]=>
object(stdClass)#14 (1) {
["object"]=>
object(stdClass)#2 (41) {
["id"]=>
string(17) "ch_00000000000000"
["object"]=>
string(6) "charge"
["amount"]=>
int(500)
["amount_refunded"]=>
int(0)
["application"]=>
NULL
["application_fee"]=>
NULL
["application_fee_amount"]=>
NULL
["balance_transaction"]=>
string(18) "txn_00000000000000"
["billing_details"]=>
object(stdClass)#4 (4) {
["address"]=>
object(stdClass)#3 (6) {
["city"]=>
NULL
["country"]=>
NULL
["line1"]=>
NULL
["line2"]=>
NULL
["postal_code"]=>
NULL
["state"]=>
NULL
}
["email"]=>
NULL
["name"]=>
string(25) "someemail#yahoo.com"
["phone"]=>
NULL
}
["captured"]=>
bool(false)
["created"]=>
int(1553691107)
["currency"]=>
string(3) "usd"
["customer"]=>
string(18) "cus_00000000000000"
["description"]=>
NULL
["destination"]=>
NULL
["dispute"]=>
NULL
["failure_code"]=>
string(13) "card_declined"
["failure_message"]=>
string(23) "Your card was declined."
["fraud_details"]=>
object(stdClass)#5 (1) {
["stripe_report"]=>
string(10) "fraudulent"
}
["invoice"]=>
NULL
["livemode"]=>
bool(false)
["metadata"]=>
object(stdClass)#6 (0) {
}
["on_behalf_of"]=>
NULL
["order"]=>
NULL
["outcome"]=>
object(stdClass)#7 (6) {
["network_status"]=>
string(19) "not_sent_to_network"
["reason"]=>
string(18) "merchant_blacklist"
["risk_level"]=>
string(7) "highest"
["risk_score"]=>
int(98)
["seller_message"]=>
string(28) "Stripe blocked this payment."
["type"]=>
string(7) "blocked"
}
["paid"]=>
bool(true)
["payment_intent"]=>
NULL
["payment_method_details"]=>
object(stdClass)#10 (2) {
["card"]=>
object(stdClass)#8 (10) {
["brand"]=>
string(4) "visa"
["checks"]=>
object(stdClass)#9 (3) {
["address_line1_check"]=>
NULL
["address_postal_code_check"]=>
NULL
["cvc_check"]=>
string(11) "unavailable"
}
["country"]=>
string(2) "US"
["exp_month"]=>
int(1)
["exp_year"]=>
int(2022)
["fingerprint"]=>
string(16) "Gawa768Trrk4fEmb"
["funding"]=>
string(6) "credit"
["last4"]=>
string(4) "0019"
["three_d_secure"]=>
NULL
["wallet"]=>
NULL
}
["type"]=>
string(4) "card"
}
["receipt_email"]=>
NULL
["receipt_number"]=>
NULL
["receipt_url"]=>
string(118) "https://pay.stripe.com/receipts/acct_1DU4J1IcP22cq9aQ/ch_1EIbENIcP22cq9aQk7r9xN3u/rcpt_Em9Xy3Ambv1b8QZISOsIHdbxCn"
["refunded"]=>
bool(false)
["refunds"]=>
object(stdClass)#11 (5) {
["object"]=>
string(4) "list"
["data"]=>
array(0) {
}
["has_more"]=>
bool(false)
["total_count"]=>
int(0)
["url"]=>
string(47) "/v1/charges/ch_1EIbENIcP22cq9aQk7r9xN3u/refunds"
}
["review"]=>
NULL
["shipping"]=>
NULL
["source"]=>
object(stdClass)#12 (23) {
["id"]=>
string(19) "card_00000000000000"
["object"]=>
string(4) "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"]=>
string(4) "Visa"
["country"]=>
string(2) "US"
["customer"]=>
string(18) "cus_00000000000000"
["cvc_check"]=>
string(11) "unavailable"
["dynamic_last4"]=>
NULL
["exp_month"]=>
int(1)
["exp_year"]=>
int(2022)
["fingerprint"]=>
string(16) "Gawa768Trrk4fEmb"
["funding"]=>
string(6) "credit"
["last4"]=>
string(4) "0019"
["metadata"]=>
object(stdClass)#13 (0) {
}
["name"]=>
string(25) "someemail#yahoo.com"
["tokenization_method"]=>
NULL
}
["source_transfer"]=>
NULL
["statement_descriptor"]=>
NULL
["status"]=>
string(6) "failed"
["transfer_data"]=>
NULL
["transfer_group"]=>
NULL
}
}
}
=
I'd like to get data from ["status"]=>
string(6) "failed" (the last part of the code).

Related

Change an object array into multidimensional array and print

I have a multidimensional array. I am retrieving this from UPS RateInTransit API. I am receiving this in an object. Then i convert it into a simple array.
i have received the data into json from UPS. So i converted it into php array by Json_encode and json_decode.
After that from Object array to simple array, so i found this.
object(Ups\Entity\RateResponse)#81 (1) {
["RatedShipment"]=>
array(1) {
[0]=>
object(Ups\Entity\RatedShipment)#82 (12) {
["Service"]=>
object(Ups\Entity\Service)#83 (3) {
["Description"]=>
NULL
["code":"Ups\Entity\Service":private]=>
string(2) "03"
["description":"Ups\Entity\Service":private]=>
NULL
}
["RateShipmentWarning"]=>
string(56) "Your invoice may vary from the displayed reference rates"
["BillingWeight"]=>
object(Ups\Entity\BillingWeight)#89 (2) {
["UnitOfMeasurement"]=>
object(Ups\Entity\UnitOfMeasurement)#91 (4) {
["Code"]=>
string(3) "LBS"
["Description"]=>
NULL
["code":"Ups\Entity\UnitOfMeasurement":private]=>
string(3) "LBS"
["description":"Ups\Entity\UnitOfMeasurement":private]=>
NULL
}
["Weight"]=>
string(4) "32.0"
}
["TransportationCharges"]=>
object(Ups\Entity\Charges)#84 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(43.17)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
["ServiceOptionsCharges"]=>
object(Ups\Entity\Charges)#86 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(0)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
["TotalCharges"]=>
object(Ups\Entity\Charges)#87 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(43.17)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
["GuaranteedDaysToDelivery"]=>
object(stdClass)#72 (0) {
}
["ScheduledDeliveryTime"]=>
object(stdClass)#73 (0) {
}
["RatedPackage"]=>
array(1) {
[0]=>
object(Ups\Entity\RatedPackage)#88 (5) {
["Weight"]=>
string(3) "4.0"
["BillingWeight"]=>
object(Ups\Entity\BillingWeight)#95 (2) {
["UnitOfMeasurement"]=>
object(Ups\Entity\UnitOfMeasurement)#97 (4) {
["Code"]=>
string(3) "LBS"
["Description"]=>
NULL
["code":"Ups\Entity\UnitOfMeasurement":private]=>
string(3) "LBS"
["description":"Ups\Entity\UnitOfMeasurement":private]=>
NULL
}
["Weight"]=>
string(4) "32.0"
}
["TransportationCharges"]=>
object(Ups\Entity\Charges)#85 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(43.17)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
["ServiceOptionsCharges"]=>
object(Ups\Entity\Charges)#92 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(0)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
["TotalCharges"]=>
object(Ups\Entity\Charges)#93 (5) {
["CurrencyCode"]=>
string(3) "USD"
["MonetaryValue"]=>
float(43.17)
["Code"]=>
NULL
["Description"]=>
NULL
["SubType"]=>
NULL
}
}
}
["SurCharges"]=>
array(0) {
}
["TimeInTransit"]=>
NULL
["NegotiatedRates"]=>
NULL
}
}
}
But i am unable to access ['RatedShipment]['BillingWeight']['Weight'].
Where did i write a wrong code???
What do you think to use $arr = (array) $obj;?
Because it still looks like an object.
Or you could access $obj->RatedShipment->BillingWeight->Weight?

print ckeditor content from mysql

I am trying to print my content from the ckeditor I uploaded to the db.
In the admin panel editing ckeditor it's normal,
but once I print it in the site via:
<?if (!empty($show['participants'])){?>
<Div class="participants">
<?=$show['participants']?>
</Div>
<?}?>
It's echo the tags only:
<p><strong>אנדרס מוסטונן</strong>, מנצח (אסטוניה)<br><strong>קרן הדר, </strong>סופרן (ישראל)<br><strong>ארה סאל</strong>, בריטון (אסטוניה)<br><strong>מקהלת עמק חפר </strong><br><strong>מקהלה אסטונית</strong><br><br><br><strong>בתוכנית:</strong><br><strong>אורף</strong>: כרמינה בורנה<br><strong>יואב תלמי</strong>: אלגריה למיתרים, טימפני ואקורדיון</p>
Var dumped $show:
array(27) { ["id"]=> string(3) "432" ["code"]=> string(36) "63c8bc24-f730-e811-bd2b-10604ba9908f" ["name"]=> string(10) "הקיסר" ["title_short"]=> string(163) "מפגש ענקים - כריסטיאן יארווי ורומן רבינוביץ' בביצוע "הפנטסטית" של ברליוז ו"הקיסר" של בטהובן" ["title_long"]=> string(0) "" ["description"]=> string(29) "<p> </p>" ["participants"]=> string(612) "<p><strong>כריסטיאן יארווי</strong>,מנצח (אסטוניה)<br><strong>רומן רבינוביץ'</strong>, פסנתר (ישראל)<br><br><strong>בתוכנית:</strong><br><strong>בן חיים</strong>: "תרועה לישראל"<br><strong>בטהובן</strong>: קונצ'רטו לפסנתר מס' 5 – הקיסר<br><strong>ברליוז</strong>: סימפוניה פנטסטית<br><strong>ארוו פרט</strong>: Fratres</p>" ["image"]=> string(11) "keisarx.jpg" ["image_banner"]=> string(15) "julioskeiar.jpg" ["img_credits"]=> string(18) "בלש בורוץ'" ["video"]=> string(0) "" ["category_id"]=> string(2) "60" ["category_order"]=> string(1) "0" ["show_on_main"]=> string(1) "1" ["main_order"]=> string(1) "2" ["show_on_slide"]=> string(1) "0" ["slide_order"]=> string(1) "1" ["home_page"]=> NULL ["direct_link"]=> string(58) "http://tickets.isorl.co.il/he-IL/shows/הקיסר/events/1" ["english_name"]=> NULL ["english_direct_link"]=> NULL ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["update_auto_timestamp"]=> string(19) "2018-09-02 12:12:33" ["active"]=> string(1) "1" ["is_amfi_show"]=> string(1) "0" ["is_kunhiya_show"]=> string(1) "0" ["events"]=> array(3) { ["by_id"]=> array(2) { [1191]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1193]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_order"]=> array(2) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_date"]=> array(2) { ["2018-10-07"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["2018-10-09"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } } } }
What is going wrong? Thanks.

Tricky PHP Array

I used stripe to return a Customer Object. I want to extract the bank account ID and save it in a database for later use. What is the proper syntax to access the array properly?
Here is what I have tried:
$bank_account=$customer->lastResponse['json']['sources']['data'][0]['id'];
I was told to try:
$bank_account=$customer->bank_accounts->data[0]['id'];
But that came up null as well...
Im not sure how to work with the object or what the right way to do this is.
I need the bank_account_id
This is what the var_dump($customer) looks like after some formatting and removing information that is not pertinent. I think I can either use a JSON decode or access the array called 'json' i dont know the proper syntax for either of those solutions. Help please (:
object(Stripe\Customer)#3572 (6)
{
["_opts":protected]=> object(Stripe\Util\RequestOptions)#3576 (2) { ["headers"]=> array(1) { ["Stripe-Account"]=> string(21) "acct_1BNn74AprSj6yALS" } ["apiKey"]=> string(32) "secretkey" }
["_values":protected]=> array(15) {//Removed For brevity}
["_unsavedValues":protected]=> object(Stripe\Util\Set)#3590 (1) { ["_elts":"Stripe\Util\Set":private]=> array(0) { } } ["_transientValues":protected]=> object(Stripe\Util\Set)#3602 (1) { ["_elts":"Stripe\Util\Set":private]=> array(0) { } } ["_retrieveOptions":protected]=> array(0) { }
["_lastResponse":protected]=>
object(Stripe\ApiResponse)#3714 (4)
{
["headers"]=> array(15) { //Removed for brevity}
// Json
["body"]=> string(1148) "{
"id": "cus_BoJOjFghfV7mmq", "object": "customer", "account_balance": 0, "created": 1511290036, "currency": null, "default_source": "bank_account_id", "delinquent": false, "description": "Name", "discount": null, "email": null, "livemode": true, "metadata": {}, "shipping": null, "sources": { "object": "list", "data": [ { "id": "bank_account_id", "object": "bank_account", "account_holder_name": "Daniel Taylor", "account_holder_type": "individual", "bank_name": "Bank Name", "country": "US", "currency": "usd", "customer": "cus_id", "fingerprint": "info", "last4": "last four of account", "metadata": {}, "routing_number": "routing number", "status": "new" } ], "has_more": false, "total_count": 1, "url": "/v1/customers/cus_BoJOjFghfV7mmq/sources" }, "subscriptions": { "object": "list", "data": [], "has_more": false, "total_count": 0, "url": "/v1/customers/cus_BoJOjFghfV7mmq/subscriptions" }
} "
["json"]=> array(15)
{
["id"]=> string(18) "cus_id"
["object"]=> string(8) "customer"
["account_balance"]=> int(0)
["created"]=> int(1511290036)
["currency"]=> NULL
["default_source"]=> string(27) "bank_account_id"
["delinquent"]=> bool(false)
["description"]=> string(13) "Name"
["discount"]=> NULL
["email"]=> NULL ["livemode"]=> bool(true)
["metadata"]=> array(0) { }
["shipping"]=> NULL
["sources"]=> array(5)
{
["object"]=> string(4) "list"
["data"]=> array(1)
{
[0]=> array(13)
{
["id"]=> string(27) "bank_account_id" ["object"]=> string(12) "bank_account"
["account_holder_name"]=> string(13) "name"
["account_holder_type"]=> string(10) "individual"
["bank_name"]=> string(26) "Bank Name"
["country"]=> string(2) "US" ["currency"]=> string(3) "usd"
["customer"]=> string(18) "cus_ID"
["fingerprint"]=> string(16) "fingerprint"
["last4"]=> string(4) "lastfour" ["metadata"]=> array(0) { }
["routing_number"]=> string(9) "routenumber"
["status"]=> string(3) "new"
}
}
["has_more"]=> bool(false)
["total_count"]=> int(1)
["url"]=> string(40) "/v1/customers/cus_BoJOjFghfV7mmq/sources"
}
["subscriptions"]=> array(5) { ["object"]=> string(4) "list" ["data"]=> array(0) { } ["has_more"]=> bool(false) ["total_count"]=> int(0) ["url"]=> string(46) "/v1/customers/cus_id/subscriptions" }
}
["code"]=> int(200)
}
}
I think it should be:
$bank_account = $customer->sources->data[0]->id
If the customer has multiple fund sources, you may need to loop through the data array to find the one you want. $customer->sources->data[$i]->object will be "bank_account" for the source you want.
Pretty sure there is a getter in there. You can just use the properties you would expect on the object.
Example:
$customer_id = $customer->id;
$bank_account_id = $customer->sources->data[0]->id;

Cake PHP how to add array to find fields

I'm using cakephp 2.x and I would like to get certain element as field from my model. the problem is with my structure. If I use find all then I recieve this:
array(9) {
[0]=> ...
[1]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(2)
["imie"]=>
string(6) "STEFAN"
["nazwisko"]=>
string(8) "ŚMIAŁY"
["tel"]=>
string(13) "+55 648989748"
["mob"]=>
string(13) "+87 489747489"
["email"]=>
string(25) "HSDJKAHSDJK#HSDFJASHF.CIJ"
["tytul_naukowy"]=>
string(7) "TEZ NIE"
["data_od"]=>
string(10) "2017-02-16"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(28)
["created"]=>
string(22) "2017-02-16 13:22:32+01"
["modified"]=>
string(22) "2017-02-16 13:22:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(17) "UDIHAS#HFSDKFH.OK"
["description"]=>
string(4) "OPIS"
["displayName"]=>
string(15) "STEFAN ŚMIAŁY"
}
["Duty"]=>
array(3) {
["id"]=>
int(28)
["nazwa"]=>
string(20) "KOORDYNATOR RECEPCJI"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(2)
["nazwa"]=>
string(10) "OBK Z ID 2"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 15:11:31+01"
["created"]=>
string(22) "2014-05-12 21:50:17+02"
["deleted"]=>
int(0)
["local_order"]=>
int(3)
["displayName"]=>
string(10) "OBK Z ID 2"
["objectTypeIdWithId"]=>
string(3) "2_2"
["PeopleObk"]=>
array(3) {
["id"]=>
int(1)
["person_id"]=>
int(2)
["obk_id"]=>
int(2)
}
}
}
}
[2]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(3)
["imie"]=>
string(5) "KAMIL"
["nazwisko"]=>
string(10) "STEFAŃSKI"
["tel"]=>
string(13) "+23 123123123"
["mob"]=>
string(13) "+21 412312312"
["email"]=>
string(16) "ASDASD#SDFDSF.LS"
["tytul_naukowy"]=>
string(3) "NIE"
["data_od"]=>
string(10) "2017-02-22"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(26)
["created"]=>
string(22) "2017-02-22 16:14:32+01"
["modified"]=>
string(22) "2017-02-22 16:14:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(22) "ADAM.2313#WEBIMPULS.PL"
["description"]=>
string(4) "TEST"
["displayName"]=>
string(16) "KAMIL STEFAŃSKI"
}
["Duty"]=>
array(3) {
["id"]=>
int(26)
["nazwa"]=>
string(41) "KOORDYNATOR OŚRODKÓW BADAŃ KLINICZNYCH"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(3)
["nazwa"]=>
string(10) "OBK Z ID 3"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 10:45:24+01"
["created"]=>
string(22) "2014-05-16 09:09:33+02"
["deleted"]=>
int(0)
["local_order"]=>
int(1)
["displayName"]=>
string(10) "OBK Z ID 3"
["objectTypeIdWithId"]=>
string(3) "2_3"
["PeopleObk"]=>
array(3) {
["id"]=>
int(2)
["person_id"]=>
int(3)
["obk_id"]=>
int(3)
}
}
}
}
And I want just to retrieve Person.id, Person.displayName and Obk.0.id. The two first are no problem, but wheneve I try to get Obk.0.id I'm getting error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM for Table Obk.
How can I get something like that? I want to set the value in codition later, but it block my work.
In CakePHP 2 you can specify the fields you want returned by a find() query using the fields option like:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name']
]);
This also works with contained models that have a belongsTo or hasOne relationship:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name', 'Bar.name'],
'contain' => ['Bar']
]);
However, if the contained model is a hasMany or HABTM relationship you need to specify the fields of that model on the contain:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name'],
'contain' => [
'Bar' => ['fields' => 'Bar.name']
]
]);
This is because CakePHP will be performing multiple SQL queries, so the contain needs to have the parameters for the query being run for the relevant model.

Access object without foreach

object(Zend_Paginator)#88 (11) {
["_cacheEnabled":protected]=>
bool(true)
["_adapter":protected]=>
object(Zend_Paginator_Adapter_Array)#89 (2) {
["_array":protected]=>
array(150) {
[0]=>
array(19) {
["location"]=>
string(15) "New York"
["id"]=>
string(3) "186"
["user_id"]=>
string(1) "2"
["date"]=>
string(10) "1367893034"
["attachment"]=>
string(1) "0"
["content"]=>
string(4) "nhzu"
["first_name"]=>
string(6) "John"
["last_name"]=>
string(6) "Doe"
["thumb_id"]=>
NULL
["thumb_user_id"]=>
NULL
["file_name"]=>
NULL
["folder_name"]=>
NULL
["server_key"]=>
NULL
["type"]=>
NULL
["photo_file_name"]=>
NULL
["photo_folder_name"]=>
NULL
["photo_server_key"]=>
NULL
["photo_id"]=>
NULL
["count_total"]=>
NULL
}
[1]=>
How do I acces the conectent of id without a foreach, I need only the first one 0 ? any ideas?
$item = $paginator->getItem(1);
See http://framework.zend.com/svn/framework/standard/tags/release-1.12.3/library/Zend/Paginator.php the public function getItem function definition

Categories