#dotan-metered-subs
1 messages ยท Page 1 of 1 (latest)
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)
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
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?
Mostly you would create a Subscription and then the underlying Invoice would have a hosted_invoice_url property set
In this example it uses create checkout session though....
great, thanks! So going back to my question - do I need to create a product for this first?
yes
that's how you make calls on behalf of connected accounts
Are you building a platform with Standard accounts?
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...
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
wdym by creating the product on the platform?
And what if we would use express instead?
Sorry for being cryptic, Discord is really busy right now
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
yes
cool
so looks like for products we could potentially use id with a prefix of acctXXX
well I would strongly discourage ever choosing your own id for Products, so no. Use metadata, or track it in your own database
๐
do
sorry
Do I need to use collection_method send_invoice for generating the payment link?
I don't understand what you mean again sorry.
PaymentLinks is a completely different product we have
So what's the problem? What do you see in the API? What have you tried?
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?
What have you tried? Please share real exact code
Do you have the extra information @sacred salmon ? Seeing your exact code will help
Using your collection, I tried create a subscription, and got a subscription object
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)
will check this
Does it mean I can add usage_type to my call? can't see it in the body parameters
I don't understand your question is that a completely different question?
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
oh boy
Have you tried creating a Price that is metered and then pass that Price id to Checkout?
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
got it
thanks
ok, going back to the subscription item, not sure how I can share what I send as I use your collection
I don't know what that means "I use your collection"
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'
yeah so really you're missing expand[0]=latest_invoice to look at the raw Invoice in the response and find the URL
cool, and do I need send_invoice there?
not unless you want to use that type of invoice
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...
then you don't need it
If I remove it I get an error
Hi ๐
Can you share the request ID for the request that gives you an error?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
wait
now I tried it again and it worked...
oh, hi Snufkin
๐
added expand[0] with latest_invoice, but can't see the url...
Once again, if you could share the request ID that would help
It makes sure we are both looking at the same data
sure, sub_1M9zjSGKb7Nib0czst3vsIkV
Okay, Im actually looking at the API request you used to create the subscription: https://dashboard.stripe.com/test/logs/req_shWHrDhQwtM6Xs
Just so we're on the same page
The url is right there in the response. latest_invoice.hosted_invoice_url
Weird, why is it different in Postman?
That I don't know. However, we are returning the data. Is Postman collapsing parts of the returned data?
Not afaik
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.
Oh, for sure not using it for prod ๐
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
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?
Yes, setting the billing cycle anchor in the future will do what you are looking for
I see that it shows licensed
You'll want to review this doc: https://stripe.com/docs/products-prices/pricing-models#usage-types
I meant where in the call I should define metered
On the price
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?
No that isn't an option with the Hosted Invoice Page
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?
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
Happy to do it ๐
๐ @sacred salmon gimme a few mins to catch up
sure thing
So the metered price worked. Now you want to set a start date in the future?
Okie, then let's use the subscription_data 's trial parameters. Either trial_end or trial_period_days
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
but that would be visible to user, no?
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
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
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
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?
Yes!
Cool, how do I use the collected payment method?
When you finished, you receive the checkout_session.completed. You will have the SetupIntent. The PaymentMethod is inside it
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
Hmm okie, can you try to create a Customer beforehand and pass its ID in when create the Checkout Session (setup mode)?
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?
It would be the checkout_session.completed, if I understand you correctly