#giuliano-invoice-subscription

1 messages ยท Page 1 of 1 (latest)

weary tapirBOT
peak shuttle
#

Hello

#

Yeah that's correct

#

So you would need to loop over the items in the array to grab each value

royal flame
#

I'm testing with $plan = $event->data->object->lines->data->plan; and it doesn't work, but when I leave it until $plan = $event->data->object->lines->data; it works

#
$billing = $event->data->object->billing_reason;
if (strval($billing) === 'subscription_create'){
  $id_sub = $event->data->object->subscription;
  $customer = $event->data->object->customer;
  $plan = $event->data->object->lines->data->plan;
  file_put_contents('stripe_webhook.txt', $plan, FILE_APPEND);
  $amount = $event->data->object->amount;
  /*$insertsub = $iN->iN_InsertNewSubscriber($id_sub, $amount);*/
}```
my code
peak shuttle
#

Yes becuase data is an array as you already stated

#

So you need to write more code to loop over the different objects in the array

royal flame
#

ok, i will try

#

thank you

peak shuttle
#

๐Ÿ‘

weary tapirBOT
torn umbra
#

@royal flame also the Plan API was deprecated in 2018. You really should use the Price API instead

#

giuliano-invoice-subscription

royal flame
#

Price API ?

torn umbra
#

don't use plan, use price

royal flame
#

ok, thanks

#

I'm having difficulty accessing the array in PHP, I'm trying data[1] and it doesn't work either

torn umbra
#

All good. Step 1: debug ๐Ÿ™‚
Add clear logs to your code to log each part of the object to understand what's missing!

torn umbra
#

@royal flame did you make progress?

royal flame
#

yeah

#

I just created a variable and then used simple json
$object = $event->data->object;

$plan = $object['lines']['data'][0]['price'];

#

I copied from here

#

@torn umbra
a question,
when a subscription is created it shows sub_, cus_ and plan_
Every time this subscription is renewed, will it have the same value in sub_ cus_ and plan_?

torn umbra
royal flame
#

thanks

#

@torn umbra
"billing_reason": "subscription_cycle",
Does this represent a subscription renewal?