Skip to content

Commit

Permalink
Add ability to fetch managment link for a Customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Goldman committed Dec 28, 2016
1 parent 1febc13 commit afd8173
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/chargify_api_ares.rb
Expand Up @@ -11,6 +11,7 @@
require 'chargify_api_ares/resources/customer_metadata'
require 'chargify_api_ares/resources/customer'
require 'chargify_api_ares/resources/event'
require 'chargify_api_ares/resources/management_link'
require 'chargify_api_ares/resources/migration'
require 'chargify_api_ares/resources/payment'
require 'chargify_api_ares/resources/payment_profile'
Expand Down
5 changes: 5 additions & 0 deletions lib/chargify_api_ares/resources/customer.rb
Expand Up @@ -15,6 +15,11 @@ def subscriptions(params = {})
Subscription.find(:all, :params => params)
end

def management_link(params = {})
params.merge!(:from => "/portal/customers/#{self.id}/management_link")
ManagementLink.find(:one, params)
end

def payment_profiles(params = {})
params.merge!({:customer_id => self.id})
PaymentProfile.find(:all, :params => params)
Expand Down
9 changes: 9 additions & 0 deletions lib/chargify_api_ares/resources/management_link.rb
@@ -0,0 +1,9 @@
module Chargify
class ManagementLink < Base
self.prefix = '/portal/customers/:customer_id/'

def self.collection_name
element_name
end
end
end
12 changes: 12 additions & 0 deletions spec/resources/customer_spec.rb
Expand Up @@ -38,4 +38,16 @@
end
end

context '#management_link' do
let(:customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
let(:management_link) { Chargify::ManagementLink.create(:customer_id => customer.id, :url => 'https://www.billingportal.com/manage/1/2/3') }

before(:each) do
FakeWeb.register_uri(:get, "#{test_domain}/portal/customers/#{customer.id}/management_link", :body => management_link.attributes.to_xml)
end

it "returns the management link belonging to the customer" do
expect(customer.management_link.attributes).to eq(management_link.attributes)
end
end
end

0 comments on commit afd8173

Please sign in to comment.