#loaderchips_code

1 messages ¡ Page 1 of 1 (latest)

pliant vortexBOT
#

👋 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.

karmic gustBOT
#

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.

slate hollow
#

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

tawdry tiger
#

hi there!

slate hollow
#

Hey Soma

#

thanks for your time

#

appreciate the help

tawdry tiger
#

this is how to set an API key in Ruby:
Stripe.api_key = 'sk_test_...'
what exactly is the issue?

slate hollow
#

we want this to be dynamic such that the scope is limited to a single request

tawdry tiger
#

in this case you can set the API key directly like this:

Stripe::Customer.retrieve('cus_xxx', {
    api_key: 'sk_test_...',
})
slate hollow
#

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

tawdry tiger
#

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.