Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new methods to the Invoice resource #693

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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