Skip to content

Commit 9c23da7

Browse files
authored
Merge pull request #150 from upper-hand/management-link
Add ability to fetch management link for a Customer
2 parents 1febc13 + afd8173 commit 9c23da7

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/chargify_api_ares.rb

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require 'chargify_api_ares/resources/customer_metadata'
1212
require 'chargify_api_ares/resources/customer'
1313
require 'chargify_api_ares/resources/event'
14+
require 'chargify_api_ares/resources/management_link'
1415
require 'chargify_api_ares/resources/migration'
1516
require 'chargify_api_ares/resources/payment'
1617
require 'chargify_api_ares/resources/payment_profile'

lib/chargify_api_ares/resources/customer.rb

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def subscriptions(params = {})
1515
Subscription.find(:all, :params => params)
1616
end
1717

18+
def management_link(params = {})
19+
params.merge!(:from => "/portal/customers/#{self.id}/management_link")
20+
ManagementLink.find(:one, params)
21+
end
22+
1823
def payment_profiles(params = {})
1924
params.merge!({:customer_id => self.id})
2025
PaymentProfile.find(:all, :params => params)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Chargify
2+
class ManagementLink < Base
3+
self.prefix = '/portal/customers/:customer_id/'
4+
5+
def self.collection_name
6+
element_name
7+
end
8+
end
9+
end

spec/resources/customer_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,16 @@
3838
end
3939
end
4040

41+
context '#management_link' do
42+
let(:customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
43+
let(:management_link) { Chargify::ManagementLink.create(:customer_id => customer.id, :url => 'https://www.billingportal.com/manage/1/2/3') }
44+
45+
before(:each) do
46+
FakeWeb.register_uri(:get, "#{test_domain}/portal/customers/#{customer.id}/management_link", :body => management_link.attributes.to_xml)
47+
end
48+
49+
it "returns the management link belonging to the customer" do
50+
expect(customer.management_link.attributes).to eq(management_link.attributes)
51+
end
52+
end
4153
end

0 commit comments

Comments
 (0)