#loaderchips_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ 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.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ 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/1266369991113052270
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- loaderchips_docs, 1 day ago, 23 messages
This is what works upto some extent --
module StripeApiKeyInjector
def self.inject!
Rails.logger.info "Injecting StripeApiKeyInjector"
Stripe::Customer.singleton_class.prepend(Module.new do
def list(*args, **kwargs)
Rails.logger.debug "StripeApiKeyInjector intercepted call to Stripe::Customer.list"
set_api_key
super
end
private
def set_api_key
nonprofit_id = Thread.current[:nonprofit_id]
Rails.logger.debug "Setting Stripe API key for nonprofit_id: #{nonprofit_id}"
new_api_key = StripeApiKeySelector.select_api_key(nonprofit_id)
Rails.logger.debug "Selected API key: #{new_api_key[0, 4]}..." # Log first 4 characters for security
Stripe.api_key = new_api_key
end
end)
# Repeat for other Stripe methods
Rails.logger.info "Successfully injected StripeApiKeyInjector"
end
end
hi there!
this is how to set an API key in Ruby:
Stripe.api_key = 'sk_test_...'
what exactly is the issue?
we want this to be dynamic such that the scope is limited to a single request
in this case you can set the API key directly like this:
Stripe::Customer.retrieve('cus_xxx', {
api_key: 'sk_test_...',
})
is this applicable across the entire request stack for eg does this apply to -- price = Stripe::Price.create({
unit_amount: fee_amount.cents,
currency: fee_amount.currency,
recurring: { interval: 'month', interval_count: 1 },
product: product_id,
nickname: "Fee - #{::ApplicationController.helpers.humanized_money_with_symbol(@donation_tier.amount)}",
})
in other words can i apply similar approach to all requests that i send to stripe
in other words can i apply similar approach to all requests that i send to stripe
yes I just shared one example, but it works with all API requests.