-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #758 from stripe/remi-add-creditnote
Add support for CreditNote
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stripe | ||
class CreditNote < APIResource | ||
extend Stripe::APIOperations::List | ||
include Stripe::APIOperations::Save | ||
extend Stripe::APIOperations::Create | ||
|
||
OBJECT_NAME = "credit_note".freeze | ||
|
||
custom_method :void_credit_note, http_verb: :post, http_path: "void" | ||
|
||
def void_credit_note(params = {}, opts = {}) | ||
url = resource_url + "/void" | ||
resp, opts = request(:post, url, params, opts) | ||
initialize_from(resp.data, opts) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require ::File.expand_path("../../test_helper", __FILE__) | ||
|
||
module Stripe | ||
class CreditNoteTest < Test::Unit::TestCase | ||
should "be listable" do | ||
credit_notes = Stripe::CreditNote.list | ||
assert_requested :get, "#{Stripe.api_base}/v1/credit_notes" | ||
assert credit_notes.data.is_a?(Array) | ||
assert credit_notes.first.is_a?(Stripe::CreditNote) | ||
end | ||
|
||
should "be retrievable" do | ||
credit_note = Stripe::CreditNote.retrieve("cn_123") | ||
assert_requested :get, "#{Stripe.api_base}/v1/credit_notes/cn_123" | ||
assert credit_note.is_a?(Stripe::CreditNote) | ||
end | ||
|
||
should "be creatable" do | ||
credit_note = Stripe::CreditNote.create( | ||
amount: 100, | ||
invoice: "in_123", | ||
reason: "duplicate" | ||
) | ||
assert_requested :post, "#{Stripe.api_base}/v1/credit_notes" | ||
assert credit_note.is_a?(Stripe::CreditNote) | ||
end | ||
|
||
should "be saveable" do | ||
credit_note = Stripe::CreditNote.retrieve("cn_123") | ||
credit_note.metadata["key"] = "value" | ||
credit_note.save | ||
assert_requested :post, "#{Stripe.api_base}/v1/credit_notes/#{credit_note.id}" | ||
end | ||
|
||
should "be updateable" do | ||
credit_note = Stripe::CreditNote.update("cn_123", metadata: { key: "value" }) | ||
assert_requested :post, "#{Stripe.api_base}/v1/credit_notes/cn_123" | ||
assert credit_note.is_a?(Stripe::CreditNote) | ||
end | ||
|
||
context "#void_credit_note" do | ||
should "void credit_note" do | ||
credit_note = Stripe::CreditNote.retrieve("cn_123") | ||
credit_note = credit_note.void_credit_note | ||
assert_requested :post, | ||
"#{Stripe.api_base}/v1/credit_notes/#{credit_note.id}/void" | ||
assert credit_note.is_a?(Stripe::CreditNote) | ||
end | ||
end | ||
|
||
context ".void_credit_note" do | ||
should "void credit_note" do | ||
credit_note = Stripe::CreditNote.void_credit_note("cn_123") | ||
assert_requested :post, "#{Stripe.api_base}/v1/credit_notes/cn_123/void" | ||
assert credit_note.is_a?(Stripe::CreditNote) | ||
end | ||
end | ||
end | ||
end |