Stripe checkout.session.completed and expanded objects

193 Views Asked by At

I've been working on Stripe for some time but with simple payments. I'm trying to get subscriptions going, have a good bit of the flow working but have hit a roadblock.

On the "checkout.session.completed" I should be able to get further information back on the subscription so I can tie up the next step (payment_intent)

Have setup Subscription and generally working but unable to get the expanded response in correct format.

https://stripe.com/docs/expand shows this format:

{
  "id": "cs_test_xyzabc",
  "object": "checkout.session",
  ...
  "customer": {
    "id": "cus_123456",
    "object": "customer",
    ...
    "metadata": {
      "user_id": "user_xyz"
    },
    ...
  }
}

but all I get is something like this:

Stripe\Service\Checkout\SessionService Object
(
    [client:protected] => Stripe\StripeClient Object
        (
            [coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object
                (
                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                        (
                            [checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object
                                (
                                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                                        (
                                            [sessions] => Stripe\Service\Checkout\SessionService Object


here is my code:
    $stripe = new \Stripe\StripeClient($KEY);
    $stripe->checkout->sessions->retrieve(
  $SUB_CS,
  ['expand' => ['customer']]
    );

and the only way I can seem to get any response is by:

print_r ( $stripe->checkout->sessions, true ) ; // this is the checkout/SessionService object above above

I thought I could do this to get data:

$CUST_ID = $stripe->checkout->sessions->customer->id ; but it fails to extract the data.

I also tried this but got no data foreach ($stripe->checkout->sessions as $line) print "$line\n" ;

thanks for any pointers here. Brian

I've tried a variety of formats to get the data, tried dumping the response but only way seems to be the print_r the data shown is clearly wrong so I'm doing something silly :o) I've also tried to get the subscription and invoice data but all i get is the wrongly formatted response.

0

There are 0 best solutions below