#dotan-metered-subs

1 messages ยท Page 1 of 1 (latest)

stable coralBOT
inner chasm
#

I can help you out here! What's your question?

#

dotan-metered-subs

sacred salmon
#

Hey, how's it going?

#

So yesterday we figured out that metered and scheduled subscription aren't supported via create checkout session

#

But that we can use subscription, and the hosted invoice URL as a method of payment collection instead

#

But can't make it work

#

(I'm using postman for API calls)

jade gorge
#

Hey @sacred salmon can you provide a more specific question? A good summary, with what's not working clearly explained and what you tried, all in one message if possible

sacred salmon
#

Sure, I'm trying to use create subscription that will generate a URL for payment instead of using create checkout session. Do I need to create a product first for this?

#

Or can you please share an example of an API call like that?

jade gorge
#

Mostly you would create a Subscription and then the underlying Invoice would have a hosted_invoice_url property set

sacred salmon
#

In this example it uses create checkout session though....

jade gorge
#

there's a choice at the top

sacred salmon
#

great, thanks! So going back to my question - do I need to create a product for this first?

jade gorge
#

yes

sacred salmon
#

thanks

#

How can I associate a product with a connected account?

jade gorge
#

that's how you make calls on behalf of connected accounts

#

Are you building a platform with Standard accounts?

sacred salmon
#

no

#

custom

#

I wanted to avoid creating products since it's pretty dynamic per customer<>connected account

#

rate, freq. etc.

#

With checkout session I can create everything dynamically, but it doesn't support metered and scheduled...

jade gorge
#

Okay so if you use Custom accounts then ignore what I said earlier. Everything happens on your own platform, so you create the Product on the platform. There's no way to make it specific to a connected account, you'd track this yourself for example with metadata or in your own database

sacred salmon
#

wdym by creating the product on the platform?

#

And what if we would use express instead?

jade gorge
#

Sorry for being cryptic, Discord is really busy right now

sacred salmon
#

no worries

#

Appreciate your help ๐Ÿ™‚

jade gorge
#

You are a platform, you create a Subscription, everything happens in your account so all the Subscriptions, Products, Prices, Invoices, etc. all live in your account

sacred salmon
#

got it

#

thanks

#

and that's true for express too?

jade gorge
#

yes

sacred salmon
#

cool

#

so looks like for products we could potentially use id with a prefix of acctXXX

jade gorge
#

well I would strongly discourage ever choosing your own id for Products, so no. Use metadata, or track it in your own database

sacred salmon
#

๐Ÿ‘

#

do

#

sorry

#

Do I need to use collection_method send_invoice for generating the payment link?

jade gorge
#

I don't understand what you mean again sorry.

#

PaymentLinks is a completely different product we have

sacred salmon
#

I meant the hosted_invoice_url

#

Sorry

jade gorge
#

So what's the problem? What do you see in the API? What have you tried?

sacred salmon
#

I tried generating a subscription, with a product and customer I created

#

Is the url supposed to be in the response, or I need to retrieve it somewhere else?

jade gorge
#

What have you tried? Please share real exact code

#

Do you have the extra information @sacred salmon ? Seeing your exact code will help

sacred salmon
#

Using your collection, I tried create a subscription, and got a subscription object

jade gorge
#

Please I need your exact code

#

the problem is likely that you get latest_invoice: 'in_123' in the response, but you want the full Invoice object instead so you want to use our Expand feature (https://stripe.com/docs/expand)

sacred salmon
#

will check this

#

Does it mean I can add usage_type to my call? can't see it in the body parameters

jade gorge
#

I don't understand your question is that a completely different question?

sacred salmon
#

I got a reply in the email from support with a suggestion to use checkout session still, but leave quantity empty

#

but can't see where I can set usage_type to metered

jade gorge
#

oh boy

#

Have you tried creating a Price that is metered and then pass that Price id to Checkout?

sacred salmon
#

nope

#

I do it inline

jade gorge
#

then that's impossible

#

either you create the Product/Price upfront first and use the Price id price_123 after that, or you can't do what you are after

sacred salmon
#

got it

#

thanks

#

ok, going back to the subscription item, not sure how I can share what I send as I use your collection

jade gorge
#

I don't know what that means "I use your collection"

sacred salmon
#

Sorry, Stripe Postman API collection

#

Well, found it:

#

--data-urlencode 'items[0][price_data][currency]=usd'
--data-urlencode 'items[0][price_data][product]=prod_Mtn65DEZHHtjUH'
--data-urlencode 'items[0][price_data][recurring][interval]=week'
--data-urlencode 'items[0][price_data][recurring][interval_count]=2'
--data-urlencode 'items[0][price_data][unit_amount]=125000'
--data-urlencode 'customer=cus_MtkgNyOcKkJ6Da'
--data-urlencode 'collection_method=send_invoice'
--data-urlencode 'days_until_due=14'
--data-urlencode 'transfer_data[destination]=acct_1M9YbE4esDfbqzim'
--data-urlencode 'transfer_data[amount_percent]=93'

jade gorge
#

yeah so really you're missing expand[0]=latest_invoice to look at the raw Invoice in the response and find the URL

sacred salmon
#

cool, and do I need send_invoice there?

jade gorge
#

not unless you want to use that type of invoice

sacred salmon
#

wdym

#

I prefer not to send any emails

#

As I'd like to redirect to payment immediately instead

#

but otherwise I'd need to add customer payment details which I don't have yet...

jade gorge
#

then you don't need it

sacred salmon
#

If I remove it I get an error

mild bronze
sacred salmon
#

wait

#

now I tried it again and it worked...

#

oh, hi Snufkin

#

๐Ÿ™‚

#

added expand[0] with latest_invoice, but can't see the url...

mild bronze
#

Once again, if you could share the request ID that would help

#

It makes sure we are both looking at the same data

sacred salmon
#

sure, sub_1M9zjSGKb7Nib0czst3vsIkV

mild bronze
#

Just so we're on the same page

#

The url is right there in the response. latest_invoice.hosted_invoice_url

sacred salmon
#

Weird, why is it different in Postman?

mild bronze
#

That I don't know. However, we are returning the data. Is Postman collapsing parts of the returned data?

sacred salmon
#

Not afaik

mild bronze
#

Have you tried using curl or any of our client libraries to retrieve the subscription? I doubt you would be using Postman in a production application.

sacred salmon
#

Oh, for sure not using it for prod ๐Ÿ˜Š

mild bronze
#

In that case can you try retrieving the Subscription using whichever Stripe client library you have? I think we may get better results

#

On the plus side, the creation request is doing what you are looking for

sacred salmon
#

Awesome, thanks!

#

As for what we discussed yesterday

#

For scheduling in the future I put the date in billing_cycle_anchor, right?

#

What about metered usage?

mild bronze
#

Yes, setting the billing cycle anchor in the future will do what you are looking for

sacred salmon
#

I see that it shows licensed

mild bronze
sacred salmon
#

I meant where in the call I should define metered

mild bronze
#

On the price

sacred salmon
#

So I need to make a different call then?

#

And I see that there's no success/cancel urls for subscription like in checkout session... is there a way to redirect?

mild bronze
#

No that isn't an option with the Hosted Invoice Page

sacred salmon
#

ok, thanks

#

and reg. price, can't do it in the same call?

#

Meaning I'd need to make a different call for creating price with metered?

mild bronze
#

I recall yesterday I said these were different interfaces. This is one of the shortcomings of the HIP in comparison to the Checkout Session. As for the Price, yes you will want to create a Price record separate from the Subscription API call

sacred salmon
#

Thanks for all the help

#

Appreciate it!

mild bronze
#

Happy to do it ๐Ÿ™‚

vapid mango
#

๐Ÿ‘‹ @sacred salmon gimme a few mins to catch up

sacred salmon
#

sure thing

vapid mango
#

So the metered price worked. Now you want to set a start date in the future?

sacred salmon
#

yes

#

preferably using create checkout session

vapid mango
#

Okie, then let's use the subscription_data 's trial parameters. Either trial_end or trial_period_days

sacred salmon
#

but that would be visible to user, no?

vapid mango
#

It's to setup a trial, so yes. Your customer would need to know when the Subscription starts since they are paying to receive a service

sacred salmon
#

yes, but the use case is that customers book recurring sessions

#

And the cycle won't start immediately

#

doesn't mean they're on a trial...

#

Just a future date to start

#

Wanted to use scheduled sub.

#

Something like subscription start_date (or billing_cycle_anchor?)

#

But in checkout session

vapid mango
#

Ah I see, unfortunately it's not available via Checkout. All the Subscription setting on Checkouts is inside the subscription_data above

#

alternatively, you can use Checkout Session to collect PaymentMethod only (setup mode), then in backend, using the collected payment methods to freely use Subscription Schedule API, for example

sacred salmon
#

that sounds good, how do I do that? just change to 'setup' instead of subscription?

#

Well just tried it. So in setup I don't need all the other fields, which I'll handle later?

vapid mango
#

Yes!

sacred salmon
#

Cool, how do I use the collected payment method?

vapid mango
#

When you finished, you receive the checkout_session.completed. You will have the SetupIntent. The PaymentMethod is inside it

sacred salmon
#

And then I call create a subscription and put the payment method here: default_payment_method?

#

I got this error:
The customer does not have a payment method with the ID pm_1MA20IGKb7Nib0czpvYDd74h. The payment method must be attached to the customer.

#

And looking in the checkout session response I don't think it even creates a customer ID

#

cs_test_c1FUT5l9PfkPWEURPdEXBs0ulYHt6DG4WkQWyO0or522KCsPWbmOm63cfD

vapid mango
#

Hmm okie, can you try to create a Customer beforehand and pass its ID in when create the Checkout Session (setup mode)?

sacred salmon
#

yes

#

BOOM

#

this is sweet

#

Now last thing

#

well maybe 2

#

How do I get a trigger when payment method collection is done?

#

And probably would want to embed the payment collection in our app, I guess it's possible?

vapid mango
#

It would be the checkout_session.completed, if I understand you correctly

sacred salmon
#

Yes, do I need to create a webhook?

#

well I can generate it using the success url