Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-site support? #174

Open
toddrun opened this issue Feb 27, 2020 · 1 comment
Open

Multi-site support? #174

toddrun opened this issue Feb 27, 2020 · 1 comment

Comments

@toddrun
Copy link

toddrun commented Feb 27, 2020

We're currently using chargify_api_ares for a small set of products. The business would like to convert another profit center to use Chargify, but because the products are so different, they've asked to create the products in a new Site.

Because Chargify.config sets the domain/site globally, how would we be able to support using the gem with different Sites? Any suggestions are most appreciated!

@toddrun
Copy link
Author

toddrun commented Feb 27, 2020

We attempted to solve this by cloning Chargify, but THIS DOES NOT WORK.

In "lib/chargify_sites":

module ChargifySites
  def self.acme
    @acme ||= Chargify.clone
  end

  def self.other
    @other ||= Chargify.clone
  end
end

In an initializer:

ChargifySites.acme.configure do |config|
  config.api_key = ENV["CHARGIFY_ACME_API_KEY"]
  config.subdomain = ENV["CHARGIFY_ACME_SUBDOMAIN"]
end

ChargifySites.other.configure do |config|
  config.api_key = ENV["CHARGIFY_OTHER_ACME_API_KEY"]
  config.subdomain = ENV["CHARGIFY_OTHER_ACME_SUBDOMAIN"]
end

# To allow our legacy code to continue working until we convert it to be part of ChargifySite 
Chargify.configure do |config|
  config.api_key = ENV["CHARGIFY_API_KEY"]
  config.subdomain = ENV["CHARGIFY_SUBDOMAIN"]
end

This lets us get objects with different "api_key" and "subdomain" values. However, calls are made through Chargify, meaning you're still stuck with a single site.

Here's an example of why this won't work:


Chargify set to "other"
irb(main):001:0> ENV["CHARGIFY_API_KEY"]
=> "qd...D4"
irb(main):002:0> ChargifySite.other::Subscription.find(:all).count
=> 15
irb(main):003:0> ChargifySite.acme::Subscription.find(:all).count
=> 15

Chargify set to "acme"
irb(main):001:0> Chargify.subdomain
=> "demo-4930603888"
irb(main):002:0> ENV["CHARGIFY_API_KEY"]
=> "Ac..LI"
irb(main):003:0> ChargifySite.other::Subscription.find(:all).count
=> 20
irb(main):004:0> ChargifySite.acme::Subscription.find(:all).count
=> 20

Chargify set to nothing
irb(main):001:0> ENV["CHARGIFY_API_KEY"]
=> "XXXXXXXXXXXXXXXXXXXX"
irb(main):006:0> ChargifySite.other::Subscription.find(:all)
Traceback (most recent call last):
        1: from (irb):6
ActiveResource::UnauthorizedAccess (Failed.  Response code = 401.  Response message = Unauthorized.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant