Skip to content

Commit

Permalink
Merge pull request #138 from carsonreinke/invoice_payment
Browse files Browse the repository at this point in the history
Adding invoice payment creation
  • Loading branch information
davidcole committed Aug 22, 2016
2 parents cc54438 + ef6d3ea commit 07c9693
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/chargify_api_ares/resources/invoice.rb
@@ -1,6 +1,12 @@
module Chargify
class Invoice < Base

class Payment < Base
include ResponseHelper

self.prefix = '/invoices/:invoice_id/'
end

def self.find_by_invoice_id(id)
find(:first, {:params => {:id => id}})
end
Expand Down Expand Up @@ -32,5 +38,9 @@ def self.find_pdf(scope, options = {})
path = element_path(scope, prefix_options, query_options).gsub(/\.\w+$/, ".pdf")
connection.get(path, headers).body
end

def payment(attrs = {})
Payment.create(attrs.merge({:invoice_id => self.id}))
end
end
end
11 changes: 11 additions & 0 deletions spec/resources/invoice_spec.rb
Expand Up @@ -114,3 +114,14 @@
expect(invoice.attributes).to eql({ "id" => 99, "subscription_id" => 1, "state" => "partial" })
end
end

describe Chargify::Invoice, '#payment', :fake_resource do
let(:invoice_id) {1}
let(:invoice) { Chargify::Invoice.create(:id => invoice_id) }
let(:invoice_payment) { Chargify::Invoice::Payment.create(:invoice_id => invoice_id, :amount_in_cents => 10000, :memo => 'lorem ipsum') }

it 'creates payment' do
payment = invoice.payment(:amount_in_cents => 10000, :memo => 'lorem ipsum')
payment.amount_in_cents.should == 10000
end
end

0 comments on commit 07c9693

Please sign in to comment.