#arielbo - PHP
1 messages ยท Page 1 of 1 (latest)
hello rubeus
please I want to do this:
foreach ($d_json as $k => $v)
{
$clase = $v['c'];
$producto_id = $v['p'];
$precio_stripe = $v['a'];
$order_dcarrito .= [ 'price_data' => [ 'unit_amount' => $precio_stripe, 'currency' => 'usd', 'product' => '$producto_id', 'recurring' => [ 'interval' => 'month', 'interval_count'=> 1, ], 'tax_behavior' => 'exclusive', ], ];
}
//$order_dcarrito = str_replace('\n','',$order_dcarrito);
$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [
$order_dcarrito
],
'cancel_at_period_end' => false,
'automatic_tax' => [
'enabled' => true,
], ```
my questions is how can add in this place
'items' => [
$order_dcarrito
],
multiples [ 'price_data' => [ ..... I use a string in variable $order_dcarrito but I think that maybe your code need array or another notation ? please your help in this issue
You mean in here you want to specify multiple price_data objects?
$order_dcarrito .= [ 'price_data' => [ 'unit_amount' => $precio_stripe, 'currency' => 'usd', 'product' => '$producto_id', 'recurring' => [ 'interval' => 'month', 'interval_count'=> 1, ], 'tax_behavior' => 'exclusive', ], ];
yes inside foreach
I'm a bit lost in how I will inject the multiple price_data into the stripe object of create subscription
Have you tried something like this?
$order_dcarrito .= [
'price_data' => [
'unit_amount' => $precio_stripe,
'currency' => 'usd',
'product' => '$producto_id',
'recurring' => [
'interval' => 'month',
'interval_count'=> 1,
],
'tax_behavior' => 'exclusive',
],
'price_data' => [
'unit_amount' => // New values here...
],
];
Status
400 ERR
ID
req_bA7UyLc0fJ3tn5
Can you show me the updated code?
Wait, why is it in quotes?
That makes it a string.
Let's back up... are you trying to add a new price_data each time the foreach loop iterates?
Okay, so you need to create an array to hold the items, then add each one to the array.
Where is $order_dcarrito defined?
ok your code accept array yes?
Yes.
You need to do something like $order_dcarrito = []; to make it an empty array to start with (outside the foreach loop), then add each item to the array inside the foreach loop with something like $order_dcarrito[] = [ 'price_data' => /* ... */ ]; and then do 'items' => $order_dcarrito when you create the Subscription.
Does that make sense?
let me try
I understand
Status
400 ERR
ID
req_w4osiD4a9NxV7Y
foreach ($d_json as $k => $v)
{
$clase = $v['c'];
$producto_id = $v['p'];
$precio_stripe = $v['a'];
$order_dcarrito[] = [ 'price_data' => [
'unit_amount' => $precio_stripe,
'currency' => 'usd',
'product' => '$product_id_stripe',
'recurring' => [
'interval' => 'month',
'interval_count'=> 1,
],
'tax_behavior' => 'exclusive',
],
];
}
$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [
$order_dcarrito
],
'cancel_at_period_end' => false, ```
not work ๐ฆ still
it's hard to say right now. Add logs to your code to figure out what's not working. The error says that $order_dcarrito is empty. Are you sure you even get inside the foreach? Add an echo there, what's in the variable at the end?
please give me a few minutes I try better maybe not save my file sftp
Of course! But really as the dev, you need to debug your own code. The error is fairly clear and says that items is missing so you add logs and you debug quickly!
yey
POST /v1/subscriptions
Status
200 OK
ID
req_g89yHbglxuUIEM
works ! I mean maybe you can confirme this ?
Without your help it would not have been possible, I really appreciate your collaboration with your entire team, thank you very much
you're creating a subscription with multiple prices so it seems to work fine yes, congrats!
yes with this can I create my own cart flow
thanks a lot your support service is first class really
Thanks for the kind words ๐
thanks to you, in this implementation
I realized that it would be important that when the price_data is used, the interval is not limited to the subscription created, but rather different intervals can be combined (monthly, yearly, etc.) because in this way a subscription cart can be created in such a way For people to choose different products and they can all be paid in the same invoice, I understand that this option does not exist for now, but how could you make this requirement known to your stripe development team so that they may value it for later?
@static jewel It's honestly not something we'll build for a long time. You can totally share the feedback with our support team https://support.stripe.com/contact and we'll log it but by design we have no plans to support multiple periods on a Subscription
I understand