doc1355 Posted November 15, 2021 Share Posted November 15, 2021 I have a stripe session that when I print I get the following: Stripe\LineItem Object ( [id] => li_1JwCsEAy5kUVbSuGjlYtZ6l7 [object] => item [amount_subtotal] => 2599 [amount_total] => 2340 [currency] => usd [description] => 2022 - Season 1 [price] => Stripe\Price Object ( [id] => price_1JwCsEAy5kUVbSuGHcfoxDhg [object] => price [active] => [billing_scheme] => per_unit [created] => 1637012278 [currency] => usd [livemode] => [lookup_key] => [metadata] => Stripe\StripeObject Object ( ) [nickname] => [product] => prod_KbPhMZ545KIQ90 [recurring] => [tax_behavior] => unspecified [tiers_mode] => [transform_quantity] => [type] => one_time [unit_amount] => 2599 [unit_amount_decimal] => 2599 ) [quantity] => 1 ) Stripe\LineItem Object ( [id] => li_1JwCsEAy5kUVbSuGDqbrfvRm [object] => item [amount_subtotal] => 2899 [amount_total] => 2608 [currency] => usd [description] => 2022 - Season 2 [price] => Stripe\Price Object ( [id] => price_1JwCsEAy5kUVbSuGW58akYjw [object] => price [active] => [billing_scheme] => per_unit [created] => 1637012278 [currency] => usd [livemode] => [lookup_key] => [metadata] => Stripe\StripeObject Object ( ) [nickname] => [product] => prod_KbPhcd6yq2Mrl6 [recurring] => [tax_behavior] => unspecified [tiers_mode] => [transform_quantity] => [type] => one_time [unit_amount] => 2899 [unit_amount_decimal] => 2899 ) [quantity] => 1 ) I don't know how to get the values from this data, like value of amount_total and ... Also, and more importantly, I need to get the values from [metadata]. There are two metadata information for each price, which I like to get. Thank you, Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/ Share on other sites More sharing options...
Barand Posted November 15, 2021 Share Posted November 15, 2021 Have you tried $amount_total = $line_item->amount_total; where $line_item is on of your line item objects? Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592153 Share on other sites More sharing options...
doc1355 Posted November 15, 2021 Author Share Posted November 15, 2021 That worked for the line item. I was doing more weird stuff 🤦♂️ How about the [metadata]: How can I get the values in there? Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592154 Share on other sites More sharing options...
Barand Posted November 15, 2021 Share Posted November 15, 2021 Not sure - I don't see anything in there Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592156 Share on other sites More sharing options...
doc1355 Posted November 15, 2021 Author Share Posted November 15, 2021 When I look in Stripe dashboard, I see the metadata is saved appropriately under the price. But I don't know why it is not showing here, instead it is returning Stripe\StripeObject Object that's what I'm trying to figure out so that I can use that data. Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592157 Share on other sites More sharing options...
Barand Posted November 15, 2021 Share Posted November 15, 2021 Does this show anything echo '<pre>' . print_r($line_item->price->metadata, 1) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592158 Share on other sites More sharing options...
doc1355 Posted November 15, 2021 Author Share Posted November 15, 2021 No. It returns Stripe\StripeObject Object ( ) Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592160 Share on other sites More sharing options...
Barand Posted November 16, 2021 Share Posted November 16, 2021 Plan B... echo '<pre>' . print_r($line_item->price->metadata->keys(), 1) . '</pre>'; echo '<pre>' . print_r($line_item->price->metadata->values(), 1) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592164 Share on other sites More sharing options...
Solution doc1355 Posted November 16, 2021 Author Solution Share Posted November 16, 2021 Thank you for your reply. But I was able to figure this out. The metadata is associated with another object. I used the ID from this object to retrieve the second object and was able to retrieve the metadata there. Thank you again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/314237-get-metadata-from-stripe-session/#findComment-1592165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.