#arielbo-subs

1 messages · Page 1 of 1 (latest)

pale flame
#

hello, some of the terms you have used are not clear, can you rephrase where you are blocked? What Stripe part are you blocked on

foggy drum
#

The problem I have is that I have a product that has multiple prices and I generate it online but this product must be bought multiple times with different prices.

#

When I use this code:

#

if(empty($json_obj->s_price_id)) {
$subscription = $stripe->subscriptions->create([
'customer' => $json_obj->cus,
'items' => [[
'price_data' => [
'unit_amount' => 123,
'currency' => 'usd',
'product' => 22222t,
'recurring' => [
'interval' => 'day',
'interval_count'=> 7,
],
'tax_behavior' => 'inclusive',
],
'price_data' => [
'unit_amount' => 345,
'currency' => 'usd',
'product' => 2222,
'recurring' => [
'interval' => 'day',
'interval_count'=> 14,
],
'tax_behavior' => 'inclusive',
],
]],
'cancel_at_period_end' => true,
'automatic_tax' => [
'enabled' => true,
],

#

as you can see, is the same product id, price in line, but not work when I run this code just created the last price_data with 345 unit_amount but not at the first

pale flame
#

but not work when I run this code just created the last price_data with 345 unit_amount but not at the first
can you share the request ID for that Sub create request? from https://dashboard.stripe.com/test/logs

foggy drum
#

of course

#

"id": "sub_1JpG2wHHulAmiNnDFFnmyEk2",

#

Status
200 OK
ID
req_lcFTcXhatn4KGp

#

what I expected is that the two subscriptions are created separately, understand me? and are charged in a single invoice

#

do you understand me?

pale flame
#

thanks, looking

foggy drum
#

thank you please

pale flame
#

mind if I pull your other question in here too?

#
There is some way to charge in a single invoice, in php stripe, using this code:

$ sub1 = \ Stripe \ Subscription :: create ([
     'customer' => 'cus_4fdAW5ftNQow1a',
     'items' => [['price' => 'price_CZB2krKbBDOkTS']],
]);

$ sub2 = \ Stripe \ Subscription :: create ([
     'customer' => 'cus_4fdAW5ftNQow1a',
     'items' => [['price' => 'price_CZB1AX3KOacNJw']],
]);


How could I join them so that the payment is made only once? 
#

your other question

foggy drum
#

of course, really are connected

#

if this new question is answer the first question its not necesary, I need to create one invoice with múltiples items all are subscriptions

#

I need the correct method to doing this please

supple tree
#

Hello! To do this you would only create one Subscription and put both Prices inside the items array.

#

Something like this:

$sub = \Stripe\Subscription::create ([
     'customer' => 'cus_4fdAW5ftNQow1a',
     'items' => [
          ['price' => 'price_CZB2krKbBDOkTS'],
          ['price' => 'price_CZB1AX3KOacNJw'],
     ],
]);
foggy drum
#

I need to use the same product id with variable prices

#

product 1. product 123 - price 2.23 $
product 2. product 123 - price 6.23 $
product 3. product 123 - price 1.23 $

#

$sub = \Stripe\Subscription::create ([
'customer' => 'cus_4fdAW5ftNQow1a',
'items' => [
['price_data' => .....
['price_data' => ....
],
]);

supple tree
#

Right... that's how you would do this. Why would the approach above not work for you?

foggy drum
#

becouse my product have an variable price by page

foggy drum
#

??

#

In short, I am facing two possibilities to use a single subscription creation that includes several items using price_data (which is not working for me with the code that I shared with you) and the second option is to create several separate subscriptions where I think the logic of the Same product with variable price in line, but I don't know how I would associate the 2, 3 or more subscriptions created to charge them in a single invoice. Please, can you confirm that you understand my two possibilities, or am I missing something?

supple tree
#

The code above doesn't work because it doesn't look like you have the correct syntax in several places. Can you paste the exact code that produced req_lcFTcXhatn4KGp inside a code block here with no modifications?

#

Like 'product' => 22222t, is not valid PHP code.

foggy drum
#
                                'customer' => $json_obj->cus, 
                                'items' => [[
                                  'price_data' => [
                                    'unit_amount' => $json_obj->price, 
                                    'currency' => 'usd',
                                    'product' => $json_obj->s_product, 
                                    'recurring' => [
                                      'interval' => 'day',
                                      'interval_count'=> 7,
                                    ],
                                    'tax_behavior' => 'inclusive',
                                  ],
                                  'price_data' => [
                                    'unit_amount' => 22222, 
                                    'currency' => 'usd',
                                    'product' => $json_obj->s_product, 
                                    'recurring' => [
                                      'interval' => 'day',
                                      'interval_count'=> 14,
                                    ],
                                    'tax_behavior' => 'inclusive',
                                  ],
                                ]],
                                'cancel_at_period_end' => true,
                                'automatic_tax' => [
                                  'enabled' => true,
                                ],
                                'payment_behavior' => 'default_incomplete',
                                'expand' => ['latest_invoice.payment_intent.'],
                            ]);  ```
supple tree
#

Can you edit your message so that code is inside a PHP code block? You can put three backticks followed by php at the top, then three backticks at the bottom.

foggy drum
supple tree
#

Oh, you have different intervals. You can't have different intervals on the same Subscription:

Since using multiple products with a subscription results in a single invoice and payment, all of the prices for those products must use the same currency and have the same billing interval. You are also limited to 20 products in a single subscription.

#

If you changed the interval on both Prices to be the same it should work as expected.

foggy drum
#

let me try, but I have subscriptions with different intervals

#

req_3cH0fIN2a6J5gd

#

this is the new req

supple tree
#

You can have separate Subscriptions with different intervals, but you can't have a single Subscription with multiple items that have different intervals.

#

Can you share the code that produced that request? And please wrap it in a code block like this:

foggy drum
#
  "customer": "cus_KJUdqlTYBAEYCu",
  "items": {
    "0": {
      "price_data": {
        "unit_amount": "22222",
        "currency": "usd",
        "product": "prod_KPVrC4nV3rPooT",
        "recurring": {
          "interval": "day",
          "interval_count": "7"
        },
        "tax_behavior": "inclusive"
      }
    }
  },
  "cancel_at_period_end": "true", ```
#

just create one subscription

supple tree
#

Can you share the code?

#

The PHP code?

foggy drum
#

of course

#
                                'customer' => $json_obj->cus, 
                                'items' => [[
                                  'price_data' => [
                                    'unit_amount' => $json_obj->price, 
                                    'currency' => 'usd',
                                    'product' => $json_obj->s_product, 
                                    'recurring' => [
                                      'interval' => 'day',
                                      'interval_count'=> 7,
                                    ],
                                    'tax_behavior' => 'inclusive',
                                  ],
                                  'price_data' => [
                                    'unit_amount' => 22222, 
                                    'currency' => 'usd',
                                    'product' => $json_obj->s_product, 
                                    'recurring' => [
                                      'interval' => 'day',
                                      'interval_count'=> 7,
                                    ],
                                    'tax_behavior' => 'inclusive',
                                  ],
                                ]],
                                'cancel_at_period_end' => true,
                             ```
#

I put the same interval

supple tree
#

To clarify, this approach does work, I just ran this code successfully on my test account:

$subscription = \Stripe\Subscription::create([
    'customer' => $customerID,
    'items' => [
        [
            'price_data' => [
                'product' => 'prod_F7BbaXYK6k12Bl',
                'currency' => 'USD',
                'unit_amount' => '4200',
                'recurring' => [
                    'interval' => 'month',
                    'interval_count' => 1,
                ],
            ],
        ],
        [
            'price_data' => [
                'product' => 'prod_F7BbaXYK6k12Bl',
                'currency' => 'USD',
                'unit_amount' => '2400',
                'recurring' => [
                    'interval' => 'month',
                    'interval_count' => 1,
                ],
            ],
        ],
    ],
]);
foggy drum
#

let me see

#

well but this solution not work for me becaouse in my cart I have multiple subscriptions with different intervals

supple tree
#

If you need different intervals you need separate Subscriptions.

foggy drum
#

while test the first solution with the same interval (here maybe I need to unifor all product intervals ie. 1 month) , in this second scenario when I create separate subscriptions, to charge all subscriptions in a single invoice? is this possible?

supple tree
#

I think your code above isn't working as expected because you have your square brackets in the wrong place. When I format your code there's a double ]] at the end here:

'items' => [
    [
        'price_data' => [
        'unit_amount' => $json_obj->price, 
        'currency' => 'usd',
        'product' => $json_obj->s_product, 
        'recurring' => [
            'interval' => 'day',
            'interval_count'=> 7,
        ],
        'tax_behavior' => 'inclusive',
    ],
        'price_data' => [
        'unit_amount' => 22222, 
        'currency' => 'usd',
        'product' => $json_obj->s_product,
        'recurring' => [
            'interval' => 'day',
            'interval_count'=> 7,
        ],
        'tax_behavior' => 'inclusive',
    ],
]],
'cancel_at_period_end' => true,
#

No, separate Subscriptions will generate their own, separate Invoices.

#

There is no way to have a single Invoice for multiple Subscription items with different intervals.

foggy drum
#

I understand about separate subscriptions, let me try now with your advice my code

#

maybe can I uniform interval

supple tree
#

Wait, did I format that code right...

foggy drum
supple tree
#

No, I didn't!

foggy drum
#

this is my code please in which place you see the error in format?

supple tree
#

The [[ after items makes it really hard to read this code.

foggy drum
#

I cant paste all my code becaouse discord have limit

foggy drum
supple tree
#

Try this:

'items' => [
    [
        'price_data' => [
            'unit_amount' => $json_obj->price, 
            'currency' => 'usd',
            'product' => $json_obj->s_product, 
            'recurring' => [
                'interval' => 'day',
                'interval_count'=> 7,
            ],
            'tax_behavior' => 'inclusive',
        ],
    ],
    [
        'price_data' => [
            'unit_amount' => 22222, 
            'currency' => 'usd',
            'product' => $json_obj->s_product,
            'recurring' => [
                'interval' => 'day',
                'interval_count'=> 7,
            ],
            'tax_behavior' => 'inclusive',
        ],
    ]
],
foggy drum
#

trying

supple tree
#

It's generally recommended to format your code so the indentation levels match up with the nesting of the arrays/objects/etc.

foggy drum
#

well thanks for you advice let me try

#

now it works, you have an eagle eye to see the malformed code, thanks you really are a great

supple tree
#

Happy to help, and glad to hear it's working! 🙂

foggy drum
#

now to see if I understand well, before implementing it in my cart, the requirement to use this code would be that all my items would have to have the same correct interval? I have a product for example that is purchased annually, in this case they would have to buy it in a separate form since the cart would not recognize it as correct?

supple tree
#

Not sure what you mean by "cart", but Stripe Subscriptions can handle multiple Products/Prices as long at the interval for each one is the same. If you have different intervals you need to create separate Subscriptions.

#

For example, you can do two different monthly Prices on a single Subscription, but if you want one monthly and one annually you would need two different Subscriptions.

foggy drum
#

So I see what happens is I am developing a cart on my website and I want them to add their products there, now I would standardize everything to 1 month so that this code of 1 invoice works with several subscriptions, however, in 12-month products I would have to create as you suggest a separate option that creates that particular subscription.

supple tree
#

That sounds right, yep.

foggy drum
#

Im trying some like this:

#
                                'customer' => $json_obj->cus, 
                                'items' => [
                                  [
                                    'price' => 'price_1Jgev1HHulAmiNnDyuF8Tg5y',
                                  ],
                                  [
                                      'price_data' => [
                                          'unit_amount' => $json_obj->price, 
                                          'currency' => 'usd',
                                          'product' => $json_obj->s_product, 
                                          'recurring' => [
                                              'interval' => 'month',
                                              'interval_count'=> 1,
                                          ],
                                          'tax_behavior' => 'inclusive',
                                      ],
                                  ],
                                  [
                                      'price_data' => [
                                          'unit_amount' => 22222, 
                                          'currency' => 'usd',
                                          'product' => $json_obj->s_product,
                                          'recurring' => [
                                              'interval' => 'month',
                                              'interval_count'=> 1,
                                          ],
                                          'tax_behavior' => 'inclusive',
                                      ],
                                  ]
                              ], ```
#

becouse some products have price id , work too right?

supple tree
#

Yeah, that should work as long as the intervals are all the same.

foggy drum
#

And if I used your checkout system, would the problem be the same? Or could I use different intervals in the cart?

#

changing everything to a month will really complicate the commercial and marketing part

supple tree
#

Same issue with Checkout, as it uses the same Subscriptions system.