#frannavarro - tiered pricing

1 messages · Page 1 of 1 (latest)

green pond
#

Do you see in the plan there? Is it populated at all?

#

Have you tried looking at the subscription items array instead?

static glacier
#

yes, and nothing. Amount null

#

{
id: 'XXXXX',
object: 'subscription',
application_fee_percent: null,
automatic_tax: { enabled: false },
billing_cycle_anchor: 1645112524,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1645112524,
current_period_end: 1676648524,
current_period_start: 1645112524,
customer: 'XXXX',
days_until_due: null,
default_payment_method: 'XXXX',
default_source: null,
default_tax_rates: [],
discount: null,
ended_at: null,
items: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/subscription_items?subscription=XXXX'
},
latest_invoice: 'XXX',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
pause_collection: null,
payment_settings: { payment_method_options: null, payment_method_types: null },
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'XXX',
object: 'plan',
active: true,
aggregate_usage: null,
amount: null,
amount_decimal: null,
billing_scheme: 'tiered',
created: 1642789512,
currency: 'usd',
interval: 'year',
interval_count: 1,
livemode: false,
metadata: {},
nickname: null,
product: 'prod_L0SimO4rCh5Qm1',
tiers_mode: 'graduated',
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 6,
schedule: null,
start_date: 1645112524,
status: 'active',
transfer_data: null,
trial_end: null,
trial_start: null
}

green pond
#

you removed the id 😄

#

whats the plan id?

static glacier
#

I was trying not to put compromising information, I'm sending it to you now.

green pond
#

But, that seems normal right, is its dependent on the quantity, there is no fixed amount

#

All IDs are safe to share, no body can do anything with them

static glacier
#

okey

green pond
#

just never share your API secret keys

static glacier
#

{
id: 'sub_1KUC7MKpwWr0NBhXuUZX5TrF',
object: 'subscription',
application_fee_percent: null,
automatic_tax: { enabled: false },
billing_cycle_anchor: 1645112524,
billing_thresholds: null,
cancel_at: null,
cancel_at_period_end: false,
canceled_at: null,
collection_method: 'charge_automatically',
created: 1645112524,
current_period_end: 1676648524,
current_period_start: 1645112524,
customer: 'cus_LAWZAerWM2BbWH',
days_until_due: null,
default_payment_method: 'pm_1KUBWRKpwWr0NBhXprxuVzN5',
default_source: null,
default_tax_rates: [],
discount: null,
ended_at: null,
items: {
object: 'list',
data: [ [Object] ],
has_more: false,
total_count: 1,
url: '/v1/subscription_items?subscription=sub_1KUC7MKpwWr0NBhXuUZX5TrF'
},
latest_invoice: 'in_1KUC8qKpwWr0NBhXBhybE7An',
livemode: false,
metadata: {},
next_pending_invoice_item_invoice: null,
pause_collection: null,
payment_settings: { payment_method_options: null, payment_method_types: null },
pending_invoice_item_interval: null,
pending_setup_intent: null,
pending_update: null,
plan: {
id: 'price_1KKRnQKpwWr0NBhXZNXEsRkF',
object: 'plan',
active: true,
aggregate_usage: null,
amount: null,
amount_decimal: null,
billing_scheme: 'tiered',
created: 1642789512,
currency: 'usd',
interval: 'year',
interval_count: 1,
livemode: false,
metadata: {},
nickname: null,
product: 'prod_L0SimO4rCh5Qm1',
tiers_mode: 'graduated',
transform_usage: null,
trial_period_days: null,
usage_type: 'licensed'
},
quantity: 6,
schedule: null,
start_date: 1645112524,
status: 'active',
transfer_data: null,
trial_end: null,
trial_start: null
}

green pond
#

Alternately you can use expansion to get the tiers of the Price

#

It's also suggest looking in the items instead of the plan attribute to handle the case of multiple items on a subscription

static glacier
#

something like this?: this.stripe.subscriptions.retrieve(stripeSubscriptionId, { expand: [] }) ?

green pond
#

Yep!

#

(with that array populated with the path to the expansion target)

#

eg: expand: ['items.data.price.tiers']

static glacier
#

OMG!

#

thank you so much! you are the best!

green pond
#

😄

#

That gets you waht you need?

static glacier
#

yes!

green pond
#

Fantastic!

#

Quite welcome

static glacier
#

sorry, didn´t work

green pond
#

Oh?

#

What happened / or is missing?

static glacier
#

items: { object: 'list', data: [ [Object] ], has_more: false, total_count: 1, url: '/v1/subscription_items?subscription=sub_1KUC7MKpwWr0NBhXuUZX5TrF' },

#

there are not expanding

green pond
#

That looks like console.log truncation of nested objects

#

if you console.log(subscription.items.data[0].price) i would expect you to see the tiers attribute for a tiered price

static glacier
#

i´m gonna try!

#

you were right, but it still doesn't work for me 😦
I need to know the total amount to be charged to the user

green pond
#

OK, but that depends on the quantity, right?

#

To preview the amount to be charged, I'd suggest using the Upcoming Invoice endpoint to get the calculate invoice amounts for that subscription:

static glacier
#

I'm going to check it out, thank you very much

green pond
#

NP

static glacier
#

with the endpoint you sent me... perfect!

#

thanks a million!!