#arielbo - PHP

1 messages ยท Page 1 of 1 (latest)

stone heron
#

Hello! What's your question?

static jewel
#

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

stone heron
#

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', ], ]; 
static jewel
#

yes inside foreach

#

I'm a bit lost in how I will inject the multiple price_data into the stripe object of create subscription

stone heron
#

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...
  ],
]; 
static jewel
#

Status
400 ERR
ID
req_bA7UyLc0fJ3tn5

stone heron
#

Can you show me the updated code?

static jewel
stone heron
#

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?

static jewel
#

yes

#

and them put this inside $stripe->subscriptions->create([

stone heron
#

Okay, so you need to create an array to hold the items, then add each one to the array.

#

Where is $order_dcarrito defined?

static jewel
#

ok your code accept array yes?

stone heron
#

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?

static jewel
#

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

weak ginkgo
#

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?

static jewel
#

please give me a few minutes I try better maybe not save my file sftp

weak ginkgo
#

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!

static jewel
#

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

weak ginkgo
#

you're creating a subscription with multiple prices so it seems to work fine yes, congrats!

static jewel
#

yes with this can I create my own cart flow

#

thanks a lot your support service is first class really

weak ginkgo
#

Thanks for the kind words ๐Ÿ™‚

static jewel
#

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?

weak ginkgo
#

@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

static jewel
#

I understand