#stan_api

1 messages · Page 1 of 1 (latest)

still wrenBOT
dire cairnBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

still wrenBOT
#

👋 Welcome to your new thread!

⏱️ We automatically close idle threads, which makes them read-only. Make sure you stick around to chat in realtime!

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1212401393659416576

📝 Have more to share? You can add more detail below, including code, screenshots, videos, etc.

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question. Thank you for your patience!

dire cairnBOT
lost ledge
#

hey @faint maple Not able to message anywhere in the channel

faint maple
#

@lost ledge please read the message in the announcements channel
#🔊announcements message

It explains how to initiate a new thread using the buttons in the #help channel

#

Sorry about that @chilly heath

#

Quick question, is there a specific reason you're creating a subscription schedule here?
You could just straight up use the subscriptions API for this, no?

chilly heath
#

yeah I need to create a subscription with 14 free trial days and always have payment on 1st each month.
now is 28 I need to start free trial and have payment on 13 of march for the rest of the month and then a payment for the full price on 1st of may

#

the support here told me to use scheduleSubscription

faint maple
chilly heath
#

what behaviour should I try

#

by default it is: create_prorations

faint maple
#

yup, create_prorations is what you likely need

chilly heath
#

yeah it is by default

#

but the price in dashboard is the full one

#

and the date for the phace is not 13-30 march but 13.03-13.04

#

which is strange

faint maple
#

Can you share an example?

chilly heath
#

{"customer":"cus_Pe5tte3P6dfd1I","start_date":"now","end_behavior":"release","phases":[{"items":[{"price":"price_1OoSX7GogiQBpoccWvlC9PUu","quantity":100}],"trial_end":1710340149,"end_date":1714521600},{"items":[{"price":"price_1OoSX7GogiQBpoccWvlC9PUu","quantity":100}],"iterations":100}]}

#

this is how I create the subscriptioSchedule

#

this is how it looks like in the dashboard

#

I have tried also with 3 items

{"customer":"cus_Pe5tte3P6dfd1I","start_date":"now","end_behavior":"release","phases":[{"items":[{"price":"price_1OoSX7GogiQBpoccWvlC9PUu","quantity":100}],"trial":true,"end_date":1710340367},{"items":[{"price":"price_1OoSX7GogiQBpoccWvlC9PUu","quantity":100}],"end_date":1711929599},{"items":[{"price":"price_1OoSX7GogiQBpoccWvlC9PUu","quantity":100}],"iterations":100}]}

#

but again

faint maple
#

Can you share the subscription schedule ID?
sub_sched_xxx

chilly heath
#

I don't get what I need

#

is it this one from the dashboard or I should log it ?

#

sub_sched_1OooEJGogiQBpoccqmPaxAIh

#

I have created new one

faint maple
#

Thanks, looking..

chilly heath
#

ok

faint maple
chilly heath
#

let me try

#

sub_sched_1OooP3GogiQBpoccJB0cRsQ2

#

not what I expect
also the second item end_date: 1711929600 (which is Mon Apr 01 2024 00:00:00 GMT+0000) but it ends on 31 march

faint maple
#

Hmm, let me think..

chilly heath
#

ok

faint maple
#

The reason you're seeing the full amount invoice in phase 2 is due to billing_cycle_anchor is still likely anchored to April 13 for a full month.
I'm checking with a colleague about how you can change that..

chilly heath
#

ok

#

also any idea why on the second item I set end_date: 1711929600 (which is equal to: GMT Mon Apr 01 2024 00:00:00 GMT+0000), but in the dashboard it is 31 of march. I want my normal cycle to start on 1st of the month

dire cairnBOT
chilly heath
#

any thoughts what I can try ?

merry tree
#

Still talking to our colleague about how you can achieve this, I will get back to you with what we can find

chilly heath
#

ok, great

merry tree
#

Apologies, still working. Basically it looks like the second phase will always try to charge for the full amount, so we are discussing various ways to mitigate that. Discounts, calculating the phase 2 amount yourself, etc

chilly heath
#

no problem i am available, also have a look at the end date that is not correct, why is it going to 31 march instead of 1st of april

merry tree
#

Can you send me the ID of the subscription that you are seeing that on?

#

Also my colleauges are saying the best two ways to do this would be:

  1. Calculate the price yourself and add it as a one time invoice item at the end of the trial
trim ridge
#

why i am gettint this error Parameter 'company' cannot be used in conjunction with an account token. To set this field create a token with the desired changes. Pass the token with 'account_token' in a request without setting 'company'.

chilly heath
#

sub_1OooBgGogiQBpoccQUiwqT3j

merry tree
#

Can you send me the ID of the request where you got that error?

chilly heath
#

you can check this one

merry tree
#

(req_1234)

#

Sounds good, also for completeness solution #2 is "Add a coupon equal to the amount of the recurring price, to take that off that same end-of-trial Invoice". Which is probably not as good of a solution but is worth mentioning. They provided sample code to demonstrate this

  'customer'=> $customer->id,
  "start_date"=>"now",
  'phases' => [
    [
      "trial"=>true,
      "end_date" => "1710288000", // March 13
      'items' => [
        [
          'price' => $gold->id,
          'quantity' => 1,
        ],
      ],
    ],
    [
      'add_invoice_items' => [
        [
          'price_data' => [
              'unit_amount' => 56250, // manually calculated proration
              'currency' => 'usd',
              'product' => $product->id
          ]
        ]
      ],
      'coupon'=>$co->id, // coupon with amount_off == Price amount
      'items' => [
        [
          'price' => $gold->id,
          'quantity' => 1,
        ],
      ],
      "end_date"=> "1711929600", // Apr 1
    ],
    [
      
      'billing_cycle_anchor'=>"phase_start",
      'items' => [
        [
          'price' => $gold->id,
          'quantity' => 1,
        ],
      ],
    ],
  ],
  "end_behavior" => "release"
]);```
chilly heath
#

really i need to calculate my self

merry tree
#

Unfortunately that is where our API currently is

trim ridge
#

i can't msg in dev-help

merry tree
#

Also our server is very busy, will be back in a few minutes to check that subscription and that error (please provide the specific request ID if you can)

merry tree
chilly heath
#

can you really think about a normal solution not workaround

#

because in some cases i can do normal subscription creat with trial days and start of subscription 1 month

#

this is supported if the trial days don’t go to the next month

merry tree
#

We extensively tried thinking of "normal solutions". Unfortunately our API does not support your usecase at the moment so a workaround is necessary

chilly heath
#

so why do i need an coupon can i just add invoice item with price calculated by me

merry tree
#

Yeah, that was likely the better solution of the 2. I meant to stress that more

chilly heath
#

do i need schedule then can i just create normal subscription

merry tree
#

I think you need a schedule because your second phase is of variable length, rather than the full month

chilly heath
#

yes, the second phase how to lower the price there can i set it manually

#

because i have created prices and i used them

#

there i need 13-30, it should be lower price

merry tree
#

Right, but the variable length of time is something you can't do with a regular subscription.

chilly heath
#

ok can you give me example schedule creation

#

with 3 items

#

free trial for 14 days starting now

#

then 13-30 march

#

for lower price

#

and then 1 of april full price recurring each month after this

merry tree
#

Which part of that specifically are you trying to understand?

#

Making that full request would take some time with how busy the server is, but if we focus on what you are trying to figure out we can likely solve much faster

chilly heath
#

it would be very helpful if you can give me sample json for what i describe above

#

like schedule creation json example

merry tree
#

If you don't understand the entire thing, I think we should cover the concepts before I send a giant block of code for them

chilly heath
#

i do understand it

#

what i get, i need to creat dynamically coupon with calculated value by me and apply it to the second item

#

then it will work?

#

but if you send me sample i will understand it

merry tree
#

Apologies but the server keeps getting busier. If applying that discount is the sticking point, then you can try passing in the coupon to the coupon parameter on the second phase when creatig the schedule. The coupon will apply as a coupon normally would for that period. So if you give 25% off of your price, the invoice for that period will be for 75% of the normal price https://docs.stripe.com/api/subscription_schedules/create#create_subscription_schedule-phases-coupon

chilly heath
#

ok i will try with coupon

#

last thing, when creating a schedule how do i confirm the payment intent for the subscription?

merry tree
#

Same way with normal subscriptions, if you have the payment behavior set to charge_automatically we will try to charge the user ourselves though you can also call the invoice API's /pay endpoint to try outside of that. If you have it set to send_invoice , you need to manually enter payment details on the payment page

dire cairnBOT
chilly heath
#

in the frontend i need to confirm the payment after entering card numbers, i tried to get the subscription from the schedule but the payment intent is null

merry tree
#

If this is during the trialing period, there won't be a payment intent, the subscription will have a pending_setup_intent property

#

If this is during a paid period, you actually need to get the payment intent off of the latest_invoice on the subscription

chilly heath
#

yeah i always start with free trial

#

so i need to retrieve the subscription and get it from pending_setup_intent

#

could it be that it is missing from there when it is created via schedule?

#

because i had it as null before

muted sail
#

Hello! I'm taking over and catching up...

#

You had what as null before? The pending_setup_intent?

chilly heath
#

yes

#

i create a subscription with schedule, first item has 14 days trial

muted sail
#

Ah, and you want to collect payment details before the Subscription itself is created?

#

Meaning you create the Subscription Schedule first, which is set to create the Subscription later, then later when the Subscription is created it has a 14 day trial?

chilly heath
#

schedule start date is now

muted sail
#

Ah, in that case the Subscription should be created immediately and it should have a pending_setup_intent.

chilly heath
#

which creates the subscription but i need to verify the payment

muted sail
#

Note that property is on the Subscription, not the Subscription Schedule.

chilly heath
#

yeah i retrieve it separately after the schedule creation

#

i will check tomorrow may be i was wrong