#viktor-price
1 messages ยท Page 1 of 1 (latest)
lookup_keys is different parameter than metadata AFAIK. And APIConnectionError is a separated issue
I was thinking if one is slower than the other?
I like using the metadata, because it can be set in Stripes web dashboard
On my front page I am doing something like this
@lite = Stripe::Price.search({query: "metadata['repero_plan']:'lite'"}).first
@business = Stripe::Price.search({query: "metadata['repero_plan']:'business'"}).first
@premium = Stripe::Price.search({query: "metadata['repero_plan']:'premium'"}).first
In rails console I also get a network error, started 12 hours ago:
[2] pry(main)> Stripe::Price.search({query: "metadata['repero_plan']:'business'"}).first
Stripe::APIConnectionError: Timed out connecting to Stripe (https://api.stripe.com). Please check your internet connection and try again. If this problem persists, you should check Stripe's service status at https://status.stripe.com, or let us know at support@stripe.com.
(Network error: execution expired)
It's very sporadic, and I did not see anything strange on status.stripe.com
That looks like an intermittent issue. Do you have the request id? I will double check
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
All 200 OK in the dasbhoard logs
I am loading these 3 prices on my frontpage, and I don't want my frontpage to be slower or fail if Stripe does not respond.
Do you have any tips on how to handle that in Ruby on Rails?
Do you know how 'most' developers are handling this? What is the most common way for SaaS to show prices on a frontpage?
It would be easier if you have the price id beforehand / manage your prices data using price id. The Retrieve Price API https://stripe.com/docs/api/prices/retrieve?lang=ruby should be fastest among others
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok, so hardcode the price_id?
What if I have 2 servers, like production and staging, one connects to Stripe test mode
Not hardcoding...
I meant when transition from the previous page to your front page, you would somehow want to query your database to get the price ids that you want to show
Let's say you have database records like
Repero_plan | little | price_xxx
Repero_plan | business | price_yyy
Repero_plan | premium | price_zzz
with price_xxx, price_yyy, price_zzz is Stripe Ids
I was thinking how to differentiate between test and production mode
Now I use a .env file so we have different STRIPE_API_KEYS on each server
That allows us to simply use Stripe::Price.search({query: "metadata['repero_plan']:'lite'"}) for both production and test, and will return different Prices depending on the environment
Because the Prices have this metadata both in Live and Test mode (2 different prices, one in Live, one in Test)
I would prefer not to have to set anything in the Database, because it would be equally hard to change those records.
Ideally we want our Project Manager to be able to change the prices - which they can do now easily in the Dashboard using the metadata
I see. That's reasonable approach. Generally Price is static data so to reduce load before frontpage, you would want to pre-load and cache that response somewhere
Your own database like my previous suggestion is 1 example while your DB acts as a cache layer. You can also use memcache/redis/any key-value store. The ultimate purpose is having the price_id before frontpage, so in front page you will only need to perform the lightweight Retrieve Price API
Ok maybe I skip loading the Prices on the frontpage and only do that on another page
Ideally we want our Project Manager to be able to change the prices - which they can do now easily in the Dashboard using the metadata
He can continue to do this. But you can pre-load / search for metadata in previous page and obtain the Price Id
Do you know how other/most SaaS are loading prices?
Many are doing this but I don't know what is the most common way
I don't have the statistic data unfortunately. I think suggestions above should be general enough that everyone can think of
It's more of expensive resource vs cheap resource, isn't it? Not just Stripe, let's say you need to load heavy data from Facebook that took 5s, you would want to move that call out of your front page
Yes true
Just thinking in general how other SaaS do this, if they have 3 Prices, do they simply use
Stripe::Price.retrieve('price_1LDlVeJY...') for each price?
That would be the most basic way
Then, how would they do this to support live and test (staging and production)
(Because they have different IDs, but can have the same metadata or lookup_key)
I can of course create 3 new ENV variables STRIPE_LITE_ID etc which is different on each environment
But that is probably the same hassle as using the lookup_key.. neither can be done by our Project Managers
You can perform the search based on metadata in previous page, save them to 3 STRIPE_LITE_ID environment variables, then in front page loading those variables to retrieve, I think
basically use environment variables as cache layer
I tried using .retrieve instead of .search and there was almost no difference in speed, I also got the
Timed out connecting to Stripe error when using .retrieve
This only happens on localhost maybe 30% of the time. Never on staging
Probably my localhost issue, nothing for you to worry about ๐