2

I have the following array:

["entity_id"] => "1"
["customer_id"] => "18"
["public_hash"] => "xxxxxxxxxx041e6f5246f041429424422795137118223d73bb6197410f9cbc77"
["payment_method_code"] => "braintree"
["type"] => "card"
["created_at"] => "2018-12-19 21:24:13"
["expires_at" => "2020-06-01 00:00:00" "gateway_token"] => "8cx9y7"
["details"] => "{"type":"AE","maskedCC":"0005","expirationDate":"05\\\\\\\\/2020"}"
["is_active"] => "1"
["is_visible"] => "1"

And I'm trying to get the values from ["details"] separately (type, maskedCC, expirationDate)

Using $details = $card->getData('details'); I'm able to narrow it down to:

{"type":"AE","maskedCC":"0005","expirationDate":"05\/2020"}

From there, I'm not sure how to get the values AE, 0005, 05/2020.

2 Answers 2

3

You're dealing with a jsonObj. You've to decode it to array first. $key will be the attribute you want to get like (type, maskedCC, expirationDate)

$jsonArray = json_decode($details,true);
echo $jsonArray[$key];
Sign up to request clarification or add additional context in comments.

Comments

2

Since it's a string and looks to be valid JSON, you can just decode it:


$details = json_decode($card->getData('details'), true);

if (!empty($details))
{
    //Valid JSON
    echo $details['type'];
    echo $details['maskedCC'];
    echo $details['expirationDate'];
}
else
{
    echo 'The details string was not valid JSON.';
}

1 Comment

ahh, not sure why I didn't realize that.. thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.