Stripe payments 正在从订阅对象检索计划Id

Stripe payments 正在从订阅对象检索计划Id,stripe-payments,payment-gateway,Stripe Payments,Payment Gateway,我通过签出会话在条带中创建了一个订阅对象。以下是我在创建会话时指定的内容: 'mode' => 'subscription', 'line_items' => [[ 'price' => $planId, 'quantity' => 1, ]], 我的问题是,在我的情况下,由于数量=1,我是否总是有以下状态为真 $subscriptio

我通过签出会话在条带中创建了一个订阅对象。以下是我在创建会话时指定的内容:

            'mode' => 'subscription',
            'line_items' => [[
                'price' => $planId,
                'quantity' => 1,
            ]],
我的问题是,在我的情况下,由于数量=1,我是否总是有以下状态为真

$subscription\u obj->items->data['0']->plan->id==$subscription\u obj->plan->id

因为每当我需要计划Id时,我都会使用我的代码,我有时使用左手边的表达式,有时使用右手边的表达式。所以我只想确保这些在我的情况下是相同的,不会有任何:
$subscription\u obj->items->data['1']->plan->id

Here's my subscription object for a plan of 12 euros/month:

是的,你说得对。您还可以添加一个guard子句来检查
数据的大小是否为1,如果这是您一直期望的大小<代码>数量
对您的情况没有帮助,它指的是您的
客户订阅的特定
计划
的数量,它并不意味着
数据的大小

谢谢!!只是另一个无关的问题:在这种情况下,我们会看到:
$subscription\u obj->items->data['1']->plan->id
和['2']等等?如果我们添加了许多行项目,是否会生成此项?在我的例子中,它只是0,因为我只有一个行项目?没问题。如果我的回答有帮助,请接受我的回答。至于你的问题,只有当你创建了一个以上的订阅项目
,我的代码才会像这样有数据[1]。。“是吗?”模式“=>”订阅“,”行项目“=>[[“价格”=>$planId1,'quantity'=>1,]
[“价格”
=>$planId2,'quantity'=>1,]],
是。您还应该在测试模式下尝试一下,看看它。通过这样做,我们都能学得更好。:)
[id] => sub_J75FZOObndggWX
    [object] => subscription
    [application_fee_percent] => 
    [billing_cycle_anchor] => 1615717329
    [billing_thresholds] => 
    [cancel_at] => 1620984129
    [cancel_at_period_end] => 
    [canceled_at] => 1615717335
    [collection_method] => charge_automatically
    [created] => 1615717329
    [current_period_end] => 1618395729
    [current_period_start] => 1615717329
    [customer] => cus_J75Fs7RnQtMBTX
    [days_until_due] => 
    [default_payment_method] => pm_1IUr5IHEWYmoXN4GjeSdn3aK
    [default_source] => 
    [default_tax_rates] => Array
        (
        )

    [discount] => 
    [ended_at] => 
    [items] => Stripe\Collection Object
        (
            [object] => list
            [data] => Array
                (
                    [0] => Stripe\SubscriptionItem Object
                        (
                            [id] => si_J75F5QEL5Gnzqf
                            [object] => subscription_item
                            [billing_thresholds] => 
                            [created] => 1615717329
                            [metadata] => Stripe\StripeObject Object
                                (
                                )

                            [plan] => Stripe\Plan Object
                                (
                                    [id] => price_1IJes9HEWYmoXN4GiFeNywqa
                                    [object] => plan
                                    [active] => 1
                                    [aggregate_usage] => 
                                    [amount] => 1200
                                    [amount_decimal] => 1200
                                    [billing_scheme] => per_unit
                                    [created] => 1613048777
                                    [currency] => eur
                                    [interval] => month
                                    [interval_count] => 1
                                    [livemode] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_IvVt5EemrpxKcf
                                    [tiers_mode] => 
                                    [transform_usage] => 
                                    [trial_period_days] => 
                                    [usage_type] => licensed
                                )

                            [price] => Stripe\Price Object
                                (
                                    [id] => price_1IJes9HEWYmoXN4GiFeNywqa
                                    [object] => price
                                    [active] => 1
                                    [billing_scheme] => per_unit
                                    [created] => 1613048777
                                    [currency] => eur
                                    [livemode] => 
                                    [lookup_key] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_IvVt5EemrpxKcf
                                    [recurring] => Stripe\StripeObject Object
                                        (
                                            [aggregate_usage] => 
                                            [interval] => month
                                            [interval_count] => 1
                                            [trial_period_days] => 
                                            [usage_type] => licensed
                                        )

                                    [tiers_mode] => 
                                    [transform_quantity] => 
                                    [type] => recurring
                                    [unit_amount] => 1200
                                    [unit_amount_decimal] => 1200
                                )

                            [quantity] => 1
                            [subscription] => sub_J75FZOObndggWX
                            [tax_rates] => Array
                                (
                                )

                        )

                )

            [has_more] => 
            [total_count] => 1
            [url] => /v1/subscription_items?subscription=sub_J75FZOObndggWX
        )

    [latest_invoice] => in_1IUr5JHEWYmoXN4GTmJ3pJUZ
    [livemode] => 
    [metadata] => Stripe\StripeObject Object
        (
            [myID] => 1
        )

    [next_pending_invoice_item_invoice] => 
    [pause_collection] => 
    [pending_invoice_item_interval] => 
    [pending_setup_intent] => 
    [pending_update] => 
    [plan] => Stripe\Plan Object
        (
            [id] => price_1IJes9HEWYmoXN4GiFeNywqa
            [object] => plan
            [active] => 1
            [aggregate_usage] => 
            [amount] => 1200
            [amount_decimal] => 1200
            [billing_scheme] => per_unit
            [created] => 1613048777
            [currency] => eur
            [interval] => month
            [interval_count] => 1
            [livemode] => 
            [metadata] => Stripe\StripeObject Object
                (
                )

            [nickname] => 
            [product] => prod_IvVt5EemrpxKcf
            [tiers_mode] => 
            [transform_usage] => 
            [trial_period_days] => 
            [usage_type] => licensed
        )

    [quantity] => 1
    [schedule] => 
    [start_date] => 1615717329
    [status] => active
    [transfer_data] => 
    [trial_end] => 
    [trial_start] => 
)
```