Skip to content

Commit

Permalink
Merge pull request #693 from stripe/remi-add-invoice-methods
Browse files Browse the repository at this point in the history
Add new methods to the Invoice resource
  • Loading branch information
remi-stripe authored Nov 9, 2018
2 parents d62f12f + bbec79c commit a53e7d9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
37 changes: 27 additions & 10 deletions lib/stripe/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,45 @@ module Stripe
class Invoice < APIResource
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::Create

OBJECT_NAME = "invoice".freeze

def self.upcoming(params, opts = {})
resp, opts = request(:get, upcoming_url, params, opts)
Util.convert_to_stripe_object(resp.data, opts)
def finalize_invoice(params = {}, opts = {})
url = resource_url + "/finalize"
resp, opts = request(:post, url, params, opts)
initialize_from(resp.data, opts)
end

def mark_uncollectible(params = {}, opts = {})
url = resource_url + "/mark_uncollectible"
resp, opts = request(:post, url, params, opts)
initialize_from(resp.data, opts)
end

def pay(params = {}, opts = {})
resp, opts = request(:post, pay_url, params, opts)
url = resource_url + "/pay"
resp, opts = request(:post, url, params, opts)
initialize_from(resp.data, opts)
end

def self.upcoming_url
resource_url + "/upcoming"
def send_invoice(params = {}, opts = {})
url = resource_url + "/send"
resp, opts = request(:post, url, params, opts)
initialize_from(resp.data, opts)
end

def self.upcoming(params, opts = {})
url = resource_url + "/upcoming"
resp, opts = request(:get, url, params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
private_class_method :upcoming_url

def pay_url
resource_url + "/pay"
def void_invoice(params = {}, opts = {})
url = resource_url + "/void"
resp, opts = request(:post, url, params, opts)
initialize_from(resp.data, opts)
end
private :pay_url
end
end
7 changes: 7 additions & 0 deletions test/stripe/coupon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ class CouponTest < Test::Unit::TestCase
assert_requested :post, "#{Stripe.api_base}/v1/coupons/25OFF"
assert coupon.is_a?(Stripe::Coupon)
end

should "be deletable" do
coupon = Stripe::Coupon.retrieve("25OFF")
coupon = coupon.delete
assert_requested :delete, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
assert coupon.is_a?(Stripe::Coupon)
end
end
end
47 changes: 47 additions & 0 deletions test/stripe/invoice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ class InvoiceTest < Test::Unit::TestCase
assert invoice.is_a?(Stripe::Invoice)
end

should "be deletable" do
invoice = Stripe::Invoice.retrieve("in_123")
invoice = invoice.delete
assert_requested :delete, "#{Stripe.api_base}/v1/invoices/#{invoice.id}"
assert invoice.is_a?(Stripe::Invoice)
end

context "#finalize" do
should "finalize invoice" do
invoice = Stripe::Invoice.retrieve("in_123")
invoice = invoice.finalize_invoice
assert_requested :post,
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/finalize"
assert invoice.is_a?(Stripe::Invoice)
end
end

context "#mark_uncollectible" do
should "mark invoice as uncollectible" do
invoice = Stripe::Invoice.retrieve("in_123")
invoice = invoice.mark_uncollectible
assert_requested :post,
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/mark_uncollectible"
assert invoice.is_a?(Stripe::Invoice)
end
end

context "#pay" do
should "pay invoice" do
invoice = Stripe::Invoice.retrieve("in_123")
Expand All @@ -61,6 +88,16 @@ class InvoiceTest < Test::Unit::TestCase
end
end

context "#send" do
should "send invoice" do
invoice = Stripe::Invoice.retrieve("in_123")
invoice = invoice.send_invoice
assert_requested :post,
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/send"
assert invoice.is_a?(Stripe::Invoice)
end
end

context "#upcoming" do
should "retrieve upcoming invoices" do
invoice = Stripe::Invoice.upcoming(
Expand Down Expand Up @@ -109,5 +146,15 @@ class InvoiceTest < Test::Unit::TestCase
assert invoice.is_a?(Stripe::Invoice)
end
end

context "#void" do
should "void invoice" do
invoice = Stripe::Invoice.retrieve("in_123")
invoice = invoice.void_invoice
assert_requested :post,
"#{Stripe.api_base}/v1/invoices/#{invoice.id}/void"
assert invoice.is_a?(Stripe::Invoice)
end
end
end
end

0 comments on commit a53e7d9

Please sign in to comment.