Skip to content

Commit

Permalink
Add support for CreditNote preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Nov 26, 2019
1 parent da06eb2 commit 7c52ab7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/stripe/resources/credit_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ def void_credit_note(params = {}, opts = {})
opts: opts
)
end

def self.preview(params, opts = {})
resp, opts = request(:get, resource_url + "/preview", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end
end
end
15 changes: 15 additions & 0 deletions test/stripe/credit_note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ class CreditNoteTest < Test::Unit::TestCase
assert credit_note.is_a?(Stripe::CreditNote)
end

context ".preview" do
should "preview a credit note" do
invoice = Stripe::CreditNote.preview(
invoice: "in_123",
amount: 500
)
assert_requested :get, "#{Stripe.api_base}/v1/credit_notes/preview",
query: {
invoice: "in_123",
amount: 500,
}
assert invoice.is_a?(Stripe::CreditNote)
end
end

context "#void_credit_note" do
should "void credit_note" do
credit_note = Stripe::CreditNote.retrieve("cn_123")
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require ::File.expand_path("stripe_mock", __dir__)

# If changing this number, please also change it in `.travis.yml`.
MOCK_MINIMUM_VERSION = "0.72.0"
MOCK_MINIMUM_VERSION = "0.76.0"
MOCK_PORT = Stripe::StripeMock.start

# Disable all real network connections except those that are outgoing to
Expand Down

0 comments on commit 7c52ab7

Please sign in to comment.