#speedemin_code

1 messages ยท Page 1 of 1 (latest)

placid solsticeBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1308498736560869418

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

plush helm
shell shard
#

req_uPDBj9O2MfEOg9

plush helm
#

Looks like you're passing in an invalid value for the first item in the first phase. Looks like your PHP code is trying to treat a Stripe object as a string and shove the resulting JSON output in there. Have a look at the request in your Dashboard to see what I mean: https://dashboard.stripe.com/test/logs/req_uPDBj9O2MfEOg9

#

I think there's something else happening beyond the code you shared above. Do you recognize where that Stripe object is coming from?

shell shard
#

The schedule has an item already that was created using the dashboard and I want to add a second item via the code

plush helm
#

Can you share more of your code? Like more from before the code you shared above?

shell shard
#

$schedules = $stripe->subscriptionSchedules->all(['scheduled' => true]);

foreach ($schedules['data'] as $schedule) {
// create the $price_id and $quantity variables

#

That's all there is before the code I submitted

plush helm
#

I'm not sure how that code could result in this request... ๐Ÿค”

shell shard
#

It seems like this line $phase = $schedule->phases[0]; gets the existing phase with its existing item and when I add the item and call update the first item throws an error because it's not formatted the same way

plush helm
#

If you var_dump($phase) just before calling update what do you see?

placid solsticeBOT
shell shard
#

object(Stripe\StripeObject)#1435 (20) {
["add_invoice_items"]=>
array(0) {
}
["application_fee_percent"]=>
NULL
["billing_cycle_anchor"]=>
NULL
["billing_thresholds"]=>
NULL
["collection_method"]=>
NULL
["coupon"]=>
NULL
["currency"]=>
string(3) "usd"
["default_payment_method"]=>
NULL
["default_tax_rates"]=>
array(0) {
}
["description"]=>
NULL
["discounts"]=>
array(0) {
}
["end_date"]=>
int(1735707600)
["invoice_settings"]=>
object(Stripe\StripeObject)#1450 (3) {
["account_tax_ids"]=>
NULL
["days_until_due"]=>
NULL
["issuer"]=>
NULL
}
["items"]=>
array(2) {
[0]=>
object(Stripe\StripeObject)#1451 (7) {
["billing_thresholds"]=>
NULL
["discounts"]=>
array(0) {
}
["metadata"]=>
object(Stripe\StripeObject)#1459 (0) {
}
["plan"]=>
string(30) "price_1Q19kEBGIJvjY5EFNvWaWX0r"
["price"]=>
string(30) "price_1Q19kEBGIJvjY5EFNvWaWX0r"
["quantity"]=>
int(1)
["tax_rates"]=>
array(0) {
}
}
[1]=>
array(2) {
["price"]=>
string(30) "price_1Q3L0tBGIJvjY5EFhAb3zdBB"
["quantity"]=>
int(329)
}
}
["metadata"]=>
object(Stripe\StripeObject)#1455 (0) {
}
["on_behalf_of"]=>
NULL
["proration_behavior"]=>
string(4) "none"
["start_date"]=>
int(1733029200)
["transfer_data"]=>
NULL
["trial_end"]=>
NULL
}

little pawn
#

Hi, stepping in and catching up here

plush helm
#

Ah, okay, that's the entire Stripe object. You need to extract the values you want to create the new phase parameters, you can't just use the entire phase object like that.

shell shard
#

I tried changing it to this
$schedules = $stripe->subscriptionSchedules->all(['scheduled' => true]);
foreach ($schedules['data'] as $schedule) {
// create the $price_id and $quantity variables
$phase = $schedule->phases[0];
$phase->items[0] = [
'price' => $phase->items[0]->price,
'quantity' => $phase->items[0]->quantity,
];
$phase->items[1] = [
'price' => $cc_price_id,
'quantity' => $multiplier,
];
$stripe->subscriptionSchedules->update($schedule->id, [
'phases' => [$phase],
]);
}
and got this req_veYVREBADgrxQS

plush helm
#

I'm still a bit confused as to how it's being passed through as a string, but that must be happening somewhere in the library during the update call because it doesn't expect a Stripe object as a parameter value, so it treats it as a string somewhere.

#

The key is to not do $phase = $schedule->phases[0]; and then try to modify that $phase. You need to create basic parameter values to pass in, meaning plain arrays, strings, etc.

shell shard
#

Okay I'll try that

#

I got it to work with this code:
$schedules = $stripe->subscriptionSchedules->all(['scheduled' => true]);
foreach ($schedules['data'] as $schedule) {
// create the $price_id and $quantity variables
$phase = $schedule->phases[0];
$newPhase = [
'start_date' => $phase->start_date,
'end_date' => $phase->end_date,
'items' => [
['price' => $phase->items[0]->price, 'quantity' => $phase->items[0]->quantity],
['price' => $price_id, 'quantity' => $quantity]
]
];
$schedule = Cashier::stripe()->subscriptionSchedules->update($schedule->id, [
'phases' => [$newPhase],
]);
}

Thanks for your help!