Skip to content

Commit

Permalink
Merge pull request #83 from nickhammond/payment_profile
Browse files Browse the repository at this point in the history
Update payment_profile on subscriptions to return active payment profile
  • Loading branch information
jeremywrowe committed Aug 14, 2014
2 parents bc49a20 + 2a531ab commit 19e705c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/chargify_api_ares/resources/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def events(params = {})
end

def payment_profile
self.respond_to?('credit_card') ? credit_card : nil
if self.respond_to?('credit_card')
credit_card
elsif self.respond_to?('bank_account')
bank_account
end
end

# Perform a one-time charge on an existing subscription.
Expand Down
21 changes: 21 additions & 0 deletions spec/resources/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@
lambda { subscription.save! }.should_not change(subscription, :attributes)
end
end

describe "points to the correct payment profile" do
before do
@subscription = build(:subscription)
end

it 'does not have a payment profile' do
@subscription.payment_profile.should be_nil
end

it 'returns credit_card details' do
@subscription.credit_card = "CREDIT CARD"
@subscription.payment_profile.should == "CREDIT CARD"
end

it 'returns bank_account details' do
@subscription.bank_account = "BANK ACCOUNT"
@subscription.payment_profile.should == "BANK ACCOUNT"
end

end

it 'creates a one-time charge' do
id = generate(:subscription_id)
Expand Down

0 comments on commit 19e705c

Please sign in to comment.